		      X11 R5 Public Patch #22
			 MIT X Consortium

To apply this patch:

cd to the top of the source tree (to the directory containing the "mit"
and "contrib" subdirectories) and do:

	patch -p -s < ThisFile

Patch will work silently unless an error occurs.  You will likely get
the following warning messages, which can be ignored:

	mkdir: mit: File exists
	mkdir: mit/extensions: File exists
	mkdir: mit/extensions/server: File exists
	mkdir: mit/extensions/server/PEX: File exists
	mkdir: mit/extensions/server/PEX/dipex: File exists
	mkdir: mit/extensions/server/PEX/dipex/objects: File exists
	mkdir: mit: File exists
	mkdir: mit/extensions: File exists
	mkdir: mit/extensions/server: File exists
	mkdir: mit/extensions/server/PEX: File exists
	mkdir: mit/extensions/server/PEX/dipex: File exists
	mkdir: mit/extensions/server/PEX/dipex/swap: File exists
	mkdir: mit: File exists
	mkdir: mit/extensions: File exists
	mkdir: mit/extensions/server: File exists
	mkdir: mit/extensions/server/PEX: File exists
	mkdir: mit/extensions/server/PEX/ddpex: File exists
	mkdir: mit/extensions/server/PEX/ddpex/mi: File exists
	mkdir: mit/extensions/server/PEX/ddpex/mi/level3: File exists

If you want to watch patch do its thing, leave out the "-s" argument to patch.

This patch creates three new files:

mit/extensions/server/PEX/dipex/swap/convEv.c
mit/extensions/server/PEX/dipex/objects/pexRndrPick.c 
mit/extensions/server/PEX/ddpex/mi/level3/miRndrPick.c

If you are using a symbolic link tree, you will need to create new links.

Finally, to rebuild after applying this patch, cd to the "mit" subdirectory
and do:

	make Everything >& every.log

Note: this will *not* "clean" your tree.


Brief notes on this patch:

This patch updates the PEX Sample Implementation server to version 5.1
of the PEX protocol.  The PEX 5.1 Protocol specification is available
via anonymous ftp to export.lcs.mit.edu (18.24.0.12), in the directory
pub/DOCS/PEX/.

In addition, numerous bugs have been fixed in both the server and PHIGS
library (too many to list here).  A change was also made in the server
multi buffering extension to allow other extensions (such as PEX and its
workstation resource) to directly control server side double buffering.

Prereq: public-patch-21


*** -	Tue Feb  2 11:38:33 1993
--- mit/bug-report	Tue Feb  2 11:38:32 1993
***************
*** 2,8 ****
  Subject: [area]: [synopsis]   [replace with actual area and short description]
  
  VERSION:
!     R5, public-patch-21
      [MIT public patches will edit this line to indicate the patch level]
  
  CLIENT MACHINE and OPERATING SYSTEM:
--- 2,8 ----
  Subject: [area]: [synopsis]   [replace with actual area and short description]
  
  VERSION:
!     R5, public-patch-22
      [MIT public patches will edit this line to indicate the patch level]
  
  CLIENT MACHINE and OPERATING SYSTEM:
*** -	Thu Jan 28 17:48:58 1993
--- mit/extensions/include/PEX/PEXprotost.h	Thu Jan 28 17:48:58 1993
***************
*** 1,4 ****
! /* $XConsortium: PEXprotost.h,v 5.3 91/07/01 16:19:04 hersh Exp $ */
  
  
  /***********************************************************
--- 1,4 ----
! /* $XConsortium: PEXprotost.h,v 5.4 92/03/04 14:08:13 hersh Exp $ */
  
  
  /***********************************************************
***************
*** 28,34 ****
  #ifndef PEXPROTOSTR_H
  #define PEXPROTOSTR_H
  
! /* Matches revision 5.0P */
  
  #include <X11/Xmd.h>			/* defines things like CARD32 */
  
--- 28,34 ----
  #ifndef PEXPROTOSTR_H
  #define PEXPROTOSTR_H
  
! /* Matches revision 5.1C */
  
  #include <X11/Xmd.h>			/* defines things like CARD32 */
  
***************
*** 279,286 ****
      pexStructure	sid B32;
      CARD32		offset B32;
      CARD32		pickid B32;
! } pexPickPath;
  
  typedef struct {
      pexTextVAlignment		vertical B16;
      pexTextHAlignment		horizontal B16;
--- 279,294 ----
      pexStructure	sid B32;
      CARD32		offset B32;
      CARD32		pickid B32;
! } pexPickElementRef;
  
+ /* pexPickPath is the old name of the above strucutre.
+    This is wrong, since the above is a Pick Element Ref
+    a Pick Path is a list of Pick Element Refs so naming
+    this structure pexPickPath was wrong, but it can't just
+    be changed without effecting lots of other code....... */
+ 
+ typedef pexPickElementRef pexPickPath;
+ 
  typedef struct {
      pexTextVAlignment		vertical B16;
      pexTextHAlignment		horizontal B16;
***************
*** 302,307 ****
--- 310,328 ----
  } pexTrimCurve;
  
  typedef struct {
+     CARD8		depth;
+     CARD8		unused;
+     CARD16		type B16;
+     CARD32		visualID B32;
+ } pexRendererTarget;
+ 
+ typedef struct {
+     pexEnumTypeIndex	pickType B16;
+     CARD16		unused;
+     /* SINGLE HITBOX() */
+ } pexPickRecord;
+ 
+ typedef struct {
      PEXFLOAT		ambient;
      PEXFLOAT		diffuse;
      PEXFLOAT		specular;
***************
*** 557,561 ****
--- 578,590 ----
  } pexOutputCommandError;
  
  
+ /* Registered PEX Escapes */
+ 
+ typedef struct {
+     INT16	fpFormat B16;
+     CARD8	unused[2];
+     CARD32	rdr B32;	    /* renderer ID */
+     /* SINGLE ColourSpecifier()  */
+ } pexEscapeSetEchoColourData;
  
  #endif /* PEXPROTOSTR_H */
*** -	Thu Jan 28 17:49:01 1993
--- mit/extensions/include/PEX/PEX.h	Thu Jan 28 17:49:00 1993
***************
*** 1,4 ****
! /* $XConsortium: PEX.h,v 5.3 91/08/26 12:29:34 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: PEX.h,v 5.10 92/04/23 17:43:16 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 34,48 ****
  #define PEX_NAME_STRING		"X3D-PEX"
  #endif
  
! /* Matches revision 5.0P */
  
  #define PEX_PROTO_MAJOR		5	/* current protocol version */
! #define PEX_PROTO_MINOR		0	/* current minor version */
  
  /* Subsets */
  #define PEXCompleteImplementation	0
  #define PEXImmediateModeOnly		1
  #define PEXPhigsWksOnly			2
  
  /* Resources */
  #define PEXAlreadyFreed         1
--- 34,53 ----
  #define PEX_NAME_STRING		"X3D-PEX"
  #endif
  
! /* Matches revision 5.1C */
  
  #define PEX_PROTO_MAJOR		5	/* current protocol version */
! #define PEX_PROTO_MINOR		1	/* current minor version */
  
+ /* Events */
+ #define PEXMaxHitsReached     0
+ #define PEXNumberEvents       1
+ 
  /* Subsets */
  #define PEXCompleteImplementation	0
  #define PEXImmediateModeOnly		1
  #define PEXPhigsWksOnly			2
+ #define PEXStructureModeOnly		4
  
  /* Resources */
  #define PEXAlreadyFreed         1
***************
*** 109,114 ****
--- 114,140 ----
  #define PEXCurrent	1
  #define PEXEnd		2
  
+ /* Match Draw Type */
+ #define PEXDontCare     0
+ #define PEXWindow       1
+ #define PEXPixmap       2
+ #define PEXBuffer       3
+ 
+ /* Pick All State */
+ #define PEXMoreHits      0
+ #define PEXNoMoreHits    1
+ #define PEXMayBeMoreHits 2
+ 
+ /* PickOne Methods */
+ #define PEXLast			1
+ #define PEXClosestZ		2
+ #define PEXVisibleAny		3
+ #define PEXVisibleClosest	4
+ 
+ /* PickAll Methods */
+ #define PEXAllPicks		1
+ #define PEXVisible		2
+ 
  /* Element Search */
  #define PEXNotFound	1
  #define PEXFound	2
***************
*** 146,155 ****
  #define PEXETTrimCurveApproxMethod		25
  #define PEXETRenderingColourModel		26
  #define PEXETParaSurfCharacteristics		27
  
! /* Renderer state */
  #define PEXIdle 	0
  #define PEXRendering	1
  
  /* Flags (e.g., Switches, Visibility, and Edges) */
  #define PEXOff	0
--- 172,185 ----
  #define PEXETTrimCurveApproxMethod		25
  #define PEXETRenderingColourModel		26
  #define PEXETParaSurfCharacteristics		27
+ #define PEXETEscape				28
+ #define PEXETPickOneMethod			29
+ #define PEXETPickAllMethod			30
  
! /* Renderer State */
  #define PEXIdle 	0
  #define PEXRendering	1
+ #define PEXPicking	2
  
  /* Flags (e.g., Switches, Visibility, and Edges) */
  #define PEXOff	0
***************
*** 247,256 ****
--- 277,288 ----
  /* Pick Status */
  #define PEXNoPick	0
  #define PEXOk		1
+ #define PEXAborted	2
  
  /* Pick Echo Switch */
  #define PEXNoEcho	0
  #define PEXEcho		1
+ #define PEXUnEcho	2
  
  /* Pick Path Order */
  #define PEXTopFirst     0
***************
*** 371,376 ****
--- 403,409 ----
  #define PEXHlhsrPainters	3
  #define PEXHlhsrScanline	4
  #define PEXHlhsrHiddenLineOnly	5
+ #define PEXHlhsrZBufferId	6
  /* PromptEchoType */
  #define PEXEchoPrimitive	1
  #define PEXEchoStructure	2
***************
*** 390,395 ****
--- 423,430 ----
  #define PEXColourApproxHSV      3
  #define PEXColourApproxHLS      4
  #define PEXColourApproxYIQ      5
+ /* Escape */
+ #define PEXEscapeSetEchoColour   1
  /* RenderingColourModel	*/
  #define PEXRdrColourModelImpDep	0
  #define PEXRdrColourModelRGB	1
***************
*** 448,453 ****
--- 483,490 ----
  #define PEXIDChromaticityWhiteU		31
  #define PEXIDChromaticityWhiteV		32
  #define PEXIDLuminanceWhite		33
+ /* have to stick this here since others are not in order */
+ #define PEXIDMaxHitsEventSupported      34
  
  /* Constants for IDRgbBestApproximation */
  #define PEXColourApproxAnyValues	0
***************
*** 567,573 ****
  #define PEXRDNpcSubvolume		(1L<<20)
  #define PEXRDViewport			(1L<<21)
  #define PEXRDClipList			(1L<<22)
! #define PEXMaxRDShift	22
  
  /* Renderer Dynamics Bitmasks */
  /*	tables		      */
--- 604,617 ----
  #define PEXRDNpcSubvolume		(1L<<20)
  #define PEXRDViewport			(1L<<21)
  #define PEXRDClipList			(1L<<22)
! #define PEXRDPickInclusion		(1L<<23)
! #define PEXRDPickExclusion		(1L<<24)
! #define PEXRDPickStartPath		(1L<<25)
! #define PEXRDBackgroundColour		(1L<<26)
! #define PEXRDClearI    			(1L<<27)
! #define PEXRDClearZ    			(1L<<28)
! #define PEXRDEchoMode			(1L<<29)
! #define PEXMaxRDShift	29
  
  /* Renderer Dynamics Bitmasks */
  /*	tables		      */
***************
*** 583,610 ****
  #define PEXDynColourApproxTable			 (1L<<9)
  #define PEXDynPatternTable			(1L<<10)
  #define PEXDynTextFontTable			(1L<<11)
! #define PEXDynMarkerBundleContents		(1L<<12)
! #define PEXDynTextBundleContents		(1L<<13)
! #define PEXDynLineBundleContents		(1L<<14)
! #define PEXDynInteriorBundleContents		(1L<<15)
! #define PEXDynEdgeBundleContents		(1L<<16)
! #define PEXDynViewTableContents			(1L<<17)
! #define PEXDynColourTableContents		(1L<<18)
! #define PEXDynDepthCueTableContents		(1L<<19)
! #define PEXDynLightTableContents		(1L<<20)
! #define PEXDynColourApproxContents		(1L<<21)
! #define PEXDynPatternTableContents		(1L<<22)
! #define PEXDynTextFontTableContents		(1L<<23)
  /*	namesets	      */
  #define PEXDynHighlightNameset			 (1L<<0)
  #define PEXDynInvisibilityNameset		 (1L<<1)
! #define PEXDynHighlightNamesetContents		(1L<<12)
! #define PEXDynInvisibilityNamesetContents	(1L<<13)
  /*	attributes	      */
  #define PEXDynHlhsrMode				 (1L<<0)
  #define PEXDynNpcSubvolume			 (1L<<1)
  #define PEXDynViewport				 (1L<<2)
  #define PEXDynClipList				 (1L<<3)
  
  #define PEXElementType		 (1L<<0)
  #define PEXElementSize		 (1L<<1)
--- 627,657 ----
  #define PEXDynColourApproxTable			 (1L<<9)
  #define PEXDynPatternTable			(1L<<10)
  #define PEXDynTextFontTable			(1L<<11)
! #define PEXDynMarkerBundleContents		(1L<<16)
! #define PEXDynTextBundleContents		(1L<<17)
! #define PEXDynLineBundleContents		(1L<<18)
! #define PEXDynInteriorBundleContents		(1L<<19)
! #define PEXDynEdgeBundleContents		(1L<<20)
! #define PEXDynViewTableContents			(1L<<21)
! #define PEXDynColourTableContents		(1L<<22)
! #define PEXDynDepthCueTableContents		(1L<<23)
! #define PEXDynLightTableContents		(1L<<24)
! #define PEXDynColourApproxContents		(1L<<25)
! #define PEXDynPatternTableContents		(1L<<26)
! #define PEXDynTextFontTableContents		(1L<<27)
  /*	namesets	      */
  #define PEXDynHighlightNameset			 (1L<<0)
  #define PEXDynInvisibilityNameset		 (1L<<1)
! #define PEXDynPickNameset        		 (1L<<2)
! #define PEXDynHighlightNamesetContents		(1L<<16)
! #define PEXDynInvisibilityNamesetContents	(1L<<17)
! #define PEXDynPickNamesetContents		(1L<<18)
  /*	attributes	      */
  #define PEXDynHlhsrMode				 (1L<<0)
  #define PEXDynNpcSubvolume			 (1L<<1)
  #define PEXDynViewport				 (1L<<2)
  #define PEXDynClipList				 (1L<<3)
+ #define PEXDynEchoMode				 (1L<<4)
  
  #define PEXElementType		 (1L<<0)
  #define PEXElementSize		 (1L<<1)
***************
*** 656,661 ****
--- 703,710 ----
  #define PEXPWReqBufferMode	32
  #define PEXPWCurBufferMode	33
  
+ #define PEXMaxPWIndex		33
+ 
  /* Indices for GetDynamics */
  #define PEXPWDViewRep			 0
  #define PEXPWDMarkerBundle		 1
***************
*** 806,812 ****
  #define PEX_ListFonts			91
  #define PEX_ListFontsWithInfo		92
  #define PEX_QueryTextExtents 		93
! #define PEXMaxRequest			93
  
  /* Output Commands */
  #define PEXOCAll			  0
--- 855,872 ----
  #define PEX_ListFonts			91
  #define PEX_ListFontsWithInfo		92
  #define PEX_QueryTextExtents 		93
! #define PEX_MatchRendererTargets        94
! #define PEX_Escape                      95
! #define PEX_EscapeWithReply             96
! #define PEX_RenderElements              97
! #define PEX_AccumulateState             98
! #define PEX_BeginPickOne                99
! #define PEX_EndPickOne                 100
! #define PEX_PickOne                    101
! #define PEX_BeginPickAll               102
! #define PEX_EndPickAll                 103
! #define PEX_PickAll                    104
! #define PEXMaxRequest		       104
  
  /* Output Commands */
  #define PEXOCAll			  0
***************
*** 913,919 ****
  #define PEXOCExtCellArray		101
  #define PEXOCGdp			102
  #define PEXOCGdp2D			103
! #define PEXMaxOC			103
  
  #define PEXOCNil			0xffff
  
--- 973,980 ----
  #define PEXOCExtCellArray		101
  #define PEXOCGdp			102
  #define PEXOCGdp2D			103
! #define PEXOCNoop			104
! #define PEXMaxOC			104
  
  #define PEXOCNil			0xffff
  
*** -	Thu Jan 28 17:49:02 1993
--- mit/extensions/include/PEX/PEXproto.h	Thu Jan 28 17:49:01 1993
***************
*** 1,4 ****
! /* $XConsortium: PEXproto.h,v 5.3 91/07/01 16:19:18 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: PEXproto.h,v 5.5 92/04/23 16:11:29 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 76,82 ****
   */
  #include <X11/extensions/PEXprotost.h>
  
! /* Matches revision 5.0P */
  
  /****************************************************************
   *  		REPLIES 					*
--- 76,82 ----
   */
  #include <X11/extensions/PEXprotost.h>
  
! /* Matches revision 5.1C */
  
  /****************************************************************
   *  		REPLIES 					*
***************
*** 121,126 ****
--- 121,147 ----
      BYTE	type;			/* X_Reply */
      CARD8	what;			/* unused */
      CARD16	sequenceNumber	B16;
+     CARD32	length B32;		
+     CARD32	escapeID B32;
+     CARD8	escape_specific[20];
+     /* more escape specific data, treat as */
+     /* LISTof CARD8( length ) */
+     } pexEscapeWithReplyReply;
+ 
+ 
+ typedef struct {
+     BYTE	type;			/* X_Reply */
+     CARD8	what;			/* unused */
+     CARD16	sequenceNumber	B16;
+     CARD32	length B32;		
+     BYTE	pad[24];
+     /* LISTof RENDERER_TARGET( ) */
+     } pexMatchRendererTargetsReply;
+ 
+ typedef struct {
+     BYTE	type;			/* X_Reply */
+     CARD8	what;			/* unused */
+     CARD16	sequenceNumber	B16;
      CARD32	length B32;		/* 0 */
      CARD16	unused B16;
      CARD16	definableEntries B16;
***************
*** 411,416 ****
--- 432,485 ----
      CARD8	what;			/* unused */
      CARD16	sequenceNumber	B16;
      CARD32	length B32;		/* not 0 */
+     CARD32	numPickElRefs B32;	
+     pexEnumTypeIndex	pickStatus B16;
+     CARD8	betterPick;
+     BYTE	pad[17];
+     /* LISTof pexPickElementRef ( numPickElRefs ) */
+     } pexEndPickOneReply;
+ 
+ typedef struct {
+     BYTE	type;			/* X_Reply */
+     CARD8	what;			/* unused */
+     CARD16	sequenceNumber	B16;
+     CARD32	length B32;		/* not 0 */
+     CARD32	numPickElRefs B32;	
+     pexEnumTypeIndex	pickStatus B16;
+     CARD8	betterPick;
+     BYTE	pad[17];
+     /* LISTof pexPickElementRef ( numPickElRefs ) */
+     } pexPickOneReply;
+ 
+ typedef struct {
+     BYTE	type;			/* X_Reply */
+     CARD8	what;			/* unused */
+     CARD16	sequenceNumber	B16;
+     CARD32	length B32;		/* not 0 */
+     CARD32	numPicked     B32;	
+     pexEnumTypeIndex	pickStatus B16;
+     pexEnumTypeIndex	morePicks  B16;
+     BYTE	pad[16];
+     /* LISTof CLISTof pexPickElementRef ( numPicked ) */
+     } pexEndPickAllReply;
+ 
+ typedef struct {
+     BYTE	type;			/* X_Reply */
+     CARD8	what;			/* unused */
+     CARD16	sequenceNumber	B16;
+     CARD32	length B32;		/* not 0 */
+     CARD32	numPicked     B32;	
+     pexEnumTypeIndex	pickStatus B16;
+     pexEnumTypeIndex	morePicks  B16;
+     BYTE	pad[16];
+     /* LISTof CLISTof pexPickElementRef ( numPicked ) */
+     } pexPickAllReply;
+ 
+ typedef struct {
+     BYTE	type;			/* X_Reply */
+     CARD8	what;			/* unused */
+     CARD16	sequenceNumber	B16;
+     CARD32	length B32;		/* not 0 */
      CARD32	lengthFontInfo B32;
      CARD8	pad[20];
      /* SINGLE pexFontInfo() */
***************
*** 513,518 ****
--- 582,609 ----
  typedef struct {
      CARD8		reqType;
      CARD8 		opcode;
+     CARD16 		length B16;	/* 5 */
+     Drawable		drawable B32;
+     CARD8 		depth;
+     CARD8 		unused;
+     CARD16		type B16;
+     CARD32		visualID B32;
+     CARD32		maxTriplets B32;
+ } pexMatchRendererTargetsReq;
+ 
+ typedef struct {
+     CARD8		reqType;
+     CARD8 		opcode;
+     CARD16 		length B16;	/* 2 + n */
+     CARD32		escapeID B32;
+     /* 4n bytes of additional escape data to skip */
+ } pexEscapeReq;
+ 
+ typedef  pexEscapeReq   pexEscapeWithReplyReq;
+ 
+ typedef struct {
+     CARD8		reqType;
+     CARD8 		opcode;
      CARD16 		length B16;	/* 4 */
      Drawable		drawableExample B32;
      pexLookupTable	lut B32;
***************
*** 726,731 ****
--- 817,840 ----
  typedef struct {
      CARD8 		reqType;
      CARD8 		opcode;
+     CARD16 		length B16;	/* 7 */
+     pexRenderer		rdr B32;
+     pexStructure	sid B32;
+     pexElementRange	range;
+ } pexRenderElementsReq;
+ 
+ typedef struct {
+     CARD8 		reqType;
+     CARD8 		opcode;
+     CARD16 		length B16;	/* 3 + 2n */
+     pexRenderer		rdr B32;
+     CARD32              numElRefs B32;
+     /* LISTof pexElementRef( numElRefs ) */
+ } pexAccumulateStateReq;
+ 
+ typedef struct {
+     CARD8 		reqType;
+     CARD8 		opcode;
      CARD16 		length B16;	/* 4 */
      pexRenderer		rdr B32;
      Drawable		drawable B32;
***************
*** 1195,1205 ****
      CARD16 		length B16;
      pexPickMeasure	pm B32;
      CARD32		numBytes B32;
!     /* LISTof CARD8( numBytes ) -- don't swap */
      /* pad( numBytes ) */
  } pexUpdatePickMeasureReq;
  
  typedef struct {
      CARD8 	reqType;
      CARD8 	opcode;
      CARD16 	length B16;
--- 1304,1379 ----
      CARD16 		length B16;
      pexPickMeasure	pm B32;
      CARD32		numBytes B32;
!     /* LISTof CARD8( numBytes ) */
      /* pad( numBytes ) */
  } pexUpdatePickMeasureReq;
  
  typedef struct {
+     CARD8 		reqType;
+     CARD8 		opcode;
+     CARD16 		length B16;   /* 6 + n */
+     pexEnumTypeIndex	fpFormat B16;
+     pexEnumTypeIndex	method B16;
+     pexRenderer		rdr B32;
+     Drawable		drawable B32;
+     INT32 		sid B32;
+     /* SINGLE PickRecord () */
+ } pexBeginPickOneReq;
+ 
+ typedef struct {
+     CARD8 		reqType;
+     CARD8 		opcode;
+     CARD16 		length B16;   /* 2 */
+     pexRenderer		rdr B32;
+ } pexEndPickOneReq;
+ 
+ typedef struct {
+     CARD8 		reqType;
+     CARD8 		opcode;
+     CARD16 		length B16;   /* 6 + n */
+     pexEnumTypeIndex	fpFormat B16;
+     pexEnumTypeIndex	method B16;
+     pexRenderer		rdr B32;
+     Drawable		drawable B32;
+     pexStructure	sid B32;
+     /* SINGLE PickRecord () */
+ } pexPickOneReq;
+ 
+ typedef struct {
+     CARD8 		reqType;
+     CARD8 		opcode;
+     CARD16 		length B16;   /* 7 + n */
+     pexEnumTypeIndex	fpFormat B16;
+     pexEnumTypeIndex	method B16;
+     CARD8 		sendEvent;
+     CARD8 		unused[3];
+     pexRenderer		rdr B32;
+     Drawable		drawable B32;
+     INT32		sid B32;
+     CARD32              pickMaxHits B32;
+     /* SINGLE PickRecord () */
+ } pexBeginPickAllReq;
+ 
+ typedef struct {
+     CARD8 		reqType;
+     CARD8 		opcode;
+     CARD16 		length B16;   /* 2 */
+     pexRenderer		rdr B32;
+ } pexEndPickAllReq;
+ 
+ typedef struct {
+     CARD8 		reqType;
+     CARD8 		opcode;
+     CARD16 		length B16;   /* 6 + n */
+     pexEnumTypeIndex	fpFormat B16;
+     pexEnumTypeIndex	method B16;
+     pexRenderer		rdr B32;
+     Drawable		drawable B32;
+     CARD32              pickMaxHits B32;
+     /* SINGLE RendererPickRecord () */
+ } pexPickAllReq;
+ 
+ typedef struct {
      CARD8 	reqType;
      CARD8 	opcode;
      CARD16 	length B16;
***************
*** 1826,1831 ****
--- 2000,2022 ----
      /* LISTof CARD8( numBytes ) -- don't swap */
      /* pad( numBytes ) */
  } pexGdp2D;
+ 
+ typedef struct {
+     pexElementInfo	head;
+ } pexNoop;
+ 
+ /****************************************************************
+  *  		EVENTS 						*
+  ****************************************************************/
+ /* Event structure */
+ 
+ typedef struct {
+     BYTE	type;			/* X_Event */
+     CARD8	what;			/* unused */
+     CARD16	sequenceNumber	B16;
+     CARD32	rdr B32;		
+     BYTE	pad[24];
+ } pexMaxHitsReachedEvent;
  
  #endif /* PEXPROTO_H */
  
*** -	Thu Jan 28 17:49:05 1993
--- mit/extensions/include/PEX/pexSwap.h	Thu Jan 28 17:49:05 1993
***************
*** 1,4 ****
! /* $XConsortium: pexSwap.h,v 5.3 91/07/01 16:19:41 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pexSwap.h,v 5.5 92/03/04 14:08:10 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 34,42 ****
  
  #include <X11/extensions/PEXErr.h>
  
! typedef PEXFLOAT	    (*ConvFunction)();
! typedef CARD16	    (*SwapShortFunction)();
! typedef CARD32	    (*SwapLongFunction)();
  typedef ErrorCode   (*OCFunction)();
  
  typedef struct {
--- 34,42 ----
  
  #include <X11/extensions/PEXErr.h>
  
! typedef void	    (*ConvFunction)();
! typedef void	    (*SwapShortFunction)();
! typedef void	    (*SwapLongFunction)();
  typedef ErrorCode   (*OCFunction)();
  
  typedef struct {
***************
*** 45,54 ****
      ConvFunction	ConvertFLOAT;
  } pexSwap;
  
! extern CARD16 SwapCARD16();
! extern CARD32 SwapCARD32();
! extern PEXFLOAT  SwapFLOAT();
! extern PEXFLOAT  ConvertFLOAT();
  
  
  #endif
--- 45,56 ----
      ConvFunction	ConvertFLOAT;
  } pexSwap;
  
! extern void SwapCARD16();
! extern void SwapCARD32();
! extern void  SwapFLOAT();
! extern void  ConvertFLOAT();
  
+ /* not sure if this is the right place for this */
+ extern void SwapPEXMaxHitsReachedEvent();
  
  #endif
*** -	Thu Jan 28 17:49:48 1993
--- mit/extensions/server/PEX/include/pexError.h	Thu Jan 28 17:49:47 1993
***************
*** 1,4 ****
! /* $XConsortium: pexError.h,v 5.1 91/02/16 09:57:55 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pexError.h,v 5.2 92/12/04 18:45:00 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 38,47 ****
  #define PEX_ERROR_CODE(error_code) ((error_code) + PexErrorBase)
  
  #define PEX_ERR_EXIT(error_code, problem, cntxt) { \
!     unsigned short temp; \
!     temp = MinorOpcodeOfRequest((cntxt)->client); \
!     SendErrorToClient(	(cntxt)->client, (unsigned) PexReqCode, \
! 			(temp), (XID) (problem), (int) (error_code)); \
      return(error_code); }
  
  
--- 38,44 ----
  #define PEX_ERROR_CODE(error_code) ((error_code) + PexErrorBase)
  
  #define PEX_ERR_EXIT(error_code, problem, cntxt) { \
!     (cntxt)->client->errorValue = problem;	\
      return(error_code); }
  
  
*** -	Thu Jan 28 17:49:50 1993
--- mit/extensions/server/PEX/include/pexExtract.h	Thu Jan 28 17:49:49 1993
***************
*** 1,5 ****
! /* $XConsortium: pexExtract.h,v 5.4 91/07/01 16:25:41 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
--- 1,6 ----
! /* $XConsortium: pexExtract.h,v 5.7 91/12/11 18:11:43 hersh Exp $ */
  
+ 
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
***************
*** 113,122 ****
--- 114,138 ----
  #define EXTRACT_LISTOF_COORD2D(num, dstPtr, srcPtr) \
      EXTRACT_STRUCT(num, ddCoord2D, dstPtr, srcPtr)
  
+ /* Takes a CARD8 from a 4 byte Protocol Field  */
+ #define EXTRACT_CARD8_FROM_4B(dst, srcPtr)	{   \
+     (dst) = (CARD8) (*((CARD32 *)(srcPtr)));	    \
+     (srcPtr) = ((CARD8 *) (srcPtr)) + sizeof(CARD32); }
+ 
  #define EXTRACT_CARD8(dst, srcPtr)	{   \
      (dst) = *((CARD8 *)(srcPtr));	    \
      (srcPtr) = ((CARD8 *) (srcPtr)) + sizeof(CARD8); }
  
+ /* Takes a CARD16 from a 4 byte Protocol Field  */
+ #define EXTRACT_CARD16_FROM_4B(dst, srcPtr)	{   \
+     (dst) = (CARD16) (*((CARD32 *)(srcPtr)));	    \
+     (srcPtr) = ((CARD8 *) (srcPtr)) + sizeof(CARD32); }
+ 
+ /* Takes a INT16 from a 4 byte Protocol Field  */
+ #define EXTRACT_INT16_FROM_4B(dst, srcPtr)	{   \
+     (dst) = (INT16) (*((CARD32 *)(srcPtr)));	    \
+     (srcPtr) = ((CARD8 *) (srcPtr)) + sizeof(CARD32); }
+ 
  #define EXTRACT_CARD16(dst, srcPtr)	{   \
      (dst) = *((CARD16 *)(srcPtr));	    \
      (srcPtr) = ((CARD8 *) (srcPtr)) + sizeof(CARD16); }
***************
*** 299,305 ****
  
  #define PACK_LISTOF_STRUCT(num,data_type,srcPtr,dstPtr){\
      bcopy(  (char *)(srcPtr), (char *)(dstPtr),		\
! 	    ((*((int *)&(num)) * sizeof(data_type))));	\
      SKIP_STRUCT(dstPtr, num, data_type); }
  /*
  	Other useful macros
--- 315,321 ----
  
  #define PACK_LISTOF_STRUCT(num,data_type,srcPtr,dstPtr){\
      bcopy(  (char *)(srcPtr), (char *)(dstPtr),		\
! 	    (int)(num * sizeof(data_type)));	\
      SKIP_STRUCT(dstPtr, num, data_type); }
  /*
  	Other useful macros
*** -	Thu Jan 28 17:49:51 1993
--- mit/extensions/server/PEX/include/ddpex.h	Thu Jan 28 17:49:51 1993
***************
*** 1,4 ****
! /* $XConsortium: ddpex.h,v 5.4 91/06/27 14:48:40 hersh Exp $ */
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: ddpex.h,v 5.12 92/11/17 17:26:04 hersh Exp $ */
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 28,33 ****
--- 28,34 ----
  #include "X.h"
  #include "PEX.h"
  #include "pixmapstr.h"
+ #include "dix.h"
  
  #ifndef DDPEX_H
  #define DDPEX_H
***************
*** 164,171 ****
  
  typedef struct {
  	ddSHORT		xmin;
- 	ddSHORT		xmax;
  	ddSHORT		ymin;
  	ddSHORT		ymax;
  } ddDeviceRect;
  
--- 165,172 ----
  
  typedef struct {
  	ddSHORT		xmin;
  	ddSHORT		ymin;
+ 	ddSHORT		xmax;
  	ddSHORT		ymax;
  } ddDeviceRect;
  
***************
*** 206,215 ****
--- 207,223 ----
  } ddViewport;
  
  typedef struct {
+     ddCoord2DS      position;
+     ddFLOAT         distance;
+ } ddDC_HitBox;
+ 
+ typedef struct {
      ddCoord3D	minval;
      ddCoord3D	maxval;
  } ddNpcSubvolume;
  
+ typedef  ddNpcSubvolume ddNPC_HitVolume;
+ 
  typedef struct {
  	ddUSHORT	clipFlags;
  	ddUSHORT	unused;
***************
*** 246,251 ****
--- 254,273 ----
  } ddPickPath;
  
  typedef struct {
+     ddULONG		sid;
+     ddULONG             offset;
+     ddULONG             pickid;
+ } ddPickElementRef;
+ 
+ typedef struct {
+       ddUSHORT        pickType;
+       union {
+ 	  ddDC_HitBox        DC_HitBox;
+ 	  ddNPC_HitVolume    NPC_HitVolume;
+       } hit_box;
+ } ddPickRecord;
+ 
+ typedef struct {
  	ddUSHORT	elementType;
  	ddUSHORT	length;
  } ddElementInfo;
***************
*** 381,387 ****
          DD_DEVICE_RECT=7,
  	DD_NAME=8,
  	DD_INDEX=9,
!         DD_NUM_TYPES=10
  } ddListType;
  
  typedef struct {
--- 403,410 ----
          DD_DEVICE_RECT=7,
  	DD_NAME=8,
  	DD_INDEX=9,
!         DD_LIST_OF_LIST=10,
! 	DD_NUM_TYPES=11
  } ddListType;
  
  typedef struct {
***************
*** 413,419 ****
  	ddCoord3D	origin;
  	ddVector3D	direction;
  	ddUSHORT	numberIntersections;
! 	ddCoord3D	*pPoints;
  } ddPSC_LevelCurves;
  
  typedef struct {
--- 436,442 ----
  	ddCoord3D	origin;
  	ddVector3D	direction;
  	ddUSHORT	numberIntersections;
! 	ddFLOAT 	*pPoints;
  } ddPSC_LevelCurves;
  
  typedef struct {
***************
*** 503,510 ****
  
  /*	Output Command Procedure Vector	used in renderer */
  /*	The index of a procedure is the output command number	*/
! #define OCTABLE_LENGTH PEXMaxOC+1
! #define SEPROC_VECTOR_LENGTH PEXMaxOC+1
  
  typedef	ddpex2rtn	(*ocTableType)();
  
--- 526,533 ----
  
  /*	Output Command Procedure Vector	used in renderer */
  /*	The index of a procedure is the output command number	*/
! #define OCTABLE_LENGTH (PEXMaxOC+1)
! #define SEPROC_VECTOR_LENGTH (PEXMaxOC+1)
  
  typedef	ddpex2rtn	(*ocTableType)();
  
***************
*** 522,531 ****
  	DD_HIGH_EXCL_NS=1,
  	DD_INVIS_INCL_NS=2,
  	DD_INVIS_EXCL_NS=3,
! 	DD_MAX_FILTERS=4
  } ddNSFilters; 
  
  typedef struct {
  	ddULONG 		rendId;		/* renderer id */
  	ddPCPtr			pPC;		/* pipeline context handle */
  	ddDrawableInfo		drawExample;	/* info from drawable example */
--- 545,581 ----
  	DD_HIGH_EXCL_NS=1,
  	DD_INVIS_INCL_NS=2,
  	DD_INVIS_EXCL_NS=3,
! 	DD_PICK_INCL_NS=4,
! 	DD_PICK_EXCL_NS=5,
! 	DD_MAX_FILTERS=6
  } ddNSFilters; 
  
+ /* pick state for Renderer picking */
+ #define DD_PICK_ONE 1
+ #define DD_PICK_ALL 2
+ #define DD_SERVER	1
+ #define DD_CLIENT	2
+ #define DD_NEITHER	3
+ 
  typedef struct {
+ 	ddUSHORT	  state;        /* pick state one or all */
+ 	ddUSHORT	  server;       /* client or server traversal */
+ 	ddSHORT           pick_method;
+ 	ddBOOL            send_event;
+ 	ddULONG           max_hits;
+ 	ddULONG           more_hits;
+ 	ClientPtr         client;       /* need to send the event */
+         diStructHandle    strHandle;	/* struct handle for PickOne */
+ 	diPMHandle	  pseudoPM;      /* fake PM for Renderer Pick */
+ 	listofObj	  *list;	/* list of list for pick all */
+ 	listofObj	  *fakeStrlist;	/* list of fake struct handle for
+ 					   picking */
+ 	listofObj	  *sIDlist;	/* list of IDs, struct handles  and
+ 					   offsets for reverse mapping
+ 					   BeginStructures when picking */
+ } ddRdrPickStr, *ddRdrPickPtr;       /* need to send the event */ 
+ 
+ typedef struct {
  	ddULONG 		rendId;		/* renderer id */
  	ddPCPtr			pPC;		/* pipeline context handle */
  	ddDrawableInfo		drawExample;	/* info from drawable example */
***************
*** 539,544 ****
--- 589,604 ----
  	ddNpcSubvolume		npcSubvolume;
  	ddViewport		viewport;
  	listofObj		*clipList;	 /* clip list */
+ 						 /* Begin 5.1 additions */
+ 						 /* pick_inclusion is in ns */
+ 						 /* pick_exclusion is in ns */
+ 	listofObj		*pickStartPath;	 /* pick start path */
+ 	ddColourSpecifier	backgroundColour;
+ 	ddBOOL			clearI;
+ 	ddBOOL			clearZ;
+ 	ddUSHORT		echoMode;
+ 	ddColourSpecifier	echoColour;
+ 						 /* End 5.1 additions */
  	ddBitmask		tablesMask;	/* renderer dynamics */
  	ddBitmask		namesetsMask;	/* renderer dynamics */
  	ddBitmask		attrsMask;	/* renderer dynamics */
***************
*** 549,555 ****
--- 609,621 ----
  	ddBOOL			immediateMode;
  	ddUSHORT		render_mode;
  	ddPointer		pDDContext;	/* device dependent attribute context */
+ 	ddRdrPickStr		pickstr;
  } ddRendererStr, *ddRendererPtr;
+ 
+ typedef struct {
+ 	ddULONG			numElRefs;	/* number of element refs */
+ 	listofObj		*Path;		/* path */
+ } ddAccStStr, *ddAccStPtr;
  
  /* render_mode values */
  #define	MI_REND_DRAWING 0
*** -	Thu Jan 28 17:49:55 1993
--- mit/extensions/server/PEX/include/dipex.h	Thu Jan 28 17:49:54 1993
***************
*** 1,4 ****
! /* $XConsortium: dipex.h,v 5.3 91/03/15 18:27:41 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: dipex.h,v 5.5 92/11/24 13:00:28 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 60,65 ****
--- 60,66 ----
  
  LOCAL_FLAG ErrorCode PexReqCode;
  LOCAL_FLAG ErrorCode PexErrorBase;
+ LOCAL_FLAG ErrorCode PexEventBase;
  
  /* resources */
  extern Bool AddResource();
***************
*** 66,72 ****
  
  #define ADDRESOURCE(id,what,stuff) \
      if (!(AddResource((id),(what),(pointer)(stuff)))) { \
- 	Xfree((pointer)stuff); \
  	PEX_ERR_EXIT(BadAlloc,0,cntxtPtr); \
      }
  
--- 67,72 ----
***************
*** 163,172 ****
      Drawable	    did;
  } dipexPhigsWks;
  
  typedef struct {
-     long	    refcnt;
      ddFontResource  ddFont;
  } dipexFont;
  
  /*
      Some data structures so that we can keep track of Drawables,
--- 163,180 ----
      Drawable	    did;
  } dipexPhigsWks;
  
+ 
+ /*
+  * NOTE: The following structure has it's fields layed out in an
+  *       order dependent way.  It is created in the DI as a dipexFont,
+  *       and is sometime referenced in the DD as a ddFontResource.
+  */
+ 
  typedef struct {
      ddFontResource  ddFont;
+     long	    refcnt;
  } dipexFont;
+ 
  
  /*
      Some data structures so that we can keep track of Drawables,
*** -	Thu Jan 28 17:50:19 1993
--- mit/extensions/server/PEX/dipex/dispatch/dipexBuf.c	Thu Jan 28 17:50:19 1993
***************
*** 1,4 ****
! /* $XConsortium: dipexBuf.c,v 5.1 91/02/16 09:56:37 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: dipexBuf.c,v 5.2 93/01/25 16:11:56 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 37,46 ****
      if (!(temp = (ddBuffer *)Xalloc((unsigned long)(sizeof(ddBuffer)))))
  	return (0);
      if (!(temp->pHead =(ddPointer)Xalloc((unsigned long)(INIT_PEX_BUFFER_SIZE))))
! 	return (0);
      temp->bufSize = (ddULONG)INIT_PEX_BUFFER_SIZE;
      temp->dataSize = 0;
      temp->pBuf = temp->pHead;
      return (temp);
  }
  
--- 37,57 ----
      if (!(temp = (ddBuffer *)Xalloc((unsigned long)(sizeof(ddBuffer)))))
  	return (0);
      if (!(temp->pHead =(ddPointer)Xalloc((unsigned long)(INIT_PEX_BUFFER_SIZE))))
!     {
!   	Xfree(temp);
!    	return (0);
!     }
      temp->bufSize = (ddULONG)INIT_PEX_BUFFER_SIZE;
      temp->dataSize = 0;
      temp->pBuf = temp->pHead;
      return (temp);
+ }
+ 
+   
+ void diFreePEXBuffer(buffer)
+     ddBuffer *buffer;
+ {
+     Xfree(buffer->pHead);
+     Xfree(buffer);
  }
  
*** -	Thu Jan 28 17:50:20 1993
--- mit/extensions/server/PEX/dipex/dispatch/dipexExt.c	Thu Jan 28 17:50:20 1993
***************
*** 1,4 ****
! /* $XConsortium: dipexExt.c,v 5.4 91/07/21 12:01:49 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: dipexExt.c,v 5.9 93/01/25 16:12:22 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 61,68 ****
  extern ddBuffer *pPEXBuffer;
  extern ddBuffer *diInitPEXBuffer();
  extern RequestFunction PEXRequest[];
! extern CARD32 SwapCARD32();
! extern CARD16 SwapCARD16();
  static int DeletePexClient();
  
  /*
--- 61,68 ----
  extern ddBuffer *pPEXBuffer;
  extern ddBuffer *diInitPEXBuffer();
  extern RequestFunction PEXRequest[];
! extern void SwapCARD32();
! extern void SwapCARD16();
  static int DeletePexClient();
  
  /*
***************
*** 82,87 ****
--- 82,88 ----
  		FreePickMeasure(), dipexFreePhigsWks(), FreePipelineContext(),
  		FreeNameSet(), FreeLUT(), FreePEXFont(), FreeWksDrawable();
      extern ddpex43rtn OpenPEXFont();
+     dipexFont	*pPEXFont;
  
      PEXStructType   = CreateNewResourceType (DeleteStructure);
      PEXSearchType   = CreateNewResourceType (FreeSearchContext);
***************
*** 120,166 ****
  
      if (ddpexInit()) {
  	ErrorF("PEXExtensionInit: Couldn't init ddPEX!");
! 	return; }
  
      /*
       *  Open up the default font
       */
!     defaultPEXFont=(diFontHandle)Xalloc((unsigned long)(sizeof(ddFontResource)));
!     if (!defaultPEXFont) {
  	ErrorF("PEXExtensionInit: Memory error--could not allocate default PEX font");
! 	return; }
  	
!     defaultPEXFont->id = FakeClientID(0);
      
      if ( OpenPEXFont(	(ddULONG)(strlen(DEFAULT_PEX_FONT_NAME)), 
  			(ddUCHAR *)(DEFAULT_PEX_FONT_NAME),
! 			defaultPEXFont) != Success) {
! 	char errmsg[80];
  	char *static_message =
  		    "PEXExtensionInit: Couldn't open default PEX font file ";
! 	bcopy(	static_message, errmsg, strlen(static_message));
! 	bcopy(	DEFAULT_PEX_FONT_NAME,&(errmsg[strlen(&(errmsg[0]))]),
! 		strlen(DEFAULT_PEX_FONT_NAME));
! 	ErrorF(errmsg);
! 	Xfree(defaultPEXFont);
  	defaultPEXFont = 0; 
! 	return; }
      
!     if (!AddResource(	defaultPEXFont->id, PEXFontType,
! 			(pointer)(defaultPEXFont))) {
  	ErrorF("PEXExtensionInit: Couldn't add default PEX font resource.");
  	return;
      }
  
!     PextEntry = AddExtension(   PEX_NAME_STRING, 0, (PEXMaxError+1),
  				    ProcPEXDispatch, ProcPEXDispatch,
  				    PEXResetProc, StandardMinorOpcode);
      if (!PextEntry) {
  	ErrorF("PEXExtensionInit: AddExtensions failed\n");
! 	return; }
  
      PexReqCode = PextEntry->base;
      PexErrorBase = PextEntry->errorBase;
      
  }
  
--- 121,208 ----
  
      if (ddpexInit()) {
  	ErrorF("PEXExtensionInit: Couldn't init ddPEX!");
! 	/* this isn't needed for the SI since ddpexInit won't fail
! 	   in the SI but maybe some vendors versions might...
! 	*/
!   	diFreePEXBuffer(pPEXBuffer);
! 	return; 
!     }
  
      /*
       *  Open up the default font
       */
!     pPEXFont=(dipexFont *)Xalloc((unsigned long)(sizeof(dipexFont)));
!     if (!pPEXFont) {
  	ErrorF("PEXExtensionInit: Memory error--could not allocate default PEX font");
!   	diFreePEXBuffer(pPEXBuffer);
! 	return; 
!     }
  	
!     pPEXFont->refcnt = 1;
!     pPEXFont->ddFont.id = FakeClientID(0);
      
+     defaultPEXFont = &(pPEXFont->ddFont);
+ 
      if ( OpenPEXFont(	(ddULONG)(strlen(DEFAULT_PEX_FONT_NAME)), 
  			(ddUCHAR *)(DEFAULT_PEX_FONT_NAME),
! 			pPEXFont) != Success) {
! 	char *errmsg;
  	char *static_message =
  		    "PEXExtensionInit: Couldn't open default PEX font file ";
! 
!         errmsg = (char *) Xalloc(strlen(static_message) +
! 				 strlen(DEFAULT_PEX_FONT_NAME) +
! 				 2  /* 1 byte for space between strings,
! 				     * 1 byte for null */
! 				 );
!         if (errmsg) {
!           sprintf(errmsg, "%s %s", static_message, DEFAULT_PEX_FONT_NAME);
! 
! 	  ErrorF(errmsg);
!           Xfree(errmsg);
!         }
! 
! 	Xfree(pPEXFont);
  	defaultPEXFont = 0; 
!   	diFreePEXBuffer(pPEXBuffer);
! 	return; 
!     }
      
!     /*
!      * Note that fonts resources are stored with the type (dipexFont *),
!      * and they are referenced sometimes in the DD layer as diFontHandle
!      * (which is a pointer to a ddFontResource).  Since the first part
!      * of the dipexFont structure consists of a ddFontResource, this
!      * works.  Even though it is ugly, it's best not to start changing
!      * all of the font code at this time (right before a public release),
!      * and hopefully, it will get cleaned up for PEX 6.0.
!      */
! 
!     if (!AddResource(	pPEXFont->ddFont.id, PEXFontType,
! 			(pointer)(pPEXFont))) {
  	ErrorF("PEXExtensionInit: Couldn't add default PEX font resource.");
+ 	Xfree(pPEXFont);
+ 	defaultPEXFont = 0; 
+   	diFreePEXBuffer(pPEXBuffer);
  	return;
      }
  
!     PextEntry = AddExtension( PEX_NAME_STRING, PEXNumberEvents, (PEXMaxError+1),
  				    ProcPEXDispatch, ProcPEXDispatch,
  				    PEXResetProc, StandardMinorOpcode);
      if (!PextEntry) {
  	ErrorF("PEXExtensionInit: AddExtensions failed\n");
! 	Xfree(pPEXFont);
! 	defaultPEXFont = 0; 
!   	diFreePEXBuffer(pPEXBuffer);
! 	return; 
!     }
  
      PexReqCode = PextEntry->base;
      PexErrorBase = PextEntry->errorBase;
+     PexEventBase = PextEntry->eventBase;
+     EventSwapVector[PexEventBase + PEXMaxHitsReached] = 
+ 						    SwapPEXMaxHitsReachedEvent;
      
  }
  
***************
*** 247,252 ****
--- 289,295 ----
      FreeResource(temp->id, RT_NONE);
  
      ddpexReset();
+     diFreePEXBuffer(pPEXBuffer);
  }
  
  
*** -	Thu Jan 28 17:50:24 1993
--- mit/extensions/server/PEX/dipex/dispatch/pexUtils.c	Thu Jan 28 17:50:24 1993
***************
*** 1,4 ****
! /* $XConsortium: pexUtils.c,v 5.5 91/05/06 18:15:36 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pexUtils.c,v 5.6 92/10/05 17:01:54 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 112,118 ****
  	sizeof(diStructHandle),
  	sizeof(ddDeviceRect),
  	sizeof(ddULONG),
! 	sizeof(ddUSHORT)
  };
  
  /* sizes of chunks that arrays in the lists are allocated and grow in 
--- 112,119 ----
  	sizeof(diStructHandle),
  	sizeof(ddDeviceRect),
  	sizeof(ddULONG),
! 	sizeof(ddUSHORT),
! 	sizeof(ddPointer)
  };
  
  /* sizes of chunks that arrays in the lists are allocated and grow in 
***************
*** 146,151 ****
--- 147,153 ----
   *	device rect: for the clip list.  I think this is used for window 
   *		clipping (?), so it may get large.
   *	index: is used for list state in the pc. 10 lights is a lot
+  *	list of list: used for doing list of pick path for PickAll 
   *  You can adjust these any way you'd like.  Maybe you want them all to be
   *	built in small chunks so not so much (possibly unused) memory is
   *	laying around and are willing to take the performance hit whenever
***************
*** 162,168 ****
  	20,	/* structure handle */
  	30,	/* device rect */
  	10,	/* name */
! 	10	/* index */
  };
  
  #define PU_CHECK_LIST( plist )	if (!plist)	 return( PU_BAD_LIST )
--- 164,171 ----
  	20,	/* structure handle */
  	30,	/* device rect */
  	10,	/* name */
! 	10,	/* index */
! 	50	/* list of list */
  };
  
  #define PU_CHECK_LIST( plist )	if (!plist)	 return( PU_BAD_LIST )
***************
*** 222,227 ****
--- 225,233 ----
  #define PU_INDEX_COMPARE( p1, p2 ) \
  	( *(p1) == *(p2) ) 
  
+ #define PU_LIST_COMPARE( p1, p2 ) \
+ 	( *(p1) == *(p2) ) 
+ 
  /*
      Returns the number of bytes needed to create a list of this type
   */
***************
*** 377,382 ****
--- 383,397 ----
  		}
  		break;
  	
+ 		case	DD_LIST_OF_LIST:
+ 		{
+ 			listofObj	**pi = (listofObj **)pitem;
+ 			listofObj	**pl = (listofObj **)plist->pList;
+ 
+ 			PU_COMPARE_LOOP( PU_LIST_COMPARE( pi, pl ) );
+ 		}
+ 		break;
+ 
  		default:
  			return( PU_FALSE );
  	}
***************
*** 517,522 ****
--- 532,547 ----
  		}
  		break;
  	
+ 		case	DD_LIST_OF_LIST:
+ 		{
+ 			listofObj	**pi = (listofObj **)pitem;
+ 			listofObj	**pl = (listofObj **)plist->pList;
+ 
+ 			PU_REMOVE_LOOP( PU_LIST_COMPARE( pi, pl ) );
+ 
+ 		}
+ 		break;
+ 	
  		default:
  			return( PU_BAD_LIST );
  	}
***************
*** 557,562 ****
--- 582,588 ----
  	
  	return( Success );
  }	/* puCopyList */
+ 
  
  /* merges two lists into one list without duplicates */
  short
*** -	Thu Jan 28 17:50:30 1993
--- mit/extensions/server/PEX/dipex/objects/pexPhigs.c	Thu Jan 28 17:50:29 1993
***************
*** 1,4 ****
! /* $XConsortium: pexPhigs.c,v 5.1 91/02/16 09:56:44 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pexPhigs.c,v 5.4 92/12/01 17:17:22 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 104,110 ****
      diNSHandle ns = 0;
      DrawablePtr pdraw = 0;
  
!     if (pw = (dipexPhigsWks *)LookupIDByType(strmPtr->wks, PEXWksType))
  	PEX_ERR_EXIT(BadIDChoice,strmPtr->wks,cntxtPtr);
  
      LU_DRAWABLE(strmPtr->drawable, pdraw);
--- 104,110 ----
      diNSHandle ns = 0;
      DrawablePtr pdraw = 0;
  
!     if (!LegalNewID(strmPtr->wks, cntxtPtr->client))
  	PEX_ERR_EXIT(BadIDChoice,strmPtr->wks,cntxtPtr);
  
      LU_DRAWABLE(strmPtr->drawable, pdraw);
***************
*** 113,118 ****
--- 113,121 ----
      if (!pw) {
  	PEX_ERR_EXIT(BadAlloc,0,cntxtPtr);
      }
+     pw->did = strmPtr->drawable;
+     pw->dd_data.id = strmPtr->wks;
+     pw->dd_data.deviceData = NULL;
  
      tables.pDrawable = pdraw;
      tables.drawableId = strmPtr->drawable;
***************
*** 161,168 ****
      tables.bufferMode = strmPtr->bufferMode;
  
      /* workstation-drawable cross-references */
!     if (!((wks_draw) = (dipexWksDrawable *) LookupIDByType(strmPtr->drawable,
! 							PEXWksDrawableType))) {
  	wks_draw =
  	    (dipexWksDrawable *) Xalloc ((unsigned long)(sizeof(dipexWksDrawable)
  						+ sizeof(dipexWksDrawableLink)));
--- 164,171 ----
      tables.bufferMode = strmPtr->bufferMode;
  
      /* workstation-drawable cross-references */
!     if (!LegalNewID(strmPtr->drawable, cntxtPtr->client)) {
! 
  	wks_draw =
  	    (dipexWksDrawable *) Xalloc ((unsigned long)(sizeof(dipexWksDrawable)
  						+ sizeof(dipexWksDrawableLink)));
***************
*** 170,181 ****
  	wks_draw->id = strmPtr->drawable;
  	wks_draw->x_drawable = pdraw;
  	wks_draw->wks_list = (dipexWksDrawableLink *)(wks_draw +1);
  	wks_draw->wks_list->wksid = strmPtr->wks;
  	wks_draw->wks_list->next = 0;
  	if (!( AddResource(   strmPtr->drawable, PEXWksDrawableType,
  				    (pointer)wks_draw))) {
- 	    Xfree((pointer)wks_draw);
- 	    Xfree(pw->dd_data);
  	    PEX_ERR_EXIT(BadAlloc,0,cntxtPtr); }
      } else {
  	plink = (dipexWksDrawableLink *) 
--- 173,183 ----
  	wks_draw->id = strmPtr->drawable;
  	wks_draw->x_drawable = pdraw;
  	wks_draw->wks_list = (dipexWksDrawableLink *)(wks_draw +1);
+ 	wks_draw->wks_list->wks = pw;
  	wks_draw->wks_list->wksid = strmPtr->wks;
  	wks_draw->wks_list->next = 0;
  	if (!( AddResource(   strmPtr->drawable, PEXWksDrawableType,
  				    (pointer)wks_draw))) {
  	    PEX_ERR_EXIT(BadAlloc,0,cntxtPtr); }
      } else {
  	plink = (dipexWksDrawableLink *) 
***************
*** 188,199 ****
  	wks_draw->wks_list = plink;
      }
  
-     wks_draw->wks_list->wks = pw;
-     pw->did = strmPtr->drawable;
  
      /* ddpex create */
-     pw->dd_data.id = strmPtr->wks;
-     pw->dd_data.deviceData = NULL;
      err = CreatePhigsWks (&tables, &(pw->dd_data));
      if (err) {
  	RemoveWksFromDrawableList(strmPtr->wks, wks_draw);
--- 190,197 ----
***************
*** 325,330 ****
--- 323,329 ----
      pexGetDynamicsReply *reply = (pexGetDynamicsReply *)(pPEXBuffer->pHead);
  
      LU_DRAWABLE(strmPtr->drawable, pdraw);
+     SETUP_INQ(pexGetDynamicsReply);
  
      err = InquireWksDynamics (pdraw, (ddWksDynamics *)&(reply->viewRep));
      if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
***************
*** 351,356 ****
--- 350,357 ----
      unsigned long size = 0;
  
      LU_PHIGSWKS(strmPtr->wks, pw);
+ 
+     SETUP_INQ(pexGetViewRepReply);
  
      if (pPEXBuffer->bufSize < size) {
  	err = puBuffRealloc(pPEXBuffer, size);
*** -	Thu Jan 28 17:50:31 1993
--- mit/extensions/server/PEX/dipex/objects/pexPick.c	Thu Jan 28 17:50:31 1993
***************
*** 1,4 ****
! /* $XConsortium: pexPick.c,v 5.1 91/02/16 09:56:45 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pexPick.c,v 5.2 92/03/04 14:16:12 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 26,31 ****
--- 26,33 ----
  
  
  /*++
+  *  --- Workstation Picking ---
+  *
   *	PEXCreatePickMeasure
   *	PEXFreePickMeasure
   *	PEXGetPickDevice
***************
*** 32,37 ****
--- 34,40 ----
   *	PEXChangePickDevice
   *	PEXGetPickMeasure
   *	PEXUpdatePickMeasure
+  *
   --*/
  
  #include "X.h"
***************
*** 169,179 ****
      if (strmPtr->itemMask & PEXPDPickStatus) ptr++;
  
      if (strmPtr->itemMask & PEXPDPickPath) {
! 	pexPickPath *per;
  	diStructHandle sh, *psh;
  	CARD32 i, numRefs = *((CARD32 *)(ptr));
  	ptr++;
! 	for (i=0, per = (pexPickPath *)ptr; i<numRefs; i++, per++) {
  		LU_STRUCTURE(per->sid,sh);
  		psh = (diStructHandle *)&(per->sid);
  		*psh = sh;
--- 172,182 ----
      if (strmPtr->itemMask & PEXPDPickStatus) ptr++;
  
      if (strmPtr->itemMask & PEXPDPickPath) {
! 	pexPickElementRef *per;
  	diStructHandle sh, *psh;
  	CARD32 i, numRefs = *((CARD32 *)(ptr));
  	ptr++;
! 	for (i=0, per = (pexPickElementRef *)ptr; i<numRefs; i++, per++) {
  		LU_STRUCTURE(per->sid,sh);
  		psh = (diStructHandle *)&(per->sid);
  		*psh = sh;
***************
*** 250,255 ****
--- 253,260 ----
      return( err );
  
  } /* end-PEXUpdatePickMeasure() */
+ 
+ 
  /*++
   *
   *	End of File
*** -	Thu Jan 28 17:50:32 1993
--- mit/extensions/server/PEX/dipex/objects/pexSc.c	Thu Jan 28 17:50:31 1993
***************
*** 1,4 ****
! /* $XConsortium: pexSc.c,v 5.2 91/07/12 17:57:07 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pexSc.c,v 5.7 93/01/06 13:57:17 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 56,71 ****
  
  #define SC_NS_LIMIT  20				/* arbitrary value */
  
! #define CHK_PEX_BUF(SIZE,INCR,REPLY,TYPE,PTR) \
!     SIZE+=INCR; \
!     if (pPEXBuffer->dataSize < SIZE) { \
  	ErrorCode err = Success; \
! 	int offset = (int)PTR - (int)(pPEXBuffer->pHead); \
! 	err = puBuffRealloc(pPEXBuffer,(ddULONG)SIZE); \
  	if (err) PEX_ERR_EXIT(err,0,cntxtPtr); \
! 	REPLY = (TYPE *)(pPEXBuffer->pHead); \
! 	PTR = (unsigned char *)(pPEXBuffer->pHead + offset); }
!     
  
  static ErrorCode
  AddToNSPair( incl, excl, pair )
--- 56,71 ----
  
  #define SC_NS_LIMIT  20				/* arbitrary value */
  
! #define CHK_PEX_BUF(SIZE,INCR,REPLY,TYPE,PTR) {\
!     (SIZE)+=(INCR); \
!       if (pPEXBuffer->bufSize < (SIZE)) { \
  	ErrorCode err = Success; \
! 	int offset = (int)(((unsigned char *)(PTR)) - ((unsigned char *)(pPEXBuffer->pHead))); \
! 	err = puBuffRealloc(pPEXBuffer,(ddULONG)(SIZE)); \
  	if (err) PEX_ERR_EXIT(err,0,cntxtPtr); \
! 	(REPLY) = (TYPE *)(pPEXBuffer->pHead); \
! 	(PTR) = (unsigned char *)(pPEXBuffer->pHead + offset); } \
! }
  
  static ErrorCode
  AddToNSPair( incl, excl, pair )
***************
*** 181,193 ****
      };
  
      if (itemMask & PEXSCCeiling) {
! 	EXTRACT_CARD16 (psc->ceiling, ptr);
! 	SKIP_PADDING (ptr,2);
      }
  
      if (itemMask & PEXSCModelClipFlag) {
! 	EXTRACT_CARD8 (psc->modelClipFlag, ptr);
! 	SKIP_PADDING (ptr, 3);
      }
  
      if (itemMask & PEXSCStartPath) {
--- 181,191 ----
      };
  
      if (itemMask & PEXSCCeiling) {
! 	EXTRACT_CARD16_FROM_4B (psc->ceiling, ptr);
      }
  
      if (itemMask & PEXSCModelClipFlag) {
! 	EXTRACT_CARD8_FROM_4B (psc->modelClipFlag, ptr);
      }
  
      if (itemMask & PEXSCStartPath) {
***************
*** 257,263 ****
      ddSCStr *psc;
      unsigned char *ptr;
  
!     if ( (psc = (ddSCStr *) LookupIDByType (strmPtr->sc, PEXSearchType)))
  	PEX_ERR_EXIT(BadIDChoice,strmPtr->sc,cntxtPtr);
  
      CHECK_FP_FORMAT (strmPtr->fpFormat);
--- 255,261 ----
      ddSCStr *psc;
      unsigned char *ptr;
  
!     if (!LegalNewID(strmPtr->sc, cntxtPtr->client))
  	PEX_ERR_EXIT(BadIDChoice,strmPtr->sc,cntxtPtr);
  
      CHECK_FP_FORMAT (strmPtr->fpFormat);
***************
*** 273,280 ****
      psc->inverted.maxPairs=SC_NS_LIMIT;
      psc->inverted.pPairs =
  		(ddNSPair *)Xalloc(psc->inverted.maxPairs * sizeof(ddNSPair));
-     psc->startPath = 0;
  
      ptr = (unsigned char *) (strmPtr + 1);
  
  
--- 271,287 ----
      psc->inverted.maxPairs=SC_NS_LIMIT;
      psc->inverted.pPairs =
  		(ddNSPair *)Xalloc(psc->inverted.maxPairs * sizeof(ddNSPair));
  
+     psc->position.x = psc->position.y = psc->position.z = 0.0;
+     psc->distance = 0.0;
+     psc->ceiling = 1;
+     psc->modelClipFlag = xFalse;
+ 
+     if (strmPtr->itemMask & PEXSCStartPath)
+ 	psc->startPath = 0;   /* list will be created in UpdateSearchContext */
+     else
+ 	psc->startPath = puCreateList(DD_ELEMENT_REF);
+ 
      ptr = (unsigned char *) (strmPtr + 1);
  
  
***************
*** 309,314 ****
--- 316,323 ----
  
      if (strmPtr->itemMask & PEXSCCeiling) dst->ceiling = src->ceiling;
  
+     if (strmPtr->itemMask & PEXSCModelClipFlag)
+ 	dst->modelClipFlag = src->modelClipFlag;
  
      if (strmPtr->itemMask & PEXSCStartPath) {
  	puDeleteList (dst->startPath);
***************
*** 396,402 ****
      ErrorCode err = Success;
      ddSCStr *psc;
      extern ddBuffer *pPEXBuffer;
!     unsigned char *ptr = pPEXBuffer->pHead;
      pexGetSearchContextReply *reply
  			    = (pexGetSearchContextReply *)(pPEXBuffer->pHead);
      int size = 0;
--- 405,411 ----
      ErrorCode err = Success;
      ddSCStr *psc;
      extern ddBuffer *pPEXBuffer;
!     unsigned char *ptr = 0;
      pexGetSearchContextReply *reply
  			    = (pexGetSearchContextReply *)(pPEXBuffer->pHead);
      int size = 0;
***************
*** 406,411 ****
--- 415,421 ----
      CHK_PEX_BUF(size, sizeof(pexGetSearchContextReply), reply,
  		pexGetSearchContextReply, ptr);
      SETUP_INQ(pexGetSearchContextReply);
+     ptr = pPEXBuffer->pBuf;
  
      if (strmPtr->itemMask & PEXSCPosition) {
  	CHK_PEX_BUF(size, sizeof(pexCoord3D), reply, pexGetSearchContextReply,
***************
*** 420,443 ****
  
      if (strmPtr->itemMask & PEXSCCeiling) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetSearchContextReply, ptr);
! 	PACK_CARD16 (psc->ceiling, ptr);
! 	SKIP_PADDING(ptr,2);
      }
  
      if (strmPtr->itemMask & PEXSCModelClipFlag) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetSearchContextReply, ptr);
! 	PACK_CARD8 (psc->modelClipFlag, ptr);
! 	SKIP_PADDING (ptr, 3);
      }
  
      if (strmPtr->itemMask & PEXSCStartPath) {
  	CHK_PEX_BUF(size,
  		    psc->startPath->numObj*sizeof(pexElementRef) +sizeof(CARD32),
  		    reply, pexGetSearchContextReply,ptr);
  	PACK_CARD32(psc->startPath->numObj,ptr);
! 	bcopy(((char *)(psc->startPath->pList)), ((char *)(ptr)),
! 	      (int)((psc->startPath->numObj) * sizeof(pexElementRef))); 
! 	ptr += psc->startPath->numObj * sizeof(pexElementRef);
      };
  
      if (strmPtr->itemMask & PEXSCNormalList) {
--- 430,457 ----
  
      if (strmPtr->itemMask & PEXSCCeiling) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetSearchContextReply, ptr);
! 	PACK_CARD32 (psc->ceiling, ptr);
      }
  
      if (strmPtr->itemMask & PEXSCModelClipFlag) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetSearchContextReply, ptr);
! 	PACK_CARD32 (psc->modelClipFlag, ptr);
      }
  
      if (strmPtr->itemMask & PEXSCStartPath) {
+ 	pexStructure sid = 0;
+ 	unsigned long i;
+ 	ddElementRef *per = (ddElementRef *)(psc->startPath->pList);
+ 
  	CHK_PEX_BUF(size,
  		    psc->startPath->numObj*sizeof(pexElementRef) +sizeof(CARD32),
  		    reply, pexGetSearchContextReply,ptr);
  	PACK_CARD32(psc->startPath->numObj,ptr);
! 	for (i=0; i<psc->startPath->numObj; i++, per++) {
! 	    sid = GetId(per->structure);
! 	    PACK_CARD32(sid, ptr);
! 	    PACK_CARD32(per->offset, ptr);
! 	}
      };
  
      if (strmPtr->itemMask & PEXSCNormalList) {
***************
*** 444,450 ****
  	int i;
  	ddNSPair *src;
  	pexNameSet *dst;
! 	CHK_PEX_BUF(size, psc->normal.numPairs * sizeof(pexNameSet) + 4,
  		    reply, pexGetSearchContextReply, ptr);
  	PACK_CARD32(psc->normal.numPairs, ptr);
  	for (i=0, src = psc->normal.pPairs, dst = (pexNameSet *)ptr;
--- 458,464 ----
  	int i;
  	ddNSPair *src;
  	pexNameSet *dst;
! 	CHK_PEX_BUF(size, psc->normal.numPairs * 2 * sizeof(pexNameSet) + 4,
  		    reply, pexGetSearchContextReply, ptr);
  	PACK_CARD32(psc->normal.numPairs, ptr);
  	for (i=0, src = psc->normal.pPairs, dst = (pexNameSet *)ptr;
***************
*** 458,464 ****
  	int i;
  	ddNSPair *src;
  	pexNameSet *dst;
! 	CHK_PEX_BUF(size, psc->inverted.numPairs * sizeof(pexNameSet) + 4,
  		    reply, pexGetSearchContextReply, ptr);
  	PACK_CARD32(psc->inverted.numPairs, ptr);
  	for (i=0, src = psc->inverted.pPairs, dst = (pexNameSet *)ptr;
--- 472,478 ----
  	int i;
  	ddNSPair *src;
  	pexNameSet *dst;
! 	CHK_PEX_BUF(size, psc->inverted.numPairs * 2 * sizeof(pexNameSet) + 4,
  		    reply, pexGetSearchContextReply, ptr);
  	PACK_CARD32(psc->inverted.numPairs, ptr);
  	for (i=0, src = psc->inverted.pPairs, dst = (pexNameSet *)ptr;
***************
*** 470,476 ****
  
      reply->length = size - sizeof(pexGetSearchContextReply);
      reply->length = LWORDS(reply->length);
!     WritePEXReplyToClient(  cntxtPtr, strmPtr, size, reply);
  
      return( err );
  
--- 484,492 ----
  
      reply->length = size - sizeof(pexGetSearchContextReply);
      reply->length = LWORDS(reply->length);
!     WritePEXReplyToClient(  cntxtPtr, strmPtr,
!         sizeof (pexGetSearchContextReply) + sizeof(CARD32) * reply->length,
! 	reply);
  
      return( err );
  
*** -	Thu Jan 28 17:50:34 1993
--- mit/extensions/server/PEX/dipex/objects/pexPc.c	Thu Jan 28 17:50:33 1993
***************
*** 1,4 ****
! /* $XConsortium: pexPc.c,v 5.2 91/07/12 17:57:32 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pexPc.c,v 5.9 92/12/01 17:17:54 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 50,68 ****
  #undef max
  #endif
  
  
! #define CHK_PEX_BUF(SIZE,INCR,REPLY,TYPE,PTR) \
      (SIZE)+=(INCR); \
! /*    if (pPEXBuffer->dataSize < (SIZE)) { \
! */    if (pPEXBuffer->bufSize < (SIZE)) { \
! 	int check_size = 0; \
  	int offset = (int)(((unsigned char *)(PTR)) - ((unsigned char *)(pPEXBuffer->pHead))); \
! 	check_size = puBuffRealloc(pPEXBuffer,(ddULONG)(SIZE)); \
! /*	if (check_size <= 0) PEX_ERR_EXIT(BadAlloc,0,cntxtPtr); \
! */	if (!check_size) PEX_ERR_EXIT(BadAlloc,0,cntxtPtr); \
  	(REPLY) = (TYPE *)(pPEXBuffer->pHead); \
! 	(PTR) = (unsigned char *)(pPEXBuffer->pHead + offset); }
  
  
  ErrorCode
  UpdatePCRefs (pc, pr, action)
--- 50,70 ----
  #undef max
  #endif
  
+ /* need to do this to return correct ASF_ENABLES bits per Encoding */
+ #define ASF_ALL   0x3FFFFFFF
  
! #define CHK_PEX_BUF(SIZE,INCR,REPLY,TYPE,PTR) {\
      (SIZE)+=(INCR); \
!       if (pPEXBuffer->bufSize < (SIZE)) { \
! 	ErrorCode err = Success; \
  	int offset = (int)(((unsigned char *)(PTR)) - ((unsigned char *)(pPEXBuffer->pHead))); \
! 	err = puBuffRealloc(pPEXBuffer,(ddULONG)(SIZE)); \
! 	if (err) PEX_ERR_EXIT(err,0,cntxtPtr); \
  	(REPLY) = (TYPE *)(pPEXBuffer->pHead); \
! 	(PTR) = (unsigned char *)(pPEXBuffer->pHead + offset); } \
! }
  
+ #define PADDING(n) ( (n)&3 ? (4 - ((n)&3)) : 0)
  
  ErrorCode
  UpdatePCRefs (pc, pr, action)
***************
*** 84,97 ****
  UpdatePipelineContext (cntxtPtr, pca, itemMask, ptr)
  pexContext	*cntxtPtr;
  ddPCAttr	*pca;
! CARD32		itemMask[2];
  unsigned char	*ptr;
  {
      ErrorCode err = Success;
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCMarkerType) {
! 	EXTRACT_CARD16 (pca->markerType, ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCMarkerScale) {
--- 86,98 ----
  UpdatePipelineContext (cntxtPtr, pca, itemMask, ptr)
  pexContext	*cntxtPtr;
  ddPCAttr	*pca;
! CARD32		itemMask[3];
  unsigned char	*ptr;
  {
      ErrorCode err = Success;
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCMarkerType) {
! 	EXTRACT_INT16_FROM_4B (pca->markerType, ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCMarkerScale) {
***************
*** 103,120 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCMarkerBundleIndex) {
! 	EXTRACT_CARD16 (pca->markerIndex, ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextFont) {
! 	EXTRACT_CARD16 (pca->textFont, ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextPrecision) {
! 	EXTRACT_CARD16 (pca->textPrecision, ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCCharExpansion) {
--- 104,118 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCMarkerBundleIndex) {
! 	EXTRACT_CARD16_FROM_4B (pca->markerIndex, ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextFont) {
! 	EXTRACT_CARD16_FROM_4B (pca->textFont, ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextPrecision) {
! 	EXTRACT_CARD16_FROM_4B (pca->textPrecision, ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCCharExpansion) {
***************
*** 139,146 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextPath) {
! 	EXTRACT_CARD16 (pca->textPath, ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextAlignment) {
--- 137,143 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextPath) {
! 	EXTRACT_CARD16_FROM_4B (pca->textPath, ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextAlignment) {
***************
*** 158,165 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCAtextPath) {
! 	EXTRACT_CARD16 (pca->atextPath, ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCAtextAlignment) {
--- 155,161 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCAtextPath) {
! 	EXTRACT_CARD16_FROM_4B (pca->atextPath, ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCAtextAlignment) {
***************
*** 168,185 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCAtextStyle) {
! 	EXTRACT_CARD16 (pca->atextStyle, ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextBundleIndex) {
! 	EXTRACT_CARD16 (pca->textIndex, ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLineType) {
! 	EXTRACT_CARD16 (pca->lineType, ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLineWidth) {
--- 164,178 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCAtextStyle) {
! 	EXTRACT_INT16_FROM_4B (pca->atextStyle, ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextBundleIndex) {
! 	EXTRACT_CARD16_FROM_4B (pca->textIndex, ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLineType) {
! 	EXTRACT_INT16_FROM_4B (pca->lineType, ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLineWidth) {
***************
*** 191,219 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCCurveApproximation) {
! 	EXTRACT_CARD16 (pca->curveApprox.approxMethod, ptr);
! 	SKIP_PADDING (ptr, 2);
  	EXTRACT_FLOAT (pca->curveApprox.tolerance, ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCPolylineInterp) {
! 	EXTRACT_CARD16 (pca->lineInterp,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLineBundleIndex) {
! 	EXTRACT_CARD16 (pca->lineIndex,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCInteriorStyle) {
! 	EXTRACT_CARD16 (pca->intStyle,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCInteriorStyleIndex) {
! 	EXTRACT_CARD16 (pca->intStyleIndex,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceColour) {
--- 184,207 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCCurveApproximation) {
! 	EXTRACT_INT16_FROM_4B (pca->curveApprox.approxMethod, ptr);
  	EXTRACT_FLOAT (pca->curveApprox.tolerance, ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCPolylineInterp) {
! 	EXTRACT_INT16_FROM_4B (pca->lineInterp,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLineBundleIndex) {
! 	EXTRACT_CARD16_FROM_4B (pca->lineIndex,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCInteriorStyle) {
! 	EXTRACT_INT16_FROM_4B (pca->intStyle,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCInteriorStyleIndex) {
! 	EXTRACT_INT16_FROM_4B (pca->intStyleIndex,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceColour) {
***************
*** 230,252 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceReflModel) {
! 	EXTRACT_CARD16 (pca->reflModel,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceInterp) {
! 	EXTRACT_CARD16 (pca->surfInterp,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfInteriorStyle) {
! 	EXTRACT_CARD16 (pca->bfIntStyle,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfInteriorStyleIndex) {
! 	EXTRACT_CARD16 (pca->bfIntStyleIndex,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfSurfaceColour) {
--- 218,236 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceReflModel) {
! 	EXTRACT_INT16_FROM_4B (pca->reflModel,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceInterp) {
! 	EXTRACT_INT16_FROM_4B (pca->surfInterp,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfInteriorStyle) {
! 	EXTRACT_INT16_FROM_4B (pca->bfIntStyle,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfInteriorStyleIndex) {
! 	EXTRACT_INT16_FROM_4B (pca->bfIntStyleIndex,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfSurfaceColour) {
***************
*** 263,287 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfSurfaceReflModel) {
! 	EXTRACT_CARD16 (pca->bfReflModel,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfSurfaceInterp) {
! 	EXTRACT_CARD16 (pca->bfSurfInterp,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceApproximation) {
! 	EXTRACT_CARD16 (pca->surfApprox.approxMethod,ptr);
! 	SKIP_PADDING (ptr, 2);
  	EXTRACT_FLOAT (pca->surfApprox.uTolerance, ptr);
  	EXTRACT_FLOAT (pca->surfApprox.vTolerance, ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCDistinguishFlag) {
! 	EXTRACT_CARD8 (pca->distFlag,ptr);
! 	SKIP_PADDING (ptr, 3);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCPatternSize) {
--- 247,271 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfSurfaceReflModel) {
! 	EXTRACT_INT16_FROM_4B (pca->bfReflModel,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfSurfaceInterp) {
! 	EXTRACT_INT16_FROM_4B (pca->bfSurfInterp,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceApproximation) {
! 	EXTRACT_INT16_FROM_4B (pca->surfApprox.approxMethod,ptr);
  	EXTRACT_FLOAT (pca->surfApprox.uTolerance, ptr);
  	EXTRACT_FLOAT (pca->surfApprox.vTolerance, ptr);
      }
  
+     CHECK_BITMASK_ARRAY(itemMask, PEXPCCullingMode) {
+          EXTRACT_CARD16_FROM_4B (pca->cullMode,ptr);
+     }
+ 
      CHECK_BITMASK_ARRAY(itemMask, PEXPCDistinguishFlag) {
! 	EXTRACT_CARD8_FROM_4B (pca->distFlag,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCPatternSize) {
***************
*** 308,325 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCInteriorBundleIndex) {
! 	EXTRACT_CARD16 (pca->intIndex,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceEdgeFlag) {
! 	EXTRACT_CARD16 (pca->edges,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceEdgeType) {
! 	EXTRACT_CARD16 (pca->edgeType,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceEdgeWidth) {
--- 292,306 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCInteriorBundleIndex) {
! 	EXTRACT_CARD16_FROM_4B (pca->intIndex,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceEdgeFlag) {
! 	EXTRACT_CARD16_FROM_4B (pca->edges,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceEdgeType) {
! 	EXTRACT_INT16_FROM_4B (pca->edgeType,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceEdgeWidth) {
***************
*** 331,338 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCEdgeBundleIndex) {
! 	EXTRACT_CARD16 (pca->edgeIndex,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLocalTransform) {
--- 312,318 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCEdgeBundleIndex) {
! 	EXTRACT_CARD16_FROM_4B (pca->edgeIndex,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLocalTransform) {
***************
*** 350,392 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCModelClip) {
! 	EXTRACT_CARD16 (pca->modelClip,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCModelClipVolume) {
! 	unsigned long i;
! 	EXTRACT_CARD32 (i, ptr);
  	PU_EMPTY_LIST(pca->modelClipVolume);
! /*	puDeleteList(pca->modelClipVolume);
  	pca->modelClipVolume = puCreateList(DD_HALF_SPACE);
  	if (!pca->modelClipVolume) PEX_ERR_EXIT(BadAlloc,0,cntxtPtr);
! */	puAddToList((ddPointer)ptr, i, pca->modelClipVolume);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCViewIndex) {
! 	EXTRACT_CARD16 (pca->viewIndex,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLightState) {
! /*	EXTRACT_CARD32 (pca->lightState,ptr);
! */	unsigned long i;
  	EXTRACT_CARD32(i,ptr);
  	PU_EMPTY_LIST(pca->lightState);
! /*	puDeleteList(pca->lightState);
! 	pca->lightState = puCreateList(DD_INDEX);
! 	if (!pca->lightState) PEX_ERR_EXIT(BadAlloc,0,cntxtPtr);
! */	puAddToList((ddPointer)ptr,i,pca->lightState);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCDepthCueIndex) {
! 	EXTRACT_CARD16 (pca->depthCueIndex,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSetAsfValues) {
! 	EXTRACT_CARD32 (pca->asfs,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCPickId) {
--- 330,378 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCModelClip) {
! 	EXTRACT_CARD16_FROM_4B (pca->modelClip,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCModelClipVolume) {
! 	unsigned long i, numHalfSpaces;
! 	EXTRACT_CARD32 ( numHalfSpaces, ptr);
  	PU_EMPTY_LIST(pca->modelClipVolume);
!       /* don't need to do this emptying the list and adding is sufficient
! 	puDeleteList(pca->modelClipVolume);
  	pca->modelClipVolume = puCreateList(DD_HALF_SPACE);
  	if (!pca->modelClipVolume) PEX_ERR_EXIT(BadAlloc,0,cntxtPtr);
!       */
! 	puAddToList((ddPointer)ptr, numHalfSpaces, pca->modelClipVolume);
! 	/* skip past list of Half Space */
! 	for ( i = 0; i < numHalfSpaces; i++) {
! 	  SKIP_STRUCT(ptr, 1, ddCoord3D);
! 	  SKIP_STRUCT(ptr, 1, ddVector3D);
! 	}
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCViewIndex) {
! 	EXTRACT_CARD16_FROM_4B (pca->viewIndex,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLightState) {
! 	unsigned long i, numskip;
  	EXTRACT_CARD32(i,ptr);
  	PU_EMPTY_LIST(pca->lightState);
! 	puAddToList((ddPointer)ptr,i,pca->lightState);
! 	/* skip over CARD16 and pad if any */
! 	numskip = (i + 1) / 2;
! 	SKIP_PADDING( ptr, numskip * 4);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCDepthCueIndex) {
! 	EXTRACT_CARD16_FROM_4B (pca->depthCueIndex,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSetAsfValues) {
! 	CARD32  asf_enables, asfs;
! 	EXTRACT_CARD32 (asf_enables,ptr);
! 	EXTRACT_CARD32 (asfs,ptr);
! 	pca->asfs = (pca->asfs & ~asf_enables) | (asfs & asf_enables);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCPickId) {
***************
*** 404,420 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCColourApproxIndex) {
! 	EXTRACT_CARD16 (pca->colourApproxIndex,ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCRenderingColourModel) {
! 	EXTRACT_CARD16 (pca->rdrColourModel, ptr);
! 	SKIP_PADDING (ptr, 2);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCParaSurfCharacteristics) {
! 	EXTRACT_CARD16 (pca->psc.type, ptr);
  	SKIP_PADDING(ptr,2);
  	switch (pca->psc.type) {
  	    case PEXPSCNone:
--- 390,404 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCColourApproxIndex) {
! 	EXTRACT_CARD16_FROM_4B (pca->colourApproxIndex,ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCRenderingColourModel) {
! 	EXTRACT_INT16_FROM_4B (pca->rdrColourModel, ptr);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCParaSurfCharacteristics) {
! 	EXTRACT_INT16 (pca->psc.type, ptr);
  	SKIP_PADDING(ptr,2);
  	switch (pca->psc.type) {
  	    case PEXPSCNone:
***************
*** 425,430 ****
--- 409,415 ----
  		SKIP_PADDING(ptr,2);
  		EXTRACT_CARD16(pca->psc.data.isoCurves.numUcurves, ptr);
  		EXTRACT_CARD16(pca->psc.data.isoCurves.numVcurves, ptr);
+ 		break;
  	    }
  	    case PEXPSCMcLevelCurves: {
  		EXTRACT_COORD3D((&(pca->psc.data.mcLevelCurves.origin)),ptr);
***************
*** 431,442 ****
  		EXTRACT_COORD3D((&(pca->psc.data.mcLevelCurves.direction)),ptr);
  		EXTRACT_CARD16(pca->psc.data.mcLevelCurves.numberIntersections,ptr);
  		SKIP_PADDING(ptr,2);
! 		pca->psc.data.mcLevelCurves.pPoints = (ddCoord3D *)
! 		    Xalloc((unsigned long) (sizeof(ddCoord3D) *
  			    pca->psc.data.mcLevelCurves.numberIntersections));
  		EXTRACT_STRUCT(	pca->psc.data.mcLevelCurves.numberIntersections,
! 				pexCoord3D, pca->psc.data.mcLevelCurves.pPoints,
  				ptr);
  	    }
  
  	    case PEXPSCWcLevelCurves: {
--- 416,428 ----
  		EXTRACT_COORD3D((&(pca->psc.data.mcLevelCurves.direction)),ptr);
  		EXTRACT_CARD16(pca->psc.data.mcLevelCurves.numberIntersections,ptr);
  		SKIP_PADDING(ptr,2);
! 		pca->psc.data.mcLevelCurves.pPoints = (ddFLOAT *)
! 		    Xalloc((unsigned long) (sizeof(ddFLOAT) *
  			    pca->psc.data.mcLevelCurves.numberIntersections));
  		EXTRACT_STRUCT(	pca->psc.data.mcLevelCurves.numberIntersections,
! 				PEXFLOAT, pca->psc.data.mcLevelCurves.pPoints,
  				ptr);
+ 		break;
  	    }
  
  	    case PEXPSCWcLevelCurves: {
***************
*** 444,455 ****
  		EXTRACT_COORD3D(&(pca->psc.data.wcLevelCurves.direction),ptr);
  		EXTRACT_CARD16(pca->psc.data.wcLevelCurves.numberIntersections,ptr);
  		SKIP_PADDING(ptr,2);
! 		pca->psc.data.wcLevelCurves.pPoints = (ddCoord3D *)
! 		    Xalloc((unsigned long) (sizeof(ddCoord3D) *
  			    pca->psc.data.wcLevelCurves.numberIntersections));
  		EXTRACT_STRUCT(	pca->psc.data.wcLevelCurves.numberIntersections,
! 				pexCoord3D, pca->psc.data.wcLevelCurves.pPoints,
  				ptr);
  	    }
  
  	}
--- 430,442 ----
  		EXTRACT_COORD3D(&(pca->psc.data.wcLevelCurves.direction),ptr);
  		EXTRACT_CARD16(pca->psc.data.wcLevelCurves.numberIntersections,ptr);
  		SKIP_PADDING(ptr,2);
! 		pca->psc.data.wcLevelCurves.pPoints = (ddFLOAT *)
! 		    Xalloc((unsigned long) (sizeof(ddFLOAT) *
  			    pca->psc.data.wcLevelCurves.numberIntersections));
  		EXTRACT_STRUCT(	pca->psc.data.wcLevelCurves.numberIntersections,
! 				PEXFLOAT, pca->psc.data.wcLevelCurves.pPoints,
  				ptr);
+ 		break;
  	    }
  
  	}
***************
*** 531,537 ****
      ddPCStr *pc;
      extern	void	DefaultPC();
  
!     if (pc = (ddPCStr *) LookupIDByType (strmPtr->pc, PEXPipeType))
  	PEX_ERR_EXIT(BadIDChoice,strmPtr->pc,cntxtPtr);
  
      pc = (ddPCStr *)Xalloc((unsigned long)(sizeof(ddPCStr) + sizeof(ddPCAttr)));
--- 518,524 ----
      ddPCStr *pc;
      extern	void	DefaultPC();
  
!     if (!LegalNewID(strmPtr->pc, cntxtPtr->client))
  	PEX_ERR_EXIT(BadIDChoice,strmPtr->pc,cntxtPtr);
  
      pc = (ddPCStr *)Xalloc((unsigned long)(sizeof(ddPCStr) + sizeof(ddPCAttr)));
***************
*** 768,773 ****
--- 755,764 ----
  					= src->pPCAttr->surfApprox.vTolerance;
      }
  
+     CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCCullingMode) {
+         dst->pPCAttr->cullMode = src->pPCAttr->cullMode;
+     }
+ 
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCDistinguishFlag) {
  	dst->pPCAttr->distFlag = src->pPCAttr->distFlag;
      }
***************
*** 950,955 ****
--- 941,952 ----
  pexContext   	 		*cntxtPtr;
  pexGetPipelineContextReq 	*strmPtr;
  {
+     /* NOTE: See the Protocol Encoding for exact details of the fields
+        returned by this command. The encoding requires CARD16 and INT16
+        to be sent in 4 byte fields (CARD32) for most fields of these 
+        types, hence the use of PACK_CARD32 for these fields. - JSH
+     */
+ 
      ErrorCode err = Success;
      ddPCStr *pc;
      ddPCAttr *pca;
***************
*** 958,963 ****
--- 955,961 ----
  			    = (pexGetPipelineContextReply *)(pPEXBuffer->pHead);
      CARD8 *replyPtr = (CARD8 *)(reply);
      int size = 0;
+     int sze = 0;
  
      LU_PIPELINECONTEXT(strmPtr->pc, pc);
  
***************
*** 972,979 ****
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCMarkerType) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->markerType, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCMarkerScale) {
--- 970,976 ----
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCMarkerType) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->markerType, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCMarkerScale) {
***************
*** 991,1012 ****
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCMarkerBundleIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->markerIndex, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCTextFont) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->textFont, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCTextPrecision) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->textPrecision, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCCharExpansion) {
--- 988,1006 ----
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCMarkerBundleIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->markerIndex, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCTextFont) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->textFont, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCTextPrecision) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->textPrecision, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCCharExpansion) {
***************
*** 1043,1050 ****
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCTextPath) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->textPath, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCTextAlignment) {
--- 1037,1043 ----
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCTextPath) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->textPath, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCTextAlignment) {
***************
*** 1070,1077 ****
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCAtextPath) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->atextPath, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCAtextAlignment) {
--- 1063,1069 ----
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCAtextPath) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->atextPath, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCAtextAlignment) {
***************
*** 1084,1105 ****
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCAtextStyle) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->atextStyle, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCTextBundleIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->textIndex, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCLineType) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->lineType, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCLineWidth) {
--- 1076,1094 ----
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCAtextStyle) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->atextStyle, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCTextBundleIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->textIndex, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCLineType) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->lineType, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCLineWidth) {
***************
*** 1117,1124 ****
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCCurveApproximation) {
  	CHK_PEX_BUF(size, sizeof(PEXFLOAT) + sizeof(CARD32), reply,
  		    pexGetPipelineContextReply, replyPtr);
! 	PACK_CARD16 ( pca->curveApprox.approxMethod, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
  	PACK_FLOAT ( pca->curveApprox.tolerance, replyPtr);
      }
  
--- 1106,1112 ----
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCCurveApproximation) {
  	CHK_PEX_BUF(size, sizeof(PEXFLOAT) + sizeof(CARD32), reply,
  		    pexGetPipelineContextReply, replyPtr);
! 	PACK_CARD32 ( pca->curveApprox.approxMethod, replyPtr);
  	PACK_FLOAT ( pca->curveApprox.tolerance, replyPtr);
      }
  
***************
*** 1125,1153 ****
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCPolylineInterp) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->lineInterp, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCLineBundleIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->lineIndex, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCInteriorStyle) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->intStyle, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCInteriorStyleIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->intStyleIndex, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSurfaceColour) {
--- 1113,1137 ----
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCPolylineInterp) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->lineInterp, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCLineBundleIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->lineIndex, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCInteriorStyle) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->intStyle, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCInteriorStyleIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->intStyleIndex, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSurfaceColour) {
***************
*** 1171,1199 ****
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSurfaceReflModel) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->reflModel, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSurfaceInterp) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->surfInterp, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCBfInteriorStyle) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->bfIntStyle, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCBfInteriorStyleIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->bfIntStyleIndex, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCBfSurfaceColour) {
--- 1155,1179 ----
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSurfaceReflModel) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->reflModel, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSurfaceInterp) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->surfInterp, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCBfInteriorStyle) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->bfIntStyle, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCBfInteriorStyleIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->bfIntStyleIndex, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCBfSurfaceColour) {
***************
*** 1217,1247 ****
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCBfSurfaceReflModel) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->bfReflModel, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCBfSurfaceInterp) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->bfSurfInterp, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSurfaceApproximation) {
  	CHK_PEX_BUF(size, sizeof(CARD32) + 2 * sizeof(PEXFLOAT), reply,
  		    pexGetPipelineContextReply, replyPtr);
! 	PACK_CARD16 ( pca->surfApprox.approxMethod, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
  	PACK_FLOAT ( pca->surfApprox.uTolerance, replyPtr);
  	PACK_FLOAT ( pca->surfApprox.vTolerance, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCDistinguishFlag) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD8 ( pca->distFlag, replyPtr);
! 	SKIP_PADDING (replyPtr, 3);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCPatternSize) {
--- 1197,1229 ----
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCBfSurfaceReflModel) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->bfReflModel, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCBfSurfaceInterp) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->bfSurfInterp, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSurfaceApproximation) {
  	CHK_PEX_BUF(size, sizeof(CARD32) + 2 * sizeof(PEXFLOAT), reply,
  		    pexGetPipelineContextReply, replyPtr);
! 	PACK_CARD32 ( pca->surfApprox.approxMethod, replyPtr);
  	PACK_FLOAT ( pca->surfApprox.uTolerance, replyPtr);
  	PACK_FLOAT ( pca->surfApprox.vTolerance, replyPtr);
      }
  
+     CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCCullingMode) {
+         CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
+                     replyPtr);
+         PACK_CARD32 ( pca->cullMode, replyPtr);
+     }
+ 
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCDistinguishFlag) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->distFlag, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCPatternSize) {
***************
*** 1278,1299 ****
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCInteriorBundleIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->intIndex, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSurfaceEdgeFlag) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->edges, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSurfaceEdgeType) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->edgeType, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSurfaceEdgeWidth) {
--- 1260,1278 ----
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCInteriorBundleIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->intIndex, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSurfaceEdgeFlag) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->edges, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSurfaceEdgeType) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->edgeType, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSurfaceEdgeWidth) {
***************
*** 1311,1318 ****
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCEdgeBundleIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->edgeIndex, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCLocalTransform) {
--- 1290,1296 ----
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCEdgeBundleIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->edgeIndex, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCLocalTransform) {
***************
*** 1336,1354 ****
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCModelClip) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->modelClip, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCModelClipVolume) {
  	int i;
! 	pexHalfSpace **pphs = (pexHalfSpace **)(pca->modelClipVolume->pList);
  	CHK_PEX_BUF(size, sizeof(CARD32)+(pca->modelClipVolume->numObj * sizeof(pexHalfSpace)),
  	    reply, pexGetPipelineContextReply, replyPtr);
  	PACK_CARD32 ( pca->modelClipVolume->numObj, replyPtr);
! 	for (i=0; i<pca->modelClipVolume->numObj; i++) {
! 	    PACK_COORD3D( (&((*pphs)->point)), replyPtr);
! 	    PACK_VECTOR3D( (&((*pphs)->vector)), replyPtr);
  	}
      }
  
--- 1314,1331 ----
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCModelClip) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->modelClip, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCModelClipVolume) {
  	int i;
! 	pexHalfSpace *pphs = (pexHalfSpace *)(pca->modelClipVolume->pList);
  	CHK_PEX_BUF(size, sizeof(CARD32)+(pca->modelClipVolume->numObj * sizeof(pexHalfSpace)),
  	    reply, pexGetPipelineContextReply, replyPtr);
  	PACK_CARD32 ( pca->modelClipVolume->numObj, replyPtr);
! 	for (i=0; i<pca->modelClipVolume->numObj; i++, pphs++) {
! 	    PACK_COORD3D( &pphs->point, replyPtr);
! 	    PACK_VECTOR3D( &pphs->vector, replyPtr);
  	}
      }
  
***************
*** 1355,1362 ****
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCViewIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->viewIndex, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCLightState) {
--- 1332,1338 ----
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCViewIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->viewIndex, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCLightState) {
***************
*** 1364,1387 ****
  		    replyPtr);
  	PACK_CARD32 ( pca->lightState, replyPtr);
  */	int i;
  	CARD16 *pLS = (CARD16 *)(pca->lightState->pList);
! 	CHK_PEX_BUF(size,sizeof(CARD32)+(pca->lightState->numObj*sizeof(CARD16)),
  		    reply, pexGetPipelineContextReply, replyPtr);
  	PACK_CARD32(pca->lightState->numObj, replyPtr);
! 	for (i=0; i<pca->lightState->numObj; i++) {
! 	    PACK_CARD16(pLS, replyPtr); }
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCDepthCueIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->depthCueIndex, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSetAsfValues) {
! 	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
  	PACK_CARD32 ( pca->asfs, replyPtr);
      }
  
--- 1340,1369 ----
  		    replyPtr);
  	PACK_CARD32 ( pca->lightState, replyPtr);
  */	int i;
+ 	int sz = pca->lightState->numObj*sizeof(CARD16);
  	CARD16 *pLS = (CARD16 *)(pca->lightState->pList);
! 	CHK_PEX_BUF(size,sizeof(CARD32)+sz+PADDING(sz),
  		    reply, pexGetPipelineContextReply, replyPtr);
  	PACK_CARD32(pca->lightState->numObj, replyPtr);
! 	for (i=0; i<pca->lightState->numObj; i++, pLS++) {
! 	    PACK_CARD16(*pLS, replyPtr); 
! 	}
!         if (pca->lightState->numObj % 2)
! 	    SKIP_PADDING(replyPtr,2);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCDepthCueIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->depthCueIndex, replyPtr);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCSetAsfValues) {
! 	CARD32  asf_enables;
! 	CHK_PEX_BUF(size, 2*sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
+         asf_enables = ASF_ALL;
+ 	PACK_CARD32 ( asf_enables, replyPtr);
  	PACK_CARD32 ( pca->asfs, replyPtr);
      }
  
***************
*** 1406,1413 ****
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCColourApproxIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD16 ( pca->colourApproxIndex, replyPtr);
! 	SKIP_PADDING (replyPtr, 2);
      }
  
      pPEXBuffer->dataSize = (int)replyPtr - (int)(pPEXBuffer->pBuf); 
--- 1388,1463 ----
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCColourApproxIndex) {
  	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
  		    replyPtr);
! 	PACK_CARD32 ( pca->colourApproxIndex, replyPtr);
!     }
! 
!     CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCRenderingColourModel) {
! 	CHK_PEX_BUF(size, sizeof(CARD32), reply, pexGetPipelineContextReply,
! 		    replyPtr);
! 	PACK_CARD32 ( pca->rdrColourModel, replyPtr);
!     }
! 
!     CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPCParaSurfCharacteristics) {
! 	switch (pca->psc.type) {
!             case PEXPSCNone:
! 	    case PEXPSCImpDep: 
! 		sze = 0;
! 		break;
! 	    case PEXPSCIsoCurves: 
! 		sze = 8;
! 		break;
!             case PEXPSCMcLevelCurves: 
! 		sze = (6 * sizeof(PEXFLOAT)) + 4 +  
! 		  (pca->psc.data.mcLevelCurves.numberIntersections *
! 		  sizeof(PEXFLOAT)) ;
! 		break;
! 	    case PEXPSCWcLevelCurves: 
! 		sze = (6 * sizeof(PEXFLOAT)) + 4 +  
! 		  (pca->psc.data.wcLevelCurves.numberIntersections *
! 		  sizeof(PEXFLOAT)) ;
! 		break;
! 	    default:
! 		sze = 0;
! 		break;
! 	}
! 
! 	CHK_PEX_BUF(size, sizeof(CARD32)+sze, reply, pexGetPipelineContextReply,
! 		    replyPtr);
! 	PACK_INT16(pca->psc.type, replyPtr);
! 	PACK_INT16(sze, replyPtr);
! 	switch (pca->psc.type) {
! 	    case PEXPSCNone:
! 	    case PEXPSCImpDep:
! 		break;
! 	    case PEXPSCIsoCurves: {
! 		PACK_CARD16(pca->psc.data.isoCurves.placementType, replyPtr);
! 		SKIP_PADDING(replyPtr,2);
! 		PACK_CARD16(pca->psc.data.isoCurves.numUcurves, replyPtr);
! 		PACK_CARD16(pca->psc.data.isoCurves.numVcurves, replyPtr);
! 		break;
! 	    }
! 	    case PEXPSCMcLevelCurves: {
! 		PACK_COORD3D(&(pca->psc.data.mcLevelCurves.origin),replyPtr);
! 		PACK_COORD3D(&(pca->psc.data.mcLevelCurves.direction),replyPtr);
! 		PACK_CARD16(pca->psc.data.mcLevelCurves.numberIntersections,replyPtr);
! 		SKIP_PADDING(replyPtr,2);
! 		PACK_LISTOF_STRUCT(pca->psc.data.mcLevelCurves.numberIntersections,
! 			    PEXFLOAT, pca->psc.data.mcLevelCurves.pPoints,
! 			    replyPtr);
! 		break;
! 	    }
! 
! 	    case PEXPSCWcLevelCurves: {
! 		PACK_COORD3D(&(pca->psc.data.wcLevelCurves.origin),replyPtr);
! 		PACK_COORD3D(&(pca->psc.data.wcLevelCurves.direction),replyPtr);
! 		PACK_CARD16(pca->psc.data.wcLevelCurves.numberIntersections,replyPtr);
! 		SKIP_PADDING(replyPtr,2);
! 		PACK_LISTOF_STRUCT(pca->psc.data.wcLevelCurves.numberIntersections,
! 				PEXFLOAT, pca->psc.data.wcLevelCurves.pPoints,
! 				replyPtr);
! 		break;
! 	    }
! 	}
      }
  
      pPEXBuffer->dataSize = (int)replyPtr - (int)(pPEXBuffer->pBuf); 
*** -	Thu Jan 28 17:50:35 1993
--- mit/extensions/server/PEX/dipex/objects/pexNs.c	Thu Jan 28 17:50:35 1993
***************
*** 1,4 ****
! /* $XConsortium: pexNs.c,v 5.1 91/02/16 09:56:49 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pexNs.c,v 5.2 92/12/01 17:17:57 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 53,60 ****
      ErrorCode FreeNameSet (), CreateNameSet ();
      diNSHandle nsptr;
  
!     if (nsptr = (diNSHandle) LookupIDByType (strmPtr->id, PEXNameType))
  	PEX_ERR_EXIT(BadIDChoice,strmPtr->id,cntxtPtr);
  
      nsptr = (diNSHandle) Xalloc ((unsigned long)sizeof(ddNSResource));
      if (!nsptr) PEX_ERR_EXIT(BadAlloc,0,cntxtPtr);
--- 53,61 ----
      ErrorCode FreeNameSet (), CreateNameSet ();
      diNSHandle nsptr;
  
!     if (!LegalNewID(strmPtr->id, cntxtPtr->client))
  	PEX_ERR_EXIT(BadIDChoice,strmPtr->id,cntxtPtr);
+ 
  
      nsptr = (diNSHandle) Xalloc ((unsigned long)sizeof(ddNSResource));
      if (!nsptr) PEX_ERR_EXIT(BadAlloc,0,cntxtPtr);
*** -	Thu Jan 28 17:50:36 1993
--- mit/extensions/server/PEX/dipex/objects/pexStr.c	Thu Jan 28 17:50:36 1993
***************
*** 1,4 ****
! /* $XConsortium: pexStr.c,v 5.2 91/03/15 18:26:57 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pexStr.c,v 5.3 92/12/01 17:17:58 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 73,79 ****
      ErrorCode DeleteStructure ();
      diStructHandle sh;
  
!     if (sh = (diStructHandle) LookupIDByType (strmPtr->id, PEXStructType))
  	PEX_ERR_EXIT(BadIDChoice,strmPtr->id,cntxtPtr);
  
      sh = (diStructHandle)Xalloc((unsigned long)sizeof(ddStructResource));
--- 73,79 ----
      ErrorCode DeleteStructure ();
      diStructHandle sh;
  
!     if (!LegalNewID(strmPtr->id, cntxtPtr->client))
  	PEX_ERR_EXIT(BadIDChoice,strmPtr->id,cntxtPtr);
  
      sh = (diStructHandle)Xalloc((unsigned long)sizeof(ddStructResource));
*** -	Thu Jan 28 17:50:37 1993
--- mit/extensions/server/PEX/dipex/objects/Imakefile	Thu Jan 28 17:50:37 1993
***************
*** 1,5 ****
  XCOMM
! XCOMM $XConsortium: Imakefile,v 5.4 91/07/24 17:00:54 rws Exp $
  XCOMM
  XCOMM 
  XCOMM Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium
--- 1,5 ----
  XCOMM
! XCOMM $XConsortium: Imakefile,v 5.5 92/03/04 14:16:00 hersh Exp $
  XCOMM
  XCOMM 
  XCOMM Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium
***************
*** 48,57 ****
  
  
  SRCS =  pexRndr.c pexFont.c pexLut.c pexNs.c pexStr.c \
! 	pexPhigs.c pexInfo.c pexSc.c pexPick.c pexPc.c
  
  OBJS =  pexRndr.o pexFont.o pexLut.o pexNs.o pexStr.o \
! 	pexPhigs.o pexInfo.o pexSc.o pexPick.o pexPc.o
  
  NormalLibraryObjectRule()
  NormalLibraryTarget(diobpex,$(OBJS))
--- 48,57 ----
  
  
  SRCS =  pexRndr.c pexFont.c pexLut.c pexNs.c pexStr.c \
! 	pexPhigs.c pexInfo.c pexSc.c pexPick.c pexPc.c pexRndrPick.c
  
  OBJS =  pexRndr.o pexFont.o pexLut.o pexNs.o pexStr.o \
! 	pexPhigs.o pexInfo.o pexSc.o pexPick.o pexPc.o pexRndrPick.o
  
  NormalLibraryObjectRule()
  NormalLibraryTarget(diobpex,$(OBJS))
*** -	Thu Jan 28 17:50:38 1993
--- mit/extensions/server/PEX/dipex/objects/pexFont.c	Thu Jan 28 17:50:37 1993
***************
*** 1,4 ****
! /* $XConsortium: pexFont.c,v 5.3 91/07/02 09:51:45 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pexFont.c,v 5.6 92/12/01 17:18:00 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 51,61 ****
--- 51,63 ----
  #endif /* X_NOT_POSIX */
  #ifndef PATH_MAX
  #include <sys/param.h>
+ #ifndef PATH_MAX
  #ifdef MAXPATHLEN
  #define PATH_MAX MAXPATHLEN
  #else
  #define PATH_MAX 1024
  #endif
+ #endif
  #endif /* PATH_MAX */
  
  #ifdef min
***************
*** 90,100 ****
      extern void CopyISOLatin1Lowered();
  
      /* oh, who cares if it's already been opened under this id */
!     if (!(dif = (dipexFont *) LookupIDByType (strmPtr->font, PEXFontType) )) {
  
  	/* has this server already loaded this font */
  	CopyISOLatin1Lowered(	fName, (unsigned char *)(strmPtr+1),
! 				(int)(strmPtr->length));
  
  	dif = FindPEXFontEntry(fName);
  
--- 92,103 ----
      extern void CopyISOLatin1Lowered();
  
      /* oh, who cares if it's already been opened under this id */
! 	if (!LegalNewID(strmPtr->font,  cntxtPtr->client)) 
! 	    PEX_ERR_EXIT(BadIDChoice,strmPtr->font,cntxtPtr);
  
  	/* has this server already loaded this font */
  	CopyISOLatin1Lowered(	fName, (unsigned char *)(strmPtr+1),
! 				(int)(strmPtr->numBytes));
  
  	dif = FindPEXFontEntry(fName);
  
***************
*** 108,114 ****
  	    dif->ddFont.id = strmPtr->font;
  	    dif->refcnt = 1;
  
! 	    err = OpenPEXFont(	(ddULONG)(strmPtr->length), 
  				(ddUCHAR *)(strmPtr + 1), &(dif->ddFont));
  	    if (err) {
  		Xfree((pointer)dif);
--- 111,117 ----
  	    dif->ddFont.id = strmPtr->font;
  	    dif->refcnt = 1;
  
! 	    err = OpenPEXFont(	(ddULONG)(strmPtr->numBytes), 
  				(ddUCHAR *)(strmPtr + 1), &(dif->ddFont));
  	    if (err) {
  		Xfree((pointer)dif);
***************
*** 115,123 ****
  		PEX_ERR_EXIT(err,0,cntxtPtr);
  	    }
  
  	ADDRESOURCE(strmPtr->font, PEXFontType, dif);
  
! 	} }
  
      return(err);
  
--- 118,136 ----
  		PEX_ERR_EXIT(err,0,cntxtPtr);
  	    }
  
+ 	/*
+          * Note that fonts resources are stored with the type (dipexFont *),
+          * and they are referenced sometimes in the DD layer as diFontHandle
+          * (which is a pointer to a ddFontResource).  Since the first part
+          * of the dipexFont structure consists of a ddFontResource, this
+          * works.  Even though it is ugly, it's best not to start changing
+          * all of the font code at this time (right before a public release),
+          * and hopefully, it will get cleaned up for PEX 6.0.
+ 	 */
+ 
  	ADDRESOURCE(strmPtr->font, PEXFontType, dif);
  
! 	} 
  
      return(err);
  
*** -	Thu Jan 28 17:50:39 1993
--- mit/extensions/server/PEX/dipex/objects/pexLut.c	Thu Jan 28 17:50:38 1993
***************
*** 1,4 ****
! /* $XConsortium: pexLut.c,v 5.1 91/02/16 09:56:53 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pexLut.c,v 5.3 92/12/01 17:18:02 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 74,81 ****
      if (!VALID_TABLETYPE(strmPtr->tableType))
  	PEX_ERR_EXIT(BadValue,strmPtr->tableType,cntxtPtr);
  
!     lutptr = (diLUTHandle) LookupIDByType (strmPtr->lut, PEXLutType);
!     if (lutptr) PEX_ERR_EXIT(BadIDChoice,strmPtr->lut,cntxtPtr); 
  
      LU_DRAWABLE(strmPtr->drawableExample, pdraw);
  
--- 74,81 ----
      if (!VALID_TABLETYPE(strmPtr->tableType))
  	PEX_ERR_EXIT(BadValue,strmPtr->tableType,cntxtPtr);
  
!     if (!LegalNewID(strmPtr->lut, cntxtPtr->client))
! 	PEX_ERR_EXIT(BadIDChoice,strmPtr->lut,cntxtPtr);
  
      LU_DRAWABLE(strmPtr->drawableExample, pdraw);
  
***************
*** 255,260 ****
--- 255,272 ----
  			    &status, pPEXBuffer);
      if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
  
+     /*
+      * If this is a font table, we have to convert font handles to font ids.
+      */
+ 
+     if (pf->lutType == PEXTextFontLUT) {
+ 	int i;
+ 	pexTextFontEntry *ptfe = (pexTextFontEntry *)(pPEXBuffer->pBuf);
+ 	pexFont *ptr = (pexFont *)(ptfe + 1);
+ 	for (i=0; i<ptfe->numFonts; i++, ptr++)
+ 	    *ptr = ((diFontHandle) *ptr)->id;
+     }
+ 
      {
  	SETUP_VAR_REPLY(pexGetTableEntryReply);
  	reply->status = status;
***************
*** 285,290 ****
--- 297,317 ----
  				strmPtr->valueType, &numEntries, pPEXBuffer);
      if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
  
+     /*
+      * If this is a font table, we have to convert font handles to font ids.
+      */
+ 
+     if (pf->lutType == PEXTextFontLUT) {
+ 	int i, j;
+ 	pexTextFontEntry *ptfe = (pexTextFontEntry *)(pPEXBuffer->pBuf);
+  	for (i=0; i<strmPtr->count; i++) {
+  	    pexFont *ptr = (pexFont *)(ptfe + 1);
+  	    for (j=0; j<ptfe->numFonts; j++, ptr++)
+  		*ptr = ((diFontHandle) *ptr)->id;
+  	    ptfe = (pexTextFontEntry *) ptr;
+   	}
+     }
+ 
      {
  	SETUP_VAR_REPLY(pexGetTableEntriesReply);
  	reply->tableType = pf->lutType;
***************
*** 314,326 ****
  	the that longword, so ddpex gets its handles instead of ids.
       */
      if (pf->lutType == PEXTextFontLUT) {
! 	int i;
  	diFontHandle fh;
! 	pexFont *ptr = (pexFont *)(strmPtr + 1);
! 	for (i=0; i<strmPtr->count; i++, ptr++) {
! 	    LU_PEXFONT(*ptr, fh);
! 	    ptr = (pexFont *)fh;
! 	}
      }
  
      err = SetLUTEntries(    pf, strmPtr->start, strmPtr->count,
--- 341,357 ----
  	the that longword, so ddpex gets its handles instead of ids.
       */
      if (pf->lutType == PEXTextFontLUT) {
! 	int i, j;
  	diFontHandle fh;
! 	pexTextFontEntry *ptfe = (pexTextFontEntry *)(strmPtr + 1);
!  	for (i=0; i<strmPtr->count; i++) {
!  	    pexFont *ptr = (pexFont *)(ptfe + 1);
!  	    for (j=0; j<ptfe->numFonts; j++, ptr++) {
!  		LU_PEXFONT(*ptr, fh);
!  		*ptr = (pexFont) fh;
!  	    }
!  	    ptfe = (pexTextFontEntry *) ptr;
!   	}
      }
  
      err = SetLUTEntries(    pf, strmPtr->start, strmPtr->count,
*** -	Thu Jan 28 17:50:41 1993
--- mit/extensions/server/PEX/dipex/objects/pexRndr.c	Thu Jan 28 17:50:39 1993
***************
*** 1,4 ****
! /* $XConsortium: pexRndr.c,v 5.4 91/07/15 15:13:57 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pexRndr.c,v 5.23 92/12/03 19:56:51 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 33,38 ****
--- 33,40 ----
   *	PEXEndRendering
   *	PEXBeginStructure
   *	PEXEndStructure
+  *	PEXRenderElements
+  *	PEXAccumulateState
   *	PEXRenderNetwork
   *	PEXRenderOutputCommands
   --*/
***************
*** 48,53 ****
--- 50,56 ----
  #include "X.h"
  #include "pexError.h"
  #include "ddpex3.h"
+ #include "ddpex4.h"
  #include "pexLookup.h"
  #include "pexExtract.h"
  #include "pexUtils.h"
***************
*** 98,127 ****
  
  
  #define CHK_PEX_BUF(SIZE,INCR,REPLY,TYPE,PTR) { \
! 	SIZE+=INCR; \
! 	if (pPEXBuffer->dataSize < SIZE) { \
  	    ErrorCode err = Success; \
! 	    int offset = (int)ptr - (int)(pPEXBuffer->pHead); \
  	    err = puBuffRealloc(pPEXBuffer,(ddULONG)(SIZE)); \
  	    if (err) PEX_ERR_EXIT(err,0,cntxtPtr); \
! 	    REPLY = (TYPE *)(pPEXBuffer->pHead); \
! 	    PTR = (unsigned char *)(pPEXBuffer->pHead + offset); } \
      }
  
  
  
! /*
!     From mail from Sally C. Barry
! */
! #define CO_(mask)   ((mask) \
! 		    - (((mask)>>1)&0x77777777) \
! 		    - (((mask)>>1)&0x33333333) \
! 		    - (((mask)>>1)&0x11111111))
  
- #define CountOnes(mask, countReturn) \
-     countReturn = (((CO_(mask)+(CO_(mask)>>4)) & 0x0F0F0F0F) % 255)
  
- 
  extern ErrorCode UpdatePCRefs();
  
  
--- 101,127 ----
  
  
  #define CHK_PEX_BUF(SIZE,INCR,REPLY,TYPE,PTR) { \
! 	(SIZE)+=(INCR); \
! 	if (pPEXBuffer->bufSize < (SIZE)) { \
  	    ErrorCode err = Success; \
! 	    int offset = (int)(((unsigned char *)(PTR)) - ((unsigned char *)(pPEXBuffer->pHead))); \
  	    err = puBuffRealloc(pPEXBuffer,(ddULONG)(SIZE)); \
  	    if (err) PEX_ERR_EXIT(err,0,cntxtPtr); \
! 	    (REPLY) = (TYPE *)(pPEXBuffer->pHead); \
! 	    (PTR) = (unsigned char *)(pPEXBuffer->pHead + offset); } \
      }
  
  
  
! #define CountOnes(mask, countReturn)                            \
!   {                                                             \
!     register unsigned long y;                                   \
!     y = ((mask) >> 1) &033333333333;                            \
!     y = (mask) - y - ((y >>1) & 033333333333);                  \
!     countReturn = (((y + (y >> 3)) & 030707070707) % 077);      \
!   }
  
  
  extern ErrorCode UpdatePCRefs();
  
  
***************
*** 136,143 ****
      ErrorCode freeRenderer();
      ddRendererStr *prend = 0;
      CARD8 *ptr = (CARD8 *)(strmPtr+1);
  	
!     if (prend = (ddRendererStr *) LookupIDByType (strmPtr->rdr, PEXRendType))
  	PEX_ERR_EXIT(BadIDChoice,strmPtr->rdr,cntxtPtr);
  
      prend = (ddRendererStr *) Xalloc ((unsigned long)(sizeof(ddRendererStr)));
--- 136,147 ----
      ErrorCode freeRenderer();
      ddRendererStr *prend = 0;
      CARD8 *ptr = (CARD8 *)(strmPtr+1);
+     XID  fakepm, fakeStrID;
+     diStructHandle    fakeStr;   
+     ddPickPath		fakeStrpp, sIDpp;
+ 
  	
!     if (!LegalNewID(strmPtr->rdr, cntxtPtr->client))
  	PEX_ERR_EXIT(BadIDChoice,strmPtr->rdr,cntxtPtr);
  
      prend = (ddRendererStr *) Xalloc ((unsigned long)(sizeof(ddRendererStr)));
***************
*** 153,164 ****
      prend->drawExample.rootDepth = prend->pDrawable->pScreen->rootDepth;
      prend->drawExample.rootVisual = prend->pDrawable->pScreen->rootVisual;
  
-     prend->curPath = puCreateList(DD_ELEMENT_REF);	
-     if (!(prend->curPath)) {
-         Xfree((pointer)prend);
-         PEX_ERR_EXIT(BadAlloc,0,cntxtPtr);
-     }
- 
      prend->state = PEXIdle;
      /* renderer dynamics masks are set by ddPEX */
      prend->tablesMask = 0;
--- 157,162 ----
***************
*** 181,187 ****
--- 179,240 ----
      prend->ns[(unsigned)DD_HIGH_EXCL_NS] = 0;
      prend->ns[(unsigned)DD_INVIS_INCL_NS] = 0;
      prend->ns[(unsigned)DD_INVIS_EXCL_NS] = 0;
+     prend->ns[(unsigned)DD_PICK_INCL_NS] = 0;
+     prend->ns[(unsigned)DD_PICK_EXCL_NS] = 0;
  
+     /* Create the Psuedo Pick Measure. Real values are filled
+        in with ChangePsuedoPickMeasure called by BeginPickXXX routines
+     */
+     fakepm = FakeClientID(cntxtPtr->client->index);
+     prend->pickstr.client = cntxtPtr->client;
+     prend->pickstr.pseudoPM = (diPMHandle) Xalloc ((unsigned long)sizeof(ddPMResource));
+     if (!prend->pickstr.pseudoPM)  PEX_ERR_EXIT(BadAlloc,0,cntxtPtr);
+     (prend->pickstr.pseudoPM)->id = fakepm;
+     err = CreatePseudoPickMeasure (prend);
+     if (err){
+ 	Xfree((pointer)(prend->pickstr.pseudoPM));
+ 	PEX_ERR_EXIT(err,0,cntxtPtr);	
+     }
+     /* the fakepm resource gets added at the end of this routine now */
+ 
+ 
+     /* create listoflist for doing Pick All */
+     prend->pickstr.list = puCreateList(DD_LIST_OF_LIST);
+     prend->immediateMode = TRUE;
+ 
+     /* create a phony structure to pack OCs into 
+        for doing immediate mode renderer picking
+     */
+     fakeStr = (diStructHandle)Xalloc((unsigned long)
+ 					  sizeof(ddStructResource));
+     if (!fakeStr) PEX_ERR_EXIT(BadAlloc,0,cntxtPtr);
+     fakeStr->id = -666;
+     err = CreateStructure(fakeStr);
+     if (err) {
+ 	Xfree((pointer)(fakeStr));
+ 	PEX_ERR_EXIT(err,0,cntxtPtr);
+     }
+ 
+     /* Now create 2 ddPickPaths, one for the fakeStrlist and the other
+        for maintaining the correspondence between the user supplied 
+        structure ID and the structure handle
+     */
+ 
+     fakeStrpp.structure = fakeStr;
+     fakeStrpp.offset = 0;
+     fakeStrpp.pickid = 0;
+     prend->pickstr.fakeStrlist = puCreateList(DD_PICK_PATH);
+     err = puAddToList((ddPointer) &fakeStrpp, (ddULONG) 1, prend->pickstr.fakeStrlist);
+     if (err != Success) return(err);
+ 
+     sIDpp.structure = fakeStr;
+     sIDpp.offset = 0;
+     sIDpp.pickid = 0;
+     prend->pickstr.sIDlist = puCreateList(DD_PICK_PATH);
+     err = puAddToList((ddPointer) &sIDpp, (ddULONG) 1, prend->pickstr.sIDlist);
+     if (err != Success) return(err);
+ 
+ 
      if (strmPtr->itemMask & PEXRDPipelineContext) {
  	ddPCStr *ppc = 0;
  	LU_PIPELINECONTEXT((*((CARD32 *)ptr)), ppc);
***************
*** 193,204 ****
  	    PEX_ERR_EXIT(err,0,cntxtPtr); }
      } else prend->pPC = 0;
  
      if (strmPtr->itemMask & PEXRDCurrentPath)  {
! 	puDeleteList(prend->curPath);
! 	if (prend->pPC)
! 	    (void)UpdatePCRefs (prend->pPC, prend, (ddAction)(REMOVE));
! 	Xfree((pointer)prend);
! 	PEX_ERR_EXIT(BadValue,0,cntxtPtr);
      }
  
      if (strmPtr->itemMask & PEXRDMarkerBundle)
--- 246,264 ----
  	    PEX_ERR_EXIT(err,0,cntxtPtr); }
      } else prend->pPC = 0;
  
+ 
+     prend->curPath = puCreateList(DD_ELEMENT_REF);	
+     if (!(prend->curPath)) {
+         Xfree((pointer)prend);
+         PEX_ERR_EXIT(BadAlloc,0,cntxtPtr);
+     }
      if (strmPtr->itemMask & PEXRDCurrentPath)  {
! 	unsigned long npaths;
! 
! 	/* Protocol says ignore this so skip past it in the Request Stream */
! 	npaths = *(CARD32 *)ptr;
! 	SKIP_PADDING(ptr,sizeof(CARD32));
! 	SKIP_STRUCT(ptr, npaths, pexElementRef);
      }
  
      if (strmPtr->itemMask & PEXRDMarkerBundle)
***************
*** 249,257 ****
      if (strmPtr->itemMask & PEXRDInvisibilityExcl)
  	CHANGENS(DD_INVIS_EXCL_NS, PEXDynInvisibilityNameset);
  
      if (strmPtr->itemMask & PEXRDHlhsrMode) {
! 	EXTRACT_INT16(prend->hlhsrMode,ptr);
! 	SKIP_PADDING(ptr,sizeof(CARD16));
      } else prend->hlhsrMode = PEXHlhsrOff;		/* default */
  
      if (strmPtr->itemMask & PEXRDNpcSubvolume) { 
--- 309,321 ----
      if (strmPtr->itemMask & PEXRDInvisibilityExcl)
  	CHANGENS(DD_INVIS_EXCL_NS, PEXDynInvisibilityNameset);
  
+     if (strmPtr->itemMask & PEXRDRendererState) {
+ 	/* Protocol says ignore this it's read-only */
+ 	SKIP_PADDING(ptr,sizeof(CARD32));
+     }
+ 
      if (strmPtr->itemMask & PEXRDHlhsrMode) {
! 	EXTRACT_INT16_FROM_4B(prend->hlhsrMode,ptr);
      } else prend->hlhsrMode = PEXHlhsrOff;		/* default */
  
      if (strmPtr->itemMask & PEXRDNpcSubvolume) { 
***************
*** 268,278 ****
  
  
      if (strmPtr->itemMask & PEXRDViewport) {
! 	EXTRACT_CARD16(prend->viewport.minval.x,ptr);
! 	EXTRACT_CARD16(prend->viewport.minval.y,ptr);
  	EXTRACT_FLOAT(prend->viewport.minval.z,ptr);
! 	EXTRACT_CARD16(prend->viewport.maxval.x,ptr);
! 	EXTRACT_CARD16(prend->viewport.maxval.y,ptr);
  	EXTRACT_FLOAT(prend->viewport.maxval.z,ptr);
  	EXTRACT_CARD8(prend->viewport.useDrawable,ptr);
  	SKIP_PADDING(ptr,(sizeof(CARD8)+sizeof(CARD16)));
--- 332,342 ----
  
  
      if (strmPtr->itemMask & PEXRDViewport) {
! 	EXTRACT_INT16(prend->viewport.minval.x,ptr);
! 	EXTRACT_INT16(prend->viewport.minval.y,ptr);
  	EXTRACT_FLOAT(prend->viewport.minval.z,ptr);
! 	EXTRACT_INT16(prend->viewport.maxval.x,ptr);
! 	EXTRACT_INT16(prend->viewport.maxval.y,ptr);
  	EXTRACT_FLOAT(prend->viewport.maxval.z,ptr);
  	EXTRACT_CARD8(prend->viewport.useDrawable,ptr);
  	SKIP_PADDING(ptr,(sizeof(CARD8)+sizeof(CARD16)));
***************
*** 298,303 ****
--- 362,441 ----
  	SKIP_STRUCT(ptr, nrects, pexDeviceRect);
      }; /* else prend->clipList = 0;*/				/* default */
  
+     if (strmPtr->itemMask & PEXRDPickInclusion) {
+ 	CHANGENS(DD_PICK_INCL_NS, PEXDynPickNameset);
+     }
+ 
+     if (strmPtr->itemMask & PEXRDPickExclusion) {
+ 	CHANGENS(DD_PICK_EXCL_NS, PEXDynPickNameset);
+     }
+ 
+ 
+     prend->pickStartPath = puCreateList(DD_PICK_PATH);	
+     if (!(prend->pickStartPath)) {
+         Xfree((pointer)prend);
+         PEX_ERR_EXIT(BadAlloc,0,cntxtPtr);
+     }
+     if (strmPtr->itemMask & PEXRDPickStartPath) {
+ 	pexElementRef *per;
+ 	diStructHandle sh, *psh;
+ 	ddPickPath	*ppath, *ppathStart;
+ 	CARD32 i, numpaths;
+ 	extern ddpex3rtn ValidatePickPath();
+ 
+ 	/* must convert list of Element Ref into Pick Path for internal
+ 	   storage and use 
+ 	*/
+ 	EXTRACT_CARD32( numpaths, ptr);
+ 	ppath = (ddPickPath *)Xalloc(numpaths * sizeof(ddPickPath));
+ 	ppathStart = ppath;
+ 
+ 	for (i=0, per = (pexElementRef *)ptr; i<numpaths; i++, per++,
+ 	  ppath++) {
+ 		LU_STRUCTURE(per->structure,sh);
+ 		ppath->structure = sh;
+ 		ppath->offset = per->offset;
+ 		ppath->pickid = 0;
+ 	  }
+ 
+ 	puAddToList((ddPointer)ppathStart, numpaths, prend->pickStartPath);
+ 	err = ValidatePickPath(prend->pickStartPath);
+ 	if (err != Success) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 	ptr = (unsigned char *)per;
+ 	Xfree((pointer)ppath);
+     }
+ 
+     if (strmPtr->itemMask & PEXRDBackgroundColour) {
+ 	EXTRACT_COLOUR_SPECIFIER(prend->backgroundColour,ptr);
+     }
+     else						/* default */
+     {
+       prend->backgroundColour.colourType = PEXIndexedColour;
+       prend->backgroundColour.colour.indexed.index = 0;
+     }
+ 
+     if (strmPtr->itemMask & PEXRDClearI) {
+ 	EXTRACT_CARD8_FROM_4B(prend->clearI,ptr);
+     }
+     else						/* default */
+       prend->clearI = xFalse;
+ 
+     if (strmPtr->itemMask & PEXRDClearZ) {
+ 	EXTRACT_CARD8_FROM_4B(prend->clearZ,ptr);
+     }
+     else						/* default */
+       prend->clearZ = xTrue;
+ 
+     if (strmPtr->itemMask & PEXRDEchoMode) {
+ 	EXTRACT_CARD16_FROM_4B(prend->echoMode,ptr);
+     }
+     else						/* default */
+       prend->echoMode = PEXNoEcho;
+ 
+     /* set the default echoColour */
+     prend->echoColour.colourType = PEXIndexedColour;
+     prend->echoColour.colour.indexed.index = 0;
+ 
      err = InitRenderer(prend);
      if (err) {
  	puDeleteList(prend->clipList);
***************
*** 309,314 ****
--- 447,453 ----
      };
  
      ADDRESOURCE(strmPtr->rdr, PEXRendType, prend);
+     ADDRESOURCE(fakepm, PEXPickType, prend->pickstr.pseudoPM);
      return( err );
  
  } /* end-PEXCreateRenderer() */
***************
*** 321,331 ****
--- 460,478 ----
  ddRendererStr *prend;
  pexRenderer id;
  {
+     ddPickPath 	*strpp;
+ 
      if (prend) {
  	DeleteDDContext(prend->pDDContext);
  
  	puDeleteList(prend->clipList);
  	puDeleteList(prend->curPath);
+ 	puDeleteList(prend->pickStartPath);
+ 	puDeleteList(prend->pickstr.list);
+ 	strpp = (ddPickPath *)(prend->pickstr.fakeStrlist)->pList;
+ 	DeleteStructure(strpp[0].structure, (strpp[0].structure)->id );
+ 	puDeleteList(prend->pickstr.fakeStrlist);
+ 	puDeleteList(prend->pickstr.sIDlist);
  	Xfree((pointer)prend);
      }
  
***************
*** 383,390 ****
  	prend->pPC = ppc;
      };
  
!     if (strmPtr->itemMask & PEXRDCurrentPath)
! 	PEX_ERR_EXIT(BadValue,0,cntxtPtr);
  
      if (strmPtr->itemMask & PEXRDMarkerBundle)
  	CHANGELUT(PEXMarkerBundleLUT, PEXDynMarkerBundle);
--- 530,542 ----
  	prend->pPC = ppc;
      };
  
!     if (strmPtr->itemMask & PEXRDCurrentPath) {
! 	/* Protocol Spec says ignore this field it is read-only */
! 	CARD32 i;
! 	i = *(CARD32 *)ptr;
! 	SKIP_PADDING(ptr,sizeof(CARD32));
! 	SKIP_STRUCT(ptr, i, pexElementRef);
!     }
  
      if (strmPtr->itemMask & PEXRDMarkerBundle)
  	CHANGELUT(PEXMarkerBundleLUT, PEXDynMarkerBundle);
***************
*** 434,442 ****
      if (strmPtr->itemMask & PEXRDInvisibilityExcl)
  	CHANGENS(DD_INVIS_EXCL_NS, PEXDynInvisibilityNameset);
  
      if (strmPtr->itemMask & PEXRDHlhsrMode) {
! 	EXTRACT_INT16(prend->hlhsrMode,ptr);
! 	SKIP_PADDING(ptr,sizeof(CARD16));
  	prend->attrsChanges |= PEXDynHlhsrMode;
      }
  
--- 586,598 ----
      if (strmPtr->itemMask & PEXRDInvisibilityExcl)
  	CHANGENS(DD_INVIS_EXCL_NS, PEXDynInvisibilityNameset);
  
+     if (strmPtr->itemMask & PEXRDRendererState) {
+ 	/* Spec says ignore this in Change Renderer */
+ 	SKIP_PADDING(ptr,sizeof(CARD32));
+     }
+ 
      if (strmPtr->itemMask & PEXRDHlhsrMode) {
! 	EXTRACT_INT16_FROM_4B(prend->hlhsrMode,ptr);
  	prend->attrsChanges |= PEXDynHlhsrMode;
      }
  
***************
*** 447,457 ****
      }
  
      if (strmPtr->itemMask & PEXRDViewport) {
! 	EXTRACT_CARD16(prend->viewport.minval.x,ptr);
! 	EXTRACT_CARD16(prend->viewport.minval.y,ptr);
  	EXTRACT_FLOAT(prend->viewport.minval.z,ptr);
! 	EXTRACT_CARD16(prend->viewport.maxval.x,ptr);
! 	EXTRACT_CARD16(prend->viewport.maxval.y,ptr);
  	EXTRACT_FLOAT(prend->viewport.maxval.z,ptr);
  	EXTRACT_CARD8(prend->viewport.useDrawable,ptr);
  	SKIP_PADDING(ptr,(sizeof(CARD8)+sizeof(CARD16)));
--- 603,613 ----
      }
  
      if (strmPtr->itemMask & PEXRDViewport) {
! 	EXTRACT_INT16(prend->viewport.minval.x,ptr);
! 	EXTRACT_INT16(prend->viewport.minval.y,ptr);
  	EXTRACT_FLOAT(prend->viewport.minval.z,ptr);
! 	EXTRACT_INT16(prend->viewport.maxval.x,ptr);
! 	EXTRACT_INT16(prend->viewport.maxval.y,ptr);
  	EXTRACT_FLOAT(prend->viewport.maxval.z,ptr);
  	EXTRACT_CARD8(prend->viewport.useDrawable,ptr);
  	SKIP_PADDING(ptr,(sizeof(CARD8)+sizeof(CARD16)));
***************
*** 467,472 ****
--- 623,685 ----
  	SKIP_STRUCT(ptr, nrects, pexDeviceRect);
      }
  
+     if (strmPtr->itemMask & PEXRDPickInclusion) {
+ 	CHANGENS(DD_PICK_INCL_NS, PEXDynPickNameset);
+     }
+ 
+     if (strmPtr->itemMask & PEXRDPickExclusion) {
+ 	CHANGENS(DD_PICK_EXCL_NS, PEXDynPickNameset);
+     }
+ 
+     if (strmPtr->itemMask & PEXRDPickStartPath) {
+ 	pexElementRef *per;
+ 	diStructHandle sh, *psh;
+         ddPickPath      *ppath, *ppathStart;
+ 	CARD32 i, numpaths;
+ 	extern ddpex3rtn ValidatePickPath();
+ 
+         /* must convert list of Element Ref into Pick Path for internal
+            storage and use 
+ 	*/
+ 	EXTRACT_CARD32( numpaths, ptr);
+         ppath = (ddPickPath *)Xalloc(numpaths * sizeof(ddPickPath));
+         ppathStart = ppath;
+ 
+ 	for (i=0, per = (pexElementRef *)ptr; i<numpaths; i++, per++,
+ 	  ppath++) {
+ 		LU_STRUCTURE(per->structure,sh);
+                 ppath->structure = sh;
+                 ppath->offset = per->offset;
+                 ppath->pickid = 0;
+ 	  }
+ 
+ 	PU_EMPTY_LIST(prend->pickStartPath);
+ 	puAddToList((ddPointer)ppathStart, numpaths, prend->pickStartPath);
+ 	err = ValidatePickPath(prend->pickStartPath);
+ 	if (err != Success) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 	ptr = (unsigned char *)per;
+ 	Xfree((pointer)ppath);
+     }
+ 
+ 
+     if (strmPtr->itemMask & PEXRDBackgroundColour) {
+ 	EXTRACT_COLOUR_SPECIFIER(prend->backgroundColour,ptr);
+     }
+ 
+     if (strmPtr->itemMask & PEXRDClearI) {
+ 	EXTRACT_CARD8_FROM_4B(prend->clearI,ptr);
+     }
+ 
+     if (strmPtr->itemMask & PEXRDClearZ) {
+ 	EXTRACT_CARD8_FROM_4B(prend->clearZ,ptr);
+     }
+ 
+     if (strmPtr->itemMask & PEXRDEchoMode) {
+ 	EXTRACT_CARD16_FROM_4B(prend->echoMode,ptr);
+ 	prend->attrsChanges |= PEXDynEchoMode;
+     }
+ 
+ 
      return( err );
  
  } /* end-PEXChangeRenderer() */
***************
*** 493,503 ****
      ptr = (CARD8 *) (pPEXBuffer->pBuf);
  
      lwords_mask = strmPtr->itemMask
! 			& ~(PEXRDNpcSubvolume | PEXRDViewport | PEXRDClipList);
      CountOnes(lwords_mask, num_lwords);
      num_lwords += ((strmPtr->itemMask & PEXRDCurrentPath)
  		    ? (prend->curPath->numObj * sizeof(pexElementRef) / 4) + 1
  		    : 0);
      CHK_PEX_BUF(size, sizeof(pexGetRendererAttributesReply)
  			+ num_lwords * sizeof(CARD32),
  		reply, pexGetRendererAttributesReply, ptr);
--- 706,720 ----
      ptr = (CARD8 *) (pPEXBuffer->pBuf);
  
      lwords_mask = strmPtr->itemMask
! 		  & ~(PEXRDNpcSubvolume | PEXRDViewport | PEXRDClipList |
! 		      PEXRDBackgroundColour);
      CountOnes(lwords_mask, num_lwords);
      num_lwords += ((strmPtr->itemMask & PEXRDCurrentPath)
  		    ? (prend->curPath->numObj * sizeof(pexElementRef) / 4) + 1
  		    : 0);
+     num_lwords += ((strmPtr->itemMask & PEXRDPickStartPath)
+ 		    ? (prend->pickStartPath->numObj * sizeof(pexElementRef) / 4)
+ 		    + 1 : 0);
      CHK_PEX_BUF(size, sizeof(pexGetRendererAttributesReply)
  			+ num_lwords * sizeof(CARD32),
  		reply, pexGetRendererAttributesReply, ptr);
***************
*** 510,517 ****
  	unsigned long i;
  	ddElementRef *per = (ddElementRef *)(prend->curPath->pList);
  	PACK_CARD32( prend->curPath->numObj, ptr);
! 	for (i=0, prend->curPath->pList; i<prend->curPath->numObj; i++, per++) {
! 	    sid = GetId(per->structure);
  	    PACK_CARD32(sid, ptr);
  	    PACK_CARD32(per->offset, ptr);
  	}
--- 727,737 ----
  	unsigned long i;
  	ddElementRef *per = (ddElementRef *)(prend->curPath->pList);
  	PACK_CARD32( prend->curPath->numObj, ptr);
! 	for (i=0; i<prend->curPath->numObj; i++, per++) {
! 	    /* Begin Structure uses the structure handle field to store the
! 	       ID so there is no need to look it up, just assign it
! 	    */
! 	    sid = (pexStructure) per->structure;
  	    PACK_CARD32(sid, ptr);
  	    PACK_CARD32(per->offset, ptr);
  	}
***************
*** 565,570 ****
--- 785,792 ----
      if (strmPtr->itemMask & PEXRDInvisibilityExcl)
  	PACK_CARD32( GetId(prend->ns[(unsigned)DD_INVIS_EXCL_NS]), ptr);
  
+     if (strmPtr->itemMask & PEXRDRendererState) PACK_CARD32( prend->state, ptr);
+ 
      if (strmPtr->itemMask & PEXRDHlhsrMode) PACK_CARD32( prend->hlhsrMode, ptr);
  
      if (strmPtr->itemMask & PEXRDNpcSubvolume) { 
***************
*** 577,589 ****
      if (strmPtr->itemMask & PEXRDViewport) {
  	CHK_PEX_BUF(size, sizeof(pexViewport),
  		    reply, pexGetRendererAttributesReply, ptr);
! 	PACK_CARD32( prend->viewport.minval.x, ptr);
! 	PACK_CARD32( prend->viewport.minval.y, ptr);
! 	PACK_CARD32( prend->viewport.minval.z, ptr);
! 	PACK_CARD32( prend->viewport.maxval.x, ptr);
! 	PACK_CARD32( prend->viewport.maxval.y, ptr);
! 	PACK_CARD32( prend->viewport.maxval.z, ptr);
! 	PACK_CARD32( prend->viewport.useDrawable, ptr);
      }
  
      if (strmPtr->itemMask & PEXRDClipList) {
--- 799,812 ----
      if (strmPtr->itemMask & PEXRDViewport) {
  	CHK_PEX_BUF(size, sizeof(pexViewport),
  		    reply, pexGetRendererAttributesReply, ptr);
! 	PACK_INT16( prend->viewport.minval.x, ptr);
! 	PACK_INT16( prend->viewport.minval.y, ptr);
! 	PACK_FLOAT( prend->viewport.minval.z, ptr);
! 	PACK_INT16( prend->viewport.maxval.x, ptr);
! 	PACK_INT16( prend->viewport.maxval.y, ptr);
! 	PACK_FLOAT( prend->viewport.maxval.z, ptr);
! 	PACK_CARD8( prend->viewport.useDrawable, ptr);
! 	SKIP_PADDING( ptr, (sizeof(CARD8)+sizeof(CARD16)));
      }
  
      if (strmPtr->itemMask & PEXRDClipList) {
***************
*** 592,601 ****
  		    reply, pexGetRendererAttributesReply, ptr);
  	PACK_CARD32(prend->clipList->numObj, ptr);
  	bcopy((char *)(prend->clipList->pList), (char *)ptr, num_bytes);
! 	ptr += num_bytes + 4;
      }
  
!     reply->length = (unsigned long)(ptr) - (unsigned long)(pPEXBuffer->pBuf) +1;
      reply->length = LWORDS(reply->length);
      WritePEXReplyToClient(	cntxtPtr, strmPtr,
  				sizeof(pexGetRendererAttributesReply)
--- 815,860 ----
  		    reply, pexGetRendererAttributesReply, ptr);
  	PACK_CARD32(prend->clipList->numObj, ptr);
  	bcopy((char *)(prend->clipList->pList), (char *)ptr, num_bytes);
! 	ptr += num_bytes;
      }
  
!     if (strmPtr->itemMask & PEXRDPickInclusion)
! 	PACK_CARD32( GetId(prend->ns[(unsigned)DD_PICK_INCL_NS]), ptr);
! 
!     if (strmPtr->itemMask & PEXRDPickExclusion)
! 	PACK_CARD32( GetId(prend->ns[(unsigned)DD_PICK_EXCL_NS]), ptr);
! 
!     if (strmPtr->itemMask & PEXRDPickStartPath) {
! 	/* StartPath is stored as a Pick Path even though the spec
! 	   and encoding define it as an Element Ref since the Renderer
! 	   Pikcing needs to use it as a Pick Path
! 	*/
! 	pexStructure sid = 0;
! 	unsigned long i;
! 	ddPickPath *per = (ddPickPath *)(prend->pickStartPath->pList);
! 	PACK_CARD32( prend->pickStartPath->numObj, ptr);
! 	for (i=0; i<prend->pickStartPath->numObj; i++, per++) {
! 	    sid = GetId(per->structure);
! 	    PACK_CARD32(sid, ptr);
! 	    PACK_CARD32(per->offset, ptr);
! 	}
!     }
! 
!     if (strmPtr->itemMask & PEXRDBackgroundColour) {
!         CHK_PEX_BUF(size, sizeof(CARD32) 
! 			  + SIZE_COLOURSPEC(prend->backgroundColour),
! 			  reply, pexGetRendererAttributesReply, ptr);
! 	PACK_COLOUR_SPECIFIER(prend->backgroundColour,ptr);
!     }
!     
!     if (strmPtr->itemMask & PEXRDClearI) PACK_CARD32( prend->clearI, ptr);
! 
!     if (strmPtr->itemMask & PEXRDClearZ) PACK_CARD32( prend->clearZ, ptr);
! 
!     if (strmPtr->itemMask & PEXRDEchoMode) PACK_CARD32( prend->echoMode, ptr);
! 
! 
!     reply->length = (unsigned long)(ptr) - (unsigned long)(pPEXBuffer->pBuf);
      reply->length = LWORDS(reply->length);
      WritePEXReplyToClient(	cntxtPtr, strmPtr,
  				sizeof(pexGetRendererAttributesReply)
***************
*** 712,718 ****
      sizeof(pexExecuteStructure),    /* length	    */
      0				    /* id	    */
  };
! 
  ErrorCode
  PEXRenderNetwork( cntxtPtr, strmPtr )
  pexContext      	*cntxtPtr;
--- 971,978 ----
      sizeof(pexExecuteStructure),    /* length	    */
      0				    /* id	    */
  };
! /*++	PEXRenderNetwork
!  --*/
  ErrorCode
  PEXRenderNetwork( cntxtPtr, strmPtr )
  pexContext      	*cntxtPtr;
***************
*** 725,730 ****
--- 985,998 ----
      LU_RENDERER(strmPtr->rdr, prend);
      LU_STRUCTURE(strmPtr->sid, ps);
  
+     /* set drawableId = 0 : this helps protect us if we error-return
+        out of the lookup id, and then later try to RenderOC's on this
+        renderer with a bad drawable */
+     prend->drawableId = 0;
+ 
+     LU_DRAWABLE(strmPtr->drawable, prend->pDrawable);
+     prend->drawableId = strmPtr->drawable;
+ 
      err = BeginRendering(prend, prend->pDrawable);
      if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
  
***************
*** 741,749 ****
  
  } /* end-PEXRenderNetwork() */
  
! /*++	PEXRenderNetwork
!  --*/
  ErrorCode
  PEXGetRendererDynamics( cntxtPtr, strmPtr )
  pexContext		    *cntxtPtr;
  pexGetRendererDynamicsReq   *strmPtr;
--- 1009,1085 ----
  
  } /* end-PEXRenderNetwork() */
  
! 
  ErrorCode
+ PEXRenderElements( cntxtPtr, strmPtr )
+ pexContext      	*cntxtPtr;
+ pexRenderElementsReq    	*strmPtr;
+ {
+     ErrorCode err = PEXNYI;
+     ddRendererStr *prend = 0;
+     diStructHandle ps = 0;
+     ddElementRange *range;
+ 
+     LU_RENDERER(strmPtr->rdr, prend);
+     LU_STRUCTURE(strmPtr->sid, ps);
+ 
+     range = (ddElementRange *) &(strmPtr->range);
+   
+     err = RenderElements(prend, ps, range );
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     return( err );
+ 
+ } /* end-PEXRenderElements() */
+ 
+ 
+ ErrorCode
+ PEXAccumulateState( cntxtPtr, strmPtr )
+ pexContext      	*cntxtPtr;
+ pexAccumulateStateReq   *strmPtr;
+ {
+     ErrorCode err = PEXNYI;
+     ddRendererStr *prend = 0;
+     ddAccStStr    *pAccSt = 0;
+     pexElementRef *per;
+     diStructHandle sh, *psh;
+     CARD32 i;
+     extern ddpex4rtn ValidateStructurePath();
+ 
+     LU_RENDERER(strmPtr->rdr, prend);
+ 
+     pAccSt = (ddAccStStr *)Xalloc((unsigned long)sizeof(ddAccStStr));
+     if (!pAccSt) PEX_ERR_EXIT(BadAlloc,0,cntxtPtr);
+ 
+     pAccSt->numElRefs = strmPtr->numElRefs;
+     pAccSt->Path = 0;
+ 
+     per = (pexElementRef *)(strmPtr+1);
+     for (i = 0 ; i < strmPtr->numElRefs; i++, per++) {
+ 	LU_STRUCTURE(per->structure,sh);
+ 	psh = (diStructHandle *)&(per->structure);
+ 	*psh = sh;
+     }
+ 
+     pAccSt->Path = puCreateList(DD_ELEMENT_REF);
+     if (!(pAccSt->Path)) PEX_ERR_EXIT(BadAlloc,0,cntxtPtr);
+     puAddToList((ddPointer)(strmPtr+1),  pAccSt->numElRefs, pAccSt->Path);
+     err = ValidateStructurePath(pAccSt->Path);
+     if (err != Success) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     err = AccumulateState(prend, pAccSt );
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     /* clean up */
+     puDeleteList(pAccSt->Path);
+     Xfree((pointer)pAccSt);
+ 
+     return( err );
+ 
+ } /* end-PEXAccumulateState() */
+ 
+ 
+ ErrorCode
  PEXGetRendererDynamics( cntxtPtr, strmPtr )
  pexContext		    *cntxtPtr;
  pexGetRendererDynamicsReq   *strmPtr;
***************
*** 795,804 ****
       */
      LU_DRAWABLE(prend->drawableId, prend->pDrawable);
  
!     curOC = (CARD32 *)(strmPtr + 1);
! 
!     for (i = 0, curOC = (CARD32 *)(strmPtr + 1);
! 	 i < strmPtr->numCommands;
  	 i++, curOC += pe->length  ) {
  	pe = (pexElementInfo *)curOC;
      	if ((PEXOCAll < pe->elementType ) && (pe->elementType <= PEXMaxOC)) { 
--- 1131,1137 ----
       */
      LU_DRAWABLE(prend->drawableId, prend->pDrawable);
  
!     for (i = 0, curOC = (CARD32 *)(strmPtr + 1); i < strmPtr->numCommands;
  	 i++, curOC += pe->length  ) {
  	pe = (pexElementInfo *)curOC;
      	if ((PEXOCAll < pe->elementType ) && (pe->elementType <= PEXMaxOC)) { 
***************
*** 808,819 ****
  		*ps = (pexStructure)(ph);
  	    }
  	}
- 
      }
  
!     err = RenderOCs(prend, strmPtr->numCommands, (strmPtr+1), &pErr);
  
      if (err) PEX_OC_ERROR(pErr, cntxtPtr);
  
      return( err );
  
--- 1141,1153 ----
  		*ps = (pexStructure)(ph);
  	    }
  	}
      }
  
!     err = RenderOCs(prend, strmPtr->numCommands, (strmPtr+1));
  
+     /* this line is useless pErr never gets returned from anywhere
      if (err) PEX_OC_ERROR(pErr, cntxtPtr);
+     */
  
      return( err );
  
*** -	Thu Jan 28 17:50:43 1993
--- mit/extensions/server/PEX/dipex/objects/pexInfo.c	Thu Jan 28 17:50:42 1993
***************
*** 1,4 ****
! /* $XConsortium: pexInfo.c,v 5.1 91/02/16 09:56:56 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pexInfo.c,v 5.2 92/03/04 14:16:15 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 30,35 ****
--- 30,38 ----
   *	Contents:   PEXGetExtensionInfo
   *		    PEXGetEnumeratedTypeInfo
   *		    PEXGetImpDepConstants
+  *		    PEXMatchRendererTargets
+  *		    PEXEscape
+  *		    PEXEscapeWithReply
   *
   --*/
  
***************
*** 40,45 ****
--- 43,49 ----
  #include "dipex.h"
  #include "pexError.h"
  #include "pexLookup.h"
+ #include "pexExtract.h"
  #ifdef min
  #undef min
  #endif
***************
*** 140,145 ****
--- 144,224 ----
      return( err );
  
  } /* end-PEXGetImpDepConstants() */
+ 
+ ErrorCode
+ PEXMatchRendererTargets( cntxtPtr, strmPtr )
+ pexContext			*cntxtPtr;
+ pexMatchRendererTargetsReq      *strmPtr;
+ {
+     ErrorCode err = Success;
+     DrawablePtr d;
+     extern ddBuffer *pPEXBuffer;
+ 
+     LU_DRAWABLE (strmPtr->drawable, d);
+ 
+     /* no way to check visualID besides doing the work of Match */
+ 
+     SETUP_INQ(pexMatchRendererTargetsReply);
+ 
+     err = MatchRendererTargets(d, (int)strmPtr->depth, (int)strmPtr->type, 
+ 			   (VisualID)strmPtr->visualID,
+ 			   (int)strmPtr->maxTriplets, pPEXBuffer );
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     {
+ 	SETUP_VAR_REPLY(pexMatchRendererTargetsReply);
+ 	WritePEXBufferReply(pexMatchRendererTargetsReply);
+     }
+     return( err );
+ 
+ } /* end-PEXMatchRendererTargets() */
+ 
+ ErrorCode
+ PEXEscape( cntxtPtr, strmPtr )
+ pexContext		  	*cntxtPtr;
+ pexEscapeReq	   	 	*strmPtr;
+ {
+     ErrorCode err = Success;
+     ddRendererStr *prend = 0;
+     pexEscapeSetEchoColourData *ptr;
+     CARD8 *pcs;
+ 
+     ptr = (pexEscapeSetEchoColourData *)(strmPtr + 1);
+     pcs = (CARD8 *)(ptr+1); 
+ 
+     LU_RENDERER(ptr->rdr, prend);
+ 
+     /* Support the one Registered Escape, Set Echo Color */
+     switch (strmPtr->escapeID) {
+ 	case  PEXEscapeSetEchoColour: {
+ 	  EXTRACT_COLOUR_SPECIFIER(prend->echoColour,pcs);
+ 	  break;
+ 	}
+     }
+ 
+ 
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     return( err );
+ 
+ } /* end-PEXEscape() */
+ 
+ 
+ ErrorCode
+ PEXEscapeWithReply( cntxtPtr, strmPtr )
+ pexContext		  	*cntxtPtr;
+ pexEscapeWithReplyReq	   	*strmPtr;
+ {
+     ErrorCode err = Success;
+ 
+     /* Do nothing here, Escape is not implemented in SI 
+     */
+ 
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     return( err );
+ 
+ } /* end-PEXEscapeWithReply() */
  /*++
   *
   *	End of File
*** /dev/null	Thu Jan 28 17:50:43 1993
--- mit/extensions/server/PEX/dipex/objects/pexRndrPick.c	Thu Jan 28 17:50:43 1993
***************
*** 0 ****
--- 1,311 ----
+ /* $XConsortium: pexRndrPick.c,v 1.8 92/12/14 16:17:44 hersh Exp $ */
+ 
+ /************************************************************
+ Copyright 1992 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
+ docu- mentation, 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.
+ 
+ ******************************************************************/
+ 
+ 
+ 
+ /*++
+  *  --- Renderer Picking ---
+  *      PEXBeginPickOne
+  *      PEXEndPickOne
+  *      PEXPickOne
+  *      PEXBeginPickAll
+  *      PEXEndPickAll
+  *      PEXPickAll
+  --*/
+ 
+ #include "X.h"
+ #define NEED_EVENTS
+ #include "Xproto.h"
+ #include "pexError.h"
+ #include "dipex.h"
+ #include "PEXprotost.h"
+ #include "pex_site.h"
+ #include "ddpex3.h"
+ #include "ddpex4.h"
+ #include "pexLookup.h"
+ 
+ #ifdef min
+ #undef min
+ #endif
+  
+ #ifdef max
+ #undef max
+ #endif
+ 
+ 
+ /*++  Renderer Picking ++*/
+ 
+ ErrorCode
+ PEXBeginPickOne( cntxtPtr, strmPtr )
+ pexContext      	*cntxtPtr;
+ pexBeginPickOneReq      *strmPtr;
+ {
+     ErrorCode err = Success;
+     ddRendererStr *prend = 0;
+     pexPickRecord *pr = (pexPickRecord *)(strmPtr+1);
+     ddPickPath    *sIDpp;
+ 
+     LU_RENDERER(strmPtr->rdr, prend);
+     LU_DRAWABLE(strmPtr->drawable, prend->pDrawable);
+     prend->drawableId = strmPtr->drawable;
+     /* this is evil but necessary, use the pickid field of the
+        sIDlist to store the structure ID that corresponds to the 
+        top level fake structure
+     */
+     sIDpp = (ddPickPath *)(prend->pickstr.sIDlist)->pList;
+     sIDpp->pickid = strmPtr->sid;
+ 
+     prend->pickstr.pick_method = strmPtr->method;
+     prend->pickstr.state = DD_PICK_ONE;
+     prend->pickstr.server = DD_CLIENT;
+ 
+     err = ChangePseudoPickMeasure (prend, pr);
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     /* This is set up to use this instead of defining a BeginPickOne */
+     err = BeginPicking(prend, prend->pickstr.pseudoPM);
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     return( err );
+ } /* end-PEXBeginPickOne() */
+ 
+ ErrorCode
+ PEXEndPickOne( cntxtPtr, strmPtr )
+ pexContext      	*cntxtPtr;
+ pexEndPickOneReq        *strmPtr;
+ {
+     ErrorCode err = Success;
+     ddRendererStr *prend = 0;
+     extern ddBufferPtr pPEXBuffer;
+     pexEndPickOneReply *reply = (pexEndPickOneReply*)(pPEXBuffer->pHead);
+ 
+     LU_RENDERER(strmPtr->rdr, prend);
+ 
+     if (prend->pickstr.state != DD_PICK_ONE)
+ 	PEX_ERR_EXIT(PEX_ERROR_CODE(PEXRendererStateError),0,cntxtPtr);
+ 
+     SETUP_INQ(pexEndPickOneReply);
+ 
+     err = EndPickOne(prend, pPEXBuffer, &(reply->numPickElRefs),
+ 		     &(reply->pickStatus), &(reply->betterPick));
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     err = EndPicking(prend);
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     {
+ 	reply->length = LWORDS(pPEXBuffer->dataSize);
+ 	WritePEXBufferReply(pexEndPickOneReply);
+ 
+     }
+     return( err );
+ } /* end-PEXEndPickOne() */
+ 
+ ErrorCode
+ PEXPickOne( cntxtPtr, strmPtr )
+ pexContext      	*cntxtPtr;
+ pexPickOneReq           *strmPtr;
+ {
+     ErrorCode err = Success;
+     extern ddBufferPtr pPEXBuffer;
+     ddRendererStr *prend = 0;
+     pexPickRecord *pr = (pexPickRecord *)(strmPtr+1);
+     pexPickOneReply *reply = (pexPickOneReply*)(pPEXBuffer->pHead);
+ 
+     /* do stuff same as BeginPickOne */
+     LU_RENDERER(strmPtr->rdr, prend);
+     LU_DRAWABLE(strmPtr->drawable, prend->pDrawable);
+     prend->drawableId = strmPtr->drawable;
+     LU_STRUCTURE(strmPtr->sid, prend->pickstr.strHandle);
+ 
+     prend->pickstr.pick_method = strmPtr->method;
+     prend->pickstr.state = DD_PICK_ONE;
+     prend->pickstr.server = DD_SERVER;
+ 
+     err = ChangePseudoPickMeasure (prend, pr);
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     err = BeginPicking(prend, prend->pickstr.pseudoPM);
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     /* now call PickOne which does set up and calls the traverser */
+     err = PickOne(prend);
+ 
+     /* now do stuff same as EndPickOne */
+     SETUP_INQ(pexPickOneReply);
+ 
+     err = EndPickOne(prend, pPEXBuffer, &(reply->numPickElRefs),
+ 		     &(reply->pickStatus), &(reply->betterPick));
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     err = EndPicking(prend);
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     {
+ 	reply->length = LWORDS(pPEXBuffer->dataSize);
+ 	WritePEXBufferReply(pexPickOneReply);
+     }
+     return( err );
+ } /* end-PEXPickOne() */
+ 
+ ErrorCode
+ PEXBeginPickAll( cntxtPtr, strmPtr )
+ pexContext      	*cntxtPtr;
+ pexBeginPickAllReq      *strmPtr;
+ {
+     ErrorCode err = Success;
+     ddRendererStr *prend = 0;
+     pexPickRecord *pr = (pexPickRecord *)(strmPtr+1);
+     ddPickPath    *sIDpp;
+ 
+     LU_RENDERER(strmPtr->rdr, prend);
+     LU_DRAWABLE(strmPtr->drawable, prend->pDrawable);
+     prend->drawableId = strmPtr->drawable;
+     /* this is evil but necessary, use the pickid field of the
+        sIDlist to store the structure ID that corresponds to the 
+        top level fake structure
+     */
+     sIDpp = (ddPickPath *)(prend->pickstr.sIDlist)->pList;
+     sIDpp->pickid = strmPtr->sid;
+ 
+     prend->pickstr.pick_method = strmPtr->method;
+     prend->pickstr.state = DD_PICK_ALL;
+     prend->pickstr.server = DD_CLIENT;
+     prend->pickstr.send_event = strmPtr->sendEvent;
+     prend->pickstr.max_hits = strmPtr->pickMaxHits;
+     prend->pickstr.client = cntxtPtr->client;
+ 
+     err = ChangePseudoPickMeasure (prend, pr);
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     /* This is set up to use this instead of defining a BeginPickOne */
+     err = BeginPicking(prend, prend->pickstr.pseudoPM);
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+ 
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+     return( err );
+ } /* end-PEXBeginPickAll() */
+ 
+ ErrorCode
+ PEXEndPickAll( cntxtPtr, strmPtr )
+ pexContext      	*cntxtPtr;
+ pexEndPickAllReq        *strmPtr;
+ {
+     ErrorCode err = Success;
+     extern ddBufferPtr pPEXBuffer;
+     ddRendererStr *prend = 0;
+ 
+     LU_RENDERER(strmPtr->rdr, prend);
+ 
+     if (prend->pickstr.state != DD_PICK_ALL)
+ 	PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     SETUP_INQ(pexEndPickAllReply);
+ 
+     err = EndPickAll(prend, pPEXBuffer);
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     err = EndPicking(prend);
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     {
+ 	SETUP_VAR_REPLY(pexEndPickAllReply);
+ 	WritePEXBufferReply(pexEndPickAllReply);
+     }
+     return( err );
+ } /* end-PEXEndPickAll() */
+ 
+ ErrorCode
+ PEXPickAll( cntxtPtr, strmPtr )
+ pexContext      	*cntxtPtr;
+ pexPickAllReq           *strmPtr;
+ {
+     ErrorCode err = Success;
+     extern ddBufferPtr pPEXBuffer;
+     ddRendererStr *prend = 0;
+     pexPickRecord *pr = (pexPickRecord *)(strmPtr+1);
+ 
+     /* do stuff same as BeginPickAll */
+     LU_RENDERER(strmPtr->rdr, prend);
+     LU_DRAWABLE(strmPtr->drawable, prend->pDrawable);
+     prend->drawableId = strmPtr->drawable;
+ 
+     prend->pickstr.pick_method = strmPtr->method;
+     prend->pickstr.state = DD_PICK_ALL;
+     prend->pickstr.server = DD_SERVER;
+     prend->pickstr.max_hits = strmPtr->pickMaxHits;
+ 
+     err = ChangePseudoPickMeasure (prend, pr);
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     err = BeginPicking(prend, prend->pickstr.pseudoPM);
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     /* now call PickAll which does set up and calls RenderElements */
+     err = PickAll(prend);
+ 
+     /* now do stuff same as EndPickOne */
+     SETUP_INQ(pexPickAllReply);
+ 
+     err = EndPickAll(prend, pPEXBuffer);
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     err = EndPicking(prend);
+     if (err) PEX_ERR_EXIT(err,0,cntxtPtr);
+ 
+     {
+ 	SETUP_VAR_REPLY(pexPickAllReply);
+ 
+ 	WritePEXBufferReply(pexPickAllReply);
+     }
+     return( err );
+ } /* end-PEXPickAll() */
+ 
+ 
+ /**** Renderer Pick Events ****/
+ 
+ ErrorCode
+ PEXMaxHitsReachedNotify(client, rendId)
+ ClientPtr           client;
+ ddULONG             rendId;
+ {
+     pexMaxHitsReachedEvent mhre;
+ 
+     mhre.type = PexEventBase + PEXMaxHitsReached; 
+     mhre.sequenceNumber = client->sequence;
+     mhre.rdr = rendId;
+ 
+     WriteEventsToClient (client, 1, (xEvent *) &mhre);
+     return(client->noClientException);
+ }
+ /*++
+  *
+  *	End of File
+  *
+  --*/
*** -	Thu Jan 28 17:50:58 1993
--- mit/extensions/server/PEX/dipex/swap/floatconv.h	Thu Jan 28 17:50:58 1993
***************
*** 1,4 ****
! /* $XConsortium: floatconv.h,v 5.4 91/07/01 16:27:01 hersh Exp $ */
  
  /*
   * Copyright (c) 1988-1991 by Sun Microsystems and the X Consortium.
--- 1,4 ----
! /* $XConsortium: floatconv.h,v 5.5 91/12/30 18:23:15 hersh Exp $ */
  
  /*
   * Copyright (c) 1988-1991 by Sun Microsystems and the X Consortium.
***************
*** 48,54 ****
  #define MyFloatType Ieee_754_32
  #endif
  
! extern PEXFLOAT ConvertIEEEtoVax();
! extern PEXFLOAT ConvertVaxToIEEE();
  
  #endif /* FLOAT_CON_H */
--- 48,54 ----
  #define MyFloatType Ieee_754_32
  #endif
  
! extern void ConvertIEEEtoVax();
! extern void ConvertVaxToIEEE();
  
  #endif /* FLOAT_CON_H */
*** -	Thu Jan 28 17:50:59 1993
--- mit/extensions/server/PEX/dipex/swap/Imakefile	Thu Jan 28 17:50:59 1993
***************
*** 1,5 ****
  XCOMM
! XCOMM $XConsortium: Imakefile,v 5.7 91/07/24 17:01:28 rws Exp $
  XCOMM
  XCOMM 
  XCOMM Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium
--- 1,5 ----
  XCOMM
! XCOMM $XConsortium: Imakefile,v 5.8 92/03/04 14:18:33 hersh Exp $
  XCOMM
  XCOMM 
  XCOMM Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium
***************
*** 51,61 ****
  
  SRCS =  convUtil.c cOCprim.c uOCprim.c floatconv.c check.c \
  	OCattr.c OCcolour.c convReq.c uconvRep.c Convert.c \
! 	OCTables.c ReqTables.c RepTables.c
  
  OBJS =  convUtil.o cOCprim.o uOCprim.o floatconv.o check.o \
  	OCattr.o OCcolour.o convReq.o uconvRep.o Convert.o \
! 	OCTables.o ReqTables.o RepTables.o
  
  
  PEX_SW_LIBNAME = libdiswapex.a
--- 51,61 ----
  
  SRCS =  convUtil.c cOCprim.c uOCprim.c floatconv.c check.c \
  	OCattr.c OCcolour.c convReq.c uconvRep.c Convert.c \
! 	OCTables.c ReqTables.c RepTables.c convEv.c
  
  OBJS =  convUtil.o cOCprim.o uOCprim.o floatconv.o check.o \
  	OCattr.o OCcolour.o convReq.o uconvRep.o Convert.o \
! 	OCTables.o ReqTables.o RepTables.o convEv.o
  
  
  PEX_SW_LIBNAME = libdiswapex.a
*** -	Thu Jan 28 17:51:00 1993
--- mit/extensions/server/PEX/dipex/swap/Convert.c	Thu Jan 28 17:51:00 1993
***************
*** 1,4 ****
! /* $XConsortium: Convert.c,v 5.3 91/07/01 16:29:05 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: Convert.c,v 5.4 91/12/30 18:23:37 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 31,52 ****
  #include "dipex.h"
  
  
! extern PEXFLOAT SwapIEEEToVax();
! extern PEXFLOAT SwapVaxToIEEE();
! extern PEXFLOAT ConvertIEEEToVax();
! extern PEXFLOAT ConvertVaxToIEEE();
  
  unsigned char temp;	/* only used for conversions */
  
  
  /* Byte swap a long */
! CARD32
  SwapCARD32(i)
  CARD32 *i;
  {
-     CARD32 *j = i;
      CARD8  n;
!     CARD8  *x = (CARD8 *)j;
  
      n = x[0];
      x[0] = x[3];
--- 31,51 ----
  #include "dipex.h"
  
  
! extern void SwapIEEEToVax();
! extern void SwapVaxToIEEE();
! extern void ConvertIEEEToVax();
! extern void ConvertVaxToIEEE();
  
  unsigned char temp;	/* only used for conversions */
  
  
  /* Byte swap a long */
! void
  SwapCARD32(i)
  CARD32 *i;
  {
      CARD8  n;
!     CARD8  *x = (CARD8 *)i;
  
      n = x[0];
      x[0] = x[3];
***************
*** 55,113 ****
      x[1] = x[2];
      x[2] = n;
  
!     return (*j);
  }
  
  /* Byte swap a short */
! CARD16
  SwapCARD16(i)
  CARD16 *i;
  {
-     CARD16 *j = i;
      CARD8  n;
!     CARD8  *x = (CARD8 *)j;
  
      n = x[0];
      x[0] = x[1];
      x[1] = n;
  
!     return (*j);
  }
  
  
  /* Byte swap and convert a float */
! PEXFLOAT
  SwapIEEEToVax(f)
  PEXFLOAT *f;
  {
-     PEXFLOAT x;
-     CARD32 i;
  
!     i = SwapCARD32((CARD32 *) f);
  
!     x = ConvertIEEEToVax((PEXFLOAT *)(&i));
  
-     return (x);
  }
  
  
! PEXFLOAT
  SwapVaxToIEEE(f)
  PEXFLOAT *f;
  {
!     PEXFLOAT x;
!     CARD32 i;
  
!     i = SwapCARD32((CARD32 *) f);
  
-     x = ConvertVaxToIEEE((PEXFLOAT *)(&i));
- 
-     return (x);
  }
  
  
  /* Byte swap a float */
! PEXFLOAT
  SwapFLOAT (f)
  PEXFLOAT *f;
  {
--- 54,104 ----
      x[1] = x[2];
      x[2] = n;
  
!     return;
  }
  
  /* Byte swap a short */
! void
  SwapCARD16(i)
  CARD16 *i;
  {
      CARD8  n;
!     CARD8  *x = (CARD8 *)i;
  
      n = x[0];
      x[0] = x[1];
      x[1] = n;
  
!     return;
  }
  
  
  /* Byte swap and convert a float */
! void
  SwapIEEEToVax(f)
  PEXFLOAT *f;
  {
  
!     SwapCARD32((CARD32 *) f);
  
!     ConvertIEEEToVax((PEXFLOAT *)(f));
  
  }
  
  
! void
  SwapVaxToIEEE(f)
  PEXFLOAT *f;
  {
!     SwapCARD32((CARD32 *) f);
  
!     ConvertVaxToIEEE((PEXFLOAT *)(f));
  
  }
  
  
  /* Byte swap a float */
! void
  SwapFLOAT (f)
  PEXFLOAT *f;
  {
***************
*** 121,125 ****
      x[1] = x[2];
      x[2] = n;
  
-     return (*f);
  }
--- 112,115 ----
*** -	Thu Jan 28 17:51:02 1993
--- mit/extensions/server/PEX/dipex/swap/Replies.ci	Thu Jan 28 17:51:02 1993
***************
*** 1,4 ****
! /* $XConsortium: Replies.ci,v 5.2 91/03/15 18:31:38 keith Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: Replies.ci,v 5.3 92/03/04 14:18:42 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 126,129 ****
--- 126,140 ----
  /*  91  */   SWAP_FUNC_PREFIX(ConvertListFontsReply),
  /*  92  */   SWAP_FUNC_PREFIX(ConvertListFontsWithInfoReply),
  /*  93  */   SWAP_FUNC_PREFIX(ConvertQueryTextExtentsReply),
+ /*  94  */   SWAP_FUNC_PREFIX(ConvertMatchRendererTargetsReply),
+ /*  95  */   SWAP_FUNC_PREFIX(NoReply),   /*Escape*/
+ /*  96  */   SWAP_FUNC_PREFIX(EscapeWithReplyReply),   /*EscapeWithReply*/
+ /*  97  */   SWAP_FUNC_PREFIX(NoReply),   /*RenderElements*/
+ /*  98  */   SWAP_FUNC_PREFIX(NoReply),   /*AccumulateState*/
+ /*  99  */   SWAP_FUNC_PREFIX(NoReply),   /*BeginPickOne*/
+ /* 100  */   SWAP_FUNC_PREFIX(ConvertEndPickOneReply),
+ /* 101  */   SWAP_FUNC_PREFIX(ConvertPickOneReply),
+ /* 102  */   SWAP_FUNC_PREFIX(NoReply),   /*BeginPickAll*/
+ /* 103  */   SWAP_FUNC_PREFIX(ConvertEndPickAllReply),
+ /* 104  */   SWAP_FUNC_PREFIX(ConvertPickAllReply)
  };
*** -	Thu Jan 28 17:51:04 1993
--- mit/extensions/server/PEX/dipex/swap/uOCprim.c	Thu Jan 28 17:51:03 1993
***************
*** 1,4 ****
! /* $XConsortium: uOCprim.c,v 5.5 91/07/01 16:29:35 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: uOCprim.c,v 5.7 92/06/02 19:41:24 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 747,758 ****
  	case PEXPSCMcLevelCurves:
  	case PEXPSCWcLevelCurves: {
  	    pexPSC_LevelCurves *ptr = (pexPSC_LevelCurves *)(strmPtr+1);
! 	    pexCoord3D *pc = (pexCoord3D *)(ptr+1);
  	    CARD16 i;
  	    SWAP_COORD3D (ptr->origin);
  	    SWAP_VECTOR3D (ptr->direction);
  	    for (i=0; i<ptr->numberIntersections; i++, pc++) {
! 		SWAP_COORD3D(*pc);
  	    }
  	    SWAP_CARD16 (ptr->numberIntersections);
  	    break;
--- 747,758 ----
  	case PEXPSCMcLevelCurves:
  	case PEXPSCWcLevelCurves: {
  	    pexPSC_LevelCurves *ptr = (pexPSC_LevelCurves *)(strmPtr+1);
! 	    PEXFLOAT *pc = (PEXFLOAT *)(ptr+1);
  	    CARD16 i;
  	    SWAP_COORD3D (ptr->origin);
  	    SWAP_VECTOR3D (ptr->direction);
  	    for (i=0; i<ptr->numberIntersections; i++, pc++) {
! 		SWAP_FLOAT(*pc);
  	    }
  	    SWAP_CARD16 (ptr->numberIntersections);
  	    break;
***************
*** 760,763 ****
--- 760,770 ----
      }
  
      SWAP_INT16 (strmPtr->characteristics);
+ }
+ 
+ ErrorCode
+ SWAP_FUNC_PREFIX(PEXNoop) (swapPtr, strmPtr)
+ pexSwap	*swapPtr;
+ pexNoop	*strmPtr;
+ {
  }
*** -	Thu Jan 28 17:51:07 1993
--- mit/extensions/server/PEX/dipex/swap/convReq.c	Thu Jan 28 17:51:06 1993
***************
*** 1,4 ****
! /* $XConsortium: convReq.c,v 5.8 91/07/18 20:36:35 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: convReq.c,v 5.16 92/11/24 13:12:52 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 52,58 ****
--- 52,60 ----
  
  extern RequestFunction PEXRequest[];
  
+ #define PADDING(n) ( (n)&3 ? (4 - ((n)&3)) : 0)
  
+ 
  /****************************************************************
   *  		REQUESTS 					*
   ****************************************************************/
***************
*** 337,343 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_INT16 (strmPtr->fpFormat);
      SWAP_RENDERER (strmPtr->rdr);
      SWAP_DRAWABLE (strmPtr->drawable);
      SWAP_BITMASK (strmPtr->itemMask);
--- 339,345 ----
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_RENDERER (strmPtr->rdr);
      SWAP_DRAWABLE (strmPtr->drawable);
      SWAP_BITMASK (strmPtr->itemMask);
***************
*** 357,363 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_INT16 (strmPtr->fpFormat);
      SWAP_RENDERER (strmPtr->rdr);
      SWAP_BITMASK (strmPtr->itemMask);
  
--- 359,365 ----
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_RENDERER (strmPtr->rdr);
      SWAP_BITMASK (strmPtr->itemMask);
  
***************
*** 374,380 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_INT16 (strmPtr->fpFormat);
      SWAP_RENDERER (strmPtr->rdr);
      SWAP_BITMASK (strmPtr->itemMask);
      CALL_REQUEST;
--- 376,382 ----
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_RENDERER (strmPtr->rdr);
      SWAP_BITMASK (strmPtr->itemMask);
      CALL_REQUEST;
***************
*** 428,433 ****
--- 430,471 ----
  
  
  ErrorCode
+ SWAP_FUNC_PREFIX(PEXRenderElements) (cntxtPtr, strmPtr)
+ pexContext		*cntxtPtr;
+ pexRenderElementsReq	*strmPtr;
+ {
+     pexSwap *swapPtr = cntxtPtr->swap;
+     SWAP_CARD16 (strmPtr->length);
+     SWAP_RENDERER (strmPtr->rdr);
+     SWAP_STRUCTURE (strmPtr->sid);
+     SwapElementRange (swapPtr, &strmPtr->range);
+ 
+     CALL_REQUEST;
+ }
+ 
+ 
+ ErrorCode
+ SWAP_FUNC_PREFIX(PEXAccumulateState) (cntxtPtr, strmPtr)
+ pexContext		*cntxtPtr;
+ pexAccumulateStateReq	*strmPtr;
+ {
+     pexElementRef	*pe;
+     CARD32              i;
+ 
+     pexSwap *swapPtr = cntxtPtr->swap;
+     SWAP_CARD16 (strmPtr->length);
+     SWAP_RENDERER (strmPtr->rdr);
+     SWAP_CARD32 (strmPtr->numElRefs);
+ 
+     pe = (pexElementRef *)(strmPtr+1);
+     for (i = 0; i < strmPtr->numElRefs; i++, pe++)
+ 	SWAP_ELEMENT_REF (*pe);
+ 
+     CALL_REQUEST;
+ }
+ 
+ 
+ ErrorCode
  SWAP_FUNC_PREFIX(PEXRenderNetwork) (cntxtPtr, strmPtr)
  pexContext		*cntxtPtr;
  pexRenderNetworkReq	*strmPtr;
***************
*** 492,498 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_CARD16 (strmPtr->fpFormat);
      SWAP_STRUCTURE (strmPtr->sid);
  
      SwapElementRange (swapPtr, &strmPtr->range);
--- 530,536 ----
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_STRUCTURE (strmPtr->sid);
  
      SwapElementRange (swapPtr, &strmPtr->range);
***************
*** 736,742 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_INT16 (strmPtr->fpFormat);
      SWAP_SC (strmPtr->sc);
      SWAP_BITMASK (strmPtr->itemMask);
  
--- 774,780 ----
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_SC (strmPtr->sc);
      SWAP_BITMASK (strmPtr->itemMask);
  
***************
*** 768,774 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_INT16 (strmPtr->fpFormat);
      SWAP_SC (strmPtr->sc);
      SWAP_BITMASK (strmPtr->itemMask);
      CALL_REQUEST;
--- 806,812 ----
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_SC (strmPtr->sc);
      SWAP_BITMASK (strmPtr->itemMask);
      CALL_REQUEST;
***************
*** 781,787 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_INT16 (strmPtr->fpFormat);
      SWAP_SC (strmPtr->sc);
      SWAP_BITMASK (strmPtr->itemMask);
  
--- 819,825 ----
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_SC (strmPtr->sc);
      SWAP_BITMASK (strmPtr->itemMask);
  
***************
*** 802,822 ****
      SWAP_CARD16 (strmPtr->length);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SWAP_DRAWABLE (strmPtr->drawable);
-     SWAP_LOOKUP_TABLE (strmPtr->lineBundle);
      SWAP_LOOKUP_TABLE (strmPtr->markerBundle);
      SWAP_LOOKUP_TABLE (strmPtr->textBundle);
      SWAP_LOOKUP_TABLE (strmPtr->interiorBundle);
      SWAP_LOOKUP_TABLE (strmPtr->edgeBundle);
      SWAP_LOOKUP_TABLE (strmPtr->colourTable);
-     SWAP_LOOKUP_TABLE (strmPtr->patternTable);
-     SWAP_LOOKUP_TABLE (strmPtr->textFontTable);
      SWAP_LOOKUP_TABLE (strmPtr->depthCueTable);
      SWAP_LOOKUP_TABLE (strmPtr->lightTable);
      SWAP_LOOKUP_TABLE (strmPtr->colourApproxTable);
      SWAP_NAMESET (strmPtr->highlightIncl);
      SWAP_NAMESET (strmPtr->highlightExcl);
      SWAP_NAMESET (strmPtr->invisIncl);
      SWAP_NAMESET (strmPtr->invisExcl);
      CALL_REQUEST;
  }
  
--- 840,861 ----
      SWAP_CARD16 (strmPtr->length);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SWAP_DRAWABLE (strmPtr->drawable);
      SWAP_LOOKUP_TABLE (strmPtr->markerBundle);
      SWAP_LOOKUP_TABLE (strmPtr->textBundle);
+     SWAP_LOOKUP_TABLE (strmPtr->lineBundle);
      SWAP_LOOKUP_TABLE (strmPtr->interiorBundle);
      SWAP_LOOKUP_TABLE (strmPtr->edgeBundle);
      SWAP_LOOKUP_TABLE (strmPtr->colourTable);
      SWAP_LOOKUP_TABLE (strmPtr->depthCueTable);
      SWAP_LOOKUP_TABLE (strmPtr->lightTable);
      SWAP_LOOKUP_TABLE (strmPtr->colourApproxTable);
+     SWAP_LOOKUP_TABLE (strmPtr->patternTable);
+     SWAP_LOOKUP_TABLE (strmPtr->textFontTable);
      SWAP_NAMESET (strmPtr->highlightIncl);
      SWAP_NAMESET (strmPtr->highlightExcl);
      SWAP_NAMESET (strmPtr->invisIncl);
      SWAP_NAMESET (strmPtr->invisExcl);
+     SWAP_CARD16 (strmPtr->bufferMode);
      CALL_REQUEST;
  }
  
***************
*** 829,835 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_INT16 (strmPtr->fpFormat);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SWAP_BITMASK (strmPtr->itemMask[0]);
      SWAP_BITMASK (strmPtr->itemMask[1]);
--- 868,874 ----
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SWAP_BITMASK (strmPtr->itemMask[0]);
      SWAP_BITMASK (strmPtr->itemMask[1]);
***************
*** 854,860 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_INT16 (strmPtr->fpFormat);
      SWAP_TABLE_INDEX (strmPtr->index);
      SWAP_PHIGS_WKS (strmPtr->wks);
      CALL_REQUEST;
--- 893,899 ----
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_TABLE_INDEX (strmPtr->index);
      SWAP_PHIGS_WKS (strmPtr->wks);
      CALL_REQUEST;
***************
*** 920,926 ****
      pexDeviceCoord *pc;
  
      SWAP_CARD16 (strmPtr->length);
!     SWAP_INT16 (strmPtr->fpFormat);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SWAP_CARD32 (strmPtr->numCoords);
  
--- 959,965 ----
      pexDeviceCoord *pc;
  
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SWAP_CARD32 (strmPtr->numCoords);
  
***************
*** 940,946 ****
      pexCoord3D *pc;
  
      SWAP_CARD16 (strmPtr->length);
!     SWAP_INT16 (strmPtr->fpFormat);
      SWAP_CARD16 (strmPtr->index);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SWAP_CARD32 (strmPtr->numCoords);
--- 979,985 ----
      pexCoord3D *pc;
  
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_CARD16 (strmPtr->index);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SWAP_CARD32 (strmPtr->numCoords);
***************
*** 958,964 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_INT16 (strmPtr->fpFormat);
      SWAP_PHIGS_WKS (strmPtr->wks);
  
      SwapViewRep (swapPtr, &strmPtr->viewRep);
--- 997,1003 ----
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_PHIGS_WKS (strmPtr->wks);
  
      SwapViewRep (swapPtr, &strmPtr->viewRep);
***************
*** 973,979 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_INT16 (strmPtr->fpFormat);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SwapNpcSubvolume (swapPtr, &strmPtr->npcSubvolume);
  
--- 1012,1018 ----
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SwapNpcSubvolume (swapPtr, &strmPtr->npcSubvolume);
  
***************
*** 987,993 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_INT16 (strmPtr->fpFormat);
      SWAP_PHIGS_WKS (strmPtr->wks);
  
      SwapViewport (swapPtr, &strmPtr->viewport);
--- 1026,1032 ----
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_PHIGS_WKS (strmPtr->wks);
  
      SwapViewport (swapPtr, &strmPtr->viewport);
***************
*** 1026,1032 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_CARD16 (strmPtr->fpFormat);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SWAP_STRUCTURE (strmPtr->sid);
      SWAP_FLOAT (strmPtr->priority);
--- 1065,1071 ----
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SWAP_STRUCTURE (strmPtr->sid);
      SWAP_FLOAT (strmPtr->priority);
***************
*** 1058,1064 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_INT16 (strmPtr->fpFormat);
      SWAP_ENUM_TYPE_INDEX (strmPtr->devType);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SWAP_BITMASK (strmPtr->itemMask);
--- 1097,1103 ----
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_ENUM_TYPE_INDEX (strmPtr->devType);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SWAP_BITMASK (strmPtr->itemMask);
***************
*** 1072,1078 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_CARD16 (strmPtr->fpFormat);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SWAP_ENUM_TYPE_INDEX (strmPtr->devType);
      SWAP_BITMASK (strmPtr->itemMask);
--- 1111,1117 ----
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_PHIGS_WKS (strmPtr->wks);
      SWAP_ENUM_TYPE_INDEX (strmPtr->devType);
      SWAP_BITMASK (strmPtr->itemMask);
***************
*** 1116,1122 ****
  pexUpdatePickMeasureReq	*strmPtr;
  {
  
!     extern PEXFLOAT SwapFLOAT();
  
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
--- 1155,1161 ----
  pexUpdatePickMeasureReq	*strmPtr;
  {
  
!     extern void SwapFLOAT();
  
      pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
***************
*** 1151,1156 ****
--- 1190,1297 ----
  }
  
  ErrorCode
+ SWAP_FUNC_PREFIX(PEXBeginPickOne) (cntxtPtr, strmPtr)
+ pexContext		*cntxtPtr;
+ pexBeginPickOneReq	*strmPtr;
+ {
+     pexSwap *swapPtr = cntxtPtr->swap;
+     SWAP_CARD16 (strmPtr->length);
+     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
+     SWAP_ENUM_TYPE_INDEX (strmPtr->method);
+     SWAP_RENDERER (strmPtr->rdr);
+     SWAP_DRAWABLE (strmPtr->drawable);
+     SWAP_INT32 (strmPtr->sid);
+ 
+     SWAP_FUNC_PREFIX(SwapPickRecord) (swapPtr, 
+ 				    (pexPickRecord *)(strmPtr+1));
+ 
+     CALL_REQUEST;
+ }
+ 
+ ErrorCode
+ SWAP_FUNC_PREFIX(PEXEndPickOne) (cntxtPtr, strmPtr)
+ pexContext		*cntxtPtr;
+ pexEndPickOneReq	*strmPtr;
+ {
+     pexSwap *swapPtr = cntxtPtr->swap;
+     SWAP_CARD16 (strmPtr->length);
+     SWAP_RENDERER (strmPtr->rdr);
+ 
+     CALL_REQUEST;
+ }
+ 
+ ErrorCode
+ SWAP_FUNC_PREFIX(PEXPickOne) (cntxtPtr, strmPtr)
+ pexContext		*cntxtPtr;
+ pexPickOneReq	*strmPtr;
+ {
+     pexSwap *swapPtr = cntxtPtr->swap;
+     SWAP_CARD16 (strmPtr->length);
+     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
+     SWAP_ENUM_TYPE_INDEX (strmPtr->method);
+     SWAP_RENDERER (strmPtr->rdr);
+     SWAP_DRAWABLE (strmPtr->drawable);
+     SWAP_STRUCTURE (strmPtr->sid);
+ 
+     SWAP_FUNC_PREFIX(SwapPickRecord) (swapPtr, 
+ 				    (pexPickRecord *)(strmPtr+1));
+ 
+     CALL_REQUEST;
+ }
+ 
+ ErrorCode
+ SWAP_FUNC_PREFIX(PEXBeginPickAll) (cntxtPtr, strmPtr)
+ pexContext		*cntxtPtr;
+ pexBeginPickAllReq	*strmPtr;
+ {
+     pexSwap *swapPtr = cntxtPtr->swap;
+     SWAP_CARD16 (strmPtr->length);
+     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
+     SWAP_ENUM_TYPE_INDEX (strmPtr->method);
+     SWAP_RENDERER (strmPtr->rdr);
+     SWAP_DRAWABLE (strmPtr->drawable);
+     SWAP_INT32 (strmPtr->sid);
+     SWAP_CARD32 (strmPtr->pickMaxHits);
+ 
+     SWAP_FUNC_PREFIX(SwapPickRecord) (swapPtr, 
+ 				    (pexPickRecord *)(strmPtr+1));
+ 
+     CALL_REQUEST;
+ }
+ 
+ ErrorCode
+ SWAP_FUNC_PREFIX(PEXEndPickAll) (cntxtPtr, strmPtr)
+ pexContext		*cntxtPtr;
+ pexEndPickAllReq	*strmPtr;
+ {
+     pexSwap *swapPtr = cntxtPtr->swap;
+     SWAP_CARD16 (strmPtr->length);
+     SWAP_RENDERER (strmPtr->rdr);
+ 
+     CALL_REQUEST;
+ }
+ 
+ ErrorCode
+ SWAP_FUNC_PREFIX(PEXPickAll) (cntxtPtr, strmPtr)
+ pexContext		*cntxtPtr;
+ pexPickAllReq	*strmPtr;
+ {
+     pexSwap *swapPtr = cntxtPtr->swap;
+     SWAP_CARD16 (strmPtr->length);
+     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
+     SWAP_ENUM_TYPE_INDEX (strmPtr->method);
+     SWAP_RENDERER (strmPtr->rdr);
+     SWAP_DRAWABLE (strmPtr->drawable);
+     SWAP_CARD32 (strmPtr->pickMaxHits);
+ 
+     SWAP_FUNC_PREFIX(SwapPickRecord) (swapPtr, 
+ 				    (pexPickRecord *)(strmPtr+1));
+ 
+     CALL_REQUEST;
+ }
+ 
+ 
+ ErrorCode
  SWAP_FUNC_PREFIX(PEXOpenFont) (cntxtPtr, strmPtr)
  pexContext	*cntxtPtr;
  pexOpenFontReq	*strmPtr;
***************
*** 1204,1212 ****
  pexContext		*cntxtPtr;
  pexQueryTextExtentsReq	*strmPtr;
  {
!     pexSwap *swapPtr = cntxtPtr->swap;
      SWAP_CARD16 (strmPtr->length);
!     SWAP_CARD16 (strmPtr->fpFormat);
      SWAP_CARD16 (strmPtr->textPath);
      SWAP_CARD16 (strmPtr->fontGroupIndex);
      SWAP_CARD32 (strmPtr->id);
--- 1345,1357 ----
  pexContext		*cntxtPtr;
  pexQueryTextExtentsReq	*strmPtr;
  {
!     pexSwap		*swapPtr = cntxtPtr->swap;
!     pexMonoEncoding	*pEnc;
!     CARD32		*numEnc;
!     int			bytes, i;
! 
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_CARD16 (strmPtr->textPath);
      SWAP_CARD16 (strmPtr->fontGroupIndex);
      SWAP_CARD32 (strmPtr->id);
***************
*** 1218,1225 ****
      
      SWAP_CARD32 (strmPtr->numStrings);
  
!     SWAP_FUNC_PREFIX(SwapMonoEncoding) (swapPtr, (pexMonoEncoding *)(strmPtr+1),
! 					strmPtr->numStrings);
      CALL_REQUEST;
  }
  
--- 1363,1384 ----
      
      SWAP_CARD32 (strmPtr->numStrings);
  
!     numEnc = (CARD32 *) (strmPtr + 1);
! 
!     for (i = 0; i < strmPtr->numStrings; i++)
!     {
! 	SWAP_CARD32 (*numEnc);
! 
! 	pEnc = (pexMonoEncoding *) (numEnc + 1);
! 	SWAP_FUNC_PREFIX(SwapMonoEncoding) (swapPtr, pEnc, *numEnc);
! 
! 	bytes = pEnc->numChars * ((pEnc->characterSetWidth == PEXCSByte) ?
! 	  sizeof(CARD8) : ((pEnc->characterSetWidth == PEXCSShort) ?
! 	  sizeof(CARD16) : sizeof(CARD32)));
! 
! 	numEnc = (CARD32 *) ((char *) (pEnc + 1) + bytes + PADDING (bytes));
!     }
! 
      CALL_REQUEST;
  }
  
***************
*** 1233,1239 ****
      CARD32 i;
  
      SWAP_CARD16 (strmPtr->length);
!     SWAP_CARD16 (strmPtr->fpFormat);
      SWAP_CARD32 (strmPtr->drawable);
      SWAP_CARD32 (strmPtr->numNames);
  
--- 1392,1398 ----
      CARD32 i;
  
      SWAP_CARD16 (strmPtr->length);
!     SWAP_ENUM_TYPE_INDEX (strmPtr->fpFormat);
      SWAP_CARD32 (strmPtr->drawable);
      SWAP_CARD32 (strmPtr->numNames);
  
***************
*** 1243,1250 ****
--- 1402,1471 ----
      CALL_REQUEST;
  }
  
+ ErrorCode
+ SWAP_FUNC_PREFIX(PEXMatchRendererTargets) (cntxtPtr, strmPtr)
+ pexContext			*cntxtPtr;
+ pexMatchRendererTargetsReq     	*strmPtr;
+ {
+     pexSwap *swapPtr = cntxtPtr->swap;
  
+     SWAP_CARD16 (strmPtr->length);
+     SWAP_CARD32 (strmPtr->drawable);
+     SWAP_CARD16 (strmPtr->type);
+     SWAP_CARD32 (strmPtr->visualID);
+     SWAP_CARD32 (strmPtr->maxTriplets);
+ 
+     CALL_REQUEST;
+ }
+ 
  ErrorCode
+ SWAP_FUNC_PREFIX(PEXEscape) (cntxtPtr, strmPtr)
+ pexContext			*cntxtPtr;
+ pexEscapeReq               	*strmPtr;
+ {
+     pexSwap *swapPtr = cntxtPtr->swap;
+ 
+     SWAP_CARD16 (strmPtr->length);
+     SWAP_CARD32 (strmPtr->escapeID);
+ 
+     /* do MIT Registered Escapes */
+     switch (strmPtr->escapeID) {
+       case  PEXEscapeSetEchoColour: {
+ 	pexEscapeSetEchoColourData *psec;
+ 
+ 	psec = (pexEscapeSetEchoColourData *)(strmPtr+1);
+ 	SWAP_ENUM_TYPE_INDEX (psec->fpFormat);
+ 	SWAP_CARD32 (psec->rdr);
+ 	SWAP_FUNC_PREFIX(SwapColourSpecifier) (swapPtr,
+ 					      (pexColourSpecifier *)(psec+1));
+ 	break;
+       }
+     }
+ 	  
+     CALL_REQUEST;
+ }
+ 
+ ErrorCode
+ SWAP_FUNC_PREFIX(PEXEscapeWithReply) (cntxtPtr, strmPtr)
+ pexContext			*cntxtPtr;
+ pexEscapeWithReplyReq          	*strmPtr;
+ {
+     pexSwap *swapPtr = cntxtPtr->swap;
+ 
+     SWAP_CARD16 (strmPtr->length);
+     SWAP_CARD16 (strmPtr->escapeID);
+ 
+     /* do MIT Registered Escapes , none with Replies */
+     /*
+     switch (strmPtr->escapeID) {
+     }
+     */
+ 	  
+ 
+     CALL_REQUEST;
+ }
+ 
+ ErrorCode
  SWAP_FUNC_PEX_PFX(RequestUnused)()
  {
  
***************
*** 1365,1377 ****
  	sc_data += sizeof(PEXFLOAT);
      };
  
      if (im & PEXSCCeiling) {
! 	SWAP_CARD16 ((*((CARD16 *)sc_data)));
! 	sc_data += sizeof(CARD32);	    /* include pad */
      }
  
      if (im & PEXSCModelClipFlag) {
! 	sc_data += sizeof (CARD32);	    /* no swapping needed for CARD8 */
      }
  
      if (im & PEXSCStartPath) 
--- 1586,1600 ----
  	sc_data += sizeof(PEXFLOAT);
      };
  
+     /* next 2 are sent as CARD32 so swap them as if they are */
      if (im & PEXSCCeiling) {
! 	SWAP_CARD32 ((*((CARD32 *)sc_data)));
! 	sc_data += sizeof(CARD32);	    
      }
  
      if (im & PEXSCModelClipFlag) {
! 	SWAP_CARD32 ((*((CARD32 *)sc_data)));
! 	sc_data += sizeof (CARD32);	   
      }
  
      if (im & PEXSCStartPath) 
***************
*** 1442,1472 ****
  }
  
  
- void
- SWAP_FUNC_PREFIX(SwapPickMeasAttr) (swapPtr, im, p_data)
- pexSwap		*swapPtr;
- CARD32		im;
- unsigned char	*p_data;
- {
-     unsigned char *ptr = p_data;
- 
-     if (im & PEXPMStatus) {
- 	SWAP_CARD32((*((CARD32 *)ptr)));
- 	ptr += sizeof(CARD32);
-     }
- 
-     if (im & PEXPMPath) {
- 	CARD32 i;
- 	CARD32 numRefs = *((CARD32 *)ptr);
- 	pexPickPath *pp;
- 	SWAP_CARD32((*((CARD32 *)ptr)));
- 	ptr += sizeof(CARD32);
- 	for (i=0, pp = (pexPickPath *)ptr; i<numRefs; i++, pp++) {
- 	    SWAP_PICK_PATH((*pp));
- 	}
-     }
- }
- 
  unsigned char *
  SWAP_FUNC_PREFIX(SwapLightEntry) (swapPtr, p_data) 
  pexSwap		    *swapPtr;
--- 1665,1670 ----
***************
*** 1616,1625 ****
  CARD32 *itemMask;
  CARD8 *p_data;
  {
      CARD8 *ptr = p_data;
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCMarkerType) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
--- 1814,1829 ----
  CARD32 *itemMask;
  CARD8 *p_data;
  {
+     /* NOTE: See the Protocol Encoding for a desription of these fields
+        in places where CARD16 or INT16 are packed into a 4 byte field
+        (essentially a CARD32) for transmission these fields must be
+        byte swapped as a CARD32. - JSH
+     */
+ 
      CARD8 *ptr = p_data;
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCMarkerType) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
***************
*** 1634,1650 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCMarkerBundleIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextFont) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextPrecision) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
--- 1838,1854 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCMarkerBundleIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextFont) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextPrecision) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
***************
*** 1676,1682 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextPath) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
--- 1880,1886 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextPath) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
***************
*** 1700,1706 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCAtextPath) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
--- 1904,1910 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCAtextPath) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
***************
*** 1712,1728 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCAtextStyle) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextBundleIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLineType) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
--- 1916,1932 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCAtextStyle) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCTextBundleIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLineType) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
***************
*** 1737,1743 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCCurveApproximation) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
--- 1941,1947 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCCurveApproximation) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
***************
*** 1744,1765 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCPolylineInterp) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLineBundleIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCInteriorStyle) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCInteriorStyleIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
--- 1948,1969 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCPolylineInterp) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLineBundleIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCInteriorStyle) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCInteriorStyleIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
***************
*** 1784,1805 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceReflModel) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceInterp) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfInteriorStyle) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfInteriorStyleIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
--- 1988,2009 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceReflModel) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceInterp) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfInteriorStyle) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfInteriorStyleIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
***************
*** 1824,1840 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfSurfaceReflModel) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfSurfaceInterp) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceApproximation) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
--- 2028,2044 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfSurfaceReflModel) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCBfSurfaceInterp) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceApproximation) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
***************
*** 1843,1853 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCCullingMode) {
! 	SWAP_CARD16((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCDistinguishFlag) {
  	ptr += sizeof(CARD32);
      }
  
--- 2047,2058 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCCullingMode) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCDistinguishFlag) {
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
***************
*** 1886,1902 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCInteriorBundleIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceEdgeFlag) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceEdgeType) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
--- 2091,2107 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCInteriorBundleIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceEdgeFlag) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceEdgeType) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
***************
*** 1911,1917 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCEdgeBundleIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
--- 2116,2122 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCEdgeBundleIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
***************
*** 1934,1940 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCModelClip) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
--- 2139,2145 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCModelClip) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
***************
*** 1951,1973 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCViewIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLightState) {
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCDepthCueIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSetAsfValues) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCPickId) {
--- 2156,2188 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCViewIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCLightState) {
+ 	CARD32 i, numLights;
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
+ 	numLights = *((CARD32 *)ptr);
  	ptr += sizeof(CARD32);
+ 	for (i=0; i<numLights; i++) {
+ 	    SWAP_CARD16 ((*((CARD16 *)ptr)));
+ 	    ptr += sizeof(CARD16);
+ 	}
+ 	if (numLights%2)          /* pad odd length list to CARD32 boundary  */
+ 	    ptr += sizeof(CARD16);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCDepthCueIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCSetAsfValues) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));     /* enables BITMASK */
  	ptr += sizeof(CARD32);
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));     /* asfs themselves */
+ 	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCPickId) {
***************
*** 1986,1997 ****
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCColourApproxIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCRenderingColourModel) {
! 	SWAP_CARD16((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
--- 2201,2212 ----
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCColourApproxIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(itemMask, PEXPCRenderingColourModel) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
***************
*** 2029,2036 ****
  		num = *((CARD16 *)ptr);
  		ptr += sizeof(CARD32);
  		for (i=0; i<num; i++) {
! 		    SWAP_COORD3D((*((pexCoord3D *)ptr)));
! 		    ptr += sizeof(pexCoord3D);
  		}
  	    }
  	}
--- 2244,2251 ----
  		num = *((CARD16 *)ptr);
  		ptr += sizeof(CARD32);
  		for (i=0; i<num; i++) {
! 		    SWAP_FLOAT((*((PEXFLOAT *)ptr)));
! 		    ptr += sizeof(PEXFLOAT);
  		}
  	    }
  	}
***************
*** 2050,2056 ****
      int len, i;
  
      if (im & PEXPDPickStatus) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
--- 2265,2271 ----
      int len, i;
  
      if (im & PEXPDPickStatus) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
***************
*** 2058,2070 ****
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	len = (int)(*ptr);
  	ptr += sizeof(CARD32);
! 	for (i=0; i<len; i++, ptr += sizeof(pexPickPath)) {
! 	    SWAP_PICK_PATH ((*((pexPickPath *)ptr)));
  	};
      };
  
      if (im & PEXPDPickPathOrder) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
--- 2273,2285 ----
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	len = (int)(*ptr);
  	ptr += sizeof(CARD32);
! 	for (i=0; i<len; i++, ptr += sizeof(pexPickElementRef)) {
! 	    SWAP_PICK_ELEMENT_REF ((*((pexPickElementRef *)ptr)));
  	};
      };
  
      if (im & PEXPDPickPathOrder) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
***************
*** 2082,2092 ****
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	len = (int)(*ptr);
  	ptr += sizeof(CARD32);
! 	ptr += (len + 3)/4;		    /*	pad it out  */
      };
  
      if (im & PEXPDPickPromptEchoType) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
--- 2297,2307 ----
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	len = (int)(*ptr);
  	ptr += sizeof(CARD32);
! 	ptr += len + PADDING(len);		    /*	pad it out  */
      };
  
      if (im & PEXPDPickPromptEchoType) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
***************
*** 2096,2102 ****
      }
  
      if (im & PEXPDPickEchoSwitch) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
      }
  }
  
--- 2311,2317 ----
      }
  
      if (im & PEXPDPickEchoSwitch) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
      }
  }
  
***************
*** 2203,2215 ****
  	ptr += sizeof(CARD32);
      }
  
      if (im & PEXRDRendererState) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      if (im & PEXRDHlhsrMode) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
  	
      }
--- 2418,2433 ----
  	ptr += sizeof(CARD32);
      }
  
+   /* Swap this and HLHSR as CARD32 since they're in a 4 byte field in
+      the LISTofVALUE                                                  */
+ 
      if (im & PEXRDRendererState) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      if (im & PEXRDHlhsrMode) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
  	
      }
***************
*** 2229,2234 ****
--- 2447,2530 ----
  	num = *((CARD32 *)ptr);
  	ptr += sizeof(CARD32);
  	SwapDeviceRects (swapPtr, num, (pexDeviceRect *)ptr);
+ 	ptr += sizeof(pexDeviceRect) * num;
      }
+ 
+     if (im & PEXRDPickInclusion) {
+ 	SWAP_NAMESET ((*((pexNameSet *)ptr)));
+ 	ptr += sizeof(pexNameSet);
+     }
+ 
+     if (im & PEXRDPickExclusion) {
+ 	SWAP_NAMESET ((*((pexNameSet *)ptr)));
+ 	ptr += sizeof(pexNameSet);
+     }
+ 
+     if (im & PEXRDPickStartPath) {
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
+ 	num = *((CARD32 *)ptr);
+ 	ptr += sizeof(CARD32);
+ 	for (i=0; i<num; i++, ptr += sizeof(pexElementRef))
+ 	    SWAP_ELEMENT_REF((*((pexElementRef *)ptr)));
+     }
+ 
+     if (im & PEXRDBackgroundColour) {
+ 	ptr = SWAP_FUNC_PREFIX(SwapColourSpecifier) (swapPtr,
+ 						   (pexColourSpecifier *)ptr);
+     }
+ 
+     /* this is CARD8 cast into a CARD32 so it must get swapped as CARD32 */
+     if (im & PEXRDClearI) {
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
+ 	ptr += sizeof(CARD32);
+     }
+ 
+     /* this is CARD8 cast into a CARD32 so it must get swapped as CARD32 */
+     if (im & PEXRDClearZ) {
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
+ 	ptr += sizeof(CARD32);
+     }
+ 
+     /* this is CARD16 cast into a CARD32 so it must get swapped as CARD32 */
+     if (im & PEXRDEchoMode) {
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
+ 	ptr += sizeof(CARD32);
+     }
+ }
+ 
+ void
+ SWAP_FUNC_PREFIX(SwapPickRecord) (swapPtr, p_data)
+ pexSwap	  		    *swapPtr;
+ pexPickRecord	            *p_data;
+ {
+ 
+     SWAP_CARD16 (p_data->pickType);
+ 
+     switch(p_data->pickType) {
+ 	case PEXPickDeviceDC_HitBox: {
+ 	  unsigned char *ptr = (unsigned char *)(p_data+1);
+ 	  SWAP_CARD16 ((*((CARD16 *)ptr)));
+ 	  ptr += sizeof(CARD16);
+ 	  SWAP_CARD16 ((*((CARD16 *)ptr)));
+ 	  ptr += sizeof(CARD16);
+ 	  SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
+ 	  break;
+ 	} 
+ 	case PEXPickDeviceNPC_HitVolume: {
+ 	  unsigned char *ptr = (unsigned char *)(p_data+1);
+ 	  SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
+ 	  ptr += sizeof(PEXFLOAT);
+ 	  SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
+ 	  ptr += sizeof(PEXFLOAT);
+ 	  SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
+ 	  ptr += sizeof(PEXFLOAT);
+ 	  SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
+ 	  ptr += sizeof(PEXFLOAT);
+ 	  SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
+ 	  ptr += sizeof(PEXFLOAT);
+ 	  SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
+ 	  break;
+ 	} 
+     } 
  }
  
*** -	Thu Jan 28 17:51:09 1993
--- mit/extensions/server/PEX/dipex/swap/convReq.h	Thu Jan 28 17:51:09 1993
***************
*** 1,4 ****
! /* $XConsortium: convReq.h,v 5.1 91/02/16 09:57:11 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: convReq.h,v 5.2 92/03/04 14:18:57 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 25,34 ****
--- 25,36 ----
  ******************************************************************/
  
  LOCAL_FLAG ErrorCode
+ 	SWAP_FUNC_PREFIX(PEXRequestUnused)(),
  	SWAP_FUNC_PREFIX(PEXGenericRequest) (),
  	SWAP_FUNC_PREFIX(PEXGenericResourceRequest) (),
  	SWAP_FUNC_PREFIX(PEXGetExtensionInfo) (),
  	SWAP_FUNC_PREFIX(PEXGetEnumeratedTypeInfo) (),
+ 	SWAP_FUNC_PREFIX(PEXGetImpDepConstants) (),
  	SWAP_FUNC_PREFIX(PEXCreateLookupTable) (),
  	SWAP_FUNC_PREFIX(PEXCopyLookupTable) (),
  	SWAP_FUNC_PREFIX(PEXGetTableInfo) (),
***************
*** 97,110 ****
  	SWAP_FUNC_PREFIX(PEXListFonts) (),
  	SWAP_FUNC_PREFIX(PEXListFontsWithInfo) (),
  	SWAP_FUNC_PREFIX(PEXQueryTextExtents) (),
! 	SWAP_FUNC_PREFIX(PEXGetImpDepConstants) (),
! 	SWAP_FUNC_PREFIX(PEXRequestUnused)();
  
  LOCAL_FLAG void
  	SWAP_FUNC_PREFIX(SwapTable)(),
  	SWAP_FUNC_PREFIX(SwapSearchContext)(),
  	SWAP_FUNC_PREFIX(SwapPickMeasAttr) (),
  	SWAP_FUNC_PREFIX(SwapPickDevAttr) (),
  	SWAP_FUNC_PREFIX(SwapRendererAttributes) ();
  
  LOCAL_FLAG unsigned char * SWAP_FUNC_PREFIX(SwapLightEntry) ();
--- 99,123 ----
  	SWAP_FUNC_PREFIX(PEXListFonts) (),
  	SWAP_FUNC_PREFIX(PEXListFontsWithInfo) (),
  	SWAP_FUNC_PREFIX(PEXQueryTextExtents) (),
!         SWAP_FUNC_PREFIX(PEXMatchRendererTargets) (),
! 	SWAP_FUNC_PREFIX(PEXEscape) (),
! 	SWAP_FUNC_PREFIX(PEXEscapeWithReply) (),
! 	SWAP_FUNC_PREFIX(PEXRenderElements) (),
! 	SWAP_FUNC_PREFIX(PEXAccumulateState) (),
! 	SWAP_FUNC_PREFIX(PEXBeginPickOne) (),
! 	SWAP_FUNC_PREFIX(PEXEndPickOne) (),
!         SWAP_FUNC_PREFIX(PEXPickOne) (),
! 	SWAP_FUNC_PREFIX(PEXBeginPickAll) (),
! 	SWAP_FUNC_PREFIX(PEXEndPickAll) (),
! 	SWAP_FUNC_PREFIX(PEXPickAll) ();
  
+ 
  LOCAL_FLAG void
  	SWAP_FUNC_PREFIX(SwapTable)(),
  	SWAP_FUNC_PREFIX(SwapSearchContext)(),
  	SWAP_FUNC_PREFIX(SwapPickMeasAttr) (),
  	SWAP_FUNC_PREFIX(SwapPickDevAttr) (),
+ 	SWAP_FUNC_PREFIX(SwapPickRecord) (),
  	SWAP_FUNC_PREFIX(SwapRendererAttributes) ();
  
  LOCAL_FLAG unsigned char * SWAP_FUNC_PREFIX(SwapLightEntry) ();
*** -	Thu Jan 28 17:51:10 1993
--- mit/extensions/server/PEX/dipex/swap/check.c	Thu Jan 28 17:51:09 1993
***************
*** 1,4 ****
! /* $XConsortium: check.c,v 5.3 91/07/01 16:42:42 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: check.c,v 5.5 92/03/04 14:18:59 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 32,38 ****
  #include "dipex.h"
  #include "pexSwap.h"
  #include "pex_site.h"
- #include "swapmacros.h"
  #include "pexError.h"
  
  /*
--- 32,37 ----
***************
*** 44,54 ****
  	as a floating point specifier;
   */
  
! extern PEXFLOAT SwapFLOAT();
! extern PEXFLOAT SwapIEEEToVax();
! extern PEXFLOAT SwapVaxToIEEE();
! extern PEXFLOAT ConvertIEEEToVax();
! extern PEXFLOAT ConvertVaxToIEEE();
  extern OCFunction cPEXOutputCmd[];
  extern OCFunction uPEXOutputCmd[];
  extern RequestFunction PEXRequest[];
--- 43,53 ----
  	as a floating point specifier;
   */
  
! extern void SwapFLOAT();
! extern void SwapIEEEToVax();
! extern void SwapVaxToIEEE();
! extern void ConvertIEEEToVax();
! extern void ConvertVaxToIEEE();
  extern OCFunction cPEXOutputCmd[];
  extern OCFunction uPEXOutputCmd[];
  extern RequestFunction PEXRequest[];
***************
*** 55,61 ****
--- 54,66 ----
  extern RequestFunction cPEXRequest[];
  extern ReplyFunction uPEXReply[];
  
+ /* define some macros previously taken from swapmacros.h */
+ /* byte swap AND COPY a short (given pointer) */
+ #define SWAPSHORTC(x, y)\
+ ((char *) (y))[1] = ((char *) (x))[0];\
+ ((char *) (y))[0] = ((char *) (x))[1]
  
+ 
  typedef struct {
      CARD8 	reqType;
      CARD8 	opcode;
***************
*** 115,121 ****
  	cntxtPtr->pexSwapRequestOC  =  cPEXOutputCmd; 
  	cntxtPtr->pexSwapReply	    =  uPEXReply;
  	cntxtPtr->pexSwapReplyOC    =  uPEXOutputCmd;
! 	swapshortc(strmPtr->fpFormat, fp);
  
  	if ( fp == SERVER_NATIVE_FP ) {
  	    cntxtPtr->swap->ConvertFLOAT =  (ConvFunction)SwapFLOAT;
--- 120,126 ----
  	cntxtPtr->pexSwapRequestOC  =  cPEXOutputCmd; 
  	cntxtPtr->pexSwapReply	    =  uPEXReply;
  	cntxtPtr->pexSwapReplyOC    =  uPEXOutputCmd;
! 	SWAPSHORTC(&(strmPtr->fpFormat), &fp);
  
  	if ( fp == SERVER_NATIVE_FP ) {
  	    cntxtPtr->swap->ConvertFLOAT =  (ConvFunction)SwapFLOAT;
***************
*** 315,319 ****
  /*  90	*/	NoFloat,		/* PEXQueryFont */
  /*  91	*/	NoFloat,		/* PEXListFonts */
  /*  92	*/	NoFloat,		/* PEXListFontsWithInfo */
! /*  93	*/	CheckFloat		/* PEXQueryTextExtents */
  };
--- 320,335 ----
  /*  90	*/	NoFloat,		/* PEXQueryFont */
  /*  91	*/	NoFloat,		/* PEXListFonts */
  /*  92	*/	NoFloat,		/* PEXListFontsWithInfo */
! /*  93	*/	CheckFloat,		/* PEXQueryTextExtents */
! /*  94	*/	NoFloat,    		/* PEXMatchRendererTargets */
! /*  95	*/	NoFloat,    		/* PEXEscape */
! /*  96	*/	NoFloat,    		/* PEXEscapeWithReply */
! /*  97	*/	NoFloat,    		/* PEXRenderElements */
! /*  98	*/	NoFloat,    		/* PEXAccumulateState */
! /*  99	*/	CheckFloat,    		/* PEXBeginPickOne */
! /* 100	*/	NoFloat,    		/* PEXEndPickOne */
! /* 101	*/	CheckFloat,    		/* PEXPickOne */
! /* 102	*/	CheckFloat,    		/* PEXBeginPickAll */
! /* 103	*/	NoFloat,    		/* PEXEndPickAll */
! /* 104	*/	CheckFloat    		/* PEXPickAll */
  };
*** -	Thu Jan 28 17:51:12 1993
--- mit/extensions/server/PEX/dipex/swap/convertStr.h	Thu Jan 28 17:51:12 1993
***************
*** 1,4 ****
! /* $XConsortium: convertStr.h,v 5.1 91/02/16 09:57:14 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: convertStr.h,v 5.3 92/08/12 15:46:12 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 161,175 ****
  	SWAP_TEXT_H_ALIGNMENT((A).horizontal); \
  	SWAP_TEXT_V_ALIGNMENT((A).vertical); }
  
! #define SWAP_PICK_PATH(P) \
  	SWAP_STRUCTURE ((P).sid); \
  	SWAP_CARD32 ((P).offset); \
! 	SWAP_CARD32 ((P).pickid);
  
  
! #define SWAP_STRUCT_INFO(S) \
  	SWAP_STRUCTURE((S).sid); \
! 	SWAP_FLOAT((S).priority);
  
  
  #endif	/* CONVERTSTR_H */
--- 161,178 ----
  	SWAP_TEXT_H_ALIGNMENT((A).horizontal); \
  	SWAP_TEXT_V_ALIGNMENT((A).vertical); }
  
! #define SWAP_PICK_ELEMENT_REF(P) { \
  	SWAP_STRUCTURE ((P).sid); \
  	SWAP_CARD32 ((P).offset); \
! 	SWAP_CARD32 ((P).pickid); }
  
  
! #define SWAP_STRUCT_INFO(S) { \
  	SWAP_STRUCTURE((S).sid); \
! 	SWAP_FLOAT((S).priority);}
  
+ #define SWAP_RENDERER_TARGET(S) { \
+ 	SWAP_CARD16((S).type); \
+ 	SWAP_CARD32((S).visualID); }
  
  #endif	/* CONVERTSTR_H */
*** -	Thu Jan 28 17:51:13 1993
--- mit/extensions/server/PEX/dipex/swap/cOCprim.c	Thu Jan 28 17:51:13 1993
***************
*** 1,4 ****
! /* $XConsortium: cOCprim.c,v 5.5 91/07/01 16:38:43 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cOCprim.c,v 5.7 92/06/02 19:41:04 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 753,768 ****
  	case PEXPSCMcLevelCurves:
  	case PEXPSCWcLevelCurves: {
  	    pexPSC_LevelCurves *ptr = (pexPSC_LevelCurves *)(strmPtr+1);
! 	    pexCoord3D *pc = (pexCoord3D *)(ptr+1);
  	    CARD16 i;
  	    SWAP_COORD3D (ptr->origin);
  	    SWAP_VECTOR3D (ptr->direction);
  	    SWAP_CARD16 (ptr->numberIntersections);
  	    for (i=0; i<ptr->numberIntersections; i++, pc++) {
! 		SWAP_COORD3D(*pc);
  	    }
  	    break;
  	}
      }
  
  }
--- 753,775 ----
  	case PEXPSCMcLevelCurves:
  	case PEXPSCWcLevelCurves: {
  	    pexPSC_LevelCurves *ptr = (pexPSC_LevelCurves *)(strmPtr+1);
! 	    PEXFLOAT *pc = (PEXFLOAT *)(ptr+1);
  	    CARD16 i;
  	    SWAP_COORD3D (ptr->origin);
  	    SWAP_VECTOR3D (ptr->direction);
  	    SWAP_CARD16 (ptr->numberIntersections);
  	    for (i=0; i<ptr->numberIntersections; i++, pc++) {
! 		SWAP_FLOAT(*pc);
  	    }
  	    break;
  	}
      }
  
+ }
+ 
+ ErrorCode
+ SWAP_FUNC_PREFIX(PEXNoop) (swapPtr, strmPtr)
+ pexSwap	*swapPtr;
+ pexNoop	*strmPtr;
+ {
  }
*** -	Thu Jan 28 17:51:15 1993
--- mit/extensions/server/PEX/dipex/swap/floatconv.c	Thu Jan 28 17:51:14 1993
***************
*** 1,4 ****
! /* $XConsortium: floatconv.c,v 5.4 91/07/01 16:39:12 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: floatconv.c,v 5.5 91/12/30 18:23:51 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 114,138 ****
   * 	brute force BITMASKS and shifts.
   */
  
! PEXFLOAT 
  ConvertVaxToIEEE(VaxnumR)
      PEXFLOAT *VaxnumR;
  {
      register CARD32 Vaxnum = *(CARD32 *)VaxnumR;
!     CARD32 result=0;
  
      if ((VAX_SIGN_MASK & Vaxnum)==MAX_VAX_POSITIVE)
      {
! 	result = MAX_IEEE_POSITIVE |
  	    (((0x00008000)&Vaxnum) ? 0x80000000 : 0L);
! 	return *(PEXFLOAT *)(&result);
!     };
      
      if ((VAX_SIGN_MASK & Vaxnum)==MIN_VAX_POSITIVE)
      {
! 	result = MIN_IEEE_POSITIVE;
! 	return *(PEXFLOAT *)(&result);
!     };
  
      /*
       * these bitfields should OR into mutually exclusive fields in
--- 114,139 ----
   * 	brute force BITMASKS and shifts.
   */
  
! void
  ConvertVaxToIEEE(VaxnumR)
      PEXFLOAT *VaxnumR;
  {
      register CARD32 Vaxnum = *(CARD32 *)VaxnumR;
!     CARD32 *VaxnumP = (CARD32 *)VaxnumR;
!     CARD32 result;
  
      if ((VAX_SIGN_MASK & Vaxnum)==MAX_VAX_POSITIVE)
      {
! 	*VaxnumP = MAX_IEEE_POSITIVE |
  	    (((0x00008000)&Vaxnum) ? 0x80000000 : 0L);
! 	return;
!     }
      
      if ((VAX_SIGN_MASK & Vaxnum)==MIN_VAX_POSITIVE)
      {
! 	*VaxnumP = MIN_IEEE_POSITIVE;
! 	return;
!     }
  
      /*
       * these bitfields should OR into mutually exclusive fields in
***************
*** 139,149 ****
       * result field.
       */
      
!     result |= ((((BITMASK(8)<<7) & Vaxnum)>>7)+VAX_TO_IEEE_BIAS)<<23;
      result |= (((BITMASK(7) & Vaxnum)<<16) |
  	       (((BITMASK(16)<<16) & Vaxnum)>>16));
      result |= ( (0x00008000 & Vaxnum) ? 0x80000000 : 0L);
!     return *(PEXFLOAT *)(&result);
  }
  
  /*****************************************************************
--- 140,151 ----
       * result field.
       */
      
!     result = ((((BITMASK(8)<<7) & Vaxnum)>>7)+VAX_TO_IEEE_BIAS)<<23;
      result |= (((BITMASK(7) & Vaxnum)<<16) |
  	       (((BITMASK(16)<<16) & Vaxnum)>>16));
      result |= ( (0x00008000 & Vaxnum) ? 0x80000000 : 0L);
!     *VaxnumP = result;
!     return;
  }
  
  /*****************************************************************
***************
*** 172,195 ****
   * 	brute force BITMASKS and shifts.
   */
      
! PEXFLOAT 
  ConvertIEEEToVax(IEEEnumR)
      PEXFLOAT *IEEEnumR;
  {
      register CARD32 IEEEnum = *(CARD32 *)IEEEnumR;
      CARD32 result=0;
  
      if ((IEEE_SIGN_MASK & IEEEnum)==MAX_IEEE_POSITIVE)
      {
! 	result = MAX_VAX_POSITIVE |
  	    (0x80000000&IEEEnum)>>16;
! 	return *(PEXFLOAT *)(&result);
      };
      
      if ((IEEE_SIGN_MASK & IEEEnum)==MIN_IEEE_POSITIVE)
      {
! 	result = MIN_VAX_POSITIVE;
! 	return *(PEXFLOAT *)(&result);
      };
  
      /*
--- 174,198 ----
   * 	brute force BITMASKS and shifts.
   */
      
! void 
  ConvertIEEEToVax(IEEEnumR)
      PEXFLOAT *IEEEnumR;
  {
      register CARD32 IEEEnum = *(CARD32 *)IEEEnumR;
+     CARD32 *IEEEnumP = (CARD32 *)IEEEnumR;
      CARD32 result=0;
  
      if ((IEEE_SIGN_MASK & IEEEnum)==MAX_IEEE_POSITIVE)
      {
! 	*IEEEnumP = MAX_VAX_POSITIVE |
  	    (0x80000000&IEEEnum)>>16;
! 	return;
      };
      
      if ((IEEE_SIGN_MASK & IEEEnum)==MIN_IEEE_POSITIVE)
      {
! 	*IEEEnumP = MIN_VAX_POSITIVE;
! 	return;
      };
  
      /*
***************
*** 197,205 ****
       * result field.
       */
  
!     result |= ((((BITMASK(8)<<23) & IEEEnum)>>23)+IEEE_TO_VAX_BIAS)<<7;
      result |= ((BITMASK(7)<<16)&IEEEnum)>>16;
      result |= (BITMASK(16)&IEEEnum)<<16;
      result |= (0x80000000&IEEEnum)>>16;
!     return *(PEXFLOAT *)(&result);  /* hopefully the *& will not generate code */
  }
--- 200,209 ----
       * result field.
       */
  
!     result = ((((BITMASK(8)<<23) & IEEEnum)>>23)+IEEE_TO_VAX_BIAS)<<7;
      result |= ((BITMASK(7)<<16)&IEEEnum)>>16;
      result |= (BITMASK(16)&IEEEnum)<<16;
      result |= (0x80000000&IEEEnum)>>16;
!     *IEEEnumP = result;
!     return;  
  }
*** -	Thu Jan 28 17:51:17 1993
--- mit/extensions/server/PEX/dipex/swap/uconvRep.c	Thu Jan 28 17:51:15 1993
***************
*** 1,4 ****
! /* $XConsortium: uconvRep.c,v 5.5 91/07/01 16:39:44 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: uconvRep.c,v 5.14 92/11/24 13:13:35 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 54,59 ****
--- 54,61 ----
  #define LOCAL_FLAG
  #include "uconvRep.h"
  
+ #define PADDING(n) ( (n)&3 ? (4 - ((n)&3)) : 0)
+ 
  /*************************************************************
  	Replies
  
***************
*** 83,89 ****
  {
      pexSwap *swapPtr = cntxtPtr->swap;
      int i, j, pad;
-     CARD16 *ptr, *optr;
  
      SWAP_CARD16 (reply->sequenceNumber);
      SWAP_CARD32 (reply->length);	/* NOT 0 */
--- 85,90 ----
***************
*** 91,103 ****
      switch (strmPtr->itemMask) {
  
  	case PEXETIndex : {
! 		/* PEXETIndex =1 per define in PEX.h */
  	    for (i=0, ptr = (CARD16 *)(reply+1); i < reply->numLists; i++) {
! 		j = *((CARD32 *)ptr);
! 		pad = j & 1;
  		SWAP_CARD32(*((CARD32 *)ptr));
  		ptr += 2;
! 		while (--j >= 0) {
  		    SWAP_CARD16((*ptr));
  		    ptr++;
  		}
--- 92,107 ----
      switch (strmPtr->itemMask) {
  
  	case PEXETIndex : {
! 	    CARD16 *ptr;
! 	    /* PEXETIndex =1 per define in PEX.h */
! 	    /* a LISTofLISTofINT16               */
! 	    int numints;
  	    for (i=0, ptr = (CARD16 *)(reply+1); i < reply->numLists; i++) {
! 		numints = *((CARD32 *)ptr);
! 		pad = numints & 1;
  		SWAP_CARD32(*((CARD32 *)ptr));
  		ptr += 2;
! 		for (j=0; j < numints; j++) {
  		    SWAP_CARD16((*ptr));
  		    ptr++;
  		}
***************
*** 108,144 ****
  	}
  
  	case PEXETMnemonic : {
! 		/* PEXETMnemonic =2 per define in PEX.h */
! 	    for (i=0, ptr = (CARD16 *)(reply+1); i < reply->numLists; i++) {
! 		j = *((CARD32 *)ptr);
  		SWAP_CARD32(*((CARD32 *)ptr));
! 		ptr += 2;
! 		optr = ptr;
! 		while (--j >= 0) {
! 		    pad = *ptr;
! 		    SWAP_CARD16((*ptr));
! 		    ptr += 1 + ((pad + 1) >> 1);;
  		}
- 		ptr += (ptr - optr) & 1;
  	    }
  	  break;
  	}
  
  	case PEXETBoth : {
! 		/* PEXETBOTH =3 per define in PEX.h */
! 	    for (i=0, ptr = (CARD16 *)(reply+1); i < reply->numLists; i++) {
! 		j = *((CARD32 *)ptr);
  		SWAP_CARD32(*((CARD32 *)ptr));
! 		ptr += 2;
! 		optr = ptr;
! 		while (--j >= 0) {
  		    SWAP_CARD16((*ptr));
! 		    ptr++;
! 		    pad = *ptr;
! 		    SWAP_CARD16((*ptr));
! 		    ptr += 1 + ((pad + 1) >> 1);;
  		}
- 		ptr += (ptr - optr) & 1;
  	    }
  	  break;
          }
--- 112,150 ----
  	}
  
  	case PEXETMnemonic : {
! 	    CARD8 *ptr;
! 	    /* PEXETMnemonic =2 per define in PEX.h */
! 	    /* a LISTofLISTofSTRING                 */
! 	    int numstrings, numbytes;
! 	    for (i=0, ptr = (CARD8 *)(reply+1); i < reply->numLists; i++) {
! 		numstrings = *((CARD32 *)ptr);
  		SWAP_CARD32(*((CARD32 *)ptr));
! 		ptr += 4;
! 		for (j=0; j < numstrings; j++) {
! 		    numbytes = *((CARD16 *)ptr);
! 		    SWAP_CARD16(*((CARD16 *)ptr));
! 		    ptr += 2 + numbytes + PADDING(2+numbytes);
  		}
  	    }
  	  break;
  	}
  
  	case PEXETBoth : {
! 	    CARD8 *ptr;
! 	    /* PEXETBOTH =3 per define in PEX.h */
! 	    /* a LISTofLISTofENUM_DESC 		*/
! 	    int numenums, numbytes;
! 	    for (i=0, ptr = (CARD8 *)(reply+1); i < reply->numLists; i++) {
! 		numenums = *((CARD32 *)ptr);
  		SWAP_CARD32(*((CARD32 *)ptr));
! 		ptr += 4;
! 		for (j=0; j < numenums; j++) {
  		    SWAP_CARD16((*ptr));
! 		    ptr += 2;
! 		    numbytes = *((CARD16 *)ptr);
! 		    SWAP_CARD16(*((CARD16 *)ptr));
! 		    ptr += 2 + numbytes + PADDING(numbytes);
  		}
  	    }
  	  break;
          }
***************
*** 145,150 ****
--- 151,157 ----
  
  	default: { /* counts */
  
+ 	    CARD16 *ptr;
  		/* swap the counts */
  	    for (i=0, ptr = (CARD16 *)(reply+1); i < reply->numLists; i++) {
  		SWAP_CARD32(*((CARD32 *)ptr));
***************
*** 405,411 ****
  	 i++, curCmd += length)
      {
  	pe = (pexElementInfo *)curCmd;
! 	cntxtPtr->pexSwapReplyOC[ pe->elementType ] (swapPtr, pe);
  	length = pe->length;
  	SWAP_ELEMENT_INFO (*pe);
      }
--- 412,420 ----
  	 i++, curCmd += length)
      {
  	pe = (pexElementInfo *)curCmd;
! 	/* this check must match the one done in mipex.h MI_IS_PEX_OC macro */
!         if ((PEXOCAll < pe->elementType) && (pe->elementType <= PEXMaxOC))
! 	    cntxtPtr->pexSwapReplyOC[ pe->elementType ] (swapPtr, pe);
  	length = pe->length;
  	SWAP_ELEMENT_INFO (*pe);
      }
***************
*** 482,501 ****
  
      ptr = (unsigned char *)(reply+1);
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWDisplayUpdate) {
! 	SWAP_ENUM_TYPE_INDEX ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWVisualState) {
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWDisplaySurface) {
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWViewUpdate) {
  	ptr += sizeof(CARD32);
      }
  
--- 491,517 ----
  
      ptr = (unsigned char *)(reply+1);
  
+     /*  Read the Protocol Encoding, lots of non 4 byte fields here
+ 	that are shipped as 4 bytes (effectively CARD32) so they 
+ 	are swapped as CARD32    - JSH
+     */
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWDisplayUpdate) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWVisualState) {
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWDisplaySurface) {
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWViewUpdate) {
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
***************
*** 505,515 ****
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr+=sizeof(CARD32);
  	for (i=0; i<len; i++, ptr += sizeof(CARD32)) {
! 	    SWAP_TABLE_INDEX ((*((CARD16 *)ptr)));
  	}
      };
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWWksUpdate){
  	ptr += sizeof(CARD32);
      }
  
--- 521,532 ----
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr+=sizeof(CARD32);
  	for (i=0; i<len; i++, ptr += sizeof(CARD32)) {
! 	    SWAP_CARD32 ((*((CARD32 *)ptr)));
  	}
      };
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWWksUpdate){
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
***************
*** 534,549 ****
      };
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWHlhsrUpdate) {
  	ptr += sizeof(CARD32);
      };
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWReqHlhsrMode) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWCurHlhsrMode) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
--- 551,567 ----
      };
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWHlhsrUpdate) {
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWReqHlhsrMode) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWCurHlhsrMode) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
***************
*** 646,661 ****
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWBufferUpdate) {
  	ptr += sizeof(CARD32);	
      }	
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWReqBufferMode) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);	
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWCurBufferMode) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);	
      }
  
--- 664,680 ----
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWBufferUpdate) {
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);	
      }	
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWReqBufferMode) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);	
      }
  
      CHECK_BITMASK_ARRAY(strmPtr->itemMask, PEXPWCurBufferMode) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);	
      }
  
***************
*** 787,792 ****
--- 806,920 ----
  }
  
  void
+ SWAP_FUNC_PREFIX(ConvertEndPickOneReply) (cntxtPtr, strmPtr, reply)
+ pexContext		*cntxtPtr;
+ pexEndPickOneReq	*strmPtr;
+ pexEndPickOneReply	*reply;
+ {
+     pexPickElementRef *p_data;
+     CARD32  i;
+ 
+     pexSwap *swapPtr = cntxtPtr->swap;
+ 
+     SWAP_CARD16 (reply->sequenceNumber);
+     SWAP_CARD32 (reply->length);	
+     SWAP_CARD16 (reply->pickStatus);
+ 
+     p_data = (pexPickElementRef *)(reply+1);
+     for (i=0; i < reply->numPickElRefs; i++, p_data++) 
+ 	    SWAP_PICK_ELEMENT_REF((*p_data));
+     
+     SWAP_CARD32 (reply->numPickElRefs);
+ }
+ 
+ void
+ SWAP_FUNC_PREFIX(ConvertPickOneReply) (cntxtPtr, strmPtr, reply)
+ pexContext		*cntxtPtr;
+ pexPickOneReq		*strmPtr;
+ pexPickOneReply		*reply;
+ {
+     pexPickElementRef *p_data;
+     CARD32  i;
+ 
+     pexSwap *swapPtr = cntxtPtr->swap;
+ 
+     SWAP_CARD16 (reply->sequenceNumber);
+     SWAP_CARD32 (reply->length);
+     SWAP_CARD16 (reply->pickStatus);
+ 
+     p_data = (pexPickElementRef *)(reply+1);
+     for (i=0; i < reply->numPickElRefs; i++, p_data++) 
+ 	    SWAP_PICK_ELEMENT_REF((*p_data));
+     
+     SWAP_CARD32 (reply->numPickElRefs);
+ }
+ 
+ void
+ SWAP_FUNC_PREFIX(ConvertEndPickAllReply) (cntxtPtr, strmPtr, reply)
+ pexContext		*cntxtPtr;
+ pexEndPickAllReq	*strmPtr;
+ pexEndPickAllReply	*reply;
+ {
+     pexPickElementRef *p_data;
+     CARD32 i, j, num, *buf;
+ 
+     pexSwap *swapPtr = cntxtPtr->swap;
+ 
+     SWAP_CARD16 (reply->sequenceNumber);
+     SWAP_CARD32 (reply->length);
+     SWAP_CARD16 (reply->pickStatus);
+     SWAP_CARD16 (reply->morePicks);
+ 
+     /* JSH commented out because until the Pick Functionality is
+        actually written this will seg fault on a NULL pointer
+ 
+     for ( i=0, buf=(CARD32 *)(reply+1); i < reply->numPicked; i++) {
+ 	num = *buf;
+ 	SWAP_CARD32((*buf));
+ 	buf++;
+ 	for ( j=0, p_data = (pexPickElementRef *)(buf); j < num; j++, p_data++)
+ 	    SWAP_PICK_ELEMENT_REF((*p_data));
+ 	buf = (CARD32 *)p_data;
+     }
+ 
+     */
+     SWAP_CARD32 (reply->numPicked);
+ }
+ 
+ void
+ SWAP_FUNC_PREFIX(ConvertPickAllReply) (cntxtPtr, strmPtr, reply)
+ pexContext		*cntxtPtr;
+ pexPickAllReq	*strmPtr;
+ pexPickAllReply	*reply;
+ {
+     pexPickElementRef *p_data;
+     CARD32 i, j, num, *buf;
+ 
+     pexSwap *swapPtr = cntxtPtr->swap;
+ 
+     SWAP_CARD16 (reply->sequenceNumber);
+     SWAP_CARD32 (reply->length);
+     SWAP_CARD16 (reply->pickStatus);
+     SWAP_CARD16 (reply->morePicks);
+ 
+     /* JSH commented out because until the Pick Functionality is
+        actually written this will seg fault on a NULL pointer
+ 
+     for ( i=0, buf=(CARD32 *)(reply+1); i < reply->numPicked; i++) {
+ 	num = *buf;
+ 	SWAP_CARD32((*buf));
+ 	buf++;
+ 	for ( j=0, p_data = (pexPickElementRef *)(buf); j < num; j++, p_data++)
+ 	    SWAP_PICK_ELEMENT_REF((*p_data));
+ 	buf = (CARD32 *)p_data;
+     }
+ 
+     */
+     SWAP_CARD32 (reply->numPicked);
+ }
+ 
+ 
+ void
  SWAP_FUNC_PREFIX(ConvertQueryFontReply) (cntxtPtr, strmPtr, reply)
  pexContext	    *cntxtPtr;
  pexQueryFontReq	    *strmPtr;
***************
*** 848,860 ****
  pexQueryTextExtentsReply    *reply;
  {
      pexSwap *swapPtr = cntxtPtr->swap;
!     CARD32 numInfo, *ptr = (CARD32 *)(reply+1);
  
      SWAP_CARD16 (reply->sequenceNumber);
      SWAP_CARD32 (reply->length);	/* not 0 */
  
!     numInfo = *ptr++ / 6;
!     SwapExtentInfo (swapPtr, numInfo, (pexExtentInfo *)ptr);
  }
  
  void
--- 976,989 ----
  pexQueryTextExtentsReply    *reply;
  {
      pexSwap *swapPtr = cntxtPtr->swap;
!     CARD32 numInfo;
  
+     numInfo = reply->length / 6;
+ 
      SWAP_CARD16 (reply->sequenceNumber);
      SWAP_CARD32 (reply->length);	/* not 0 */
  
!     SwapExtentInfo (swapPtr, numInfo, (pexExtentInfo *) (reply + 1));
  }
  
  void
***************
*** 916,921 ****
--- 1045,1086 ----
  }
  
  void
+ SWAP_FUNC_PREFIX(ConvertMatchRendererTargetsReply) (cntxtPtr, strmPtr, reply)
+ pexContext		    *cntxtPtr;
+ pexMatchRendererTargetsReq  *strmPtr;
+ pexMatchRendererTargetsReply    *reply;
+ {
+     pexSwap *swapPtr = cntxtPtr->swap;
+     CARD32 i, numTargets;
+     pexRendererTarget *rd_data;
+ 
+     numTargets = reply->length / 2;
+     SWAP_CARD16 (reply->sequenceNumber);
+     SWAP_CARD32 (reply->length);	/* not 0 */
+ 
+     rd_data = (pexRendererTarget *)(reply + 1);
+ 
+     for ( i = 0; i < numTargets; i++, rd_data++ )
+ 	SWAP_RENDERER_TARGET((*rd_data));
+ 
+ }
+ 
+ void
+ SWAP_FUNC_PREFIX(EscapeWithReplyReply) (cntxtPtr, strmPtr, reply)
+ pexContext		    *cntxtPtr;
+ pexEscapeWithReplyReq       *strmPtr;
+ pexEscapeWithReplyReply     *reply;
+ {
+     pexSwap *swapPtr = cntxtPtr->swap;
+ 
+     SWAP_CARD16 (reply->sequenceNumber);
+     SWAP_CARD32 (reply->length);	/* not 0 */
+     SWAP_CARD32 (reply->escapeID);
+ 
+     /* vendor specific stuff goes here */
+ }
+ 
+ void
  SWAP_FUNC_PREFIX(NoReply)()
  {
  
***************
*** 1061,1073 ****
  	sc_data += sizeof(PEXFLOAT);
      };
  
      if (im & PEXSCCeiling) {
! 	SWAP_CARD16 ((*((CARD16 *)sc_data)));
! 	sc_data += sizeof(CARD32);	    /* include pad */
      }
  
      if (im & PEXSCModelClipFlag) {
! 	sc_data += sizeof (CARD32);	    /* no swapping needed for CARD8 */
      }
  
      if (im & PEXSCStartPath) {
--- 1226,1240 ----
  	sc_data += sizeof(PEXFLOAT);
      };
  
+     /* next 2 are sent as CARD32 so swap them as if they are */
      if (im & PEXSCCeiling) {
! 	SWAP_CARD32 ((*((CARD32 *)sc_data)));
! 	sc_data += sizeof(CARD32);	    
      }
  
      if (im & PEXSCModelClipFlag) {
! 	SWAP_CARD32 ((*((CARD32 *)sc_data)));
! 	sc_data += sizeof (CARD32);	   
      }
  
      if (im & PEXSCStartPath) {
***************
*** 1138,1144 ****
      unsigned char *ptr = p_data;
  
      if (im & PEXPMStatus) {
! 	SWAP_CARD16((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
--- 1305,1311 ----
      unsigned char *ptr = p_data;
  
      if (im & PEXPMStatus) {
! 	SWAP_CARD32((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
***************
*** 1145,1156 ****
      if (im & PEXPMPath) {
  	CARD32 i;
  	CARD32 numRefs = *((CARD32 *)ptr);
! 	pexPickPath *pp;
  
  	SWAP_CARD32((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
! 	for (i=0, pp = (pexPickPath *)ptr; i<numRefs; i++, pp++) {
! 	    SWAP_PICK_PATH((*pp));
  	}
      }
  }
--- 1312,1323 ----
      if (im & PEXPMPath) {
  	CARD32 i;
  	CARD32 numRefs = *((CARD32 *)ptr);
! 	pexPickElementRef *pp;
  
  	SWAP_CARD32((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
! 	for (i=0, pp = (pexPickElementRef *)ptr; i<numRefs; i++, pp++) {
! 	    SWAP_PICK_ELEMENT_REF((*pp));
  	}
      }
  }
***************
*** 1304,1362 ****
  CARD32 	*itemMask;
  CARD8 	*p_data;
  {
      CARD8 *ptr = p_data;
  
!     if (itemMask[0] & PEXPCMarkerType) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[0] & PEXPCMarkerScale) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     if (itemMask[0] & PEXPCMarkerColour) {
  	ptr = SWAP_FUNC_PREFIX(SwapColourSpecifier) (swapPtr,
  						     (pexColourSpecifier *)ptr);
      }
  
!     if (itemMask[0] & PEXPCMarkerBundleIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[0] & PEXPCTextFont) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[0] & PEXPCTextPrecision) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[0] & PEXPCCharExpansion) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     if (itemMask[0] & PEXPCCharSpacing) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     if (itemMask[0] & PEXPCTextColour) {
  	ptr = SWAP_FUNC_PREFIX(SwapColourSpecifier) (swapPtr,
  						     (pexColourSpecifier *)ptr);
      }
  
!     if (itemMask[0] & PEXPCCharHeight) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     if (itemMask[0] & PEXPCCharUpVector) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
--- 1471,1535 ----
  CARD32 	*itemMask;
  CARD8 	*p_data;
  {
+     /* NOTE: See the Protocol Encoding for a desription of these fields
+        in places where CARD16 or INT16 are packed into a 4 byte field
+        (essentially a CARD32) for transmission these fields must be
+        byte swapped as a CARD32. - JSH
+     */
+ 
      CARD8 *ptr = p_data;
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCMarkerType) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCMarkerScale) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCMarkerColour) {
  	ptr = SWAP_FUNC_PREFIX(SwapColourSpecifier) (swapPtr,
  						     (pexColourSpecifier *)ptr);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCMarkerBundleIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCTextFont) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCTextPrecision) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCCharExpansion) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCCharSpacing) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCTextColour) {
  	ptr = SWAP_FUNC_PREFIX(SwapColourSpecifier) (swapPtr,
  						     (pexColourSpecifier *)ptr);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCCharHeight) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCCharUpVector) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
***************
*** 1363,1374 ****
  	ptr += sizeof(PEXFLOAT);
      }
  
!     if (itemMask[0] & PEXPCTextPath) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[0] & PEXPCTextAlignment) {
  	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD16);
  	SWAP_CARD16 ((*((CARD16 *)ptr)));
--- 1536,1547 ----
  	ptr += sizeof(PEXFLOAT);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCTextPath) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCTextAlignment) {
  	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD16);
  	SWAP_CARD16 ((*((CARD16 *)ptr)));
***************
*** 1375,1386 ****
  	ptr += sizeof(CARD16);
      }
  
!     if (itemMask[0] & PEXPCAtextHeight) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     if (itemMask[0] & PEXPCAtextUpVector) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
--- 1548,1559 ----
  	ptr += sizeof(CARD16);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCAtextHeight) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCAtextUpVector) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
***************
*** 1387,1398 ****
  	ptr += sizeof(PEXFLOAT);
      }
  
!     if (itemMask[0] & PEXPCAtextPath) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[0] & PEXPCAtextAlignment) {
  	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD16);
  	SWAP_CARD16 ((*((CARD16 *)ptr)));
--- 1560,1571 ----
  	ptr += sizeof(PEXFLOAT);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCAtextPath) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCAtextAlignment) {
  	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD16);
  	SWAP_CARD16 ((*((CARD16 *)ptr)));
***************
*** 1399,1462 ****
  	ptr += sizeof(CARD16);
      }
  
!     if (itemMask[0] & PEXPCAtextStyle) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[0] & PEXPCTextBundleIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[0] & PEXPCLineType) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[0] & PEXPCLineWidth) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     if (itemMask[0] & PEXPCLineColour) {
  	ptr = SWAP_FUNC_PREFIX(SwapColourSpecifier) (swapPtr,
  						     (pexColourSpecifier *)ptr);
      }
  
!     if (itemMask[0] & PEXPCCurveApproximation) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     if (itemMask[0] & PEXPCPolylineInterp) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[0] & PEXPCLineBundleIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[0] & PEXPCInteriorStyle) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[0] & PEXPCInteriorStyleIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[0] & PEXPCSurfaceColour) {
  	ptr = SWAP_FUNC_PREFIX(SwapColourSpecifier) (swapPtr,
  						     (pexColourSpecifier *)ptr);
      }
  
!     if (itemMask[0] & PEXPCSurfaceReflAttr) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
--- 1572,1635 ----
  	ptr += sizeof(CARD16);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCAtextStyle) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCTextBundleIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCLineType) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCLineWidth) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCLineColour) {
  	ptr = SWAP_FUNC_PREFIX(SwapColourSpecifier) (swapPtr,
  						     (pexColourSpecifier *)ptr);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCCurveApproximation) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCPolylineInterp) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCLineBundleIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCInteriorStyle) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCInteriorStyleIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceColour) {
  	ptr = SWAP_FUNC_PREFIX(SwapColourSpecifier) (swapPtr,
  						     (pexColourSpecifier *)ptr);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceReflAttr) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
***************
*** 1471,1502 ****
  						     (pexColourSpecifier *)ptr);
      }
  
!     if (itemMask[0] & PEXPCSurfaceReflModel) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[0] & PEXPCSurfaceInterp) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[0] & PEXPCBfInteriorStyle) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCBfInteriorStyleIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCBfSurfaceColour) {
  	ptr = SWAP_FUNC_PREFIX(SwapColourSpecifier) (swapPtr,
  						     (pexColourSpecifier *)ptr);
      }
  
!     if (itemMask[1] & PEXPCBfSurfaceReflAttr) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
--- 1644,1675 ----
  						     (pexColourSpecifier *)ptr);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceReflModel) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceInterp) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCBfInteriorStyle) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCBfInteriorStyleIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCBfSurfaceColour) {
  	ptr = SWAP_FUNC_PREFIX(SwapColourSpecifier) (swapPtr,
  						     (pexColourSpecifier *)ptr);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCBfSurfaceReflAttr) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
***************
*** 1511,1528 ****
  						     (pexColourSpecifier *)ptr);
      }
  
!     if (itemMask[1] & PEXPCBfSurfaceReflModel) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCBfSurfaceInterp) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCSurfaceApproximation) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
--- 1684,1701 ----
  						     (pexColourSpecifier *)ptr);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCBfSurfaceReflModel) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCBfSurfaceInterp) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceApproximation) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
***************
*** 1530,1545 ****
  	ptr += sizeof(PEXFLOAT);
      }
  
!     if (itemMask[1] & PEXPCCullingMode) {
! 	SWAP_CARD16((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCDistinguishFlag) {
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCPatternSize) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
--- 1703,1719 ----
  	ptr += sizeof(PEXFLOAT);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCCullingMode) {
! 	SWAP_CARD32((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCDistinguishFlag) {
! 	SWAP_CARD32((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCPatternSize) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
***************
*** 1546,1552 ****
  	ptr += sizeof(PEXFLOAT);
      }
  
!     if (itemMask[1] & PEXPCPatternRefPt) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
--- 1720,1726 ----
  	ptr += sizeof(PEXFLOAT);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCPatternRefPt) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
***************
*** 1555,1561 ****
  	ptr += sizeof(PEXFLOAT);
      }
  
!     if (itemMask[1] & PEXPCPatternRefVec1) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
--- 1729,1735 ----
  	ptr += sizeof(PEXFLOAT);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCPatternRefVec1) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
***************
*** 1564,1570 ****
  	ptr += sizeof(PEXFLOAT);
      }
  
!     if (itemMask[1] & PEXPCPatternRefVec2) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
--- 1738,1744 ----
  	ptr += sizeof(PEXFLOAT);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCPatternRefVec2) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
***************
*** 1573,1609 ****
  	ptr += sizeof(PEXFLOAT);
      }
  
!     if (itemMask[1] & PEXPCInteriorBundleIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCSurfaceEdgeFlag) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCSurfaceEdgeType) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCSurfaceEdgeWidth) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     if (itemMask[1] & PEXPCSurfaceEdgeColour) {
  	ptr = SWAP_FUNC_PREFIX(SwapColourSpecifier) (swapPtr,
  						     (pexColourSpecifier *)ptr);
      }
  
!     if (itemMask[1] & PEXPCEdgeBundleIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCLocalTransform) {
  	int i, j;
  	for (i=0; i<4; i++)
  	    for (j=0; j<4; j++) {
--- 1747,1783 ----
  	ptr += sizeof(PEXFLOAT);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCInteriorBundleIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceEdgeFlag) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceEdgeType) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceEdgeWidth) {
  	SWAP_FLOAT ((*((PEXFLOAT *)ptr)));
  	ptr += sizeof(PEXFLOAT);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCSurfaceEdgeColour) {
  	ptr = SWAP_FUNC_PREFIX(SwapColourSpecifier) (swapPtr,
  						     (pexColourSpecifier *)ptr);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCEdgeBundleIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCLocalTransform) {
  	int i, j;
  	for (i=0; i<4; i++)
  	    for (j=0; j<4; j++) {
***************
*** 1612,1618 ****
  	    }
      }
  
!     if (itemMask[1] & PEXPCGlobalTransform) {
  	int i, j;
  	for (i=0; i<4; i++)
  	    for (j=0; j<4; j++) {
--- 1786,1792 ----
  	    }
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCGlobalTransform) {
  	int i, j;
  	for (i=0; i<4; i++)
  	    for (j=0; j<4; j++) {
***************
*** 1621,1632 ****
  	    }
      }
  
!     if (itemMask[1] & PEXPCModelClip) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCModelClipVolume) {
  	CARD32 i, numHalfSpace;
  	pexHalfSpace *ph;
  	numHalfSpace = *((CARD32 *)ptr);
--- 1795,1806 ----
  	    }
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCModelClip) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCModelClipVolume) {
  	CARD32 i, numHalfSpace;
  	pexHalfSpace *ph;
  	numHalfSpace = *((CARD32 *)ptr);
***************
*** 1638,1689 ****
  	ptr = (CARD8 *)ph;
      }
  
!     if (itemMask[1] & PEXPCViewIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCLightState) {
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCDepthCueIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCSetAsfValues) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCPickId) {
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCHlhsrIdentifier) {
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCNameSet) {
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCColourApproxIndex) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCRenderingColourModel) {
! 	SWAP_CARD16((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     if (itemMask[1] & PEXPCParaSurfCharacteristics) {
  	INT16 type;
  	type = *((INT16 *)ptr);
  	SWAP_INT16((*((INT16 *)ptr)));
--- 1812,1873 ----
  	ptr = (CARD8 *)ph;
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCViewIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCLightState) {
! 	CARD32 i, numLights;
! 	numLights = *((CARD32 *)ptr);
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
+ 	for (i=0; i<numLights; i++) {
+ 	    SWAP_CARD16 ((*((CARD16 *)ptr)));
+ 	    ptr += sizeof(CARD16);
+ 	}
+ 	if (numLights%2)       /* pad odd length list to CARD32 boundary  */
+ 	    ptr += sizeof(CARD16);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCDepthCueIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCSetAsfValues) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));     /* enables BITMASK */
  	ptr += sizeof(CARD32);
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));     /* asfs themselves */
+ 	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCPickId) {
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCHlhsrIdentifier) {
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCNameSet) {
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCColourApproxIndex) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCRenderingColourModel) {
! 	SWAP_CARD32((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
!     CHECK_BITMASK_ARRAY(itemMask, PEXPCParaSurfCharacteristics) {
  	INT16 type;
  	type = *((INT16 *)ptr);
  	SWAP_INT16((*((INT16 *)ptr)));
***************
*** 1717,1724 ****
  		SWAP_CARD16((*((CARD16 *)ptr)));
  		ptr += sizeof(CARD32);
  		for (i=0; i<num; i++) {
! 		    SWAP_COORD3D((*((pexCoord3D *)ptr)));
! 		    ptr += sizeof(pexCoord3D);
  		}
  	    }
  	}
--- 1901,1908 ----
  		SWAP_CARD16((*((CARD16 *)ptr)));
  		ptr += sizeof(CARD32);
  		for (i=0; i<num; i++) {
! 		    SWAP_FLOAT((*((PEXFLOAT *)ptr)));
! 		    ptr += sizeof(PEXFLOAT);
  		}
  	    }
  	}
***************
*** 1738,1744 ****
      int len, i;
  
      if (im & PEXPDPickStatus) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
--- 1922,1928 ----
      int len, i;
  
      if (im & PEXPDPickStatus) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
***************
*** 1746,1758 ****
  	len = (int)(*ptr);
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
! 	for (i=0; i<len; i++, ptr += sizeof(pexPickPath)) {
! 	    SWAP_PICK_PATH ((*((pexPickPath *)ptr)));
  	};
      };
  
      if (im & PEXPDPickPathOrder) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
--- 1930,1942 ----
  	len = (int)(*ptr);
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
! 	for (i=0; i<len; i++, ptr += sizeof(pexPickElementRef)) {
! 	    SWAP_PICK_ELEMENT_REF ((*((pexPickElementRef *)ptr)));
  	};
      };
  
      if (im & PEXPDPickPathOrder) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      };
  
***************
*** 1770,1781 ****
  	len = (int)(*ptr);
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
! 	ptr += (len + 3)/4;		    /*	pad it out  */
      };
  
      if (im & PEXPDPickPromptEchoType) {
! 	SWAP_ENUM_TYPE_INDEX ((*ptr));
! 	ptr += sizeof(pexEnumTypeIndex);
      };
  
      if (im & PEXPDPickEchoVolume) {
--- 1954,1965 ----
  	len = (int)(*ptr);
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
! 	ptr += len + PADDING(len);		    /*	pad it out  */
      };
  
      if (im & PEXPDPickPromptEchoType) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
! 	ptr += sizeof(CARD32);
      };
  
      if (im & PEXPDPickEchoVolume) {
***************
*** 1784,1790 ****
      }
  
      if (im & PEXPDPickEchoSwitch) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
      }
  }
  
--- 1968,1974 ----
      }
  
      if (im & PEXPDPickEchoSwitch) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
      }
  }
  
***************
*** 1891,1903 ****
  	ptr += sizeof(CARD32);
      }
  
      if (im & PEXRDRendererState) {
! 	SWAP_CARD16 ((*((CARD16 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      if (im & PEXRDHlhsrMode) {
! 	SWAP_INT16 ((*((INT16 *)ptr)));
  	ptr += sizeof(CARD32);
  	
      }
--- 2075,2090 ----
  	ptr += sizeof(CARD32);
      }
  
+   /* Swap this and HLHSR as CARD32 since they're in a 4 byte field in
+      the LISTofVALUE                                                  */
+ 
      if (im & PEXRDRendererState) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
      }
  
      if (im & PEXRDHlhsrMode) {
! 	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
  	
      }
***************
*** 1917,1921 ****
--- 2104,2150 ----
  	SWAP_CARD32 ((*((CARD32 *)ptr)));
  	ptr += sizeof(CARD32);
  	SwapDeviceRects (swapPtr, num, (pexDeviceRect *)ptr);
+         ptr += sizeof(pexDeviceRect) * num;
+     }
+ 
+     if (im & PEXRDPickInclusion) {
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
+ 	ptr += sizeof(CARD32);
+     }
+ 
+     if (im & PEXRDPickExclusion) {
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
+ 	ptr += sizeof(CARD32);
+     }
+ 
+     if (im & PEXRDPickStartPath) {
+ 	num = *((CARD32 *)ptr);
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
+ 	ptr += sizeof(CARD32);
+ 	for (i=0; i<num; i++, ptr += sizeof(pexElementRef))
+ 	    SWAP_ELEMENT_REF((*((pexElementRef *)ptr)));
+     }
+ 
+     if (im & PEXRDBackgroundColour) {
+ 	ptr = SWAP_FUNC_PREFIX(SwapColourSpecifier) (swapPtr,
+ 						   (pexColourSpecifier *)ptr);
+     }
+ 
+     /* this is CARD8 cast into a CARD32 so it must get swapped as CARD32 */
+     if (im & PEXRDClearI) {
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
+ 	ptr += sizeof(CARD32);
+     }
+ 
+     /* this is CARD8 cast into a CARD32 so it must get swapped as CARD32 */
+     if (im & PEXRDClearZ) {
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
+ 	ptr += sizeof(CARD32);
+     }
+ 
+     /* this is CARD16 cast into a CARD32 so it must get swapped as CARD32 */
+     if (im & PEXRDEchoMode) {
+ 	SWAP_CARD32 ((*((CARD32 *)ptr)));
+ 	ptr += sizeof(CARD32);
      }
  }
*** -	Thu Jan 28 17:51:18 1993
--- mit/extensions/server/PEX/dipex/swap/uconvRep.h	Thu Jan 28 17:51:18 1993
***************
*** 1,4 ****
! /* $XConsortium: uconvRep.h,v 5.1 91/02/16 09:57:21 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: uconvRep.h,v 5.2 92/03/04 14:19:18 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 28,33 ****
--- 28,34 ----
  LOCAL_FLAG void
      SWAP_FUNC_PREFIX(ConvertGetExtensionInfoReply) (),
      SWAP_FUNC_PREFIX(ConvertGetEnumeratedTypeInfoReply) (),
+     SWAP_FUNC_PREFIX(ConvertGetImpDepConstantsReply) (),
      SWAP_FUNC_PREFIX(ConvertGetTableInfoReply) (),
      SWAP_FUNC_PREFIX(ConvertGetPredefinedEntriesReply) (),
      SWAP_FUNC_PREFIX(ConvertGetDefinedIndicesReply) (),
***************
*** 57,63 ****
      SWAP_FUNC_PREFIX(ConvertListFontsReply) (),
      SWAP_FUNC_PREFIX(ConvertListFontsWithInfoReply) (),
      SWAP_FUNC_PREFIX(ConvertQueryTextExtentsReply) (),
!     SWAP_FUNC_PREFIX(ConvertGetImpDepConstantsReply) (),
      SWAP_FUNC_PREFIX(NoReply)();
  
  
--- 58,69 ----
      SWAP_FUNC_PREFIX(ConvertListFontsReply) (),
      SWAP_FUNC_PREFIX(ConvertListFontsWithInfoReply) (),
      SWAP_FUNC_PREFIX(ConvertQueryTextExtentsReply) (),
!     SWAP_FUNC_PREFIX(ConvertMatchRendererTargetsReply) (),
!     SWAP_FUNC_PREFIX(EscapeWithReplyReply) (),
!     SWAP_FUNC_PREFIX(ConvertEndPickOneReply) (),
!     SWAP_FUNC_PREFIX(ConvertPickOneReply) (),
!     SWAP_FUNC_PREFIX(ConvertEndPickAllReply) (),
!     SWAP_FUNC_PREFIX(ConvertPickAllReply) (),
      SWAP_FUNC_PREFIX(NoReply)();
  
  
*** -	Thu Jan 28 17:51:19 1993
--- mit/extensions/server/PEX/dipex/swap/SwapConv.h	Thu Jan 28 17:51:19 1993
***************
*** 1,4 ****
! /* $XConsortium: SwapConv.h,v 5.1 91/02/16 09:57:22 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: SwapConv.h,v 5.2 91/12/30 18:23:59 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 27,36 ****
  #ifndef SWAPCONV_H
  #define SWAPCONV_H 1
  
! #define SWAPINT(A)   if (swapPtr->ConvertCARD32) A = swapPtr->ConvertCARD32(&(A))
  
! #define SWAPSHORT(A) if (swapPtr->ConvertCARD16) A = swapPtr->ConvertCARD16(&(A))
  
! #define SWAPFLOAT(A) if (swapPtr->ConvertFLOAT)  A = swapPtr->ConvertFLOAT(&(A))
  
  #endif	/* SWAPCONV_H */
--- 27,36 ----
  #ifndef SWAPCONV_H
  #define SWAPCONV_H 1
  
! #define SWAPINT(A)   if (swapPtr->ConvertCARD32) swapPtr->ConvertCARD32(&(A))
  
! #define SWAPSHORT(A) if (swapPtr->ConvertCARD16) swapPtr->ConvertCARD16(&(A))
  
! #define SWAPFLOAT(A) if (swapPtr->ConvertFLOAT)  swapPtr->ConvertFLOAT(&(A))
  
  #endif	/* SWAPCONV_H */
*** -	Thu Jan 28 17:51:23 1993
--- mit/extensions/server/PEX/dipex/swap/OCprim.h	Thu Jan 28 17:51:23 1993
***************
*** 1,4 ****
! /* $XConsortium: OCprim.h,v 5.1 91/02/16 09:57:28 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: OCprim.h,v 5.2 92/03/04 14:19:20 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 60,63 ****
  	SWAP_FUNC_PEX_PFX(Text2D) (),
  	SWAP_FUNC_PEX_PFX(AnnotationText) (),
  	SWAP_FUNC_PEX_PFX(AnnotationText2D) (),
! 	SWAP_FUNC_PEX_PFX(ParaSurfCharacteristics) ();
--- 60,64 ----
  	SWAP_FUNC_PEX_PFX(Text2D) (),
  	SWAP_FUNC_PEX_PFX(AnnotationText) (),
  	SWAP_FUNC_PEX_PFX(AnnotationText2D) (),
! 	SWAP_FUNC_PEX_PFX(ParaSurfCharacteristics) (),
! 	SWAP_FUNC_PREFIX(PEXNoop) ();
*** -	Tue Feb  2 12:26:00 1993
--- mit/extensions/server/PEX/dipex/swap/Requests.ci	Tue Feb  2 12:25:59 1993
***************
*** 1,6 ****
! /* $XConsortium: Requests.ci,v 5.3 91/07/19 21:13:51 rws Exp $ */
! /* Automatically generated Request table
!  */
  /******************************************************************
  Copyright 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
--- 1,5 ----
! /* $XConsortium: Requests.ci,v 5.5 93/02/02 12:14:45 mor Exp $ */
! 
  /******************************************************************
  Copyright 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
***************
*** 120,126 ****
  /*   90	*/  SWAP_FUNC_PREFIX(PEXQueryFont),
  /*   91	*/  SWAP_FUNC_PREFIX(PEXListFonts),
  /*   92	*/  SWAP_FUNC_PREFIX(PEXListFontsWithInfo),
! /*   93	*/  SWAP_FUNC_PREFIX(PEXQueryTextExtents)
  };
  
  #undef SWAP_FUNC_PREFIX
--- 119,136 ----
  /*   90	*/  SWAP_FUNC_PREFIX(PEXQueryFont),
  /*   91	*/  SWAP_FUNC_PREFIX(PEXListFonts),
  /*   92	*/  SWAP_FUNC_PREFIX(PEXListFontsWithInfo),
! /*   93	*/  SWAP_FUNC_PREFIX(PEXQueryTextExtents),
! /*   94	*/  SWAP_FUNC_PREFIX(PEXMatchRendererTargets),
! /*   95	*/  SWAP_FUNC_PREFIX(PEXEscape),
! /*   96	*/  SWAP_FUNC_PREFIX(PEXEscapeWithReply),
! /*   97	*/  SWAP_FUNC_PREFIX(PEXRenderElements),
! /*   98	*/  SWAP_FUNC_PREFIX(PEXAccumulateState),
! /*   99	*/  SWAP_FUNC_PREFIX(PEXBeginPickOne),
! /*   100	*/  SWAP_FUNC_PREFIX(PEXEndPickOne),
! /*   101	*/  SWAP_FUNC_PREFIX(PEXPickOne),
! /*   102	*/  SWAP_FUNC_PREFIX(PEXBeginPickAll),
! /*   103	*/  SWAP_FUNC_PREFIX(PEXEndPickAll),
! /*   104	*/  SWAP_FUNC_PREFIX(PEXPickAll)
  };
  
  #undef SWAP_FUNC_PREFIX
*** -	Tue Feb  2 12:26:02 1993
--- mit/extensions/server/PEX/dipex/swap/Requests.h	Tue Feb  2 12:26:01 1993
***************
*** 1,6 ****
! /* $XConsortium: Requests.h,v 5.1 91/02/16 09:57:32 rws Exp $ */
! /* Automatically generated Request table
!  */
  /******************************************************************
  Copyright 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
--- 1,5 ----
! /* $XConsortium: Requests.h,v 5.3 93/02/02 12:14:53 mor Exp $ */
! 
  /******************************************************************
  Copyright 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
***************
*** 123,129 ****
  	SWAP_FUNC_PREFIX(PEXQueryFont) (),
  	SWAP_FUNC_PREFIX(PEXListFonts) (),
  	SWAP_FUNC_PREFIX(PEXListFontsWithInfo) (),
! 	SWAP_FUNC_PREFIX(PEXQueryTextExtents) ();
  
  RequestFunction SWAP_FUNC_PREFIX(PEXRequest)[] = {
  /*   0	*/  SWAP_FUNC_PREFIX(PEXRequestUnused),
--- 122,139 ----
  	SWAP_FUNC_PREFIX(PEXQueryFont) (),
  	SWAP_FUNC_PREFIX(PEXListFonts) (),
  	SWAP_FUNC_PREFIX(PEXListFontsWithInfo) (),
! 	SWAP_FUNC_PREFIX(PEXQueryTextExtents) (),
! 	SWAP_FUNC_PREFIX(PEXMatchRendererTargets) (),
! 	SWAP_FUNC_PREFIX(PEXEscape) (),
! 	SWAP_FUNC_PREFIX(PEXEscapeWithReply) (),
! 	SWAP_FUNC_PREFIX(PEXRenderElements) (),
! 	SWAP_FUNC_PREFIX(PEXAccumulateState) (),
! 	SWAP_FUNC_PREFIX(PEXBeginPickOne) (),
! 	SWAP_FUNC_PREFIX(PEXEndPickOne) (),
! 	SWAP_FUNC_PREFIX(PEXPickOne) (),
! 	SWAP_FUNC_PREFIX(PEXBeginPickAll) (),
! 	SWAP_FUNC_PREFIX(PEXEndPickAll) (),
! 	SWAP_FUNC_PREFIX(PEXPickAll) ();
  
  RequestFunction SWAP_FUNC_PREFIX(PEXRequest)[] = {
  /*   0	*/  SWAP_FUNC_PREFIX(PEXRequestUnused),
***************
*** 219,225 ****
  /*   90	*/  SWAP_FUNC_PREFIX(PEXQueryFont),
  /*   91	*/  SWAP_FUNC_PREFIX(PEXListFonts),
  /*   92	*/  SWAP_FUNC_PREFIX(PEXListFontsWithInfo),
! /*   93	*/  SWAP_FUNC_PREFIX(PEXQueryTextExtents)
  };
  
  #undef SWAP_FUNC_PREFIX
--- 229,246 ----
  /*   90	*/  SWAP_FUNC_PREFIX(PEXQueryFont),
  /*   91	*/  SWAP_FUNC_PREFIX(PEXListFonts),
  /*   92	*/  SWAP_FUNC_PREFIX(PEXListFontsWithInfo),
! /*   93	*/  SWAP_FUNC_PREFIX(PEXQueryTextExtents),
! /*   94	*/  SWAP_FUNC_PREFIX(PEXMatchRendererTargets),
! /*   95	*/  SWAP_FUNC_PREFIX(PEXEscape),
! /*   96	*/  SWAP_FUNC_PREFIX(PEXEscapeWithReply),
! /*   97	*/  SWAP_FUNC_PREFIX(PEXRenderElements),
! /*   98	*/  SWAP_FUNC_PREFIX(PEXAccumulateState),
! /*   99	*/  SWAP_FUNC_PREFIX(PEXBeginPickOne),
! /*   100	*/  SWAP_FUNC_PREFIX(PEXEndPickOne),
! /*   101	*/  SWAP_FUNC_PREFIX(PEXPickOne),
! /*   102	*/  SWAP_FUNC_PREFIX(PEXBeginPickAll),
! /*   103	*/  SWAP_FUNC_PREFIX(PEXEndPickAll),
! /*   104	*/  SWAP_FUNC_PREFIX(PEXPickAll)
  };
  
  #undef SWAP_FUNC_PREFIX
*** /dev/null	Thu Jan 28 17:51:27 1993
--- mit/extensions/server/PEX/dipex/swap/convEv.c	Thu Jan 28 17:51:28 1993
***************
*** 0 ****
--- 1,62 ----
+ /* $XConsortium: convEv.c,v 1.1 92/03/04 14:19:24 hersh Exp $ */
+ 
+ /************************************************************
+ Copyright 1992 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
+ docu- mentation, 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.
+ 
+ ******************************************************************/
+ 
+ 
+ #include "X.h"
+ #include "Xproto.h"
+ #include "misc.h"
+ #include "PEX.h"
+ #include "PEXproto.h"
+ #include "PEXprotost.h"
+ #include "pexError.h"
+ #include "pexSwap.h"
+ #include "pex_site.h"
+ #include "ddpex.h"
+ #include "pexLookup.h"
+ #include "convertStr.h"
+ 
+ #undef LOCAL_FLAG
+ #define LOCAL_FLAG extern
+ 
+ 
+ /****************************************************************
+  *  		EVENTS   					*
+  ****************************************************************/
+ 
+ 
+ 
+ void
+ SwapPEXMaxHitsReachedEvent(from, to)
+ pexMaxHitsReachedEvent *from, *to;
+ {
+     to->type = from->type;
+     cpswaps (from->sequenceNumber, to->sequenceNumber);
+     cpswapl (from->rdr, to->rdr);
+ }
+ 
+ 
*** -	Thu Jan 28 17:51:58 1993
--- mit/extensions/server/PEX/ddpex/mi/include/miRender.h	Thu Jan 28 17:51:58 1993
***************
*** 1,5 ****
  
! /* $XConsortium: miRender.h,v 5.2 91/05/01 14:18:42 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,5 ----
  
! /* $XConsortium: miRender.h,v 5.3 92/11/09 18:51:43 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 191,196 ****
--- 191,201 ----
  	ddUSHORT		modelClip;
  	ddULONG			pickId;
  	ddULONG			hlhsrType;
+ 	ddColourSpecifier       backgroundColour;
+ 	ddUSHORT                clearI;
+ 	ddUSHORT                clearZ;
+ 	ddUSHORT                echoMode;
+ 	ddColourSpecifier       echoColour;
  } miDDContextRendAttrs;
  
  #define MI_MAXTEMPDATALISTS 4 /* Note, must be 2^n for macros to work */
*** -	Thu Jan 28 17:51:59 1993
--- mit/extensions/server/PEX/ddpex/mi/include/miWks.h	Thu Jan 28 17:51:59 1993
***************
*** 1,4 ****
! /* $XConsortium: miWks.h,v 5.1 91/02/16 09:54:41 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miWks.h,v 5.2 92/10/15 16:13:27 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 31,36 ****
--- 31,41 ----
  #include "miInfo.h"
  #include "miPick.h"
  
+ #ifdef MULTIBUFFER
+ #define _MULTIBUF_SERVER_
+ #include <X11/extensions/multibuf.h>
+ #endif
+ 
  #ifndef MIWKS_H
  #define MIWKS_H
  
***************
*** 162,167 ****
--- 167,177 ----
  	miPickDevice		devices[MIWKS_NUM_PICK_DEVICES];
  	/* pwksList is extra object used by deal with dynamics */
  	listofObj		*pwksList;
+ 	DrawablePtr		doubleDrawables[2];
+ 	int			curDoubleBuffer;
+ 	int			hasDoubleBuffer;
+ 	int			usingDoubleBuffer;
+ 	DrawablePtr		pCurDrawable;
  } miWksStr, *miWksPtr;
  
  #endif	/* MIWKS_H */
*** -	Thu Jan 28 17:52:01 1993
--- mit/extensions/server/PEX/ddpex/mi/include/miStrMacro.h	Thu Jan 28 17:52:00 1993
***************
*** 1,4 ****
! /* $XConsortium: miStrMacro.h,v 5.1 91/02/16 09:54:43 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miStrMacro.h,v 5.4 92/03/06 15:54:48 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 39,46 ****
  
  #define MISTR_LENGTH(PS)		(PS)->totalSize
  
! #define MISTR_NUM_REFS(PS)		(PS)->children->numObj
  
  #define MISTR_CURR_EL_OFFSET(PS)	(PS)->currElementOffset
  
  #define MISTR_CURR_EL_PTR(PS)		(PS)->pCurrElement
--- 39,48 ----
  
  #define MISTR_LENGTH(PS)		(PS)->totalSize
  
! #define MISTR_NUM_CHILDREN(PS)		(PS)->children->numObj
  
+ #define MISTR_NUM_PARENTS(PS)		(PS)->parents->numObj
+ 
  #define MISTR_CURR_EL_OFFSET(PS)	(PS)->currElementOffset
  
  #define MISTR_CURR_EL_PTR(PS)		(PS)->pCurrElement
***************
*** 79,93 ****
      else if ((OFFSET) == MISTR_CURR_EL_OFFSET(PSTRUCT))			\
      	(PE) = MISTR_CURR_EL_PTR(PSTRUCT);				\
      else {								\
! 	register int	i, start;					\
      	if ((OFFSET) < MISTR_CURR_EL_OFFSET(PSTRUCT)) {			\
  	    (PE) = MISTR_ZERO_EL(PSTRUCT);				\
! 	    start = 0;							\
      	} else {							\
! 	    start = MISTR_CURR_EL_OFFSET(PSTRUCT);			\
  	    (PE) = MISTR_CURR_EL_PTR(PSTRUCT);				\
  	}								\
! 	for (i=start; i<(OFFSET); i++, (PE) = MISTR_NEXT_EL(PE));	\
      }
  
  /* given pointer to element, find out what its OFFSET is in the struct */
--- 81,95 ----
      else if ((OFFSET) == MISTR_CURR_EL_OFFSET(PSTRUCT))			\
      	(PE) = MISTR_CURR_EL_PTR(PSTRUCT);				\
      else {								\
! 	register int	_i, _start;					\
      	if ((OFFSET) < MISTR_CURR_EL_OFFSET(PSTRUCT)) {			\
  	    (PE) = MISTR_ZERO_EL(PSTRUCT);				\
! 	    _start = 0;							\
      	} else {							\
! 	    _start = MISTR_CURR_EL_OFFSET(PSTRUCT);			\
  	    (PE) = MISTR_CURR_EL_PTR(PSTRUCT);				\
  	}								\
! 	for (_i=_start; _i<(OFFSET); _i++, (PE) = MISTR_NEXT_EL(PE));	\
      }
  
  /* given pointer to element, find out what its OFFSET is in the struct */
***************
*** 108,121 ****
  		i++, ptemp = MISTR_NEXT_EL(ptemp));			\
  	(OFFSET) = i;							\
      }
!     
  #define	MISTR_DEL_ONE_EL(PSTRUCT, PPREV, PEL)	{			\
      MISTR_NEXT_EL(PPREV) = MISTR_NEXT_EL(PEL);				\
      MISTR_PREV_EL(MISTR_NEXT_EL(PEL)) = (PPREV);			\
!     if (MI_IS_PEX_OC(MISTR_EL_TYPE(PEL)))				\
! 	DestroyCSSElementTable[MISTR_EL_TYPE(PEL)]((PSTRUCT), (PEL));	\
      else								\
! 	DestroyCSSElementTable[0]((PSTRUCT), (PEL)); }
  
  #define	MISTR_INSERT_ONE_EL(PPREV, PEL)				\
  	MISTR_NEXT_EL(PEL) = MISTR_NEXT_EL(PPREV);		\
--- 110,126 ----
  		i++, ptemp = MISTR_NEXT_EL(ptemp));			\
  	(OFFSET) = i;							\
      }
!    
! /* Must check Proprietary and in Range to avoid Null function ptrs */
  #define	MISTR_DEL_ONE_EL(PSTRUCT, PPREV, PEL)	{			\
      MISTR_NEXT_EL(PPREV) = MISTR_NEXT_EL(PEL);				\
      MISTR_PREV_EL(MISTR_NEXT_EL(PEL)) = (PPREV);			\
!     if (MI_HIGHBIT_ON(MISTR_EL_TYPE(PEL)))				\
! 	(*DestroyCSSElementTable[MI_OC_PROP])((PSTRUCT), (PEL));        \
      else								\
!       if (MI_IS_PEX_OC(MISTR_EL_TYPE(PEL)))				\
! 	(*DestroyCSSElementTable[MISTR_EL_TYPE(PEL)])((PSTRUCT), (PEL));\
!     }
  
  #define	MISTR_INSERT_ONE_EL(PPREV, PEL)				\
  	MISTR_NEXT_EL(PEL) = MISTR_NEXT_EL(PPREV);		\
***************
*** 126,131 ****
--- 131,137 ----
  /* PSTRUCT is structure handle; DDSTRUCT is dd structure header */
  /* first can't be 0, last can't be more than number in structure */
  /* inclusive delete, does not update structure header info */
+ /* Must check Proprietary and in Range to avoid Null function ptrs */
  #define	MISTR_DEL_ELS(PSTRUCT, DDSTRUCT, FIRST, LAST)		\
      if ((int)((LAST) - (FIRST)) >= 0) {				\
  	register int	num;					\
***************
*** 134,144 ****
  	pe = MISTR_PREV_EL(pe1);				\
  	for (num = (FIRST); num <= (LAST); num++) {		\
  	    pe2 = MISTR_NEXT_EL(pe1);				\
! 	    if (MI_IS_PEX_OC(MISTR_EL_TYPE(pe1)))		\
! 		(*DestroyCSSElementTable[MISTR_EL_TYPE(pe1)])	\
! 				((PSTRUCT), pe1);		\
  	    else						\
! 		(*DestroyCSSElementTable[0])((PSTRUCT), pe1);	\
  	    pe1 = pe2;					\
  	}							\
  	MISTR_NEXT_EL(pe) = pe1;				\
--- 140,152 ----
  	pe = MISTR_PREV_EL(pe1);				\
  	for (num = (FIRST); num <= (LAST); num++) {		\
  	    pe2 = MISTR_NEXT_EL(pe1);				\
! 	    if (MI_HIGHBIT_ON(MISTR_EL_TYPE(pe1)))		\
! 		(*DestroyCSSElementTable[MI_OC_PROP])           \
! 				       ((PSTRUCT), pe1);	\
  	    else						\
! 		if (MI_IS_PEX_OC(MISTR_EL_TYPE(pe1)))		\
! 		  (*DestroyCSSElementTable[MISTR_EL_TYPE(pe1)])	\
! 				((PSTRUCT), pe1);		\
  	    pe1 = pe2;					\
  	}							\
  	MISTR_NEXT_EL(pe) = pe1;				\
*** -	Thu Jan 28 17:52:02 1993
--- mit/extensions/server/PEX/ddpex/mi/include/miStruct.h	Thu Jan 28 17:52:01 1993
***************
*** 1,5 ****
! /* $XConsortium: miStruct.h,v 5.1 91/02/16 09:54:44 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
--- 1,6 ----
! /* $XConsortium: miStruct.h,v 5.3 92/11/17 17:32:06 hersh Exp $ */
  
+ 
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
***************
*** 97,102 ****
--- 98,110 ----
  	ES_FOLLOW_SEARCH = 3	/* follow initial search path before search */
  } miExecStrState;
  
+ /* added to allow SI to do pick last */
+ typedef struct _miPPLevel {
+   ddPickPath pp;
+   struct _miPPLevel *up;
+ } miPPLevel;
+ 
+ 
  /*
   * level 3 traversal doesn't do picking or search, so it ALWAYS sets
   * exec_str_flag to YES and the element pointers to NULL
***************
*** 104,112 ****
--- 112,122 ----
  typedef struct {
  	miExecStrState	exec_str_flag;
  	ddULONG		pickId;
+ 	ddULONG		ROCoffset;
  	ddPickPath	*p_curr_pick_el;
  	ddElementRef	*p_curr_sc_el;
  	ddSHORT		max_depth;	/* max depth reached in pick or search */
+         miPPLevel       *p_pick_path;
  }  miTraverserState;
  
  #endif	/* MISTRUCT_H */
*** -	Thu Jan 28 17:52:02 1993
--- mit/extensions/server/PEX/ddpex/mi/include/miInfo.h	Thu Jan 28 17:52:02 1993
***************
*** 1,4 ****
! /* $XConsortium: miInfo.h,v 5.2 91/07/10 08:57:59 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miInfo.h,v 5.3 92/04/23 16:00:42 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 47,53 ****
   */
  
  /* card32s */
! #define	SI_NUM_INT_IMPS		21
  
  #define	SI_DITHERING_SUPPORTED		MI_FALSE
  #define	SI_MAX_EDGE_WIDTH		~((unsigned long)0)
--- 47,53 ----
   */
  
  /* card32s */
! #define	SI_NUM_INT_IMPS		22
  
  #define	SI_DITHERING_SUPPORTED		MI_FALSE
  #define	SI_MAX_EDGE_WIDTH		~((unsigned long)0)
***************
*** 69,75 ****
  #define	SI_SUPP_MARKER_SIZES		~((unsigned long)0)	/* number of supported marker sizes */
  #define SI_BEST_COLOUR_APPROX_VALUES	PEXColourApproxAnyValues
  #define	SI_TRANSPARENCY_SUPPORTED	MI_FALSE
! #define	SI_DOUBLE_BUFFERING_SUPPORTED	MI_FALSE
  
  /* floats */
  #define	SI_NUM_FLOAT_IMPS	12
--- 69,76 ----
  #define	SI_SUPP_MARKER_SIZES		~((unsigned long)0)	/* number of supported marker sizes */
  #define SI_BEST_COLOUR_APPROX_VALUES	PEXColourApproxAnyValues
  #define	SI_TRANSPARENCY_SUPPORTED	MI_FALSE
! #define	SI_DOUBLE_BUFFERING_SUPPORTED	MI_TRUE
! #define	SI_MAX_HITS_EVENT_SUPPORTED     MI_TRUE
  
  /* floats */
  #define	SI_NUM_FLOAT_IMPS	12
***************
*** 153,158 ****
--- 154,173 ----
  #define	SI_PICK_DEVICE_1	"DC_HitBox"
  #define	SI_PICK_DEVICE_2	"NPC_HitVolume"
  
+ /* pick one methods */
+ #define SI_PICK_ONE_NUM		1
+ #define SI_PICK_ONE_LAST	"Last"
+ /* others */
+ #define SI_PICK_ONE_CLOSEST_Z	 "ClosestZ"
+ #define SI_PICK_ONE_VISIBLE_ANY	 "VisibleAny"
+ #define SI_PICK_ONE_VISIBLE_CLOSEST	 "VisibleClosest"
+ 
+ /* pick all methods */
+ #define SI_PICK_ALL_NUM		1
+ #define SI_PICK_ALL_ALL		"All"
+ /* others */
+ #define SI_PICK_ALL_VISIBLE	"Visible"
+ 
  /* polyline interpolation method */
  #define	SI_LINE_INTERP_NUM	1
  #define	SI_LINE_INTERP_1	"None"
***************
*** 245,254 ****
  #define	SI_HLHSR_NUM		1
  #define SI_HLHSR_1		"Off"
  /* others */
! #define SI_HLHSR_2		"ZBufer"
  #define SI_HLHSR_3		"Painters"
  #define SI_HLHSR_4		"Scanline"
  #define SI_HLHSR_5		"HiddenLineOnly"
  
  /* prompt echo type */
  #define	SI_PET_NUM		1
--- 260,270 ----
  #define	SI_HLHSR_NUM		1
  #define SI_HLHSR_1		"Off"
  /* others */
! #define SI_HLHSR_2		"ZBuffer"
  #define SI_HLHSR_3		"Painters"
  #define SI_HLHSR_4		"Scanline"
  #define SI_HLHSR_5		"HiddenLineOnly"
+ #define SI_HLHSR_6		"ZBufferId"
  
  /* prompt echo type */
  #define	SI_PET_NUM		1
***************
*** 287,292 ****
--- 303,312 ----
  
  /* gse */
  #define	SI_GSE_NUM		0
+ 
+ /* escape */
+ #define SI_ESCAPE_NUM           1
+ #define SI_ESCAPE_1             "SetEchoColor"
  
  /* rendering colour model */
  #define	SI_REND_COLOUR_NUM	1
*** -	Thu Jan 28 17:52:04 1993
--- mit/extensions/server/PEX/ddpex/mi/include/miLUT.h	Thu Jan 28 17:52:03 1993
***************
*** 1,4 ****
! /* $XConsortium: miLUT.h,v 5.2 91/05/03 15:21:12 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miLUT.h,v 5.3 92/12/30 16:20:43 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 346,358 ****
  #define MILUT_DEF_ENTS( pheader ) \
                  (pheader)->tableInfo.definableEntries
  
- /* number of allocated entries: if starting index = 0, 
-  * allocated entries = the number of definable entries;
-  * if starting index = 1, allocated entries = def entries + 1
-  * and entry 0 is a dummy
-  */
  #define MILUT_ALLOC_ENTS( pheader )		\
! 	(MILUT_DEF_ENTS(pheader) + MILUT_START_INDEX(pheader))
  
  /* number of predefined entries */
  #define MILUT_PRENUM( pheader ) \
--- 346,353 ----
  #define MILUT_DEF_ENTS( pheader ) \
                  (pheader)->tableInfo.definableEntries
  
  #define MILUT_ALLOC_ENTS( pheader )		\
! 	(MILUT_DEF_ENTS(pheader))
  
  /* number of predefined entries */
  #define MILUT_PRENUM( pheader ) \
*** -	Thu Jan 28 17:52:10 1993
--- mit/extensions/server/PEX/ddpex/mi/include/miLight.h	Thu Jan 28 17:52:09 1993
***************
*** 1,4 ****
! /* $XConsortium: miLight.h,v 5.2 91/05/01 14:19:32 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miLight.h,v 5.3 93/01/25 17:20:52 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 150,158 ****
      temp = 2.0 * (n_dot_l);			\
      n = (ddFLOAT *) (normal);			\
      l = (ddFLOAT *) (light);			\
!     *(r++) = temp * (*(n++) - *(l++));		\
!     *(r++) = temp * (*(n++) - *(l++));		\
!     *(r  ) = temp * (*(n  ) - *(l  ));		\
  }
  
  
--- 150,158 ----
      temp = 2.0 * (n_dot_l);			\
      n = (ddFLOAT *) (normal);			\
      l = (ddFLOAT *) (light);			\
!     *(r++) = temp * (*(n++)) - *(l++);		\
!     *(r++) = temp * (*(n++)) - *(l++);		\
!     *(r  ) = temp * (*(n  )) - *(l  );		\
  }
  
  
*** -	Thu Jan 28 17:52:12 1993
--- mit/extensions/server/PEX/ddpex/mi/include/mipex.h	Thu Jan 28 17:52:12 1993
***************
*** 1,4 ****
! /* $XConsortium: mipex.h,v 5.1 91/02/16 09:54:57 rws Exp $ */
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: mipex.h,v 5.3 91/12/26 17:52:06 hersh Exp $ */
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 42,50 ****
  #define MI_BACKGROUND 0
  #define MI_FOREGROUND 1
  
! /* see if OC (or element) is in range of PEX OCs */
! #define	MI_IS_PEX_OC(ocnum)	(((ocnum) > PEXOCAll) && ((ocnum) < PEXMaxOC))
  
  /**  redefine ASSURE even if it's already defined **/
  #ifdef ASSURE
  #undef ASSURE
--- 42,59 ----
  #define MI_BACKGROUND 0
  #define MI_FOREGROUND 1
  
! /* high bit mask for proprietary OCs */
! #define MI_OC_HIGHBIT 0x8000
  
+ /* a redefinable location for use in branching on proprietary OCs */
+ #define MI_OC_PROP 0
+ 
+ /* see if propietary bit is set in OC Type */
+ #define MI_HIGHBIT_ON(octype)   ((octype) & MI_OC_HIGHBIT)
+ 
+ /* see if OC Type (or element) is in range of PEX OCs */
+ #define	MI_IS_PEX_OC(octype)  (((octype) > PEXOCAll) && ((octype) <= PEXMaxOC))
+ 
  /**  redefine ASSURE even if it's already defined **/
  #ifdef ASSURE
  #undef ASSURE
***************
*** 189,200 ****
  
  /*
   * MI_ROUND_LISTHEADERCOUNT is used by the clip routines to round up the 
!  * header block count by 15 - in other words to allocated headerblocks
!  * in increment of 15 and thus reduce calls to Xrealloc.
   * Note that this doesn't work for beans w/ negative numbers (although
   * allocating a negative number of header blocks doesn't work well either!).
   */
! #define MI_ROUND_LISTHEADERCOUNT(val) (((val) & ~15) + 15)
  
  /* 
   * MI_ALLOCLISTHEADER insures that there are numlists headers in the
--- 198,209 ----
  
  /*
   * MI_ROUND_LISTHEADERCOUNT is used by the clip routines to round up the 
!  * header block count by 16 - in other words to allocated headerblocks
!  * in increment of 16 and thus reduce calls to Xrealloc.
   * Note that this doesn't work for beans w/ negative numbers (although
   * allocating a negative number of header blocks doesn't work well either!).
   */
! #define MI_ROUND_LISTHEADERCOUNT(val) (((val) + 15) & ~15)
  
  /* 
   * MI_ALLOCLISTHEADER insures that there are numlists headers in the
*** -	Thu Jan 28 17:52:28 1993
--- mit/extensions/server/PEX/ddpex/mi/level1/Imakefile	Thu Jan 28 17:52:28 1993
***************
*** 1,5 ****
  XCOMM
! XCOMM $XConsortium: Imakefile,v 5.3 91/07/24 16:56:57 rws Exp $
  XCOMM
  XCOMM 
  XCOMM Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium
--- 1,5 ----
  XCOMM
! XCOMM $XConsortium: Imakefile,v 5.4 92/11/11 12:08:42 rws Exp $
  XCOMM
  XCOMM 
  XCOMM Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium
***************
*** 57,69 ****
  	miPck1Prim.c
  
  OBJS = miDDCtoGC.o \
! 	miListUtil.o \ 
  	miLvl1Tab.o \
  	miRndFArea.o \
  	miRndPLine.o \
  	miRndMarkr.o \
  	miRndText.o \
! 	miRndTStrip.o \ 
  	miPck1Prim.o
  
  NormalLibraryObjectRule()
--- 57,69 ----
  	miPck1Prim.c
  
  OBJS = miDDCtoGC.o \
! 	miListUtil.o \
  	miLvl1Tab.o \
  	miRndFArea.o \
  	miRndPLine.o \
  	miRndMarkr.o \
  	miRndText.o \
! 	miRndTStrip.o \
  	miPck1Prim.o
  
  NormalLibraryObjectRule()
*** -	Thu Jan 28 17:52:30 1993
--- mit/extensions/server/PEX/ddpex/mi/level1/miDDCtoGC.c	Thu Jan 28 17:52:30 1993
***************
*** 1,4 ****
! /* $XConsortium: miDDCtoGC.c,v 5.2 91/04/03 15:11:03 hersh Exp $ */
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miDDCtoGC.c,v 5.4 92/12/03 19:45:16 hersh Exp $ */
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 70,75 ****
--- 70,76 ----
        ddULONG		colourindex;
        ddSHORT		linewidth;
  
+ 
        /*
         * Set line colour. 
         * The colour must be processed according
***************
*** 80,87 ****
        /*
         * Calculate final color index.
         */
!       linecolour = pddc->Static.attrs->lineColour;
!       miColourtoIndex(	pRend, pddc->Dynamic->pPCAttr->colourApproxIndex,
  			&linecolour, &colourindex);
  
        /* Only set GC value if necessary */
--- 81,92 ----
        /*
         * Calculate final color index.
         */
!       if (pddc->Static.attrs->echoMode == PEXEcho) 
! 	    linecolour = pddc->Static.attrs->echoColour;
!       else 
! 	    linecolour = pddc->Static.attrs->lineColour;
! 
!       miColourtoIndex(pRend, pddc->Dynamic->pPCAttr->colourApproxIndex,
  			&linecolour, &colourindex);
  
        /* Only set GC value if necessary */
***************
*** 246,251 ****
--- 251,257 ----
        ddULONG		colourindex;
        ddSHORT		edgewidth;
  
+ 
        /*
         * Set edge colour. 
         * The colour must be processed according
***************
*** 256,264 ****
        /*
         * Calculate final color index.
         */
!       edgecolour = pddc->Static.attrs->edgeColour;
!       miColourtoIndex(	pRend, pddc->Dynamic->pPCAttr->colourApproxIndex,
  			&edgecolour, &colourindex);
  
        /* Only set GC value if necessary */
        if (colourindex != pgc->fgPixel) {
--- 262,275 ----
        /*
         * Calculate final color index.
         */
!       if (pddc->Static.attrs->echoMode == PEXEcho) 
! 	  edgecolour = pddc->Static.attrs->echoColour;
!       else 
! 	  edgecolour = pddc->Static.attrs->edgeColour;
! 
!       miColourtoIndex(pRend, pddc->Dynamic->pPCAttr->colourApproxIndex,
  			&edgecolour, &colourindex);
+       
  
        /* Only set GC value if necessary */
        if (colourindex != pgc->fgPixel) {
***************
*** 411,416 ****
--- 422,430 ----
  miDDContext	*pddc;	/* dd Context handle */
  GCPtr		pgc;	/* X GC handle */
  {
+       ddLONG		gcmask = 0;
+ 
+ 
  }
  
  /*++
***************
*** 444,449 ****
--- 458,464 ----
        miColourEntry		*pmarkercolour;
        ddULONG			colourindex;
  
+ 
        /*
         * Set the marker colour. 
         * The colour must be processed according
***************
*** 454,461 ****
        /*
         * Calculate final color index.
         */
!       markercolour = pddc->Static.attrs->markerColour;
!       miColourtoIndex(	pRend, pddc->Dynamic->pPCAttr->colourApproxIndex,
  			&markercolour, &colourindex);
  
  
--- 469,480 ----
        /*
         * Calculate final color index.
         */
!       if (pddc->Static.attrs->echoMode == PEXEcho) 
! 	  markercolour = pddc->Static.attrs->echoColour;
!       else 
! 	  markercolour = pddc->Static.attrs->markerColour;
! 
!       miColourtoIndex(pRend, pddc->Dynamic->pPCAttr->colourApproxIndex,
  			&markercolour, &colourindex);
  
  
***************
*** 519,526 ****
        /*
         * Calculate final color index.
         */
!       textcolour = pddc->Static.attrs->textColour;
!       miColourtoIndex(	pRend, pddc->Dynamic->pPCAttr->colourApproxIndex,
  			&textcolour, &colourindex);
  
  
--- 538,549 ----
        /*
         * Calculate final color index.
         */
!       if (pddc->Static.attrs->echoMode == PEXEcho) 
! 	  textcolour = pddc->Static.attrs->echoColour;
!       else 
! 	  textcolour = pddc->Static.attrs->textColour;
! 
!       miColourtoIndex(pRend, pddc->Dynamic->pPCAttr->colourApproxIndex,
  			&textcolour, &colourindex);
  
  
*** -	Thu Jan 28 17:52:34 1993
--- mit/extensions/server/PEX/ddpex/mi/level1/miRndFArea.c	Thu Jan 28 17:52:34 1993
***************
*** 1,4 ****
! /* $XConsortium: miRndFArea.c,v 5.2 91/07/24 17:57:52 hersh Exp $ */
  
  
  /***********************************************************
--- 1,4 ----
! /* $XConsortium: miRndFArea.c,v 5.3 92/12/03 19:46:02 hersh Exp $ */
  
  
  /***********************************************************
***************
*** 192,199 ****
  		(!MI_DDC_IS_HIGHLIGHT(pddc)) ) {
  
  	    /* Compute index value for ddx */
! 	    intcolour.colourType = PEXRgbFloatColour;
! 	    intcolour.colour.rgbFloat = *input_facet->facets.pFacetRgbFloat;
  	    miColourtoIndex(pRend, pddc->Dynamic->pPCAttr->colourApproxIndex,
  			    &intcolour, &colourindex);
  
--- 192,203 ----
  		(!MI_DDC_IS_HIGHLIGHT(pddc)) ) {
  
  	    /* Compute index value for ddx */
! 	    if (pddc->Static.attrs->echoMode == PEXEcho)
! 		intcolour = pddc->Static.attrs->echoColour;
! 	    else {
! 		intcolour.colourType = PEXRgbFloatColour;
! 		intcolour.colour.rgbFloat = *input_facet->facets.pFacetRgbFloat;
! 	    }
  	    miColourtoIndex(pRend, pddc->Dynamic->pPCAttr->colourApproxIndex,
  			    &intcolour, &colourindex);
  
***************
*** 236,242 ****
  	     * Surface attributes are set to highlight colour 
  	     * if highlighting
  	     */
! 	    intcolour = pddc->Static.attrs->surfaceColour;
  
  	    miColourtoIndex( pRend,
  			     pddc->Dynamic->pPCAttr->colourApproxIndex,
--- 240,249 ----
  	     * Surface attributes are set to highlight colour 
  	     * if highlighting
  	     */
! 	    if (pddc->Static.attrs->echoMode == PEXEcho) 
! 		intcolour = pddc->Static.attrs->echoColour;
! 	    else 
! 		intcolour = pddc->Static.attrs->surfaceColour;
  
  	    miColourtoIndex( pRend,
  			     pddc->Dynamic->pPCAttr->colourApproxIndex,
***************
*** 359,366 ****
  		(!MI_DDC_IS_HIGHLIGHT(pddc)) ) {
  
  	    /* Compute index value for ddx */
! 	    intcolour.colourType = PEXRgbFloatColour;
! 	    intcolour.colour.rgbFloat = *input_facet->facets.pFacetRgbFloat;
  	    miColourtoIndex(pRend, pddc->Dynamic->pPCAttr->colourApproxIndex, 
  			    &intcolour, &colourindex);
  
--- 366,377 ----
  		(!MI_DDC_IS_HIGHLIGHT(pddc)) ) {
  
  	    /* Compute index value for ddx */
! 	    if (pddc->Static.attrs->echoMode == PEXEcho) 
! 		intcolour = pddc->Static.attrs->echoColour;
! 	    else {
! 		intcolour.colourType = PEXRgbFloatColour;
! 		intcolour.colour.rgbFloat = *input_facet->facets.pFacetRgbFloat;
! 	    }
  	    miColourtoIndex(pRend, pddc->Dynamic->pPCAttr->colourApproxIndex, 
  			    &intcolour, &colourindex);
  
***************
*** 404,410 ****
  	     * Surface attributes are set to highlight colour 
  	     * if highlighting
  	     */
! 	    intcolour = pddc->Static.attrs->surfaceColour;
  
  	    miColourtoIndex( pRend,
  			     pddc->Dynamic->pPCAttr->colourApproxIndex,
--- 415,424 ----
  	     * Surface attributes are set to highlight colour 
  	     * if highlighting
  	     */
! 	    if (pddc->Static.attrs->echoMode == PEXEcho)
! 		intcolour = pddc->Static.attrs->echoColour;
! 	    else 
! 		intcolour = pddc->Static.attrs->surfaceColour;
  
  	    miColourtoIndex( pRend,
  			     pddc->Dynamic->pPCAttr->colourApproxIndex,
*** -	Thu Jan 28 17:52:35 1993
--- mit/extensions/server/PEX/ddpex/mi/level1/miRndTStrip.c	Thu Jan 28 17:52:35 1993
***************
*** 1,4 ****
! /* $XConsortium: miRndTStrip.c,v 5.1 91/02/16 09:55:08 rws Exp $ */
  
  
  /***********************************************************
--- 1,4 ----
! /* $XConsortium: miRndTStrip.c,v 5.2 92/12/03 19:46:04 hersh Exp $ */
  
  
  /***********************************************************
***************
*** 232,239 ****
              pGC = pddc->Static.misc.pFillAreaGC;
              out_fct = input_facet->facets;
              DDFacetSIZE(input_facet->type, facet_size);
!             intcolour.colourType = PEXRgbFloatColour;
!             intcolour.colour.rgbFloat = *out_fct.pFacetRgbFloat;
              miColourtoIndex(	pRend, pddc->Dynamic->pPCAttr->colourApproxIndex,
  				&intcolour, &colourindex);
  
--- 232,243 ----
              pGC = pddc->Static.misc.pFillAreaGC;
              out_fct = input_facet->facets;
              DDFacetSIZE(input_facet->type, facet_size);
! 	    if (pddc->Static.attrs->echoMode == PEXEcho)
! 		intcolour = pddc->Static.attrs->echoColour;
! 	    else {
! 		intcolour.colourType = PEXRgbFloatColour;
! 		intcolour.colour.rgbFloat = *out_fct.pFacetRgbFloat;
! 	    }
              miColourtoIndex(	pRend, pddc->Dynamic->pPCAttr->colourApproxIndex,
  				&intcolour, &colourindex);
  
***************
*** 247,253 ****
  	     * the surface color attribute which has been set to the 
  	     * highlight color
               */
!             intcolour = pddc->Static.attrs->surfaceColour;
                 
  	    miColourtoIndex( pRend, 
  			     pddc->Dynamic->pPCAttr->colourApproxIndex,
--- 251,261 ----
  	     * the surface color attribute which has been set to the 
  	     * highlight color
               */
! 	    if (pddc->Static.attrs->echoMode == PEXEcho)
! 		intcolour = pddc->Static.attrs->echoColour;
! 	    else {
! 		intcolour = pddc->Static.attrs->surfaceColour;
! 	    }
                 
  	    miColourtoIndex( pRend, 
  			     pddc->Dynamic->pPCAttr->colourApproxIndex,
***************
*** 314,321 ****
                   (DD_IsFacetColour(input_facet->type)) ) {
  		 out_fct.pNoFacet += facet_size;
  	
!             	 intcolour.colourType = PEXRgbFloatColour;
!             	 intcolour.colour.rgbFloat = *out_fct.pFacetRgbFloat;
              	 miColourtoIndex(   pRend, 
  				    pddc->Dynamic->pPCAttr->colourApproxIndex,
  				    &intcolour, &colourindex);
--- 322,333 ----
                   (DD_IsFacetColour(input_facet->type)) ) {
  		 out_fct.pNoFacet += facet_size;
  	
! 		  if (pddc->Static.attrs->echoMode == PEXEcho)
! 		      intcolour = pddc->Static.attrs->echoColour;
! 		  else {
! 		      intcolour.colourType = PEXRgbFloatColour;
! 		      intcolour.colour.rgbFloat = *out_fct.pFacetRgbFloat;
! 		  }
              	 miColourtoIndex(   pRend, 
  				    pddc->Dynamic->pPCAttr->colourApproxIndex,
  				    &intcolour, &colourindex);
***************
*** 460,466 ****
              out_fct = input_facet->facets;
              DDFacetSIZE(input_facet->type, facet_size);
   
-             intcolour.colourType = PEXRgbFloatColour;
   
              /* Render each bound as a polygon */
  
--- 472,477 ----
***************
*** 486,492 ****
  
  
                  /* Compute index value for ddx */
!                 intcolour.colour.rgbFloat = *out_fct.pFacetRgbFloat;
                  miColourtoIndex(pRend, pddc->Dynamic->pPCAttr->colourApproxIndex,
                                  &intcolour, &colourindex);
   
--- 497,508 ----
  
  
                  /* Compute index value for ddx */
! 		if (pddc->Static.attrs->echoMode == PEXEcho)
! 		    intcolour = pddc->Static.attrs->echoColour;
! 		else {
! 		    intcolour.colourType = PEXRgbFloatColour;
! 		    intcolour.colour.rgbFloat = *out_fct.pFacetRgbFloat;
! 		}
                  miColourtoIndex(pRend, pddc->Dynamic->pPCAttr->colourApproxIndex,
                                  &intcolour, &colourindex);
   
***************
*** 531,537 ****
  	     * the surface color attribute which has been set to the 
  	     * highlight color
               */
!             intcolour = pddc->Static.attrs->surfaceColour;
                 
  	    miColourtoIndex( pRend,
  			     pddc->Dynamic->pPCAttr->colourApproxIndex,
--- 547,557 ----
  	     * the surface color attribute which has been set to the 
  	     * highlight color
               */
! 	    if (pddc->Static.attrs->echoMode == PEXEcho)
! 		intcolour = pddc->Static.attrs->echoColour;
! 	    else {
! 		intcolour = pddc->Static.attrs->surfaceColour;
! 	    }
                 
  	    miColourtoIndex( pRend,
  			     pddc->Dynamic->pPCAttr->colourApproxIndex,
*** -	Thu Jan 28 17:52:36 1993
--- mit/extensions/server/PEX/ddpex/mi/level1/miRndMarkr.c	Thu Jan 28 17:52:36 1993
***************
*** 1,4 ****
! /* $XConsortium: miRndMarkr.c,v 5.3 91/04/23 17:13:09 hersh Exp $ */
  
  
  /***********************************************************
--- 1,4 ----
! /* $XConsortium: miRndMarkr.c,v 5.4 92/05/06 16:32:45 hersh Exp $ */
  
  
  /***********************************************************
***************
*** 139,145 ****
  	       */
  	      if (parcs)
  	        pcurarcs = parcs = 
! 			(xArc *)Xrealloc(sizeof(xArc)*pddlist1->numPoints);
  	      else pcurarcs = parcs = 
  			(xArc *)Xalloc(sizeof(xArc)*pddlist1->numPoints);
  
--- 139,145 ----
  	       */
  	      if (parcs)
  	        pcurarcs = parcs = 
! 			(xArc *)Xrealloc(parcs,sizeof(xArc)*pddlist1->numPoints);
  	      else pcurarcs = parcs = 
  			(xArc *)Xalloc(sizeof(xArc)*pddlist1->numPoints);
  
*** -	Thu Jan 28 17:52:37 1993
--- mit/extensions/server/PEX/ddpex/mi/level1/miPck1Prim.c	Thu Jan 28 17:52:36 1993
***************
*** 1,4 ****
! /* $XConsortium: miPck1Prim.c,v 5.1 91/02/16 09:55:10 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miPck1Prim.c,v 5.2 93/01/25 16:26:11 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 251,257 ****
  
  	pt_list.ptr = poly_list->pts.ptr;
  
! 	for (j=0; j<in_list->ddList->numPoints; j++) { /* Do for all edges */
  
  	    /* Get the first vertex of current edge */
  
--- 251,257 ----
  
  	pt_list.ptr = poly_list->pts.ptr;
  
! 	for (j=0; j<in_list->ddList->numPoints-1; j++) { /* Do for all edges */
  
  	    /* Get the first vertex of current edge */
  
*** -	Thu Jan 28 17:52:46 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/miFillArea.c	Thu Jan 28 17:52:45 1993
***************
*** 1,4 ****
! /* $XConsortium: miFillArea.c,v 5.6 91/07/18 18:20:07 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miFillArea.c,v 5.8 92/12/29 17:12:27 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 130,136 ****
  
        /* Check for Model clipping */
   
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  	/* Compute  modelling coord version of clipping volume */ 
          ComputeMCVolume(pRend, pddc);      
          clip_mode = MI_MCLIP;
--- 130,136 ----
  
        /* Check for Model clipping */
   
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  	/* Compute  modelling coord version of clipping volume */ 
          ComputeMCVolume(pRend, pddc);      
          clip_mode = MI_MCLIP;
***************
*** 148,153 ****
--- 148,156 ----
          if (status = miClipFillArea(pddc, mc_clist, color_facet,
                                  &mc_list, &mc_facet, clip_mode))
              return (status);
+ 
+ 	/* if nothing left after modeling clip, return early */
+ 	if (mc_list->numLists <= 0) return(Success);
   
        } else {
          mc_list = color_list;
***************
*** 235,245 ****
--- 238,253 ----
  			      &clip_list, &clip_facet, clip_mode))
  	    return (status);
  
+       /* if nothing left after view clip, return early */
+       if (clip_list->numLists <= 0) return(Success);
+ 
        /* Now cull according to current culling mode */
        if (pddc->Dynamic->pPCAttr->cullMode) {
          if (status = miCullFillArea(pddc, clip_list, clip_facet,
  				    &cull_list, &cull_facet))
  	    return (status);
+ 
+ 	/* if nothing left after culling, return early */
  	if (cull_list->numLists <= 0) return(Success);
  	clip_list = cull_list;
  	clip_facet = cull_facet;
*** -	Thu Jan 28 17:52:48 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/miPolyLine.c	Thu Jan 28 17:52:48 1993
***************
*** 1,4 ****
! /* $XConsortium: miPolyLine.c,v 5.2 91/05/01 14:36:03 hersh Exp $ */
  
  
  /***********************************************************
--- 1,4 ----
! /* $XConsortium: miPolyLine.c,v 5.4 92/12/29 17:12:53 mor Exp $ */
  
  
  /***********************************************************
***************
*** 94,100 ****
  
      /* Check for Model clipping */
  
!     if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  
        ComputeMCVolume(pRend, pddc);	/*  Compute  modelling coord version
                                     	    of clipping volume */
--- 94,100 ----
  
      /* Check for Model clipping */
  
!     if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  
        ComputeMCVolume(pRend, pddc);	/*  Compute  modelling coord version
                                     	    of clipping volume */
***************
*** 113,119 ****
--- 113,122 ----
        if (status = miClipPolyLines(pddc, mc_clist, &mc_list, clip_mode)) 
                  return(status);
  
+       /* if nothing left, return early */
+       if (mc_list->numLists <= 0) return(Success);
  
+ 
      } else mc_list = color_list;
  
      clip_mode = MI_VCLIP;
***************
*** 129,134 ****
--- 132,140 ----
  
      if (status = miClipPolyLines(pddc, cc_list, &clip_list, clip_mode)) 
  		return(status);
+ 
+     /* if nothing left, return early */
+     if (clip_list->numLists <= 0) return(Success);
  
      /* DEPTH CUEING */
      if (pddc->Dynamic->pPCAttr->depthCueIndex) {
*** -	Thu Jan 28 17:52:51 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/miText.c	Thu Jan 28 17:52:50 1993
***************
*** 1,4 ****
! /* $XConsortium: miText.c,v 5.4 91/05/12 16:11:12 rws Exp $ */
  
  
  /***********************************************************
--- 1,4 ----
! /* $XConsortium: miText.c,v 5.11 93/01/26 10:40:36 mor Exp $ */
  
  
  /***********************************************************
***************
*** 44,56 ****
  #include "gcstruct.h"
  
  #ifndef PADDING
! #define PADDING(n) ( (n)%4 ? (4 - (n)%4) : 0)
  #endif 
  
  extern ddpex3rtn ComputeMCVolume();
  
! int
! tx_el_to_path(pRend, pddc, numFragments, pString, numChars, tx_el, align_pt)
  /* in */
      ddRendererPtr           pRend;        /* Renderer handle */
      miDDContext             *pddc;        /* Context handle */
--- 44,57 ----
  #include "gcstruct.h"
  
  #ifndef PADDING
! #define PADDING(n) ( (n)%4 ? (4 - ((n)%4)) : 0)
  #endif 
  
  extern ddpex3rtn ComputeMCVolume();
  
! ddpex2rtn
! tx_el_to_path(pRend, pddc, numFragments, pString, numChars, tx_el,
! 	align_pt, count_ret)
  /* in */
      ddRendererPtr           pRend;        /* Renderer handle */
      miDDContext             *pddc;        /* Context handle */
***************
*** 60,65 ****
--- 61,67 ----
  /* out */
      miTextElement           *tx_el;       /* text element data */
      ddCoord2D               *align_pt;    /* text alignment */
+     ddULONG		    *count_ret;   /* return character count */
  {
  /* Define required temporary variables */
  
***************
*** 73,80 ****
      register ddPointer	     ptr, save_ptr;
      miTextFontEntry          *ptr1;
      pexMonoEncoding	    *mono_enc;
!     register int             cnt=0;
!     int			     fragnum, charnum, some_characters, signum;
      CARD32		     charval;
      diFontHandle	     font_handle;
      miFontHeader	    *font;
--- 75,81 ----
      register ddPointer	     ptr, save_ptr;
      miTextFontEntry          *ptr1;
      pexMonoEncoding	    *mono_enc;
!     int			     fragnum, charnum, some_characters, signum, bytes;
      CARD32		     charval;
      diFontHandle	     font_handle;
      miFontHeader	    *font;
***************
*** 82,93 ****
      ddFLOAT		     sp; 
      Meta_font		     meta_font;
      pexCoord2D		     cur, end, cpt;
!     register float	     xmin, xmax, ymin, ymax;
      ddTextFontEntry	    *fontEntry;
      ddUSHORT                 es, clip_mode;
-     ddpex3rtn                status;
      extern void              micalc_cpt_and_align();
      
      fontIndex = pddc->Static.attrs->textFont;
      expansion = ABS(pddc->Static.attrs->charExpansion);
      spacing = pddc->Static.attrs->charSpacing;
--- 83,95 ----
      ddFLOAT		     sp; 
      Meta_font		     meta_font;
      pexCoord2D		     cur, end, cpt;
!     float	     	     xmin, xmax, ymin, ymax;
      ddTextFontEntry	    *fontEntry;
      ddUSHORT                 es, clip_mode;
      extern void              micalc_cpt_and_align();
      
+     *count_ret = 0;
+ 
      fontIndex = pddc->Static.attrs->textFont;
      expansion = ABS(pddc->Static.attrs->charExpansion);
      spacing = pddc->Static.attrs->charSpacing;
***************
*** 140,153 ****
      /* Do for each MONO_ENCODING fragment within the ISTRING */
  
      for (fragnum = 0; fragnum < numFragments; fragnum++) {
! 	
        mono_enc = (pexMonoEncoding *)ptr;
        ptr += sizeof(pexMonoEncoding);
  	    
!       if (mono_enc->characterSet > fontEntry->numFonts)
! 	mono_enc->characterSet = 0;
  
!       font_handle = fontEntry->fonts[mono_enc->characterSet];
  	    
        /* This is the font that this MONO_ENCODING would be rendered with  */
  
--- 142,156 ----
      /* Do for each MONO_ENCODING fragment within the ISTRING */
  
      for (fragnum = 0; fragnum < numFragments; fragnum++) {
! 
        mono_enc = (pexMonoEncoding *)ptr;
        ptr += sizeof(pexMonoEncoding);
  	    
!       if (mono_enc->characterSet < 1 ||
! 	  mono_enc->characterSet > fontEntry->numFonts)
! 	  mono_enc->characterSet = 1;
  
!       font_handle = fontEntry->fonts[mono_enc->characterSet - 1];
  	    
        /* This is the font that this MONO_ENCODING would be rendered with  */
  
***************
*** 161,166 ****
--- 164,176 ----
  	meta_font.bottom = font->bottom;
        if (font->max_width > meta_font.width)
  	meta_font.width = font->max_width;
+ 
+       bytes = mono_enc->numChars *
+ 	  ((mono_enc->characterSetWidth == PEXCSByte) ?
+ 	  sizeof(CARD8) : ((mono_enc->characterSetWidth == PEXCSShort) ?
+ 	  sizeof(CARD16) : sizeof(CARD32)));
+ 
+       ptr += (bytes + PADDING (bytes));
      }
  
      /* Now get the character definition and the required per character */
***************
*** 173,179 ****
  	
        mono_enc = (pexMonoEncoding *)ptr;
        ptr += sizeof(pexMonoEncoding);
! 	    
        /* Do for each character within the MONO_ENCODING */
  
        for (charnum = 0; charnum < mono_enc->numChars; charnum++) {
--- 183,192 ----
  	
        mono_enc = (pexMonoEncoding *)ptr;
        ptr += sizeof(pexMonoEncoding);
! 
!       font_handle = fontEntry->fonts[mono_enc->characterSet - 1];
!       font = (miFontHeader *)(font_handle->deviceData);
! 
        /* Do for each character within the MONO_ENCODING */
  
        for (charnum = 0; charnum < mono_enc->numChars; charnum++) {
***************
*** 245,255 ****
  	if (path==PEXPathUp || path==PEXPathDown)
  	  cur.x -= -char_data->right * 0.5 * expansion;
  		
! 	CharPtr++; cnt++;  /* Update pointer and count */
  
        }  /* for each character */
  	    
!       ptr += PADDING(2 + mono_enc->numChars * 
  		     ((mono_enc->characterSetWidth == PEXCSByte) 
  		      ? sizeof(CARD8) 
  		      : ((mono_enc->characterSetWidth == PEXCSShort) 
--- 258,268 ----
  	if (path==PEXPathUp || path==PEXPathDown)
  	  cur.x -= -char_data->right * 0.5 * expansion;
  		
! 	CharPtr++; (*count_ret)++;  /* Update pointer and count */
  
        }  /* for each character */
  	    
!       ptr += PADDING(mono_enc->numChars * 
  		     ((mono_enc->characterSetWidth == PEXCSByte) 
  		      ? sizeof(CARD8) 
  		      : ((mono_enc->characterSetWidth == PEXCSShort) 
***************
*** 263,269 ****
  
      if (some_characters) {
  	    
!       micalc_cpt_and_align(&meta_font, xmin, xmax, ymin, ymax, path, 
  			 expansion, pAlignment, &cpt, align_pt);
  						       
      } else {
--- 276,282 ----
  
      if (some_characters) {
  	    
!       micalc_cpt_and_align(&meta_font, &xmin, &xmax, &ymin, &ymax, path, 
  			 expansion, pAlignment, &cpt, align_pt);
  						       
      } else {
***************
*** 272,283 ****
        cpt.x = cpt.y = align_pt->x = align_pt->y = 0.0;
      }
  	
!     return (cnt);  /* Return the number of characters found */
  }				 
  
  
! int
! atx_el_to_path(pRend, pddc, numFragments, pString, numChars, tx_el, align_pt)
  /* in */
      ddRendererPtr           pRend;        /* Renderer handle */
      miDDContext             *pddc;        /* Context handle */
--- 285,297 ----
        cpt.x = cpt.y = align_pt->x = align_pt->y = 0.0;
      }
  	
!     return (Success);
  }				 
  
  
! ddpex2rtn
! atx_el_to_path(pRend, pddc, numFragments, pString, numChars, tx_el,
! 	align_pt, count_ret)
  /* in */
      ddRendererPtr           pRend;        /* Renderer handle */
      miDDContext             *pddc;        /* Context handle */
***************
*** 287,292 ****
--- 301,307 ----
  /* out */
      miTextElement           *tx_el;       /* text element data */
      ddCoord2D               *align_pt;    /* text alignment */
+     ddULONG		    *count_ret;   /* return character count */
  {
  /* Define required temporary variables */
  
***************
*** 300,307 ****
      register ddPointer	     ptr, save_ptr;
      miTextFontEntry          *ptr1;
      pexMonoEncoding	    *mono_enc;
!     register int             cnt=0;
!     int			     fragnum, charnum, some_characters, signum;
      CARD32		     charval;
      diFontHandle	     font_handle;
      miFontHeader	    *font;
--- 315,321 ----
      register ddPointer	     ptr, save_ptr;
      miTextFontEntry          *ptr1;
      pexMonoEncoding	    *mono_enc;
!     int			     fragnum, charnum, some_characters, signum, bytes;
      CARD32		     charval;
      diFontHandle	     font_handle;
      miFontHeader	    *font;
***************
*** 309,320 ****
      ddFLOAT		     sp;
      Meta_font		     meta_font;
      pexCoord2D		     cur, end, cpt;
!     register float	     xmin, xmax, ymin, ymax;
      ddTextFontEntry	    *fontEntry;
      ddUSHORT                 es;
-     ddpex3rtn                status;
      extern void              micalc_cpt_and_align();
      
      fontIndex = pddc->Static.attrs->textFont;
      expansion = ABS(pddc->Static.attrs->charExpansion);
      spacing = pddc->Static.attrs->charSpacing;
--- 323,335 ----
      ddFLOAT		     sp;
      Meta_font		     meta_font;
      pexCoord2D		     cur, end, cpt;
!     float	     	     xmin, xmax, ymin, ymax;
      ddTextFontEntry	    *fontEntry;
      ddUSHORT                 es;
      extern void              micalc_cpt_and_align();
      
+     *count_ret = 0;
+ 
      fontIndex = pddc->Static.attrs->textFont;
      expansion = ABS(pddc->Static.attrs->charExpansion);
      spacing = pddc->Static.attrs->charSpacing;
***************
*** 371,381 ****
        mono_enc = (pexMonoEncoding *)ptr;
        ptr += sizeof(pexMonoEncoding);
  	    
!       if (mono_enc->characterSet > fontEntry->numFonts)
! 	mono_enc->characterSet = 0;
  
!       font_handle = fontEntry->fonts[mono_enc->characterSet];
! 	    
        /* This is the font that this MONO_ENCODING would be rendered with  */
  
        font = (miFontHeader *)(font_handle->deviceData);
--- 386,397 ----
        mono_enc = (pexMonoEncoding *)ptr;
        ptr += sizeof(pexMonoEncoding);
  	    
!       if (mono_enc->characterSet < 1 ||
! 	  mono_enc->characterSet > fontEntry->numFonts)
! 	  mono_enc->characterSet = 1;
  
!       font_handle = fontEntry->fonts[mono_enc->characterSet - 1];
! 
        /* This is the font that this MONO_ENCODING would be rendered with  */
  
        font = (miFontHeader *)(font_handle->deviceData);
***************
*** 388,393 ****
--- 404,416 ----
  	meta_font.bottom = font->bottom;
        if (font->max_width > meta_font.width)
  	meta_font.width = font->max_width;
+ 
+       bytes = mono_enc->numChars *
+ 	  ((mono_enc->characterSetWidth == PEXCSByte) ?
+ 	  sizeof(CARD8) : ((mono_enc->characterSetWidth == PEXCSShort) ?
+ 	  sizeof(CARD16) : sizeof(CARD32)));
+ 
+       ptr += (bytes + PADDING (bytes));
      }
  
      /* Now get the character definition and the required per character */
***************
*** 401,406 ****
--- 424,432 ----
        mono_enc = (pexMonoEncoding *)ptr;
        ptr += sizeof(pexMonoEncoding);
  	    
+       font_handle = fontEntry->fonts[mono_enc->characterSet - 1];
+       font = (miFontHeader *)(font_handle->deviceData);
+ 
        /* Do for each character within the MONO_ENCODING */
  
        for (charnum = 0; charnum < mono_enc->numChars; charnum++) {
***************
*** 472,482 ****
  	if (path==PEXPathUp || path==PEXPathDown)
  	  cur.x -= -char_data->right * 0.5 * expansion;
  		
! 	CharPtr++; cnt++;  /* Update pointer and count */
  
        }  /* for each character */
  	    
!       ptr += PADDING(2 + mono_enc->numChars * 
  		     ((mono_enc->characterSetWidth == PEXCSByte) 
  		      ? sizeof(CARD8) 
  		      : ((mono_enc->characterSetWidth == PEXCSShort) 
--- 498,508 ----
  	if (path==PEXPathUp || path==PEXPathDown)
  	  cur.x -= -char_data->right * 0.5 * expansion;
  		
! 	CharPtr++; (*count_ret)++;  /* Update pointer and count */
  
        }  /* for each character */
  	    
!       ptr += PADDING(mono_enc->numChars * 
  		     ((mono_enc->characterSetWidth == PEXCSByte) 
  		      ? sizeof(CARD8) 
  		      : ((mono_enc->characterSetWidth == PEXCSShort) 
***************
*** 490,496 ****
  
      if (some_characters) {
  	    
!       micalc_cpt_and_align(&meta_font, xmin, xmax, ymin, ymax, path, 
  			 expansion, pAlignment, &cpt, align_pt);
  						       
      } else {
--- 516,522 ----
  
      if (some_characters) {
  	    
!       micalc_cpt_and_align(&meta_font, &xmin, &xmax, &ymin, &ymax, path, 
  			 expansion, pAlignment, &cpt, align_pt);
  						       
      } else {
***************
*** 499,505 ****
        cpt.x = cpt.y = align_pt->x = align_pt->y = 0.0;
      }
  	
!     return (cnt);  /* Return the number of characters found */
  }				 
  
  
--- 525,531 ----
        cpt.x = cpt.y = align_pt->x = align_pt->y = 0.0;
      }
  	
!     return (Success);
  }				 
  
  
***************
*** 645,667 ****
      temp[0][3] = a;
      temp[1][3] = b;
  
!     /* Let temp1 hold the base vector, the up vector, and the 
!        text position. */
  
      temp1[0][0] = vbase.x;
      temp1[0][1] = vup.x;
      temp1[0][2] = 0.0;
!     temp1[0][3] = pos->x;
  
      temp1[1][0] = vbase.y;
      temp1[1][1] = vup.y;
      temp1[1][2] = 0.0;
!     temp1[1][3] = pos->y;
  
      temp1[2][0] = temp1[3][0] = 0.0;
      temp1[2][1] = temp1[3][1] = 0.0;
      temp1[2][2] = temp1[3][3] = 1.0;
!     temp1[2][3] = pos->z;
      temp1[3][2] = 0.0;
  
      /* e3 is the cross-product of direction vectors u and v */
--- 671,692 ----
      temp[0][3] = a;
      temp[1][3] = b;
  
!     /* Let temp1 hold the base vector and the up vector */
  
      temp1[0][0] = vbase.x;
      temp1[0][1] = vup.x;
      temp1[0][2] = 0.0;
!     temp1[0][3] = 0.0;
  
      temp1[1][0] = vbase.y;
      temp1[1][1] = vup.y;
      temp1[1][2] = 0.0;
!     temp1[1][3] = 0.0;
  
      temp1[2][0] = temp1[3][0] = 0.0;
      temp1[2][1] = temp1[3][1] = 0.0;
      temp1[2][2] = temp1[3][3] = 1.0;
!     temp1[2][3] = 0.0;
      temp1[3][2] = 0.0;
  
      /* e3 is the cross-product of direction vectors u and v */
***************
*** 681,687 ****
      } else {	/* Build a 3D transform. */
  
  /* The rotation matrix, temp2, for orienting the text 
!    coordinate space consists of the row vectors, e1, e2 and e3. */
  
  /* Normalized vector e3 is row 3 of the rotation matrix */
  
--- 706,713 ----
      } else {	/* Build a 3D transform. */
  
  /* The rotation matrix, temp2, for orienting the text 
!    coordinate space consists of the row vectors, e1, e2 and e3,
!    and the position. */
  
  /* Normalized vector e3 is row 3 of the rotation matrix */
  
***************
*** 712,724 ****
  	temp2[2][1] = (e2->z *= inv_mag);
  	temp2[3][1] = 0.0;
  
! 	temp2[0][3] = temp2[1][3] = temp2[2][3] = 0.0;
  	temp2[3][3] = 1.0;
  
  /* The final transformation matrix, xf, is the product of the
!    3 matrices temp, temp1 and temp2. */
  
!         miMatMult( temp3, temp2, temp1 );
  	miMatMult( xf, temp, temp3 ); 
      }
  }
--- 738,752 ----
  	temp2[2][1] = (e2->z *= inv_mag);
  	temp2[3][1] = 0.0;
  
! 	temp2[0][3] = pos->x;
! 	temp2[1][3] = pos->y;
! 	temp2[2][3] = pos->z;
  	temp2[3][3] = 1.0;
  
  /* The final transformation matrix, xf, is the product of the
!    3 matrices: temp2 x temp1 x temp. */
  
!         miMatMult( temp3, temp1, temp2 );
  	miMatMult( xf, temp, temp3 ); 
      }
  }
***************
*** 773,779 ****
      miListHeader	*mc_path, *mclip_path, *cc_path, *clip_path, *dc_path;
      listofddPoint	*sp;
      XID		        temp;
!     ddpex3rtn		status;
      ddUSHORT            aflag, clip_mode;
  
      /* Set the annotation text flag to zero */
--- 801,807 ----
      miListHeader	*mc_path, *mclip_path, *cc_path, *clip_path, *dc_path;
      listofddPoint	*sp;
      XID		        temp;
!     int			status;
      ddUSHORT            aflag, clip_mode;
  
      /* Set the annotation text flag to zero */
***************
*** 789,803 ****
      numChars = 0;
      pMono = pText;
      for (i=0; i<numEncodings; i++) {
        numChars += (ddULONG)pMono->numChars;
!       pMono++;
      }
  
      /* Convert text string into required paths */
  
!     if (!(count = tx_el_to_path (pRend, pddc, numEncodings, pText,
! 				 numChars, &text_el, &align))) {
!       return (BadValue);
      }
  
      /* Compute the required Character Space to Modelling Space Transform */
--- 817,839 ----
      numChars = 0;
      pMono = pText;
      for (i=0; i<numEncodings; i++) {
+       int bytes = pMono->numChars * ((pMono->characterSetWidth == PEXCSByte) ?
+ 	  sizeof(CARD8) : ((pMono->characterSetWidth == PEXCSShort) ?
+ 	  sizeof(CARD16) : sizeof(CARD32)));
        numChars += (ddULONG)pMono->numChars;
!       pMono = (pexMonoEncoding *) ((char *) (pMono + 1) +
! 	  bytes + PADDING (bytes));
      }
  
+     if (numChars == 0)
+ 	return (Success);
+ 
+ 
      /* Convert text string into required paths */
  
!     if ((status = tx_el_to_path (pRend, pddc, numEncodings, pText,
! 	numChars, &text_el, &align, &count)) != Success) {
!       return (status);
      }
  
      /* Compute the required Character Space to Modelling Space Transform */
***************
*** 822,828 ****
  
      /* Check for modelling clip and set up the volume if required */
  
!     if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  	ComputeMCVolume(pRend, pddc);    /* Get the current model clip volume */
      }
  
--- 858,864 ----
  
      /* Check for modelling clip and set up the volume if required */
  
!     if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  	ComputeMCVolume(pRend, pddc);    /* Get the current model clip volume */
      }
  
***************
*** 888,894 ****
  
        /* Check to see if modelling clip is required. If so, apply it */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  
  	  /* Buffer the tc_to_mc_xform first */
  
--- 924,930 ----
  
        /* Check to see if modelling clip is required. If so, apply it */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  
  	  /* Buffer the tc_to_mc_xform first */
  
***************
*** 916,921 ****
--- 952,958 ----
  
  	  if (status = miClipPolyLines(pddc, mc_path, &mclip_path, MI_MCLIP))
  	      return (status);
+ 
        }
        else {
  	  mclip_path = text_el.paths->path;
***************
*** 940,946 ****
  
        /* Transform and clip the paths corresponding to current character */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  
  	  /* Note that we are already in Model space here */
  
--- 977,983 ----
  
        /* Transform and clip the paths corresponding to current character */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  
  	  /* Note that we are already in Model space here */
  
***************
*** 965,970 ****
--- 1002,1013 ----
        if (status = miClipPolyLines(pddc, cc_path, &clip_path, clip_mode))
            return (status);
  
+       /* if nothing left, then update pointers and continue */
+       if (clip_path->numLists <= 0) {
+ 	  text_el.paths++;
+ 	  continue;
+       }
+ 
        /* Transform to DC coordinates */
  
        if (status = miTransform(pddc, clip_path, &dc_path, 
***************
*** 1038,1044 ****
      miListHeader	*mc_path, *mclip_path, *cc_path, *clip_path, *dc_path;
      listofddPoint	*sp;
      XID		        temp;
!     ddpex3rtn		status;
      ddUSHORT            aflag, clip_mode;
  
      /* Set the annotation text flag to zero */
--- 1081,1087 ----
      miListHeader	*mc_path, *mclip_path, *cc_path, *clip_path, *dc_path;
      listofddPoint	*sp;
      XID		        temp;
!     int			status;
      ddUSHORT            aflag, clip_mode;
  
      /* Set the annotation text flag to zero */
***************
*** 1054,1068 ****
      numChars = 0;
      pMono = pText;
      for (i=0; i<numEncodings; i++) {
        numChars += (ddULONG)pMono->numChars;
!       pMono++;
      }
  
      /* Convert text string into required paths */
  
!     if (!(count = tx_el_to_path (pRend, pddc, numEncodings, pText,
! 				 numChars, &text_el, &align))) {
!       return (BadValue);
      }
  
      /* Compute the required Character Space to Modelling Space Transform */
--- 1097,1119 ----
      numChars = 0;
      pMono = pText;
      for (i=0; i<numEncodings; i++) {
+       int bytes = pMono->numChars * ((pMono->characterSetWidth == PEXCSByte) ?
+ 	  sizeof(CARD8) : ((pMono->characterSetWidth == PEXCSShort) ?
+ 	  sizeof(CARD16) : sizeof(CARD32)));
        numChars += (ddULONG)pMono->numChars;
!       pMono = (pexMonoEncoding *) ((char *) (pMono + 1) +
! 	  bytes + PADDING (bytes));
      }
  
+     if (numChars == 0)
+ 	return (Success);
+ 
+ 
      /* Convert text string into required paths */
  
!     if ((status = tx_el_to_path (pRend, pddc, numEncodings, pText,
! 	numChars, &text_el, &align, &count)) != Success) {
!       return (status);
      }
  
      /* Compute the required Character Space to Modelling Space Transform */
***************
*** 1086,1092 ****
  
      /* Check for modelling clip and set up the volume if required */
  
!     if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  	ComputeMCVolume(pRend, pddc);    /* Get the current model clip volume */
      }
  
--- 1137,1143 ----
  
      /* Check for modelling clip and set up the volume if required */
  
!     if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  	ComputeMCVolume(pRend, pddc);    /* Get the current model clip volume */
      }
  
***************
*** 1152,1158 ****
  
        /* Check to see if modelling clip is required. If so, apply it */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  
  	  /* Buffer the tc_to_mc_xform first */
  
--- 1203,1209 ----
  
        /* Check to see if modelling clip is required. If so, apply it */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  
  	  /* Buffer the tc_to_mc_xform first */
  
***************
*** 1204,1210 ****
  
        /* Transform and clip the paths corresponding to current character */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  
  	  /* Note that we are already in Model space here */
  
--- 1255,1261 ----
  
        /* Transform and clip the paths corresponding to current character */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  
  	  /* Note that we are already in Model space here */
  
***************
*** 1230,1235 ****
--- 1281,1292 ----
        if (status = miClipPolyLines(pddc, cc_path, &clip_path, clip_mode))
            return (status);
  
+       /* if nothing left, then update pointers and continue */
+       if (clip_path->numLists <= 0) {
+ 	  text_el.paths++;
+ 	  continue;
+       }
+ 
        /* Transform to DC coordinates */
  
        if (status = miTransform(pddc, clip_path, &dc_path, 
***************
*** 1307,1313 ****
      miListHeader	*mc_path, *mclip_path, *cc_path, *clip_path, *dc_path;
      listofddPoint	*sp;
      XID		        temp;
!     ddpex3rtn		status;
      ddUSHORT            aflag;
      static ddVector3D   Directions[2] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0};
      ddCoord3D           *pDirections = (ddCoord3D *)Directions;
--- 1364,1370 ----
      miListHeader	*mc_path, *mclip_path, *cc_path, *clip_path, *dc_path;
      listofddPoint	*sp;
      XID		        temp;
!     int			status;
      ddUSHORT            aflag;
      static ddVector3D   Directions[2] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0};
      ddCoord3D           *pDirections = (ddCoord3D *)Directions;
***************
*** 1330,1336 ****
      MC_Origin.z = pOrigin->z;
      MC_Origin.w = 1.0;
  
!     if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  
        ComputeMCVolume(pRend, pddc);      /* Compute  modelling coord version
                                     of clipping volume */
--- 1387,1393 ----
      MC_Origin.z = pOrigin->z;
      MC_Origin.w = 1.0;
  
!     if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  
        ComputeMCVolume(pRend, pddc);      /* Compute  modelling coord version
                                     of clipping volume */
***************
*** 1374,1388 ****
      numChars = 0;
      pMono = pText;
      for (i=0; i<numEncodings; i++) {
        numChars += (ddULONG)pMono->numChars;
!       pMono++;
      }
  
      /* Convert text string into required paths */
  
!     if (!(count = atx_el_to_path (pRend, pddc, numEncodings, pText,
! 				 numChars, &text_el, &align))) {
!       return (BadValue);
      }
  
      /* Compute the required Character Space to Modelling Space Transform */
--- 1431,1453 ----
      numChars = 0;
      pMono = pText;
      for (i=0; i<numEncodings; i++) {
+       int bytes = pMono->numChars * ((pMono->characterSetWidth == PEXCSByte) ?
+ 	  sizeof(CARD8) : ((pMono->characterSetWidth == PEXCSShort) ?
+ 	  sizeof(CARD16) : sizeof(CARD32)));
        numChars += (ddULONG)pMono->numChars;
!       pMono = (pexMonoEncoding *) ((char *) (pMono + 1) +
! 	  bytes + PADDING (bytes));
      }
  
+     if (numChars == 0)
+ 	return (Success);
+ 
+ 
      /* Convert text string into required paths */
  
!     if ((status = atx_el_to_path (pRend, pddc, numEncodings, pText,
! 	numChars, &text_el, &align, &count)) != Success) {
!       return (status);
      }
  
      /* Compute the required Character Space to Modelling Space Transform */
***************
*** 1494,1500 ****
  
        /* Check to see if modelling clip is required. If so, apply it */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  
  	  /* Buffer the tc_to_mc_xform first */
  
--- 1559,1565 ----
  
        /* Check to see if modelling clip is required. If so, apply it */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  
  	  /* Buffer the tc_to_mc_xform first */
  
***************
*** 1546,1552 ****
  
        /* Transform and clip the paths corresponding to current character */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  
  	  /* Note that we are already in Model space here */
  
--- 1611,1617 ----
  
        /* Transform and clip the paths corresponding to current character */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  
  	  /* Note that we are already in Model space here */
  
***************
*** 1573,1578 ****
--- 1638,1649 ----
        if (status = miClipPolyLines(pddc, cc_path, &clip_path, clip_mode))
            return (status);
  
+       /* if nothing left, then update pointers and continue */
+       if (clip_path->numLists <= 0) {
+ 	  text_el.paths++;
+ 	  continue;
+       }
+ 
        /* Transform to DC coordinates */
  
        if (status = miTransform(pddc, clip_path, &dc_path, 
***************
*** 1714,1720 ****
      miListHeader	*mc_path, *mclip_path, *cc_path, *clip_path, *dc_path;
      listofddPoint	*sp;
      XID		        temp;
!     ddpex3rtn		status;
      ddUSHORT            aflag;
      miListHeader        Connector;
      ddCoord4D           CC_Offset;  /* Offset in Clipping Coordinates */
--- 1785,1791 ----
      miListHeader	*mc_path, *mclip_path, *cc_path, *clip_path, *dc_path;
      listofddPoint	*sp;
      XID		        temp;
!     int			status;
      ddUSHORT            aflag;
      miListHeader        Connector;
      ddCoord4D           CC_Offset;  /* Offset in Clipping Coordinates */
***************
*** 1735,1741 ****
      MC_Origin.z = 0.0;
      MC_Origin.w = 1.0;
  
!     if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  
        ComputeMCVolume(pRend, pddc);	/*  Compute  modelling coord version
  					    of clipping volume */
--- 1806,1812 ----
      MC_Origin.z = 0.0;
      MC_Origin.w = 1.0;
  
!     if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  
        ComputeMCVolume(pRend, pddc);	/*  Compute  modelling coord version
  					    of clipping volume */
***************
*** 1779,1793 ****
      numChars = 0;
      pMono = pText;
      for (i=0; i<numEncodings; i++) {
        numChars += (ddULONG)pMono->numChars;
!       pMono++;
      }
  
      /* Convert text string into required paths */
  
!     if (!(count = atx_el_to_path (pRend, pddc, numEncodings, pText,
! 				 numChars, &text_el, &align))) {
!       return (BadValue);
      }
  
      /* Compute the required Character Space to Modelling Space Transform */
--- 1850,1872 ----
      numChars = 0;
      pMono = pText;
      for (i=0; i<numEncodings; i++) {
+       int bytes = pMono->numChars * ((pMono->characterSetWidth == PEXCSByte) ?
+ 	  sizeof(CARD8) : ((pMono->characterSetWidth == PEXCSShort) ?
+ 	  sizeof(CARD16) : sizeof(CARD32)));
        numChars += (ddULONG)pMono->numChars;
!       pMono = (pexMonoEncoding *) ((char *) (pMono + 1) +
! 	  bytes + PADDING (bytes));
      }
  
+     if (numChars == 0)
+ 	return (Success);
+ 
+ 
      /* Convert text string into required paths */
  
!     if ((status = atx_el_to_path (pRend, pddc, numEncodings, pText,
! 	numChars, &text_el, &align, &count)) != Success) {
!       return (status);
      }
  
      /* Compute the required Character Space to Modelling Space Transform */
***************
*** 1901,1907 ****
  
        /* Check to see if modelling clip is required. If so, apply it */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  
  	  /* Buffer the tc_to_mc_xform first */
  
--- 1980,1986 ----
  
        /* Check to see if modelling clip is required. If so, apply it */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  
  	  /* Buffer the tc_to_mc_xform first */
  
***************
*** 1953,1959 ****
  
        /* Transform and clip the paths corresponding to current character */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  
  	  /* Note that we are already in Model space here */
  
--- 2032,2038 ----
  
        /* Transform and clip the paths corresponding to current character */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  
  	  /* Note that we are already in Model space here */
  
***************
*** 1980,1985 ****
--- 2059,2070 ----
        clip_mode = MI_VCLIP; 
        if (status = miClipPolyLines(pddc, cc_path, &clip_path, clip_mode))
            return (status);
+ 
+       /* if nothing left, then update pointers and continue */
+       if (clip_path->numLists <= 0) {
+ 	  text_el.paths++;
+ 	  continue;
+       }
  
        /* Transform to DC coordinates */
  
*** -	Thu Jan 28 17:52:53 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/pexOCParse.c	Thu Jan 28 17:52:53 1993
***************
*** 1,4 ****
! /* $XConsortium: pexOCParse.c,v 5.3 91/07/12 17:54:19 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pexOCParse.c,v 5.6 92/11/25 10:24:08 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 96,102 ****
  	*ppExecuteOC =							\
  	    (miGenericElementPtr) Xalloc((unsigned long)((SIZE)		\
  					+ sizeof(miGenericElementStr)));\
! 	if (!(*ppExecuteOC)) return (BadAlloc);	}			\
      (DD_ST) = (TYPE *)((*ppExecuteOC)+1);
  
  #define GET_MORE_STORAGE(DD_ST, TYPE, SIZE)			\
--- 96,103 ----
  	*ppExecuteOC =							\
  	    (miGenericElementPtr) Xalloc((unsigned long)((SIZE)		\
  					+ sizeof(miGenericElementStr)));\
!       if (!(*ppExecuteOC)) return (BadAlloc);	                        \
!     }			                                                \
      (DD_ST) = (TYPE *)((*ppExecuteOC)+1);
  
  #define GET_MORE_STORAGE(DD_ST, TYPE, SIZE)			\
***************
*** 1271,1277 ****
  	EXTRACT_CARD32(numPoints, ptr);
  	ptr += CountVertexData(	ptr, pPoly->colourType, numPoints,
  				pPoly->vertexAttribs); }
!     vertexSize = ptr - (ddPointer)(pPoly+1);
      GET_DD_STORAGE( ddPoly, miListHeader,
  		    (sizeof(miListHeader) + vertexSize
  		    + pPoly->numLists * sizeof(listofddPoint)));
--- 1272,1281 ----
  	EXTRACT_CARD32(numPoints, ptr);
  	ptr += CountVertexData(	ptr, pPoly->colourType, numPoints,
  				pPoly->vertexAttribs); }
! 
!     vertexSize = ptr - (ddPointer)(pPoly+1) -
!         pPoly->numLists * sizeof(CARD32);
! 
      GET_DD_STORAGE( ddPoly, miListHeader,
  		    (sizeof(miListHeader) + vertexSize
  		    + pPoly->numLists * sizeof(listofddPoint)));
***************
*** 2200,2205 ****
--- 2204,2226 ----
  		    pPEXOC->length * sizeof(CARD32));
  
      bcopy(  (char *)pPEXOC, (char *)dstAttrib,
+ 	    (int)(pPEXOC->length * sizeof(CARD32)));
+ 
+     OC_PARSER_RETURN(pPEXOC);
+ }
+ 
+ 
+ OC_PARSER_FUNC_HEADER(PropOC)
+ {
+     /** This handles storing ProprietaryOC 
+      **/
+ 
+     ddElementInfo  *dstPropOC;
+ 
+     GET_DD_STORAGE( dstPropOC, ddElementInfo,
+ 		    pPEXOC->length * sizeof(CARD32));
+ 
+     bcopy(  (char *)pPEXOC, (char *)dstPropOC,
  	    (int)(pPEXOC->length * sizeof(CARD32)));
  
      OC_PARSER_RETURN(pPEXOC);
*** -	Thu Jan 28 17:52:55 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/miConvert.c	Thu Jan 28 17:52:54 1993
***************
*** 1,4 ****
! /* $XConsortium: miConvert.c,v 5.3 91/05/05 18:50:02 rws Exp $ */
  
  
  /***********************************************************
--- 1,4 ----
! /* $XConsortium: miConvert.c,v 5.5 92/05/01 16:15:20 hersh Exp $ */
  
  
  /***********************************************************
***************
*** 124,130 ****
      /* Insure that LUT entry is in correct color model */
      if (pintcolour->entry.colourType != PEXRgbFloatColour)
       ColourConversionRoutine[pintcolour->entry.colourType*PEXRdrColourModelRGB]
! 			(&pintcolour->entry.colour.rgbFloat, out_col);
      else *((*out_col)++) = pintcolour->entry.colour.rgbFloat;
  
  }
--- 124,130 ----
      /* Insure that LUT entry is in correct color model */
      if (pintcolour->entry.colourType != PEXRgbFloatColour)
       ColourConversionRoutine[pintcolour->entry.colourType*PEXRdrColourModelRGB]
! 			(pRend, &pintcolour->entry.colour.rgbFloat, out_col);
      else *((*out_col)++) = pintcolour->entry.colour.rgbFloat;
  
  }
***************
*** 546,552 ****
  
  	/* Copy the input normal */
  	if (DD_IsFacetNormal(finput->type))
! 	  *(out_fct.pFacetN++) = *(in_fct.pFacetN);
  
      }
   
--- 546,552 ----
  
  	/* Copy the input normal */
  	if (DD_IsFacetNormal(finput->type))
! 	  *(out_fct.pFacetN++) = *(in_fct.pFacetN++);
  
      }
   
*** -	Thu Jan 28 17:52:56 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/miLight.c	Thu Jan 28 17:52:56 1993
***************
*** 1,4 ****
! /* $XConsortium: miLight.c,v 5.2 91/05/01 14:39:31 hersh Exp $ */
  
  
  /***********************************************************
--- 1,4 ----
! /* $XConsortium: miLight.c,v 5.3 93/01/25 17:21:50 hersh Exp $ */
  
  
  /***********************************************************
***************
*** 139,147 ****
  	     */
  	    case PEXReflectionSpecular:
  
! 		CALCULATE_REFLECTION_VECTOR(&refl_vec, n_dot_l,
  					    normal,
  					    &lightentry->direction);
  		NORMALIZE_VECTOR (&refl_vec, v_dot_r);
  
  		/*
--- 139,150 ----
  	     */
  	    case PEXReflectionSpecular:
  
! 		CALCULATE_REFLECTION_VECTOR(&refl_vec, -n_dot_l,
  					    normal,
  					    &lightentry->direction);
+     		refl_vec.x *= -1.0;		
+     		refl_vec.y *= -1.0;		
+     		refl_vec.z *= -1.0;		
  		NORMALIZE_VECTOR (&refl_vec, v_dot_r);
  
  		/*
***************
*** 170,176 ****
  		   * Compute the view vector.
  		   */
  		  CALCULATE_DIRECTION_VECTOR(&pddc->Static.misc.eye_pt,
! 					     &point,
  					     &view_vec);
  		  NORMALIZE_VECTOR (&view_vec, v_dot_r);
  		}
--- 173,179 ----
  		   * Compute the view vector.
  		   */
  		  CALCULATE_DIRECTION_VECTOR(&pddc->Static.misc.eye_pt,
! 					     point,
  					     &view_vec);
  		  NORMALIZE_VECTOR (&view_vec, v_dot_r);
  		}
***************
*** 279,285 ****
  		   * Compute the view vector.
  		   */
  		  CALCULATE_DIRECTION_VECTOR(&pddc->Static.misc.eye_pt,
! 					     &point,
  					     &view_vec);
  		  NORMALIZE_VECTOR (&view_vec, v_dot_r);
  		}
--- 282,288 ----
  		   * Compute the view vector.
  		   */
  		  CALCULATE_DIRECTION_VECTOR(&pddc->Static.misc.eye_pt,
! 					     point,
  					     &view_vec);
  		  NORMALIZE_VECTOR (&view_vec, v_dot_r);
  		}
***************
*** 341,347 ****
  	   */
  
  	  CALCULATE_DIRECTION_VECTOR(&lightentry->point,
! 				     &point,
  				     &light_vec);
  	  NORMALIZE_VECTOR (&light_vec, distance);
  
--- 344,350 ----
  	   */
  
  	  CALCULATE_DIRECTION_VECTOR(&lightentry->point,
! 				     point,
  				     &light_vec);
  	  NORMALIZE_VECTOR (&light_vec, distance);
  
***************
*** 349,355 ****
  	  DOT_PRODUCT(&lightentry->direction, &light_vec, d_dot_l);
  	  /* Negate because light vec should point other way for this test */
  	  d_dot_l = -d_dot_l;
! 	  if (d_dot_l > pLUT->cosSpreadAngle) break;
  	  d_dot_l = pow(d_dot_l, lightentry->concentration);
  
  	  /* compute reflect view vector */
--- 352,358 ----
  	  DOT_PRODUCT(&lightentry->direction, &light_vec, d_dot_l);
  	  /* Negate because light vec should point other way for this test */
  	  d_dot_l = -d_dot_l;
! 	  if (d_dot_l <= pLUT->cosSpreadAngle) break;
  	  d_dot_l = pow(d_dot_l, lightentry->concentration);
  
  	  /* compute reflect view vector */
***************
*** 395,401 ****
  		   * Compute the view vector.
  		   */
  		  CALCULATE_DIRECTION_VECTOR(&pddc->Static.misc.eye_pt,
! 					     &point,
  					     &view_vec);
  		  NORMALIZE_VECTOR (&view_vec, v_dot_r);
  		}
--- 398,404 ----
  		   * Compute the view vector.
  		   */
  		  CALCULATE_DIRECTION_VECTOR(&pddc->Static.misc.eye_pt,
! 					     point,
  					     &view_vec);
  		  NORMALIZE_VECTOR (&view_vec, v_dot_r);
  		}
*** -	Thu Jan 28 17:52:57 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/miMarkers.c	Thu Jan 28 17:52:57 1993
***************
*** 1,4 ****
! /* $XConsortium: miMarkers.c,v 5.2 91/05/01 14:40:12 hersh Exp $ */
  
  
  /***********************************************************
--- 1,4 ----
! /* $XConsortium: miMarkers.c,v 5.4 92/12/29 17:14:17 mor Exp $ */
  
  
  /***********************************************************
***************
*** 77,83 ****
  
      /* Check for Model clipping */
  
!     if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  
        ComputeMCVolume(pRend, pddc);      /* Compute  modelling coord version
                                     		of clipping volume */
--- 77,83 ----
  
      /* Check for Model clipping */
  
!     if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  
        ComputeMCVolume(pRend, pddc);      /* Compute  modelling coord version
                                     		of clipping volume */
***************
*** 111,116 ****
--- 111,120 ----
      /* Note that miClipPointList discards clipped points */
      if (status = miClipPointList(pddc, cc_list, &clip_list, clip_mode)) 
  		return(status);
+ 
+     /* if nothing left, return early */
+     if (clip_list->numLists <= 0) return(Success);
+ 
  
      /* Transform to DC coordinates */
      if (status = miTransform(pddc, clip_list, &dc_list, 
*** -	Thu Jan 28 17:52:59 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/miTriStrip.c	Thu Jan 28 17:52:58 1993
***************
*** 1,4 ****
! /* $XConsortium: miTriStrip.c,v 5.4 91/07/15 21:15:44 hersh Exp $ */
  
  
  /***********************************************************
--- 1,4 ----
! /* $XConsortium: miTriStrip.c,v 5.10 93/01/25 17:06:17 hersh Exp $ */
  
  
  /***********************************************************
***************
*** 137,143 ****
  
        /* Check for Model clipping */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXOn) {
  
  	/* Compute  modelling coord version of clipping volume */ 
  	ComputeMCVolume(pRend, pddc);
--- 137,143 ----
  
        /* Check for Model clipping */
  
!       if (pddc->Dynamic->pPCAttr->modelClip == PEXClip) {
  
  	/* Compute  modelling coord version of clipping volume */ 
  	ComputeMCVolume(pRend, pddc);
***************
*** 158,163 ****
--- 158,166 ----
  				    &mc_list, &mc_facet, clip_mode))
              return (status);
  
+       /* if nothing left after model clip, return early */
+       if (mc_list->numLists <= 0) return(Success);
+ 
        } else {
  	mc_list = color_list;
  	mc_facet = color_facet;
***************
*** 254,259 ****
--- 257,265 ----
                &clip_list, &clip_facet, clip_mode))
  	return (status);
  
+       /* if nothing left after view clip, return early */
+       if (clip_list->numLists <= 0) return(Success);
+ 
        /* Note - After View clipping, the triangle strip may have
         * decomposed into a number of separate triangle strips
         */
***************
*** 263,268 ****
--- 269,276 ----
        if (status = miCullTriStrip(pddc, clip_list, clip_facet,
                                      &cull_list, &cull_facet))
            return (status);
+ 
+       /* if nothing left after culling, return early */
        if (cull_list->numLists <= 0) return(Success);
        } else {
  	cull_list = clip_list;
***************
*** 776,781 ****
--- 784,790 ----
                                  in_ptR, t_ptR, out_pt);
                                          /*Places point "B" into output list */
                    out_pt.ptr += point_size;
+ 		  pts_in_list++;
                    if (finput) {
                      COPY_FACET(in_fct, out_fct, facet_size);
                      out_fct += facet_size;
***************
*** 978,992 ****
  		}
   
  		/* Look for next point inside bounds */
! 		while(clip_code && (k < vert_count)) {
  		  clip_code = 0;
  		  in_ptR.ptr += point_size;
  		  if (finput) in_fct += facet_size;
              	  COMPUTE_CLIP_PARAMS(in_ptR, t_ptR, 2, clip_mode,
  			current_clip,MC_HSpace,clip_code);
! 		  k++;
! 		}
  		if (k < vert_count) {
  		  /* Get P & Q; re-enter loop. 
  	 	   * Next case encountered will be 3, which will
  		   * handle the odd-even rule for normals.
--- 987,1016 ----
  		}
   
  		/* Look for next point inside bounds */
! 		do {
  		  clip_code = 0;
  		  in_ptR.ptr += point_size;
  		  if (finput) in_fct += facet_size;
+ 		  k++;
+   		  if (k == vert_count)
+   		    break;
              	  COMPUTE_CLIP_PARAMS(in_ptR, t_ptR, 2, clip_mode,
  			current_clip,MC_HSpace,clip_code);
! 		} while(clip_code);
  		if (k < vert_count) {
+   		  /*
+   		   * k is incremented by the for loop, but because we have
+   		   * a new_list, the pointers won't get bumped.  Therefore,
+   		   * k must be decremented to keep it consistent with the
+   		   * pointers for reentering the for loop.
+   		   *
+   		   * However, k must not be adjusted when k == vert_count,
+   		   * because in this case P, Q and R are all clipped and it
+   		   * is necessary to leave k == vert_count to terminate the
+   		   * for loop.
+   		   */
+   		  k--;
+ 
  		  /* Get P & Q; re-enter loop. 
  	 	   * Next case encountered will be 3, which will
  		   * handle the odd-even rule for normals.
***************
*** 1234,1240 ****
          if (!out_vert->ddList) return(BadAlloc);
   
          out_vert->type = DD_RGBFLOAT_POINT4D;
!         if (pddc->Static.attrs->edges != PEXOff) {
              DD_SetVertEdge(out_vert->type);
          }
          out_vert->numLists = input_vert->numLists;
--- 1258,1265 ----
          if (!out_vert->ddList) return(BadAlloc);
   
          out_vert->type = DD_RGBFLOAT_POINT4D;
!         if (pddc->Static.attrs->edges != PEXOff &&
! 	    DD_IsVertEdge(input_vert->type)) {
              DD_SetVertEdge(out_vert->type);
          }
          out_vert->numLists = input_vert->numLists;
***************
*** 1756,1763 ****
      if (!out_vert->ddList) return(BadAlloc);
   
      out_vert->type = DD_RGBFLOAT_NORM_POINT4D;
!     if (pddc->Static.attrs->edges != PEXOff) {
!       DD_SetVertEdge(out_vert->type);
      }
      out_vert->numLists = input_vert->numLists;
      out_vert->flags =  input_vert->flags;
--- 1781,1789 ----
      if (!out_vert->ddList) return(BadAlloc);
   
      out_vert->type = DD_RGBFLOAT_NORM_POINT4D;
!     if (pddc->Static.attrs->edges != PEXOff &&
! 	DD_IsVertEdge(input_vert->type)) {
! 	DD_SetVertEdge(out_vert->type);
      }
      out_vert->numLists = input_vert->numLists;
      out_vert->flags =  input_vert->flags;
***************
*** 1779,1789 ****
        input_fct = fct_list;
      }
   
!     if ((input_fct) && (input_fct->numFacets > 0))
!       in_fct = input_fct->facets;
      else in_fct.pNoFacet = 0;
   
-     DDFacetSIZE(input_fct->type, facet_size);
  
      for(i = 0; i < input_vert->numLists; i++) { 
        pddolist->numPoints = pddilist->numPoints;
--- 1805,1816 ----
        input_fct = fct_list;
      }
   
!     if ((input_fct) && (input_fct->numFacets > 0)) {
! 	in_fct = input_fct->facets;
! 	DDFacetSIZE(input_fct->type, facet_size);
!     }
      else in_fct.pNoFacet = 0;
   
  
      for(i = 0; i < input_vert->numLists; i++) { 
        pddolist->numPoints = pddilist->numPoints;
***************
*** 1940,1959 ****
  	out_vert->numLists = 0,
  	pddilist = input_vert->ddList, pddolist = out_vert->ddList; 
  	i < input_vert->numLists; i++) {
        MI_ALLOCLISTOFDDPOINT(pddolist,(pddilist->numPoints+1),point_size);
   
-       in_pt.ptr = pddilist->pts.ptr;
-       out_pt.ptr = pddolist->pts.ptr; 
-       pddolist->numPoints = 0;
- 
        for (j= 2, verts_in_list = 0, new_list = 1,
! 	   in_pt.ptr = pddilist->pts.ptr,
  	   out_pt.ptr = pddolist->pts.ptr,
  	   pddolist->numPoints = 0; 
  		j < pddilist->numPoints; j++) {
  
          accept = 0;
- 
   
          if (pddc->Dynamic->pPCAttr->cullMode == PEXBackFaces) {
            if (DD_IsFacetColour(input_fct->type)) {
--- 1967,1983 ----
  	out_vert->numLists = 0,
  	pddilist = input_vert->ddList, pddolist = out_vert->ddList; 
  	i < input_vert->numLists; i++) {
+ 
        MI_ALLOCLISTOFDDPOINT(pddolist,(pddilist->numPoints+1),point_size);
+       if (!pddolist->pts.ptr) return(BadAlloc);
   
        for (j= 2, verts_in_list = 0, new_list = 1,
! 	   in_pt.ptr = pddilist->pts.ptr + (2 * point_size),
  	   out_pt.ptr = pddolist->pts.ptr,
  	   pddolist->numPoints = 0; 
  		j < pddilist->numPoints; j++) {
  
          accept = 0;
   
          if (pddc->Dynamic->pPCAttr->cullMode == PEXBackFaces) {
            if (DD_IsFacetColour(input_fct->type)) {
***************
*** 1969,1976 ****
  
  	  if (new_list) { /* starting new list after facet(s) culled */
  	    /*initialize first points for the first facet */
! 	    bcopy(in_pt.ptr, out_pt.ptr, (2*point_size));
! 	    in_pt.ptr += 2 * point_size;
  	    out_pt.ptr += 2 * point_size;
  	    new_list = 0;
  	    verts_in_list += 2;
--- 1993,1999 ----
  
  	  if (new_list) { /* starting new list after facet(s) culled */
  	    /*initialize first points for the first facet */
! 	    bcopy(in_pt.ptr - (2 * point_size), out_pt.ptr, (2*point_size));
  	    out_pt.ptr += 2 * point_size;
  	    new_list = 0;
  	    verts_in_list += 2;
***************
*** 1999,2009 ****
--- 2022,2034 ----
  	    /* create a new output vertex list; load first points */
  	    MI_ALLOCLISTHEADER(out_vert,
                          MI_ROUND_LISTHEADERCOUNT(out_listnum))
+ 	    if (!out_vert->ddList) return(BadAlloc);
    
  	    pddolist = out_vert->ddList + (out_listnum - 1);
  	    pddolist->numPoints = 0;
        	    MI_ALLOCLISTOFDDPOINT(pddolist,
  			(pddilist->numPoints - j + 2), point_size);
+ 	    if (!pddolist->pts.ptr) return(BadAlloc);
  	    out_pt.ptr =  pddolist->pts.ptr;
  	    verts_in_list = 0;
  	  } 
*** -	Thu Jan 28 17:53:01 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/miCopy.c	Thu Jan 28 17:53:00 1993
***************
*** 1,4 ****
! /* $XConsortium: miCopy.c,v 5.3 91/07/12 17:54:49 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miCopy.c,v 5.5 91/12/26 18:00:39 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 697,703 ****
      dstFill->pFacets = (listofddFacet *)(dstFill+1);
      dstFill->points.ddList = (listofddPoint *)((dstFill->pFacets)+1);
  
!     facetPtr = (ddPointer)(dstFill->points.ddList + 1);
      if (facetSize == 0)
  	dstFill->pFacets->facets.pNoFacet = 0;
      else
--- 697,703 ----
      dstFill->pFacets = (listofddFacet *)(dstFill+1);
      dstFill->points.ddList = (listofddPoint *)((dstFill->pFacets)+1);
  
!     facetPtr = (ddPointer)(dstFill->points.ddList + dstFill->points.numLists);
      if (facetSize == 0)
  	dstFill->pFacets->facets.pNoFacet = 0;
      else
***************
*** 1064,1066 ****
--- 1064,1076 ----
      return(Success);
  }
  
+ 
+ OC_COPY_FUNC_HEADER(PropOC)
+ {
+     COPY_DECL(PropOC, pexElementInfo);
+ 
+     DST_STORE_AND_COPY(	dstPropOC, pexElementInfo,
+ 			srcPropOC->length * sizeof(CARD32));
+ 
+     return(Success);
+ }
*** -	Thu Jan 28 17:53:02 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/miLvl2Tab.c	Thu Jan 28 17:53:01 1993
***************
*** 1,4 ****
! /* $XConsortium: miLvl2Tab.c,v 5.2 91/05/31 07:24:36 jap Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miLvl2Tab.c,v 5.4 92/08/12 15:32:49 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 154,159 ****
--- 154,160 ----
  	parseGdp(),
  	parseGdp2D(),
  	parseSetAttribute(),
+ 	parsePropOC(),
  	parseSOFAS(),
  	parsePSurfaceChars(),
  	parseSetMCVolume(),
***************
*** 160,166 ****
  	parseSetMCVolume2D();
  
  ocTableType	ParseOCTable[] = {
!     NULL,		/* 0 dummy entry */
      parseSetAttribute,		/* 1 marker type */
      parseSetAttribute,		/* 2 marker scale */
      parseColourIndexOC,		/* 3 marker colour index */
--- 161,167 ----
  	parseSetMCVolume2D();
  
  ocTableType	ParseOCTable[] = {
!     parsePropOC,	        /* 0 dummy entry */
      parseSetAttribute,		/* 1 marker type */
      parseSetAttribute,		/* 2 marker scale */
      parseColourIndexOC,		/* 3 marker colour index */
***************
*** 264,270 ****
      parseCellArray2D,		/* 100 cell array 2d */
      parseExtCellArray,		/* 101 extended cell array 3d */
      parseGdp,			/* 102 gdp 3d */
!     parseGdp2D			/* 103 gdp 2d */
  };
  
  extern void		destroyOC_PEX(),
--- 265,272 ----
      parseCellArray2D,		/* 100 cell array 2d */
      parseExtCellArray,		/* 101 extended cell array 3d */
      parseGdp,			/* 102 gdp 3d */
!     parseGdp2D,			/* 103 gdp 2d */
!     parseSetAttribute		/* 104 Noop */
  };
  
  extern void		destroyOC_PEX(),
***************
*** 273,279 ****
  			destroyNurbSurface();
  
  destroyTableType	DestroyOCTable[] = {
!     NULL,			/* 0 dummy entry */
      destroyOC_PEX,		/* 1 marker type */
      destroyOC_PEX,		/* 2 marker scale */
      destroyOC_PEX,		/* 3 marker colour index */
--- 275,281 ----
  			destroyNurbSurface();
  
  destroyTableType	DestroyOCTable[] = {
!     destroyOC_PEX,		/* 0 entry for proprietary OCs */
      destroyOC_PEX,		/* 1 marker type */
      destroyOC_PEX,		/* 2 marker scale */
      destroyOC_PEX,		/* 3 marker colour index */
***************
*** 367,375 ****
      destroyOC_PEX,		/* 91 fill area 3d with data */
      destroyOC_PEX,		/* 92 fill area set 3d */
      destroyOC_PEX,		/* 93 fill area set 2d */
!     destroyOC_PEX,	/* 94 fill area set 3d with data */
      destroyOC_PEX,		/* 95 triangle strip */
!     destroyOC_PEX,	/* 96 quadrilateral mesh */
      destroySOFAS,		/* 97 set of fill area sets */
      destroyNurbSurface,		/* 98 non-uniform b spline surface */
      destroyOC_PEX,		/* 99 cell array 3d */
--- 369,377 ----
      destroyOC_PEX,		/* 91 fill area 3d with data */
      destroyOC_PEX,		/* 92 fill area set 3d */
      destroyOC_PEX,		/* 93 fill area set 2d */
!     destroyOC_PEX,	        /* 94 fill area set 3d with data */
      destroyOC_PEX,		/* 95 triangle strip */
!     destroyOC_PEX,        	/* 96 quadrilateral mesh */
      destroySOFAS,		/* 97 set of fill area sets */
      destroyNurbSurface,		/* 98 non-uniform b spline surface */
      destroyOC_PEX,		/* 99 cell array 3d */
***************
*** 376,382 ****
      destroyOC_PEX,		/* 100 cell array 2d */
      destroyOC_PEX,		/* 101 extended cell array 3d */
      destroyOC_PEX,		/* 102 gdp 3d */
!     destroyOC_PEX		/* 103 gdp 2d */
  };
  
  /* initial setup for output command table in renderers */
--- 378,385 ----
      destroyOC_PEX,		/* 100 cell array 2d */
      destroyOC_PEX,		/* 101 extended cell array 3d */
      destroyOC_PEX,		/* 102 gdp 3d */
!     destroyOC_PEX,		/* 103 gdp 2d */
!     destroyOC_PEX		/* 104 Noop */
  };
  
  /* initial setup for output command table in renderers */
***************
*** 485,491 ****
      miCellArray,	    /* 100 cell array 2d */
      miCellArray,	    /* 101 extended cell array 3d */
      miTestGDP,		    /* 102 gdp 3d */
!     miTestGDP		    /* 103 gdp 2d */
  };
  
  /* initial setup for output command table for picking */
--- 488,495 ----
      miCellArray,	    /* 100 cell array 2d */
      miCellArray,	    /* 101 extended cell array 3d */
      miTestGDP,		    /* 102 gdp 3d */
!     miTestGDP,		    /* 103 gdp 2d */
!     miNoop		    /* 104 Noop */
  };
  
  /* initial setup for output command table for picking */
***************
*** 594,600 ****
      miPickPrimitives,	    /* 100 cell array 2d */
      miPickPrimitives,	    /* 101 extended cell array 3d */
      miTestPickGdp3d,	    /* 102 gdp 3d */
!     miTestPickGdp2d	    /* 103 gdp 2d */
  };
  
  
--- 598,605 ----
      miPickPrimitives,	    /* 100 cell array 2d */
      miPickPrimitives,	    /* 101 extended cell array 3d */
      miTestPickGdp3d,	    /* 102 gdp 3d */
!     miTestPickGdp2d,	    /* 103 gdp 2d */
!     miNoop		    /* 104 Noop  */
  };
  
  
***************
*** 704,710 ****
      miSearchPrimitives,	    /* 100 cell array 2d */
      miSearchPrimitives,	    /* 101 extended cell array 3d */
      miTestSearchGdp3d,	    /* 102 gdp 3d */
!     miTestSearchGdp2d	    /* 103 gdp 2d */
  };
  
  
--- 709,716 ----
      miSearchPrimitives,	    /* 100 cell array 2d */
      miSearchPrimitives,	    /* 101 extended cell array 3d */
      miTestSearchGdp3d,	    /* 102 gdp 3d */
!     miTestSearchGdp2d,	    /* 103 gdp 2d */
!     miNoop		    /* 104 Noop */
  };
  
  
***************
*** 736,741 ****
--- 742,748 ----
      copyMCVolume(),
      copyQuadrilateralMesh(),
      copySetAttribute(),
+     copyPropOC(),
      copySOFAS(),
      copyText(),
      copyText2D(),
***************
*** 744,750 ****
  
  
  ocTableType	CopyOCTable[] = {
!     NULL,			/* 0 dummy entry */
      copySetAttribute,		/* 1 marker type */
      copySetAttribute,		/* 2 marker scale */
      copyColourIndexOC,		/* 3 marker colour index */
--- 751,757 ----
  
  
  ocTableType	CopyOCTable[] = {
!     copyPropOC,			/* 0 dummy entry */
      copySetAttribute,		/* 1 marker type */
      copySetAttribute,		/* 2 marker scale */
      copyColourIndexOC,		/* 3 marker colour index */
***************
*** 848,854 ****
      copyCellArray2D,		/* 100 cell array 2d */
      copyExtCellArray,		/* 101 extended cell array 3d */
      copyGdp,			/* 102 gdp 3d */
!     copyGdp2D			/* 103 gdp 2d */
  };
  
  
--- 855,862 ----
      copyCellArray2D,		/* 100 cell array 2d */
      copyExtCellArray,		/* 101 extended cell array 3d */
      copyGdp,			/* 102 gdp 3d */
!     copyGdp2D,			/* 103 gdp 2d */
!     copySetAttribute		/* 104 Noop */
  };
  
  
***************
*** 881,886 ****
--- 889,895 ----
      inquirePSurfaceChars(),
      inquireQuadrilateralMesh(),
      inquireSetAttribute(),
+     inquirePropOC(),
      inquireSOFAS(),
      inquireText(),
      inquireText2D(),
***************
*** 890,896 ****
  
  
  ocTableType	InquireOCTable[] = {
!     NULL,			/* 0 dummy entry */
      inquireSetAttribute,	/* 1 marker type */
      inquireSetAttribute,	/* 2 marker scale */
      inquireColourIndexOC,	/* 3 marker colour index */
--- 899,905 ----
  
  
  ocTableType	InquireOCTable[] = {
!     inquirePropOC,		/* 0 dummy entry */
      inquireSetAttribute,	/* 1 marker type */
      inquireSetAttribute,	/* 2 marker scale */
      inquireColourIndexOC,	/* 3 marker colour index */
***************
*** 993,999 ****
      inquireCellArray2D,		/* 100 cell array 2d */
      inquireExtCellArray,	/* 101 extended cell array 3d */
      inquireGdp,			/* 102 gdp 3d */
!     inquireGdp2D		/* 103 gdp 2d */
  };
  
  
--- 1002,1009 ----
      inquireCellArray2D,		/* 100 cell array 2d */
      inquireExtCellArray,	/* 101 extended cell array 3d */
      inquireGdp,			/* 102 gdp 3d */
!     inquireGdp2D,		/* 103 gdp 2d */
!     inquireSetAttribute		/* 104 Noop */
  };
  
  
***************
*** 1005,1011 ****
  
  
  ocTableType	ReplaceOCTable[] = {
!     NULL,			/* 0 dummy entry */
      parseSetAttribute,		/* 1 marker type */
      parseSetAttribute,		/* 2 marker scale */
      parseColourIndexOC,		/* 3 marker colour index */
--- 1015,1021 ----
  
  
  ocTableType	ReplaceOCTable[] = {
!     parsePropOC,		/* 0 dummy entry */
      parseSetAttribute,		/* 1 marker type */
      parseSetAttribute,		/* 2 marker scale */
      parseColourIndexOC,		/* 3 marker colour index */
***************
*** 1030,1036 ****
      parseSetAttribute,		/* 22 line type */
      parseSetAttribute,		/* 23 line width */
      parseColourIndexOC,		/* 24 line colour index */
!     parseColourOC,			/* 25 line colour */
      parseSetAttribute,		/* 26 curve approximation method */
      parseSetAttribute,		/* 27 polyline interpolation method */
      parseSetAttribute,		/* 28 line bundle index */
--- 1040,1046 ----
      parseSetAttribute,		/* 22 line type */
      parseSetAttribute,		/* 23 line width */
      parseColourIndexOC,		/* 24 line colour index */
!     parseColourOC,		/* 25 line colour */
      parseSetAttribute,		/* 26 curve approximation method */
      parseSetAttribute,		/* 27 polyline interpolation method */
      parseSetAttribute,		/* 28 line bundle index */
***************
*** 1108,1112 ****
      parseCellArray2D,		/* 100 cell array 2d */
      parseExtCellArray,		/* 101 extended cell array 3d */
      parseGdp,			/* 102 gdp 3d */
!     parseGdp2D			/* 103 gdp 2d */
  };
--- 1118,1123 ----
      parseCellArray2D,		/* 100 cell array 2d */
      parseExtCellArray,		/* 101 extended cell array 3d */
      parseGdp,			/* 102 gdp 3d */
!     parseGdp2D,			/* 103 gdp 2d */
!     parseSetAttribute		/* 104 Noop */
  };
*** -	Thu Jan 28 17:53:03 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/miInquire.c	Thu Jan 28 17:53:03 1993
***************
*** 1,4 ****
! /* $XConsortium: miInquire.c,v 5.2 91/07/12 17:55:15 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miInquire.c,v 5.5 92/11/16 11:17:29 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 63,70 ****
  #define LEN_WO_HEADER(OCtype) (pPEXOC->length * sizeof(CARD32) - sizeof(OCtype))
  
  #define GET_INQ_STORAGE(PEX_ST, PEX_TYPE, DD_ST, DD_TYPE) \
!     if (PU_BUF_TOO_SMALL( pBuf, pExecuteOC->element.pexOClength)) { \
! 	if ((puBuffRealloc(pBuf, pExecuteOC->element.pexOClength)) != Success) {\
  	    return (BadAlloc); } } \
      *ppPEXOC = (pexElementInfo *)(pBuf->pBuf); \
      (*ppPEXOC)->elementType = pExecuteOC->element.elementType; \
--- 63,70 ----
  #define LEN_WO_HEADER(OCtype) (pPEXOC->length * sizeof(CARD32) - sizeof(OCtype))
  
  #define GET_INQ_STORAGE(PEX_ST, PEX_TYPE, DD_ST, DD_TYPE) \
!     if (PU_BUF_TOO_SMALL( pBuf, (pExecuteOC->element.pexOClength)<<2)) { \
!        if ((puBuffRealloc(pBuf, (pExecuteOC->element.pexOClength)<<2)) != Success) {\
  	    return (BadAlloc); } } \
      *ppPEXOC = (pexElementInfo *)(pBuf->pBuf); \
      (*ppPEXOC)->elementType = pExecuteOC->element.elementType; \
***************
*** 960,970 ****
      COPY_PTR(ptr);
  
      GET_INQ_STORAGE( pFill, pexSOFAS, ddFill, miSOFASStruct);
!     ptr = (ddPointer)(((pexElementInfo *)pFill)+1);
!     PACK_CARD16(ddFill->shape, ptr);
      pFill->edgeAttributes = ddFill->edgeAttribs;
!     PACK_CARD8(ddFill->contourHint, ptr);
!     pFill->numFAS = ddFill->pFacets.numFacets;
      pFill->numVertices = ddFill->points.ddList->numPoints;
      pFill->numEdges = ddFill->numEdges;
      pFill->numContours = ddFill->connects.numListLists;
--- 960,970 ----
      COPY_PTR(ptr);
  
      GET_INQ_STORAGE( pFill, pexSOFAS, ddFill, miSOFASStruct);
!     pFill->shape = ddFill->shape;
      pFill->edgeAttributes = ddFill->edgeAttribs;
!     pFill->contourHint = ddFill->contourHint;
!     pFill->contourCountsFlag = ddFill->contourCountsFlag;
!     pFill->numFAS = ddFill->numFAS;
      pFill->numVertices = ddFill->points.ddList->numPoints;
      pFill->numEdges = ddFill->numEdges;
      pFill->numContours = ddFill->connects.numListLists;
***************
*** 1166,1172 ****
      COPY_PTR(ptr);
  
      GET_INQ_STORAGE( pCell, pexExtCellArray, ddCell, miCellArrayStruct);
!     ptr = (ddPointer)&(pCell->point1);
  
      PACK_CARD16(ddCell->colours.colourType, ptr);
      SKIP_PADDING(ptr, 2);
--- 1166,1172 ----
      COPY_PTR(ptr);
  
      GET_INQ_STORAGE( pCell, pexExtCellArray, ddCell, miCellArrayStruct);
!     ptr = (ddPointer)&(pCell->colourType);
  
      PACK_CARD16(ddCell->colours.colourType, ptr);
      SKIP_PADDING(ptr, 2);
***************
*** 1229,1239 ****
  	case PEXPSCIsoCurves: {
  	    GET_INQ_STORAGE(	pPSC, pexParaSurfCharacteristics, ddPSC,
  				miPSurfaceCharsStruct);
  	    ptr = (ddPointer)(pPSC+1);
! 	    PACK_CARD16(ddPSC->data.pIsoCurves, ptr);
  	    SKIP_PADDING(ptr,2);
! 	    EXTRACT_CARD16(ddPSC->data.pIsoCurves->numUcurves, ptr);
! 	    EXTRACT_CARD16(ddPSC->data.pIsoCurves->numVcurves, ptr);
  	    break;
  	}
  
--- 1229,1241 ----
  	case PEXPSCIsoCurves: {
  	    GET_INQ_STORAGE(	pPSC, pexParaSurfCharacteristics, ddPSC,
  				miPSurfaceCharsStruct);
+             pPSC->characteristics = ddPSC->type; 
+             pPSC->length = 4 * sizeof(CARD16); 
  	    ptr = (ddPointer)(pPSC+1);
! 	    PACK_CARD16(ddPSC->data.pIsoCurves->placementType, ptr);
  	    SKIP_PADDING(ptr,2);
! 	    PACK_CARD16(ddPSC->data.pIsoCurves->numUcurves, ptr);
! 	    PACK_CARD16(ddPSC->data.pIsoCurves->numVcurves, ptr);
  	    break;
  	}
  
***************
*** 1240,1247 ****
  	case PEXPSCMcLevelCurves: {
  	    GET_INQ_STORAGE(	pPSC, pexParaSurfCharacteristics, ddPSC,
  				miPSurfaceCharsStruct);
  	    ptr = (ddPointer)(pPSC+1);
! 	    PACK_STRUCT(ddPSC_LevelCurves,ddPSC->data.pMcLevelCurves, ptr);
  	    break;
  	}
  
--- 1242,1259 ----
  	case PEXPSCMcLevelCurves: {
  	    GET_INQ_STORAGE(	pPSC, pexParaSurfCharacteristics, ddPSC,
  				miPSurfaceCharsStruct);
+             pPSC->characteristics = ddPSC->type; 
+             pPSC->length = sizeof(pexCoord3D) + sizeof(pexVector3D) +
+ 			   (2 *sizeof(CARD16)) + (sizeof(PEXFLOAT)* 
+ 			   ddPSC->data.pMcLevelCurves->numberIntersections); 
  	    ptr = (ddPointer)(pPSC+1);
! 	    PACK_STRUCT(pexCoord3D, &(ddPSC->data.pMcLevelCurves->origin),ptr);
! 	    PACK_STRUCT(pexVector3D, &(ddPSC->data.pMcLevelCurves->direction),ptr);
! 	    PACK_CARD16(ddPSC->data.pMcLevelCurves->numberIntersections, ptr);
! 	    SKIP_PADDING(ptr,2);
! 	    PACK_LISTOF_STRUCT(ddPSC->data.pMcLevelCurves->numberIntersections,
! 				PEXFLOAT, ddPSC->data.pMcLevelCurves->pPoints,
! 				ptr);
  	    break;
  	}
  
***************
*** 1248,1255 ****
  	case PEXPSCWcLevelCurves: {
  	    GET_INQ_STORAGE(	pPSC, pexParaSurfCharacteristics, ddPSC,
  				miPSurfaceCharsStruct);
  	    ptr = (ddPointer)(pPSC+1);
! 	    PACK_STRUCT(ddPSC_LevelCurves,ddPSC->data.pWcLevelCurves, ptr);
  	    break;
  	}
      }
--- 1260,1277 ----
  	case PEXPSCWcLevelCurves: {
  	    GET_INQ_STORAGE(	pPSC, pexParaSurfCharacteristics, ddPSC,
  				miPSurfaceCharsStruct);
+             pPSC->characteristics = ddPSC->type; 
+             pPSC->length = sizeof(pexCoord3D) + sizeof(pexVector3D) +
+ 			   (2 *sizeof(CARD16)) + (sizeof(PEXFLOAT)* 
+ 			   ddPSC->data.pWcLevelCurves->numberIntersections); 
  	    ptr = (ddPointer)(pPSC+1);
! 	    PACK_STRUCT(pexCoord3D, &(ddPSC->data.pWcLevelCurves->origin),ptr);
! 	    PACK_STRUCT(pexVector3D, &(ddPSC->data.pWcLevelCurves->direction),ptr);
! 	    PACK_CARD16(ddPSC->data.pWcLevelCurves->numberIntersections, ptr);
! 	    SKIP_PADDING(ptr,2);
! 	    PACK_LISTOF_STRUCT(ddPSC->data.pWcLevelCurves->numberIntersections,
! 				PEXFLOAT, ddPSC->data.pWcLevelCurves->pPoints,
! 				ptr);
  	    break;
  	}
      }
***************
*** 1315,1320 ****
--- 1337,1357 ----
  
      bcopy(  (char *)srcAttrib, (char *)dstAttrib,
  	    (int)(srcAttrib->length * sizeof(CARD32)));
+ 
+     return(Success);
+ }
+ 
+ OC_INQ_FUNC_HEADER(PropOC)
+ {
+     /** The function Handles Proprietary Vendor OCs
+      **/
+ 
+     ddElementInfo  *dstPropOC, *srcPropOC;
+ 
+     GET_INQ_STORAGE( dstPropOC, ddElementInfo, srcPropOC, ddElementInfo);
+ 
+     bcopy(  (char *)srcPropOC, (char *)dstPropOC,
+ 	    (int)(srcPropOC->length * sizeof(CARD32)));
  
      return(Success);
  }
*** -	Thu Jan 28 17:53:05 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/miCellArray.c	Thu Jan 28 17:53:05 1993
***************
*** 1,4 ****
! /* $XConsortium: miCellArray.c,v 5.3 91/07/22 19:44:13 hersh Exp $ */
  
  
  /***********************************************************
--- 1,4 ----
! /* $XConsortium: miCellArray.c,v 5.4 92/12/02 11:11:02 mor Exp $ */
  
  
  /***********************************************************
***************
*** 79,88 ****
      miPolylineStruct	*output;
      listofddPoint       *pddolist;
      int			point_size, nGridLines, i;
!     ddPointUnion	in_pt, out_pt, Ppt, Qpt, Rpt;
      ddpex3rtn		status;
      ddCoord3D		dRpt, dQpt, x_step, y_step, 
  			basept, endpt;
  
  
  
--- 79,89 ----
      miPolylineStruct	*output;
      listofddPoint       *pddolist;
      int			point_size, nGridLines, i;
!     ddPointUnion	in_pt, out_pt, Ppt, Qpt, Rpt, Spt;
      ddpex3rtn		status;
      ddCoord3D		dRpt, dQpt, x_step, y_step, 
  			basept, endpt;
+     ddCoord2D		tempQ, tempR;
  
  
  
***************
*** 131,139 ****
      output->numLists = nGridLines;
  
      /* Get input points */
!     Ppt.ptr = ddCell->point.ddList->pts.ptr;
!     Qpt.ptr = Ppt.ptr + point_size; 
!     Rpt.ptr = Qpt.ptr + point_size; 
  
      /* Calculate DQ and DR */
      dQpt.x = Qpt.p2Dpt->x - Ppt.p2Dpt->x;
--- 132,156 ----
      output->numLists = nGridLines;
  
      /* Get input points */
!     if (DD_IsVert3D(input->type))
!     {
! 	Ppt.ptr = ddCell->point.ddList->pts.ptr;
! 	Rpt.ptr = Ppt.ptr + sizeof(ddCoord3D); 
! 	Qpt.ptr = Rpt.ptr + sizeof(ddCoord3D); 
!     }
!     else
!     {
! 	Ppt.ptr = ddCell->point.ddList->pts.ptr;
! 	Spt.ptr = Ppt.ptr + sizeof(ddCoord2D);
! 
! 	tempR.x = Spt.p2Dpt->x;
! 	tempR.y = Ppt.p2Dpt->y;
! 	tempQ.x = Ppt.p2Dpt->x;
! 	tempQ.y = Spt.p2Dpt->y;
! 
! 	Rpt.p2Dpt = &tempR;
! 	Qpt.p2Dpt = &tempQ;
!     }
  
      /* Calculate DQ and DR */
      dQpt.x = Qpt.p2Dpt->x - Ppt.p2Dpt->x;
*** -	Thu Jan 28 17:53:06 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/miBldXform.c	Thu Jan 28 17:53:06 1993
***************
*** 1,4 ****
! /* $XConsortium: miBldXform.c,v 5.2 91/05/01 14:42:33 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miBldXform.c,v 5.4 92/12/21 10:35:52 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 24,33 ****
--- 24,38 ----
  
  ******************************************************************/
  
+ #include "X.h"
+ #include "Xproto.h"
+ #include "misc.h"
  #include "miLUT.h"
  #include "PEXErr.h"
  #include "pixmap.h"
  #include "windowstr.h"
+ #include "gcstruct.h"
+ #include "scrnintstr.h"
  #include "regionstr.h"
  #include "miscstruct.h"
  #include "miRender.h"
***************
*** 36,41 ****
--- 41,47 ----
  extern	void		miMatMult();
  extern  void		miMatCopy();
  extern  ddpex3rtn	InquireLUTEntryAddress();
+ extern  void		SetViewportClip();
  
  
  /*++
***************
*** 251,263 ****
        Tz = 0.0;
  
        if ((pRend->render_mode == MI_REND_DRAWING) && pDrawable && pddc) {
!       /* Set the GC clip mask to clip to the viewport */
!     
!           SetClipRects(pddc->Static.misc.pPolylineGC,  0, 0, 1, &viewport,YXBanded);
!           SetClipRects(pddc->Static.misc.pFillAreaGC,  0, 0, 1, &viewport,YXBanded);
!           SetClipRects(pddc->Static.misc.pEdgeGC,      0, 0, 1, &viewport,YXBanded);
!           SetClipRects(pddc->Static.misc.pPolyMarkerGC,0, 0, 1, &viewport,YXBanded);
!           SetClipRects(pddc->Static.misc.pTextGC,      0, 0, 1, &viewport,YXBanded);
        }
      }
  
--- 257,335 ----
        Tz = 0.0;
  
        if ((pRend->render_mode == MI_REND_DRAWING) && pDrawable && pddc) {
! 	  /* Set the GC clip mask to clip to the viewport */
! 
! 	  ddLONG numrects = pRend->clipList->numObj;
! 
! 	  if (numrects > 0) {
! 	      xRectangle      *xrects, *p;
! 	      ddDeviceRect    *ddrects;
! 	      RegionPtr	      clipRegion;
! 	      RegionRec	      tempRegion;
! 	      GCPtr	      pGC;
! 	      BoxRec	      box;
! 	      int             i;
! 
! 	      ddrects = (ddDeviceRect *) pRend->clipList->pList;
! 	      xrects = (xRectangle*) Xalloc (numrects * sizeof(xRectangle));
! 	      if (!xrects) return BadAlloc;
! 	      /* Need to convert to XRectangle format */
! 	      for (i = 0, p = xrects; i < numrects; i++, p++, ddrects++) {
! 		  p->x = ddrects->xmin;
! 		  p->y = pRend->pDrawable->height - ddrects->ymax;
! 		  p->width = ddrects->xmax - ddrects->xmin + 1;
! 		  p->height = ddrects->ymax - ddrects->ymin + 1;
! 	      }
! 
! 	      /*
! 	       * Compute the intersection of the viewport and the GC's
!                * clip region.  Note that there is a GC for each of the
!                * primitive types, and we only have to compute the
! 	       * intersected region for one of them.  This computed region
! 	       * will be good for all of the GC's.
! 	       */
! 
! 	      pGC = pddc->Static.misc.pPolylineGC;
! 
! 	      clipRegion = (*pGC->pScreen->RectsToRegion)(numrects,
! 	          xrects, Unsorted);
! 
! 	      Xfree((char *) xrects);
! 
! 	      box.x1 = viewport.x;
! 	      box.y1 = viewport.y;
! 	      box.x2 = viewport.x + viewport.width;
! 	      box.y2 = viewport.y + viewport.height;
! 
! 	      (*pGC->pScreen->RegionInit)(&tempRegion, &box, 1);
! 	      (*pGC->pScreen->Intersect)(clipRegion, clipRegion, &tempRegion);
! 	      (*pGC->pScreen->RegionUninit)(&tempRegion);
! 
! 
! 	      /*
! 	       * Now set the GC clip regions.
! 	       */
! 
! 	      SetViewportClip (pddc->Static.misc.pPolylineGC, clipRegion);
! 	      SetViewportClip (pddc->Static.misc.pFillAreaGC, clipRegion);
! 	      SetViewportClip (pddc->Static.misc.pEdgeGC, clipRegion);
! 	      SetViewportClip (pddc->Static.misc.pPolyMarkerGC, clipRegion);
! 	      SetViewportClip (pddc->Static.misc.pTextGC, clipRegion);
! 
! 	      (*pGC->pScreen->RegionDestroy)(clipRegion);
! 	  }
! 	  else {
! 	      SetClipRects(pddc->Static.misc.pPolylineGC,
! 		0, 0, 1, &viewport,YXBanded);
! 	      SetClipRects(pddc->Static.misc.pFillAreaGC,
! 		0, 0, 1, &viewport,YXBanded);
! 	      SetClipRects(pddc->Static.misc.pEdgeGC,
! 		0, 0, 1, &viewport,YXBanded);
! 	      SetClipRects(pddc->Static.misc.pPolyMarkerGC,
! 		0, 0, 1, &viewport,YXBanded);
! 	      SetClipRects(pddc->Static.misc.pTextGC,
! 		0, 0, 1, &viewport,YXBanded);
! 	  }
        }
      }
  
***************
*** 559,564 ****
--- 631,642 ----
      miMatMult ( pddc->Dynamic->wc_to_cc_xform,
  		pddc->Dynamic->wc_to_npc_xform, 
  		pddc->Dynamic->npc_to_cc_xform);
+     /*
+      * Compute the composite mc -> wc, i.e. Modelling to World
+      */
+     miMatMult(  pddc->Dynamic->mc_to_wc_xform,
+                 pddc->Dynamic->pPCAttr->localMat,
+                 pddc->Dynamic->pPCAttr->globalMat);
  
      /*
       * Compute the composite mc -> npc, i.em Modelling to NPC
***************
*** 587,589 ****
--- 665,690 ----
  }
  
  
+ void SetViewportClip(pGC, clipRegion)
+     GCPtr pGC;
+     RegionPtr clipRegion;
+ {
+     /*
+      * When we call the GC's ChangeClip function, it destroys
+      * the region we pass to it.  Since this function is called
+      * for each of the GC's, we copy clipRegion into tempRegion
+      * and use tempRegion when calling ChangeClip.
+      */
+ 
+     RegionPtr tempRegion = (*pGC->pScreen->RegionCreate)(NullBox, 0);
+ 
+     (*pGC->pScreen->RegionCopy)(tempRegion, clipRegion);
+ 
+     pGC->serialNumber |= GC_CHANGE_SERIAL_BIT;
+     pGC->clipOrg.x = 0;
+     pGC->clipOrg.y = 0;
+     pGC->stateChanges |= GCClipXOrigin|GCClipYOrigin;
+     (*pGC->funcs->ChangeClip)(pGC, CT_REGION, tempRegion, 0);
+     if (pGC->funcs->ChangeGC)
+ 	(*pGC->funcs->ChangeGC) (pGC, GCClipXOrigin|GCClipYOrigin|GCClipMask);
+ }
*** -	Thu Jan 28 17:53:10 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/miPickPrim.c	Thu Jan 28 17:53:09 1993
***************
*** 1,4 ****
! /* $XConsortium: miPickPrim.c,v 5.4 91/07/01 08:44:39 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miPickPrim.c,v 5.6 92/12/29 17:15:05 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 41,47 ****
  #define MIN(a,b) (((a)<(b))?(a):(b))
  
  extern ocTableType InitExecuteOCTable[];
! extern int tx_el_to_path();
  extern void text2_xform();
  extern void text3_xform();
  
--- 41,47 ----
  #define MIN(a,b) (((a)<(b))?(a):(b))
  
  extern ocTableType InitExecuteOCTable[];
! extern int atx_el_to_path();
  extern void text2_xform();
  extern void text3_xform();
  
***************
*** 373,379 ****
      miListHeader      *cc_path, *clip_path;
      listofddPoint     *sp;
      XID		       temp;
!     ddpex3rtn	       status;
      ddUSHORT           aflag, LUTstatus;
      ddCoord4D          MC_Origin, CC_Origin, NPC_Origin;
      ddUSHORT           oc;         /* Outcode for 4D point clipping */
--- 373,379 ----
      miListHeader      *cc_path, *clip_path;
      listofddPoint     *sp;
      XID		       temp;
!     int		       status;
      ddUSHORT           aflag, LUTstatus;
      ddCoord4D          MC_Origin, CC_Origin, NPC_Origin;
      ddUSHORT           oc;         /* Outcode for 4D point clipping */
***************
*** 392,404 ****
      MC_Origin.z = 0.0;
      MC_Origin.w = 1.0;
  
!     if (pDDC->Dynamic->pPCAttr->modelClip == PEXOn) {
  
        ComputeMCVolume(pRend, pddc);	/*  Compute  modelling coord version
  					    of clipping volume */
        CLIP_POINT4D(&MC_Origin, oc, MI_MCLIP);
  
!       if (oc) return (Success); /* origin model clipped out */
      }
  
      /* Get the current view index and the corresponding transforms */
--- 392,407 ----
      MC_Origin.z = 0.0;
      MC_Origin.w = 1.0;
  
!     if (pDDC->Dynamic->pPCAttr->modelClip == PEXClip) {
  
        ComputeMCVolume(pRend, pddc);	/*  Compute  modelling coord version
  					    of clipping volume */
        CLIP_POINT4D(&MC_Origin, oc, MI_MCLIP);
  
!       if (oc) {
! 	  pDDC->Static.pick.status = PEXNoPick;
! 	  return (Success); /* origin model clipped out */
!       }
      }
  
      /* Get the current view index and the corresponding transforms */
***************
*** 422,430 ****
      if ((ClipNPCPoint4D (pRend, &NPC_Origin, &oc)) == PEXLookupTableError)
  	return (PEXLookupTableError);
      if (oc) {
!       return (Success);  /* Don't pick anything; origin clipped out */
      }
  
      /* Keep the NPC_Origin computed above for later use */
  
      /* Get the pick aperture and convert into NPC, if required. */
--- 425,435 ----
      if ((ClipNPCPoint4D (pRend, &NPC_Origin, &oc)) == PEXLookupTableError)
  	return (PEXLookupTableError);
      if (oc) {
! 	pDDC->Static.pick.status = PEXNoPick;
! 	return (Success);  /* Don't pick anything; origin clipped out */
      }
  
+ 
      /* Keep the NPC_Origin computed above for later use */
  
      /* Get the pick aperture and convert into NPC, if required. */
***************
*** 451,465 ****
      numChars = 0;
      pMono = pText;
      for (i=0; i<numEncodings; i++) {
        numChars += (ddULONG)pMono->numChars;
!       pMono++;
      }
  
      /* Convert text string into required paths */
  
!     if (!(count = atx_el_to_path (pRend, pDDC, numEncodings, pText,
! 				 numChars, &text_el, &align))) {
!       return (BadValue);
      }
  
      /* Compute the required Character Space to Modelling Space Transform */
--- 456,481 ----
      numChars = 0;
      pMono = pText;
      for (i=0; i<numEncodings; i++) {
+       int bytes = pMono->numChars * ((pMono->characterSetWidth == PEXCSByte) ?
+ 	  sizeof(CARD8) : ((pMono->characterSetWidth == PEXCSShort) ?
+ 	  sizeof(CARD16) : sizeof(CARD32)));
        numChars += (ddULONG)pMono->numChars;
!       pMono = (pexMonoEncoding *) ((char *) (pMono + 1) +
! 	  bytes + PADDING (bytes));
      }
  
+     if (numChars == 0)
+     {
+ 	pDDC->Static.pick.status = PEXNoPick;
+ 	return (Success);
+     }
+ 
+ 
      /* Convert text string into required paths */
  
!     if ((status = atx_el_to_path (pRend, pDDC, numEncodings, pText,
! 	numChars, &text_el, &align, &count)) != Success) {
!       return (status);
      }
  
      /* Compute the required Character Space to Modelling Space Transform */
***************
*** 726,732 ****
      miListHeader      *cc_path, *clip_path;
      listofddPoint     *sp;
      XID		       temp;
!     ddpex3rtn	       status;
      ddUSHORT           aflag, LUTstatus;
      static ddVector3D   Directions[2] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0};
      ddCoord3D           *pDirections = (ddCoord3D *)Directions;
--- 742,748 ----
      miListHeader      *cc_path, *clip_path;
      listofddPoint     *sp;
      XID		       temp;
!     int		       status;
      ddUSHORT           aflag, LUTstatus;
      static ddVector3D   Directions[2] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0};
      ddCoord3D           *pDirections = (ddCoord3D *)Directions;
***************
*** 747,759 ****
      MC_Origin.z = pOrigin->z;
      MC_Origin.w = 1.0;
  
!     if (pDDC->Dynamic->pPCAttr->modelClip == PEXOn) {
  
        ComputeMCVolume(pRend, pddc);	/*  Compute  modelling coord version
  					    of clipping volume */
        CLIP_POINT4D(&MC_Origin, oc, MI_MCLIP);
  
!       if (oc) return (Success); /* origin model clipped out */
      }
  
      /* Get the current view index and the corresponding transforms */
--- 763,778 ----
      MC_Origin.z = pOrigin->z;
      MC_Origin.w = 1.0;
  
!     if (pDDC->Dynamic->pPCAttr->modelClip == PEXClip) {
  
        ComputeMCVolume(pRend, pddc);	/*  Compute  modelling coord version
  					    of clipping volume */
        CLIP_POINT4D(&MC_Origin, oc, MI_MCLIP);
  
!       if (oc) {
! 	  pDDC->Static.pick.status = PEXNoPick;
! 	  return (Success); /* origin model clipped out */
!       }
      }
  
      /* Get the current view index and the corresponding transforms */
***************
*** 777,783 ****
      if ((ClipNPCPoint4D (pRend, &NPC_Origin, &oc)) == PEXLookupTableError)
  	return (PEXLookupTableError);
      if (oc) {
!       return (Success);  /* Don't pick anything; origin clipped out */
      }
  
      /* Keep the NPC_Origin computed above for later use */
--- 796,803 ----
      if ((ClipNPCPoint4D (pRend, &NPC_Origin, &oc)) == PEXLookupTableError)
  	return (PEXLookupTableError);
      if (oc) {
! 	pDDC->Static.pick.status = PEXNoPick;
! 	return (Success);  /* Don't pick anything; origin clipped out */
      }
  
      /* Keep the NPC_Origin computed above for later use */
***************
*** 806,820 ****
      numChars = 0;
      pMono = pText;
      for (i=0; i<numEncodings; i++) {
        numChars += (ddULONG)pMono->numChars;
!       pMono++;
      }
  
      /* Convert text string into required paths */
  
!     if (!(count = atx_el_to_path (pRend, pDDC, numEncodings, pText,
! 				 numChars, &text_el, &align))) {
!       return (BadValue);
      }
  
      /* Compute the required Character Space to Modelling Space Transform */
--- 826,851 ----
      numChars = 0;
      pMono = pText;
      for (i=0; i<numEncodings; i++) {
+       int bytes = pMono->numChars * ((pMono->characterSetWidth == PEXCSByte) ?
+ 	  sizeof(CARD8) : ((pMono->characterSetWidth == PEXCSShort) ?
+ 	  sizeof(CARD16) : sizeof(CARD32)));
        numChars += (ddULONG)pMono->numChars;
!       pMono = (pexMonoEncoding *) ((char *) (pMono + 1) +
! 	  bytes + PADDING (bytes));
      }
  
+     if (numChars == 0)
+     {
+ 	pDDC->Static.pick.status = PEXNoPick;
+ 	return (Success);
+     }
+ 
+ 
      /* Convert text string into required paths */
  
!     if ((status = atx_el_to_path (pRend, pDDC, numEncodings, pText,
! 	numChars, &text_el, &align, &count)) != Success) {
!       return (status);
      }
  
      /* Compute the required Character Space to Modelling Space Transform */
*** -	Thu Jan 28 17:53:12 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/miNSurf.c	Thu Jan 28 17:53:12 1993
***************
*** 1,4 ****
! /* $XConsortium: miNSurf.c,v 5.7 91/07/01 08:53:21 rws Exp $ */
  
  #define TRIMING 1
  
--- 1,4 ----
! /* $XConsortium: miNSurf.c,v 5.8 91/10/25 18:30:41 hersh Exp $ */
  
  #define TRIMING 1
  
***************
*** 2210,2215 ****
--- 2210,2217 ----
  nurb_surf_state_free( state )
      Nurb_surf_state	*state;
  {
+     int facet;
+ 
      /* Free everything but the cache data. */
      if ( state->ruknots )
  	xfree( state->ruknots );
***************
*** 2220,2234 ****
      phg_nt_free_trim_data( &state->trim_data );
  #endif /* TRIMING */
  
-     if ( state->grids.number > 0 ) {
- 	free_grids( &state->grids );
- 	state->grids.number = 0;
- 	state->grids.grids = (Nurb_grid *)NULL;
-     }
- 
      if ( state->reps.facets ) {
        if ( state->facets ) {
  	MI_FREELISTHEADER(state->facets);
  	Xfree(state->facets);
        }
        else if ( state->sofas ) {
--- 2222,2232 ----
      phg_nt_free_trim_data( &state->trim_data );
  #endif /* TRIMING */
  
      if ( state->reps.facets ) {
        if ( state->facets ) {
  	MI_FREELISTHEADER(state->facets);
+         for (facet = 0; facet < state->grids.number; facet++)
+             MI_FREELISTHEADER(state->facets + facet);
  	Xfree(state->facets);
        }
        else if ( state->sofas ) {
*** -	Thu Jan 28 17:53:14 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/ddContext.c	Thu Jan 28 17:53:13 1993
***************
*** 1,4 ****
! /* $XConsortium: ddContext.c,v 5.3 91/07/01 08:26:24 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: ddContext.c,v 5.7 93/01/12 17:41:13 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 270,280 ****
      MINS_EMPTY_NAMESET(pddc->Static.search.invert_inclusion);
      MINS_EMPTY_NAMESET(pddc->Static.search.invert_exclusion);
  
!     /*
!      * Indicate all xforms in static are invalid *. pddc->Static.misc.flags
!      * |= ( INVTRCCTODCXFRMFLAG | INVTRWCTOCCXFRMFLAG | INVTRMCTOCCXFRMFLAG |
!      * INVTRMCTOWCXFRMFLAG | INVVIEWXFRMFLAG );
!      * 
      /* Mark as invalid any transform dependant fields in ddContext
       */
      pddc->Static.misc.flags |= (MCVOLUMEFLAG | CC_DCUEVERSION);
--- 270,279 ----
      MINS_EMPTY_NAMESET(pddc->Static.search.invert_inclusion);
      MINS_EMPTY_NAMESET(pddc->Static.search.invert_exclusion);
  
!     /* Indicate all xforms in static are invalid  */
!      pddc->Static.misc.flags |= ( INVTRCCTODCXFRMFLAG | INVTRWCTOCCXFRMFLAG 
!      | INVTRMCTOCCXFRMFLAG | INVTRMCTOWCXFRMFLAG | INVVIEWXFRMFLAG );
!       
      /* Mark as invalid any transform dependant fields in ddContext
       */
      pddc->Static.misc.flags |= (MCVOLUMEFLAG | CC_DCUEVERSION);
***************
*** 837,890 ****
  	/* only set these if it's the bundle that changed */
  	if ((tables & PEXDynInteriorBundle) ||
  	    (tables & PEXDynInteriorBundleContents)) {
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXSurfaceInterpAsf) == PEXBundled)
! 		pddc->Static.attrs->surfInterp = intbundle->real_entry.surfaceInterp;
  	    else
! 		pddc->Static.attrs->surfInterp = pddc->Dynamic->pPCAttr->surfInterp;
  
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXReflectionModelAsf) == PEXBundled)
! 		pddc->Static.attrs->reflModel = intbundle->real_entry.reflectionModel;
  	    else
! 		pddc->Static.attrs->reflModel = pddc->Dynamic->pPCAttr->reflModel;
  
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXReflectionAttrAsf) == PEXBundled)
! 		pddc->Static.attrs->reflAttr = intbundle->real_entry.reflectionAttr;
! 	    else
  		pddc->Static.attrs->reflAttr = pddc->Dynamic->pPCAttr->reflAttr;
  
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXInteriorStyleAsf) == PEXBundled)
! 		pddc->Static.attrs->intStyle = intbundle->real_entry.interiorStyle;
  	    else
  		pddc->Static.attrs->intStyle = pddc->Dynamic->pPCAttr->intStyle;
  
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXBfSurfaceInterpAsf) == PEXBundled)
  		pddc->Static.attrs->bfSurfInterp =
! 		    intbundle->real_entry.bfSurfaceInterp;
  	    else
  		pddc->Static.attrs->bfSurfInterp =
  		    pddc->Dynamic->pPCAttr->bfSurfInterp;
  
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXBfReflectionModelAsf) == PEXBundled)
  		pddc->Static.attrs->bfReflModel =
! 		    intbundle->real_entry.bfReflectionModel;
  	    else
! 		pddc->Static.attrs->bfReflModel = pddc->Dynamic->pPCAttr->bfReflModel;
  
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXBfReflectionAttrAsf) == PEXBundled)
  		pddc->Static.attrs->bfReflAttr =
! 		    intbundle->real_entry.bfReflectionAttr;
! 	    else
! 		pddc->Static.attrs->bfReflAttr = pddc->Dynamic->pPCAttr->bfReflAttr;
  
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXBfInteriorStyleAsf) == PEXBundled)
! 		pddc->Static.attrs->bfIntStyle = intbundle->real_entry.bfInteriorStyle;
  	    else
! 		pddc->Static.attrs->bfIntStyle = pddc->Dynamic->pPCAttr->bfIntStyle;
  
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXSurfaceApproxAsf) == PEXBundled)
! 		pddc->Static.attrs->surfApprox = intbundle->real_entry.surfaceApprox;
  	    else
! 		pddc->Static.attrs->surfApprox = pddc->Dynamic->pPCAttr->surfApprox;
  	}
  	pddc->Static.misc.flags |= FILLAREAGCFLAG;
      }
--- 836,930 ----
  	/* only set these if it's the bundle that changed */
  	if ((tables & PEXDynInteriorBundle) ||
  	    (tables & PEXDynInteriorBundleContents)) {
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXSurfaceInterpAsf) 
! 								== PEXBundled)
! 		pddc->Static.attrs->surfInterp = 
! 					intbundle->real_entry.surfaceInterp;
  	    else
! 		pddc->Static.attrs->surfInterp = 
! 					pddc->Dynamic->pPCAttr->surfInterp;
  
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXReflectionModelAsf) 
! 								== PEXBundled)
! 		pddc->Static.attrs->reflModel = 
! 					intbundle->real_entry.reflectionModel;
  	    else
! 		pddc->Static.attrs->reflModel = 
! 					pddc->Dynamic->pPCAttr->reflModel;
  
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXReflectionAttrAsf) 
! 								== PEXBundled){
! 		pddc->Static.attrs->reflAttr = 
! 					intbundle->real_entry.reflectionAttr;
!   		miConvertColor(pRend,
! 			&intbundle->real_entry.reflectionAttr.specularColour,
!   			pddc->Dynamic->pPCAttr->rdrColourModel,
!   			&pddc->Static.attrs->reflAttr.specularColour);
!   	    } else {
  		pddc->Static.attrs->reflAttr = pddc->Dynamic->pPCAttr->reflAttr;
+   		miConvertColor(pRend,
+   			&pddc->Dynamic->pPCAttr->reflAttr.specularColour,
+   			pddc->Dynamic->pPCAttr->rdrColourModel,
+   			&pddc->Static.attrs->reflAttr.specularColour);
+   	    }
  
! 
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXInteriorStyleAsf) 
! 								== PEXBundled)
! 		pddc->Static.attrs->intStyle = 
! 					intbundle->real_entry.interiorStyle;
  	    else
  		pddc->Static.attrs->intStyle = pddc->Dynamic->pPCAttr->intStyle;
  
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXBfSurfaceInterpAsf) 
! 								== PEXBundled)
  		pddc->Static.attrs->bfSurfInterp =
! 		    			intbundle->real_entry.bfSurfaceInterp;
  	    else
  		pddc->Static.attrs->bfSurfInterp =
  		    pddc->Dynamic->pPCAttr->bfSurfInterp;
  
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXBfReflectionModelAsf) 
! 								== PEXBundled)
  		pddc->Static.attrs->bfReflModel =
! 		    			intbundle->real_entry.bfReflectionModel;
  	    else
! 		pddc->Static.attrs->bfReflModel = 
! 					pddc->Dynamic->pPCAttr->bfReflModel;
  
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXBfReflectionAttrAsf) 
! 								== PEXBundled){
  		pddc->Static.attrs->bfReflAttr =
! 		    			intbundle->real_entry.bfReflectionAttr;
!   		miConvertColor(pRend,
!  			&intbundle->real_entry.bfReflectionAttr.specularColour,
!   			pddc->Dynamic->pPCAttr->rdrColourModel,
!   			&pddc->Static.attrs->bfReflAttr.specularColour);
!   	    } else {
! 		pddc->Static.attrs->bfReflAttr = 
! 					pddc->Dynamic->pPCAttr->bfReflAttr;
!   		miConvertColor(pRend,
!   			&pddc->Dynamic->pPCAttr->bfReflAttr.specularColour,
!   			pddc->Dynamic->pPCAttr->rdrColourModel,
!   			&pddc->Static.attrs->bfReflAttr.specularColour);
!   	    }
  
! 
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXBfInteriorStyleAsf) 
! 								== PEXBundled)
! 		pddc->Static.attrs->bfIntStyle = 
! 					intbundle->real_entry.bfInteriorStyle;
  	    else
! 		pddc->Static.attrs->bfIntStyle = 
! 					pddc->Dynamic->pPCAttr->bfIntStyle;
  
! 	    if ((pddc->Dynamic->pPCAttr->asfs & PEXSurfaceApproxAsf) 
! 								== PEXBundled)
! 		pddc->Static.attrs->surfApprox = 
! 					intbundle->real_entry.surfaceApprox;
  	    else
! 		pddc->Static.attrs->surfApprox = 
! 					pddc->Dynamic->pPCAttr->surfApprox;
  	}
  	pddc->Static.misc.flags |= FILLAREAGCFLAG;
      }
***************
*** 943,958 ****
      /*
       * View table
       */
      if ((tables & PEXDynViewTable) || (tables & PEXDynViewTableContents)) {
  	extern ddpex3rtn miBldCC_xform();
  
  	miBldCC_xform(pRend, pddc);
      }
-     if ((attrs & PEXDynNpcSubvolume) || (attrs & PEXDynViewport)) {
- 	extern ddpex3rtn miBldViewport_xform();
  
! 	miBldViewport_xform(pRend, pRend->pDrawable, 
! 			    pddc->Static.misc.viewport_xform, pddc );
      }
      return (Success);
  }
--- 983,1068 ----
      /*
       * View table
       */
+     if ((attrs & PEXDynNpcSubvolume) || (attrs & PEXDynViewport)) {
+ 	extern ddpex3rtn miBldViewport_xform();
+ 
+ 	miBldViewport_xform(pRend, pRend->pDrawable, 
+ 			    pddc->Static.misc.viewport_xform, pddc );
+     }
      if ((tables & PEXDynViewTable) || (tables & PEXDynViewTableContents)) {
  	extern ddpex3rtn miBldCC_xform();
  
  	miBldCC_xform(pRend, pddc);
      }
  
!     /* the echo colour change always take places */
!     pddc->Static.attrs->echoColour = pRend->echoColour;
! 
!     /* If the echo mode changes, we have to change all these GCs */
!     if( attrs & PEXDynEchoMode )
!       {
! 	pddc->Static.attrs->echoMode = pRend->echoMode;
!         pddc->Static.misc.flags |= POLYLINEGCFLAG;
!         pddc->Static.misc.flags |= MARKERGCFLAG;
!         pddc->Static.misc.flags |= FILLAREAGCFLAG;
!         pddc->Static.misc.flags |= EDGEGCFLAG;
!         pddc->Static.misc.flags |= TEXTGCFLAG;
!       }
! 
!     /*
!      * Set the Clip List in each GC if there are any
!      * all GCs are defined at the same time so check if any one exists
!      */
!     if ((attrs & PEXDynClipList) && pddc->Static.misc.pPolylineGC) 
!      {
! 
!       extern int      SetClipRects();
!       extern void     ValidateGC();
!       xRectangle      *xrects, *p;
!       ddDeviceRect    *ddrects;
!       ddLONG          numrects;
!       XID	      gcval;
!       int             i;
! 
!       numrects = pRend->clipList->numObj;
!       if (numrects) {
!         ddrects = (ddDeviceRect *) pRend->clipList->pList;
!         xrects = (xRectangle*) Xalloc(numrects * sizeof(xRectangle));
!         if (!xrects) return BadAlloc;
!         /* Need to convert to XRectangle format */
!         for (i = 0, p = xrects; i < numrects; i++, p++, ddrects++) {
!           p->x = ddrects->xmin;
!           p->y = pRend->pDrawable->height - ddrects->ymax;
!           p->width = ddrects->xmax - ddrects->xmin + 1;
!           p->height = ddrects->ymax - ddrects->ymin + 1;
!           }
! 
!         SetClipRects(pddc->Static.misc.pPolylineGC, 0, 0,
!                      (int)numrects, xrects, Unsorted);
!         SetClipRects(pddc->Static.misc.pFillAreaGC, 0, 0,
!                      (int)numrects, xrects, Unsorted);
!         SetClipRects(pddc->Static.misc.pEdgeGC, 0, 0,
!                      (int)numrects, xrects, Unsorted);
!         SetClipRects(pddc->Static.misc.pPolyMarkerGC, 0, 0,
!                      (int)numrects, xrects, Unsorted);
!         SetClipRects(pddc->Static.misc.pTextGC, 0, 0,
!                      (int)numrects, xrects, Unsorted);
!         Xfree((char*)xrects);
!       }
!       else {
! 	gcval = None;
! 	ChangeGC(pddc->Static.misc.pPolylineGC, GCClipMask, &gcval);
! 	ChangeGC(pddc->Static.misc.pFillAreaGC, GCClipMask, &gcval);
! 	ChangeGC(pddc->Static.misc.pEdgeGC, GCClipMask, &gcval);
! 	ChangeGC(pddc->Static.misc.pPolyMarkerGC, GCClipMask, &gcval);
! 	ChangeGC(pddc->Static.misc.pTextGC, GCClipMask, &gcval);
!       }
!       ValidateGC(pRend->pDrawable, pddc->Static.misc.pPolylineGC);
!       ValidateGC(pRend->pDrawable, pddc->Static.misc.pFillAreaGC);
!       ValidateGC(pRend->pDrawable, pddc->Static.misc.pEdgeGC);
!       ValidateGC(pRend->pDrawable, pddc->Static.misc.pPolyMarkerGC);
!       ValidateGC(pRend->pDrawable, pddc->Static.misc.pTextGC);
      }
+ 
      return (Success);
  }
*** -	Thu Jan 28 17:53:15 1993
--- mit/extensions/server/PEX/ddpex/mi/level2/miSearch.c	Thu Jan 28 17:53:15 1993
***************
*** 1,4 ****
! /* $XConsortium: miSearch.c,v 5.3 91/05/12 16:11:38 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miSearch.c,v 5.4 93/01/25 16:40:38 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 199,208 ****
        miMatMult (pDDC->Dynamic->wc_to_cc_xform, 
  		 pDDC->Dynamic->wc_to_npc_xform, buf1_xform);
  
!       /* Get mc_to_cc_xform = (mc_to_npc_xform * buf1_xform) */
  
        miMatMult (pDDC->Dynamic->mc_to_cc_xform, 
! 		 pDDC->Dynamic->mc_to_npc_xform, buf1_xform);
  
        /* Now, call the level 2 rendering function to transform and */
        /* clip the primitive. Note that the level 1 function vector */
--- 199,209 ----
        miMatMult (pDDC->Dynamic->wc_to_cc_xform, 
  		 pDDC->Dynamic->wc_to_npc_xform, buf1_xform);
  
!       /* Get mc_to_cc_xform = (mc_to_wc_xform * wc_to_cc_xform) */
  
        miMatMult (pDDC->Dynamic->mc_to_cc_xform, 
! 		 pDDC->Dynamic->mc_to_wc_xform,
! 		 pDDC->Dynamic->wc_to_cc_xform);
  
        /* Now, call the level 2 rendering function to transform and */
        /* clip the primitive. Note that the level 1 function vector */
*** -	Thu Jan 28 17:53:28 1993
--- mit/extensions/server/PEX/ddpex/mi/level3/miRender.c	Thu Jan 28 17:53:26 1993
***************
*** 1,5 ****
! /* $XConsortium: miRender.c,v 5.3 91/07/19 16:02:57 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
--- 1,6 ----
! /* $XConsortium: miRender.c,v 5.19 93/01/27 15:48:27 hersh Exp $ */
  
+ 
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
***************
*** 25,30 ****
--- 26,32 ----
  ******************************************************************/
  
  #include "miLUT.h"
+ #include "dipex.h"
  #include "ddpex3.h"
  #include "PEXproto.h"
  #include "PEXprotost.h"
***************
*** 34,43 ****
--- 36,48 ----
  #include "windowstr.h"
  #include "regionstr.h"
  #include "miscstruct.h"
+ #include "dixstruct.h"
  #include "miRender.h"
  #include "miStruct.h"
+ #include "miStrMacro.h"
  #include "miWks.h"
  #include "ddpex4.h"
+ #include "gcstruct.h"
  
  /* External variables used */
  
***************
*** 68,73 ****
--- 73,79 ----
      {0.0, 0.0, 0.0, 1.0}
  };
  
+ 
  /* Level III Rendering Procedures */
  
  /*++
***************
*** 116,123 ****
       * make sure everything is updated.
       */
      pRend->tablesMask = 0;
!     pRend->namesetsMask = ~0;
!     pRend->attrsMask = ~0;
  
      /*
       * Create a DDContext and associate it with the Renderer
--- 122,129 ----
       * make sure everything is updated.
       */
      pRend->tablesMask = 0;
!     pRend->namesetsMask = 0;
!     pRend->attrsMask = 0;
  
      /*
       * Create a DDContext and associate it with the Renderer
***************
*** 237,243 ****
      pPC->edgeIndex = 1;
      bcopy((char *) ident4x4, (char *) pPC->localMat, 16 * sizeof(ddFLOAT));
      bcopy((char *) ident4x4, (char *) pPC->globalMat, 16 * sizeof(ddFLOAT));
!     pPC->modelClip = PEXOff;
      pPC->modelClipVolume = puCreateList(DD_HALF_SPACE);
      pPC->viewIndex = 0;
      pPC->lightState = puCreateList(DD_INDEX);
--- 243,249 ----
      pPC->edgeIndex = 1;
      bcopy((char *) ident4x4, (char *) pPC->localMat, 16 * sizeof(ddFLOAT));
      bcopy((char *) ident4x4, (char *) pPC->globalMat, 16 * sizeof(ddFLOAT));
!     pPC->modelClip = PEXNoClip;
      pPC->modelClipVolume = puCreateList(DD_HALF_SPACE);
      pPC->viewIndex = 0;
      pPC->lightState = puCreateList(DD_INDEX);
***************
*** 307,379 ****
  {
  	register ddElementInfo	*poc;
  	miGenericElementPtr	pexoc;
! 	ddpex2rtn	err;
  
  #ifdef DDTEST
      ErrorF( " RenderOCs\n");
  #endif
  
      ValidateRenderer(pRend);
  
!     for ( poc=pOCs; numOCs>0; numOCs-- )
!     {
! 	switch( poc->elementType ) {
!          /* drawing primitives */
!           case PEXOCMarker:
!           case PEXOCMarker2D:
!           case PEXOCText:
!           case PEXOCText2D:
!           case PEXOCAnnotationText:
!           case PEXOCAnnotationText2D:
!           case PEXOCPolyline:
!           case PEXOCPolyline2D:
!           case PEXOCPolylineSet:
!           case PEXOCNurbCurve:
!           case PEXOCFillArea:
!           case PEXOCFillArea2D:
!           case PEXOCExtFillArea:
!           case PEXOCFillAreaSet:
!           case PEXOCFillAreaSet2D:
!           case PEXOCExtFillAreaSet:
!           case PEXOCTriangleStrip:
!           case PEXOCQuadrilateralMesh:
!           case PEXOCSOFAS:
!           case PEXOCNurbSurface:
!           case PEXOCCellArray:
!           case PEXOCCellArray2D:
!           case PEXOCExtCellArray:
!           case PEXOCGdp:
!           case PEXOCGdp2D:
  
! 		/* drop out if not doing primitives
!                  * otherwise fall through */
!                 if (!MI_DDC_DO_PRIMS(pRend)) 
!                    break; 
  
!           default:
! 	    pexoc = 0;
! 	    err = ParseOCTable[ (int)poc->elementType ]( (ddPointer)poc, &pexoc );
! 	    if (err != Success)
! 	    	return( PEXERR(PEXOutputCommandError) );
! 	    
! 	    /* add one to the current_path's element offset if a begin structure
! 	     * has been done
! 	     */
! 	    if (pRend->curPath->numObj)
! 	        ((ddElementRef *)pRend->curPath->pList)[pRend->curPath->numObj - 1].offset++;
! 	    pRend->executeOCs[ (int)poc->elementType ]( pRend, &pexoc->element );
  
! 	    DestroyOCTable[ (int)poc->elementType ](  pexoc );
  	}
  
! 	poc += poc->length;	/* length is in four byte units & sizeof(poc) is 4 */
      }
  
!     return (Success);
  }
  
  /*++
   |
   |  Function Name:	init_def_matrix
   |
   |  Note(s):
--- 313,933 ----
  {
  	register ddElementInfo	*poc;
  	miGenericElementPtr	pexoc;
! 	ddpex2rtn		err = Success;
! 	XID			fakestr;
! 	diStructHandle 		sh = 0, ph;
! 	pexStructure 		*ps;
! 	pexOutputCommandError 	*pErr;
! 	ddULONG            	offset1, offset2, numberOCs;
! 	miTraverserState      	trav_state;
! 	diPMHandle            	pPM = (diPMHandle) NULL;
! 	unsigned long 		PEXStructType;
! 	miStructPtr 		pheader;
! 	ddPickPath    		*strpp;
! 	miPPLevel		*travpp;
! 	int			i, ROCdepth;
!         ddUSHORT          	serverstate;    
  
+ 
  #ifdef DDTEST
      ErrorF( " RenderOCs\n");
  #endif
  
+     /* if renderer idle ignore.... */
+     if (pRend->state == PEXIdle)
+       return Success;
+ 
      ValidateRenderer(pRend);
  
!     /* state == PEXPicking, call through traverser */
!     if (pRend->state == PEXPicking) {
  
! 	/* get the structure handle from the last pickpath in the list of 
! 	   fake structures (these are added by BeginStructure)
! 	*/
! 	ROCdepth = (pRend->pickstr.fakeStrlist)->numObj-1;
! 	strpp = (ddPickPath *)(pRend->pickstr.fakeStrlist)->pList;
! 	sh = strpp[ROCdepth].structure;
  
! 	/* set up incoming state properly for traverser */
! 	if (ROCdepth > 0) {
! 	    travpp = (miPPLevel *)  xalloc(sizeof(miPPLevel));
! 	    trav_state.p_pick_path = travpp;
! 	    travpp->pp = strpp[ROCdepth-1];
! 	    for (i = ROCdepth-2; i >= 0; i--) {
! 		travpp->up = (miPPLevel *)  xalloc(sizeof(miPPLevel));
! 		travpp = travpp->up;
! 		travpp->pp = strpp[i];
! 	    }
! 	}
  
! 
! 	/* now do the work of storing stuff into the structure */
! 	numberOCs = numOCs;
! 	for ( poc=pOCs; numberOCs>0; numberOCs-- )
! 	{
! 
! 	    err = StoreElements( sh, 1, poc, &pErr);
! 	    if (err != Success) return(err);
! 
! 	    poc += poc->length;	
  	}
  
! 	/* now call the traverser to traverse this structure */
!         /* set exec_str_flag */
! 	trav_state.exec_str_flag = ES_YES;
! 	trav_state.p_curr_pick_el = (ddPickPath *) NULL;
! 	trav_state.p_curr_sc_el = (ddElementRef *) NULL;
! 	trav_state.max_depth = ROCdepth;
! 	trav_state.pickId =  strpp[ROCdepth].pickid;
! 	trav_state.ROCoffset =  strpp[ROCdepth].offset;
! 	pPM = pRend->pickstr.pseudoPM;
! 
! 	/* turn off this flag so BeginStructure calls made inside traverser
! 	   do not cause fake structures to be allocated
! 	*/
! 	serverstate = pRend->pickstr.server;
! 	pRend->pickstr.server = DD_NEITHER;
! 	offset1 = 1;
! 	offset2 = numOCs;
! 
! 	err = traverser(pRend, sh, offset1, offset2, pPM, NULL, &trav_state);
! 
! 	/* restore the state flag */
! 	pRend->pickstr.server = serverstate;
! 
! 	/* save pickid returned by traverser */
! 	strpp[ROCdepth].pickid = trav_state.pickId;
! 	strpp[ROCdepth].offset += numOCs;
! 
!         /* clean up structure */
!         {
!           miStructPtr pheader = (miStructPtr) sh->deviceData;
!           extern cssTableType DestroyCSSElementTable[];
!  
!           MISTR_DEL_ELS(sh, pheader, 1, numOCs);
!           MISTR_CURR_EL_PTR(pheader) = MISTR_ZERO_EL(pheader);
!           MISTR_CURR_EL_OFFSET(pheader) = 0;
!  
!         }
! 
      }
+     else { 
+     /* state == PEXRendering, call directly to level 2 for efficiency */
+ 	for ( poc=pOCs; numOCs>0; numOCs-- )
+ 	{
+ 	    switch( poc->elementType ) {
+ 	     /* drawing primitives */
+ 	      case PEXOCMarker:
+ 	      case PEXOCMarker2D:
+ 	      case PEXOCText:
+ 	      case PEXOCText2D:
+ 	      case PEXOCAnnotationText:
+ 	      case PEXOCAnnotationText2D:
+ 	      case PEXOCPolyline:
+ 	      case PEXOCPolyline2D:
+ 	      case PEXOCPolylineSet:
+ 	      case PEXOCNurbCurve:
+ 	      case PEXOCFillArea:
+ 	      case PEXOCFillArea2D:
+ 	      case PEXOCExtFillArea:
+ 	      case PEXOCFillAreaSet:
+ 	      case PEXOCFillAreaSet2D:
+ 	      case PEXOCExtFillAreaSet:
+ 	      case PEXOCTriangleStrip:
+ 	      case PEXOCQuadrilateralMesh:
+ 	      case PEXOCSOFAS:
+ 	      case PEXOCNurbSurface:
+ 	      case PEXOCCellArray:
+ 	      case PEXOCCellArray2D:
+ 	      case PEXOCExtCellArray:
+ 	      case PEXOCGdp:
+ 	      case PEXOCGdp2D:
  
! 		    /* drop out if not doing primitives
! 		     * otherwise fall through */
! 		    if (!MI_DDC_DO_PRIMS(pRend)) 
! 		       break; 
! 
! 	      default:
! 		/* if a Proprietary OC bump the counter and continue */
! 		if (MI_HIGHBIT_ON((int)poc->elementType)) {
! 		    ((ddElementRef *)pRend->curPath->pList)
! 			[pRend->curPath->numObj - 1].offset++;
! 		    break;
! 		}
! 		else {
! 		    /* not Proprietary see if valid PEX OC */
! 		    if (MI_IS_PEX_OC((int)poc->elementType)){
! 
! 			pexoc = 0;
! 			err = ParseOCTable[ (int)poc->elementType ]
! 					  ( (ddPointer)poc, &pexoc );
! 		    }
! 		    else
! 			err = !Success;
! 		  }
! 		 
! 		if (err != Success)
! 		    return( PEXERR(PEXOutputCommandError) );
! 	
! 		/* If we make it here it is a valid OC no more checking to do */
! 
! 		/* add one to the current_path's element offset if a 
! 		 * begin structure has been done
! 		 */
! 		if (pRend->curPath->numObj)
! 		    ((ddElementRef *)pRend->curPath->pList)[pRend->curPath->numObj - 1].offset++;
! 		pRend->executeOCs[ (int)poc->elementType ]( pRend, &pexoc->element );
! 
! 		DestroyOCTable[ (int)poc->elementType ](  pexoc );
! 	    }
! 
! 	    poc += poc->length;	/* length is in four byte units & sizeof(poc) is 4 */
! 	}
!     }
! 
!     return (err);
  }
  
+ ddpex3rtn
+ convertoffset(pstruct, ppos, poffset)
+ /* in */
+     miStructStr    *pstruct;  /* pointer to the structure involved */
+     ddElementPos   *ppos;     /* the position information */
+ /* out */
+     ddULONG        *poffset;  /* valid offset calculated from the postition */
+ 
+ {
+ 	/* shamelessly lifted from the pos2offset routine in miStruct.c */
+ 
+         ddUSHORT        whence = ppos->whence;
+ 	ddLONG          offset = ppos->offset, temp;
+ 
+ 	switch (whence) {
+ 	    case PEXBeginning:
+                 temp = offset;
+ 		break;
+ 
+ 	    case PEXCurrent:
+                 temp = MISTR_CURR_EL_OFFSET(pstruct) + offset;
+ 		break;
+ 
+ 	    case PEXEnd:
+                 /* numElements is the same as the last elements offset */
+ 		temp = MISTR_NUM_EL(pstruct) + offset;
+ 		break;
+ 
+ 	    default:
+                 /* value error */
+ 		return (BadValue);
+ 		break;
+         }
+ 
+         /* now check that the new offset is in range of the structure */
+ 		if (temp < 0)
+ 		    *poffset = 0;
+ 		else if (temp > MISTR_NUM_EL(pstruct))
+ 		    *poffset = MISTR_NUM_EL(pstruct);
+ 		else
+ 		    *poffset = temp;
+ 
+         return (Success);
+ 			
+ }
+ 
+ 
+ 
  /*++
   |
+  |  Function Name:	RenderElements
+  |
+  |  Function Description:
+  |	 Supports the PEXRenderElements request.
+  |
+  |  Note(s):
+  |
+  --*/
+ 
+ ddpex3rtn
+ RenderElements(pRend, pStr, range)
+ /* in */
+     ddRendererPtr       pRend;	  /* renderer handle */
+     diStructHandle      pStr;
+     ddElementRange      *range;
+ /* out */
+ {
+     ddpex3rtn		err = Success;
+     miStructPtr         pstruct;
+     miGenericElementPtr pel;
+     ddULONG             offset1, offset2, i;
+     miTraverserState      trav_state;
+     diPMHandle            pPM = (diPMHandle) NULL;
+     miDDContext           *pddc = (miDDContext *) pRend->pDDContext;
+     int                 eltype, ROCdepth, j;
+     ddPickPath          *strpp, sIDpp, *sIDlist;
+     miPPLevel           *travpp;
+     XID                 fakeStrID;
+     diStructHandle      sh = 0, REfakeStr;
+     ddUSHORT		serverstate;
+     ddElementPos	REfakePos;
+ 
+ 
+ 
+ 
+     /* if renderer idle ignore.... */
+     if (pRend->state == PEXIdle)
+       return Success;
+ 
+     pstruct = (miStructPtr) pStr->deviceData;
+ 
+     /* convert the offset based on whence value */
+     if (convertoffset(pstruct, &(range->position1), &offset1))
+ 	    return (BadValue);      /* bad whence value */
+ 
+     if (convertoffset(pstruct, &(range->position2), &offset2))
+ 	    return (BadValue);      /* bad whence value */
+ 
+     /* flip the range if necessary */
+     if (offset1 > offset2) {
+ 	    i = offset1;
+ 	    offset1 = offset2;
+ 	    offset2 = i;
+     }
+ 
+     /* return early if offsets out of range */
+     if (offset1 == 0)
+ 	if (offset2 == 0)
+ 	      return(Success);
+ 	else
+ 	      offset1 = 1;
+ 
+     ValidateRenderer(pRend);
+ 
+     if (pRend->state == PEXPicking) {
+ 
+ 	/* in client side picking RenderElements could be called
+ 	   at different levels of nested Begin Structures. In
+ 	   order to uniquely store a correspondence between 
+ 	   structure handles and the correct ID a fake structure 
+ 	   must be allocated
+ 	*/
+ 
+         REfakeStr = (diStructHandle)Xalloc((unsigned long)
+                                               sizeof(ddStructResource));
+         if (!REfakeStr) return (BadAlloc);
+         REfakeStr->id = -666;
+         err = CreateStructure(REfakeStr);
+         if (err != Success) {
+             Xfree((pointer)(REfakeStr));
+             return (err);
+         }
+ 
+ 	/* now copy the desired elements out of the structure passed in
+ 	   and into the fake structure
+ 	*/
+ 	REfakePos.whence = PEXBeginning;
+ 	REfakePos.offset = 0;
+ 	err = CopyElements(pStr, range, REfakeStr, &REfakePos);
+         if (err != Success) {
+             Xfree((pointer)(REfakeStr));
+             return (err);
+         }
+ 
+ 
+ 	/* need to handle case where RenderElements is called
+ 	   after a ROC that may or may not have Begin/End structures
+ 	   nested in it
+ 	*/
+         ROCdepth = (pRend->pickstr.fakeStrlist)->numObj-1;
+         strpp = (ddPickPath *)(pRend->pickstr.fakeStrlist)->pList;
+         sh = strpp[ROCdepth].structure;
+ 
+ 
+         /* set up incoming state properly for traverser */
+         if (ROCdepth > 0) {
+             travpp = (miPPLevel *)  xalloc(sizeof(miPPLevel));
+             trav_state.p_pick_path = travpp;
+             travpp->pp = strpp[ROCdepth-1];
+             for (j = ROCdepth-2; j >= 0; j--) {
+                 travpp->up = (miPPLevel *)  xalloc(sizeof(miPPLevel));
+                 travpp = travpp->up;
+                 travpp->pp = strpp[j];
+             }
+         }
+ 
+ 
+ 	/* set exec_str_flag */
+ 	trav_state.exec_str_flag = ES_YES;
+ 	trav_state.p_curr_pick_el = (ddPickPath *) NULL;
+ 	trav_state.p_curr_sc_el = (ddElementRef *) NULL;
+ 	trav_state.max_depth = ROCdepth;
+ 	trav_state.pickId = strpp[ROCdepth].pickid;
+ 	trav_state.ROCoffset =  strpp[ROCdepth].offset;
+ 
+ 	pPM = pRend->pickstr.pseudoPM;
+ 
+         /* turn off this flag so BeginStructure calls made inside traverser
+           do not cause fake structures to be allocated
+         */
+         serverstate = pRend->pickstr.server;
+         pRend->pickstr.server = DD_NEITHER;
+ 	/* redefine the offsets into the fake structure from the originals */
+ 	offset2 = (offset2 - offset1 + 1);
+         offset1 = 1;
+ 	
+ 	err = traverser(pRend, REfakeStr, offset1, offset2, pPM, NULL, &trav_state);
+ 
+         /* restore the state flag */
+         pRend->pickstr.server = serverstate;
+ 
+         /* save pickid returned by traverser */
+         strpp[ROCdepth].pickid = trav_state.pickId;
+         strpp[ROCdepth].offset += offset2;
+ 
+ 	/* now find the ID that corresponds to the handle sh and
+ 	   save that as the corresponding ID for pStr in the sIDlist
+ 	   note that the IDs ARE stored in the pickid field
+ 	*/
+         sIDpp.structure = REfakeStr;
+         sIDpp.offset = 0;
+ 	sIDlist = (ddPickPath *) (pRend->pickstr.sIDlist)->pList;
+ 	for (j = 0; j < (pRend->pickstr.sIDlist)->numObj; j++, sIDlist++) 
+ 	    if (sh == sIDlist->structure) {
+ 		sIDpp.pickid = sIDlist->pickid;
+ 		break;
+ 	    }
+ 
+         err = puAddToList((ddPointer) &sIDpp, (ddULONG) 1, pRend->pickstr.sIDlist);
+         if (err != Success)   return (err);
+  
+         /* clean up structure */
+         {
+           miStructPtr pheader = (miStructPtr) REfakeStr->deviceData;
+           extern cssTableType DestroyCSSElementTable[];
+  
+           MISTR_DEL_ELS(REfakeStr, pheader, offset1, offset2);
+           MISTR_CURR_EL_PTR(pheader) = MISTR_ZERO_EL(pheader);
+           MISTR_CURR_EL_OFFSET(pheader) = 0;
+  
+         }
+ 
+     }
+     else {
+     /* state == PEXRendering call directly into level 2 for efficiency */
+ 	for (i = offset1; i <= offset2; i++){
+ 
+ 		/* set the element pointer */
+ 		if ( i == offset1) {
+ 		    MISTR_FIND_EL(pstruct, offset1, pel);
+ 		}
+ 		else
+ 		    pel = MISTR_NEXT_EL(pel);
+ 
+ 		eltype = MISTR_EL_TYPE (pel);
+ 
+ 		switch (eltype) {
+ 		   /* drawing primitives */
+ 		    case PEXOCMarker:
+ 		    case PEXOCMarker2D:
+ 		    case PEXOCText:
+ 		    case PEXOCText2D:
+ 		    case PEXOCAnnotationText:
+ 		    case PEXOCAnnotationText2D:
+ 		    case PEXOCPolyline:
+ 		    case PEXOCPolyline2D:
+ 		    case PEXOCPolylineSet:
+ 		    case PEXOCNurbCurve:
+ 		    case PEXOCFillArea:
+ 		    case PEXOCFillArea2D:
+ 		    case PEXOCExtFillArea:
+ 		    case PEXOCFillAreaSet:
+ 		    case PEXOCFillAreaSet2D:
+ 		    case PEXOCExtFillAreaSet:
+ 		    case PEXOCTriangleStrip:
+ 		    case PEXOCQuadrilateralMesh:
+ 		    case PEXOCSOFAS:
+ 		    case PEXOCNurbSurface:
+ 		    case PEXOCCellArray:
+ 		    case PEXOCCellArray2D:
+ 		    case PEXOCExtCellArray:
+ 		    case PEXOCGdp:
+ 
+ 		    /* drop out if not doing primitives
+ 		     * otherwise fall through */
+ 		     if (!MI_DDC_DO_PRIMS(pRend))
+ 			break;
+ 		default:
+ 		    /* if a Proprietary OC call the correct routine */
+ 		    if (MI_HIGHBIT_ON(eltype)) {
+ 			pRend->executeOCs[MI_OC_PROP]( pRend,
+ 					    (ddPointer)&(MISTR_EL_DATA (pel)));
+ 		    }
+ 		    else {
+ 			/* not Proprietary see if valid PEX OC */
+ 			if (MI_IS_PEX_OC(eltype))
+ 			    pRend->executeOCs[ eltype]( pRend,
+ 					    (ddPointer)&(MISTR_EL_DATA (pel)));
+ 			else
+ 			    err = !Success;
+ 		    }
+ 
+ 		    if (err != Success)
+ 			return( PEXERR(PEXOutputCommandError) );
+ 		 
+ 	    }
+ 	}
+     }	
+ 
+     return(err);
+ }
+ 
+ /*++
+  |
+  |  Function Name:      AccumulateState	
+  |
+  |  Function Description:
+  |	 Supports the PEXAccumulateState request.
+  |
+  |  Note(s):
+  |
+  --*/
+ 
+ ddpex3rtn
+ AccumulateState(pRend,  pAccSt )
+ /* in */
+     ddRendererPtr       pRend;	  /* renderer handle */
+ ddAccStPtr          pAccSt;	  /* accumulate state handle */
+ /* out */
+ {
+     register int	depth, offset;
+     ddpex3rtn		err = Success;
+     ddElementRef	*elemRef;
+     miStructPtr		structPtr;
+     miGenericElementPtr	elemPtr;
+ 
+     /* if renderer idle ignore.... */
+     if (pRend->state == PEXIdle)
+       return Success;
+ 
+     ValidateRenderer(pRend);
+ 
+     /* The path has already been validated */
+     
+     elemRef = (ddElementRef *) pAccSt->Path->pList;
+     for (depth = 1; depth <= pAccSt->numElRefs; depth++) {
+ 	structPtr = (miStructPtr) elemRef->structure->deviceData;
+ 	elemPtr = MISTR_NEXT_EL (MISTR_ZERO_EL (structPtr));
+ 	for (offset = 0; offset < elemRef->offset; offset++) {
+ 	    switch (MISTR_EL_TYPE (elemPtr)) {
+ 	    case PEXOCMarkerType:
+ 	    case PEXOCMarkerScale:
+ 	    case PEXOCMarkerColourIndex:
+ 	    case PEXOCMarkerColour:
+ 	    case PEXOCMarkerBundleIndex:
+ 	    case PEXOCTextFontIndex:
+ 	    case PEXOCTextPrecision:
+ 	    case PEXOCCharExpansion:
+ 	    case PEXOCCharSpacing:
+ 	    case PEXOCTextColourIndex:
+ 	    case PEXOCTextColour:
+ 	    case PEXOCCharHeight:
+ 	    case PEXOCCharUpVector:
+ 	    case PEXOCTextPath:
+ 	    case PEXOCTextAlignment:
+ 	    case PEXOCAtextHeight:
+ 	    case PEXOCAtextUpVector:
+ 	    case PEXOCAtextPath:
+ 	    case PEXOCAtextAlignment:
+ 	    case PEXOCAtextStyle:
+ 	    case PEXOCTextBundleIndex:
+ 	    case PEXOCLineType:
+ 	    case PEXOCLineWidth:
+ 	    case PEXOCLineColourIndex:
+ 	    case PEXOCLineColour:
+ 	    case PEXOCCurveApproximation:
+ 	    case PEXOCPolylineInterp:
+ 	    case PEXOCLineBundleIndex:
+ 	    case PEXOCInteriorStyle:
+ 	    case PEXOCInteriorStyleIndex:
+ 	    case PEXOCSurfaceColourIndex:
+ 	    case PEXOCSurfaceColour:
+ 	    case PEXOCSurfaceReflAttr:
+ 	    case PEXOCSurfaceReflModel:
+ 	    case PEXOCSurfaceInterp:
+ 	    case PEXOCBfInteriorStyle:
+ 	    case PEXOCBfInteriorStyleIndex:
+ 	    case PEXOCBfSurfaceColourIndex:
+ 	    case PEXOCBfSurfaceColour:
+ 	    case PEXOCBfSurfaceReflAttr:
+ 	    case PEXOCBfSurfaceReflModel:
+ 	    case PEXOCBfSurfaceInterp:
+ 	    case PEXOCSurfaceApproximation:
+ 	    case PEXOCCullingMode:
+ 	    case PEXOCDistinguishFlag:
+ 	    case PEXOCPatternSize:
+ 	    case PEXOCPatternRefPt:
+ 	    case PEXOCPatternAttr:
+ 	    case PEXOCInteriorBundleIndex:
+ 	    case PEXOCSurfaceEdgeFlag:
+ 	    case PEXOCSurfaceEdgeType:
+ 	    case PEXOCSurfaceEdgeWidth:
+ 	    case PEXOCSurfaceEdgeColourIndex:
+ 	    case PEXOCSurfaceEdgeColour:
+ 	    case PEXOCEdgeBundleIndex:
+ 	    case PEXOCSetAsfValues:
+ 	    case PEXOCLocalTransform:
+ 	    case PEXOCLocalTransform2D:
+ 	    case PEXOCGlobalTransform:
+ 	    case PEXOCGlobalTransform2D:
+ 	    case PEXOCModelClip:
+ 	    case PEXOCModelClipVolume:
+ 	    case PEXOCModelClipVolume2D:
+ 	    case PEXOCRestoreModelClip:
+ 	    case PEXOCViewIndex:
+ 	    case PEXOCLightState:
+ 	    case PEXOCDepthCueIndex:
+ 	    case PEXOCPickId:
+ 	    case PEXOCHlhsrIdentifier:
+ 	    case PEXOCColourApproxIndex:
+ 	    case PEXOCRenderingColourModel:
+ 	    case PEXOCParaSurfCharacteristics:
+ 	    case PEXOCAddToNameSet:
+ 	    case PEXOCRemoveFromNameSet:
+ 		/* if a Proprietary OC call the correct routine */
+ 		if (MI_HIGHBIT_ON(MISTR_EL_TYPE (elemPtr))) {
+ 		    pRend->executeOCs[MI_OC_PROP]( pRend,
+ 				    (ddPointer)&(MISTR_EL_DATA (elemPtr)));
+ 		}
+ 		else {
+ 		    /* not Proprietary see if valid PEX OC */
+ 		    if (MI_IS_PEX_OC(MISTR_EL_TYPE (elemPtr)))
+ 			pRend->executeOCs[(int) MISTR_EL_TYPE (elemPtr)]( pRend,
+ 				     (ddPointer)&(MISTR_EL_DATA (elemPtr)));
+ 		    else
+ 			err = !Success;
+ 		}
+ 
+ 		if (err != Success)
+ 		    return( PEXERR(PEXOutputCommandError) );
+ 		 
+ 		break;
+ 	    default:
+ 		break;
+ 	    }
+ 
+ 	    elemPtr = MISTR_NEXT_EL (elemPtr);
+ 	}
+ 
+ 	elemRef++;
+     }
+ 
+   return(err);
+ }
+ 
+ 
+ /*++
+  |
   |  Function Name:	init_def_matrix
   |
   |  Note(s):
***************
*** 470,475 ****
--- 1024,1030 ----
      /* this must be called before the rendering state is set 
       * and after the filters are set */
  
+     MI_SET_ALL_CHANGES(pRend);
      ValidateRenderer(pRend);
  
      /* 
***************
*** 528,533 ****
--- 1083,1146 ----
       */
       miBldCC_xform(pRend, pddc);
  
+     /*
+      * Clear the window if clearI flag is on.
+      * Use the background color in the renderer attributes.
+      * The default (0) entry in the Color Approx Table is used
+      * to compute the pixel.
+      */
+     if (pRend->clearI) {
+ 
+       unsigned long   colorindex, gcmask;
+       GCPtr           pGC;
+       extern GCPtr    CreateScratchGC();
+       extern int      ChangeGC();
+       extern void     ValidateGC();
+       xRectangle      xrect;
+       DrawablePtr     pDraw;
+       xRectangle      *xrects, *p;
+       ddDeviceRect    *ddrects;
+       ddLONG          numrects;
+       int             i;
+       ddTableIndex    colourApproxIndex;
+ 
+       pDraw = pRend->pDrawable;
+       if ((!pRend->pPC) || (!pRend->pPC->pPCAttr)) colourApproxIndex = 0;
+       else colourApproxIndex = pRend->pPC->pPCAttr->colourApproxIndex;
+       miColourtoIndex(pRend, colourApproxIndex, 
+ 			&pRend->backgroundColour, &colorindex);
+       pGC = CreateScratchGC(pDraw->pScreen, pDraw->depth);
+       gcmask = GCForeground;
+       ChangeGC(pGC, gcmask, &colorindex);
+       /* Set the Clip List if there is one */
+       numrects = pRend->clipList->numObj;
+       if (numrects) {
+         ddrects = (ddDeviceRect *) pRend->clipList->pList;
+         xrects = (xRectangle*) Xalloc(numrects * sizeof(xRectangle));
+         if (!xrects) return BadAlloc;
+         /* Need to convert to XRectangle format and flip Y */
+         for (i = 0, p = xrects; i < numrects; i++, p++, ddrects++) {
+           p->x = ddrects->xmin;
+           p->y = pDraw->height - ddrects->ymax;
+           p->width = ddrects->xmax - ddrects->xmin + 1;
+           p->height = ddrects->ymax - ddrects->ymin + 1;
+         }
+         SetClipRects(pGC, 0, 0, (int)numrects, xrects, Unsorted);
+         Xfree((char*)xrects);
+       }
+       ValidateGC(pDraw, pGC);
+       /* Now draw a filled rectangle to clear the image buffer */
+       xrect.x = 0;
+       xrect.y = 0;
+       xrect.width = pDraw->width;
+       xrect.height = pDraw->height;
+       (*pGC->ops->PolyFillRect) (pDraw, pGC, 1, &xrect);
+       gcmask = GCClipMask;
+       colorindex = 0;
+       ChangeGC(pGC, gcmask, &colorindex);
+       FreeScratchGC(pGC);
+     }
+ 
      /* do double buffering stuff */
      /* do hlhsr stuff */
  
***************
*** 595,607 ****
--- 1208,1229 ----
  /* out */
  {
      ddpex3rtn		PushddContext();
+     ddpex3rtn		err = Success;
      ddElementRef	newRef;
      ddpex3rtn		status;
+     XID  		fakeStrID;
+     diStructHandle    	fakeStr;
+     ddPickPath          fakeStrpp, sIDpp, *curpp;
  
+ 
  #ifdef DDTEST
      ErrorF( " BeginStructure %d\n", sId);
  #endif
  
+     /* if renderer idle ignore.... */
+     if (pRend->state == PEXIdle)
+       return Success;
+ 
      /* 
       * Push the current ddContext attributes onto the stack and create
       * a new instance of these attributes.
***************
*** 613,619 ****
       ((ddElementRef *)pRend->curPath->pList)[pRend->curPath->numObj-1].offset++;
  
      /** Add a new element to the cur_path for the new structure **/
!     /* sid is really a handle not an id */
      newRef.structure = (diStructHandle)sId;
      newRef.offset = 0;
  
--- 1235,1241 ----
       ((ddElementRef *)pRend->curPath->pList)[pRend->curPath->numObj-1].offset++;
  
      /** Add a new element to the cur_path for the new structure **/
!     /* sid is really an id not a handle*/
      newRef.structure = (diStructHandle)sId;
      newRef.offset = 0;
  
***************
*** 623,628 ****
--- 1245,1291 ----
  	return (BadAlloc);
      }
  
+     /* when doing client side picking fake structures must be allocated 
+        and the correspondence between their structure handles and IDs
+        saved for later lookup by the appropriate EndPick routine
+     */
+     if ((pRend->state == PEXPicking) && (pRend->pickstr.server == DD_CLIENT)) {
+ 
+ 	/* bump up the offset in the current element to simulate ExecStr */
+         curpp = (ddPickPath *)(pRend->pickstr.fakeStrlist)->pList;
+ 	curpp[(pRend->pickstr.fakeStrlist)->numObj-1].offset++;
+ 
+ 	/* allocate a new fake structure and add to both lists */
+ 	fakeStr = (diStructHandle)Xalloc((unsigned long)
+ 					      sizeof(ddStructResource));
+ 	if (!fakeStr) return (BadAlloc);
+ 	fakeStr->id = -666;
+ 	err = CreateStructure(fakeStr);
+ 	if (err != Success) {
+ 	    Xfree((pointer)(fakeStr));
+ 	    return (err);
+ 	}
+ 
+ 	fakeStrpp.structure = fakeStr;
+ 	fakeStrpp.offset = 0;
+ 	fakeStrpp.pickid = 0;
+ 	err = puAddToList((ddPointer) &fakeStrpp, (ddULONG) 1, pRend->pickstr.fakeStrlist);
+ 	if (err != Success) {
+ 	    Xfree((pointer)(fakeStr));
+ 	    return (err);
+ 	}
+ 
+ 	sIDpp.structure = fakeStr;
+ 	sIDpp.offset = 0;
+ 	/* Store the supplied structure ID here for retrieval at EndPick */
+ 	sIDpp.pickid = sId;
+ 	err = puAddToList((ddPointer) &sIDpp, (ddULONG) 1, pRend->pickstr.sIDlist);
+ 	if (err != Success) {
+ 	    Xfree((pointer)(fakeStr));
+ 	    return (err);
+ 	}
+ 
+     }
      return (Success);
  }	/* BeginStructure */
  
***************
*** 644,656 ****
  /* out */
  {
      ddpex3rtn		PopddContext();
- 
      ddpex3rtn		status;
  
  #ifdef DDTEST
      ErrorF( " EndStructure\n");
  #endif
  
      /*
       * Pop ddContext off stack - retrieve attributes for current structure */
      if (status = PopddContext(pRend)) return (status);
--- 1307,1335 ----
  /* out */
  {
      ddpex3rtn		PopddContext();
      ddpex3rtn		status;
+     miStructPtr 	pheader; 
+     diStructHandle      sh = 0;
+     ddPickPath          *strpp;
+     miDDContext    *pddc = (miDDContext *) pRend->pDDContext;
  
+ 
+ 
+ 
  #ifdef DDTEST
      ErrorF( " EndStructure\n");
  #endif
  
+     /* if renderer idle ignore.... */
+     if (pRend->state == PEXIdle)
+       return Success;
+ 
+     /* if there is no next then BeginStructure has not been
+        called so simply ignore this EndStructure call.... 
+     */
+     if (pddc->Dynamic->next == NULL)
+       return Success;
+ 
      /*
       * Pop ddContext off stack - retrieve attributes for current structure */
      if (status = PopddContext(pRend)) return (status);
***************
*** 665,670 ****
--- 1344,1361 ----
      /** Remove the last currentPath element from the renderer **/
      PU_REMOVE_LAST_OBJ(pRend->curPath);
  
+     if ((pRend->state == PEXPicking) && (pRend->pickstr.server == DD_CLIENT)) {
+ 
+ 	/* the fake structure can not be freed until End Picking
+ 	   since otherwise that chunk of memory could be allocated
+ 	   to another client provided sID thus destroying the 1 to 1
+ 	   mapping that the sIDlist counts up, so just remove the info 
+ 	   for the structure from the fakeStrlist. The handle and ID 
+ 	   must stay on the sID list until after the reply is processed
+ 	*/
+ 	PU_REMOVE_LAST_OBJ(pRend->pickstr.fakeStrlist);
+     }
+ 
      return (Success);
  
  }	/* EndStructure */
***************
*** 787,793 ****
  	tables = pRend->tablesChanges & ~pRend->tablesMask;
  	namesets = pRend->namesetsChanges & ~pRend->namesetsMask;
  	attrs = pRend->attrsChanges & ~pRend->attrsMask;
! 	ValidateFilters(pRend, pddc, tables, namesets, attrs);
  	ValidateDDContextAttrs(pRend, pddc, tables, namesets, attrs);
  	pRend->tablesChanges &= (~tables);
  	pRend->namesetsChanges &= (~namesets);
--- 1478,1484 ----
  	tables = pRend->tablesChanges & ~pRend->tablesMask;
  	namesets = pRend->namesetsChanges & ~pRend->namesetsMask;
  	attrs = pRend->attrsChanges & ~pRend->attrsMask;
! 	ValidateFilters(pRend, pddc, namesets);
  	ValidateDDContextAttrs(pRend, pddc, tables, namesets, attrs);
  	pRend->tablesChanges &= (~tables);
  	pRend->namesetsChanges &= (~namesets);
***************
*** 799,805 ****
  	namesets = pRend->namesetsChanges;
  	attrs = pRend->attrsChanges;
  	ValidateDDContextAttrs(pRend, pddc, tables, namesets, attrs);
! 	ValidateFilters(pRend, pddc, tables, namesets, attrs);
  	/* reset change masks */
  	MI_ZERO_ALL_CHANGES(pRend);
      }
--- 1490,1496 ----
  	namesets = pRend->namesetsChanges;
  	attrs = pRend->attrsChanges;
  	ValidateDDContextAttrs(pRend, pddc, tables, namesets, attrs);
! 	ValidateFilters(pRend, pddc, namesets);
  	/* reset change masks */
  	MI_ZERO_ALL_CHANGES(pRend);
      }
***************
*** 874,879 ****
--- 1565,1574 ----
  
      pRend->render_mode = MI_REND_PICKING;
  
+     /* make sure this gets initialized for every pick */
+     pRend->pickstr.more_hits = PEXNoMoreHits;
+ 
+ 
      /*
       * Reinitialize level 1 procedure jump table for PICKING !
       */
***************
*** 927,933 ****
      /* do double buffering stuff */
      /* do hlhsr stuff */
  
!     pRend->state = PEXRendering;
  
      return (Success);
  }
--- 1622,1628 ----
      /* do double buffering stuff */
      /* do hlhsr stuff */
  
!     pRend->state = PEXPicking;
  
      return (Success);
  }
***************
*** 951,961 ****
--- 1646,1679 ----
  {
  /* Locals */
        miDDContext      *pddc = (miDDContext *)(pRend->pDDContext);
+       ddPickPath        *strpp;
+       diStructHandle    sh = 0;
+       int		i;
  
+ 
  #ifdef DDTEST
      ErrorF( " EndPicking\n");
  #endif
  
+     if (pRend->immediateMode == TRUE) {
+ 	/*  empty listoflist for Pick All
+ 	   this assumes the individual pick paths lists that this
+ 	   pointed to have already been deleted by the EndPickAll routine 
+ 	*/
+ 	PU_EMPTY_LIST(pRend->pickstr.list);
+ 
+ 	/* free all but the first the fake structure
+ 	   it should always be there to support ROCs  
+ 	*/
+ 	strpp = (ddPickPath *)(pRend->pickstr.sIDlist)->pList;
+ 	for (i = 1; i < (pRend->pickstr.sIDlist)->numObj; i++) {
+ 	    sh = strpp[i].structure;
+ 	    DeleteStructure(sh, sh->id);    
+ 	}
+ 
+ 	(pRend->pickstr.sIDlist)->numObj = 1;
+     }
+ 
      pRend->state = PEXIdle;
  
      pRend->render_mode = MI_REND_DRAWING;
***************
*** 1021,1026 ****
--- 1739,1745 ----
      miDDContext		*pddc = (miDDContext *) pRend->pDDContext;
  
  	*pStatus = pddc->Static.pick.status;
+ 	pddc->Static.pick.status = PEXNoPick;
  	return;
  }
  #endif
*** -	Thu Jan 28 17:53:30 1993
--- mit/extensions/server/PEX/ddpex/mi/level3/Imakefile	Thu Jan 28 17:53:29 1993
***************
*** 1,5 ****
  XCOMM
! XCOMM $XConsortium: Imakefile,v 5.4 91/07/24 16:58:06 rws Exp $
  XCOMM
  XCOMM 
  XCOMM Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium
--- 1,5 ----
  XCOMM
! XCOMM $XConsortium: Imakefile,v 5.5 92/03/04 14:11:42 hersh Exp $
  XCOMM
  XCOMM 
  XCOMM Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium
***************
*** 46,54 ****
  	-I$(PEXSERVINC) \
  	-I$(SERVERSRC)/include
  
! SRCS = miRender.c 
  
! OBJS = miRender.o 
  
  NormalLibraryObjectRule()
  
--- 46,54 ----
  	-I$(PEXSERVINC) \
  	-I$(SERVERSRC)/include
  
! SRCS = miRender.c miRndrPick.c
  
! OBJS = miRender.o miRndrPick.o
  
  NormalLibraryObjectRule()
  
*** /dev/null	Thu Jan 28 17:53:30 1993
--- mit/extensions/server/PEX/ddpex/mi/level3/miRndrPick.c	Thu Jan 28 17:53:30 1993
***************
*** 0 ****
--- 1,483 ----
+ /* $XConsortium: miRndrPick.c,v 1.8 92/12/14 16:53:30 hersh Exp $ */
+ 
+ /************************************************************
+ Copyright 1992 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
+ docu- mentation, 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.
+ 
+ ******************************************************************/
+ 
+ #include "miLUT.h"
+ #include "ddpex3.h"
+ #include "PEXproto.h"
+ #include "PEXprotost.h"
+ #include "pexExtract.h"
+ #include "PEXErr.h"
+ #include "pexUtils.h"
+ #include "pixmap.h"
+ #include "windowstr.h"
+ #include "regionstr.h"
+ #include "miscstruct.h"
+ #include "miRender.h"
+ #include "miStruct.h"
+ #include "miStrMacro.h"
+ #include "miWks.h"
+ #include "ddpex4.h"
+ 
+ /* External variables used */
+ 
+ extern  void		mi_set_filters();
+ extern	void		miMatMult();
+ extern	ddpex3rtn	miBldViewport_xform();
+ extern	ddpex3rtn	miBldCC_xform();
+ extern	ocTableType	ParseOCTable[];
+ extern  void		(*DestroyOCTable[])();
+ extern  ocTableType	InitExecuteOCTable[];
+ extern  ocTableType	PickExecuteOCTable[];
+ extern  ocTableType	SearchExecuteOCTable[];
+ extern  RendTableType	RenderPrimitiveTable[];
+ extern  RendTableType	PickPrimitiveTable[];
+ 
+ 
+ /* Level III Renderer Pick Procedures */
+ 
+ /*++
+ |
+ |  Function Name:      CreatePseudoPickMeasure
+ |
+ |  Function Description:
+ |     Create a Pick Measure for Renderer Picking use 
+ |
+ |  Note(s):
+ |
+ --*/
+ 
+ ddpex3rtn
+ CreatePseudoPickMeasure( pRend)
+ ddRendererPtr       pRend;    /* renderer handle */
+ {
+     register miPickMeasureStr *ppm;
+ 
+     ppm = (miPickMeasureStr *) xalloc(sizeof(miPickMeasureStr));
+     if (!ppm) return (BadAlloc);
+ 
+     ppm->path = puCreateList(DD_PICK_PATH);
+     if (!ppm->path) {
+ 	xfree(ppm);
+ 	return (BadAlloc);
+     }
+ 
+     /* initialize pointers to NULL values */
+     ppm->pWks = 0;
+     /* initialize type to an out of range value */
+     ppm->type = -1;
+     ppm->status = PEXNoPick;
+     ppm->pathOrder = PEXTopFirst;
+     ppm->incl_handle = 0;
+     ppm->excl_handle = 0;
+     ppm->devPriv = (ddPointer) NULL;
+ 
+     (pRend->pickstr.pseudoPM)->deviceData = (ddPointer) ppm;
+     return(Success);
+ }
+ 
+ 
+ /*++
+ |
+ |  Function Name:      ChangePseudoPickMeasure
+ |
+ |  Function Description:
+ |     Change a Pick Measure for Renderer Picking use 
+ |
+ |  Note(s):
+ |
+ --*/
+ 
+ ddpex3rtn
+ ChangePseudoPickMeasure( pRend, pRec)
+ ddRendererPtr       pRend;    /* renderer handle */
+ ddPickRecord       *pRec;     /* PickRecord */
+ {
+     register miPickMeasureStr *ppm;
+     
+     ppm = (miPickMeasureStr *) (pRend->pickstr.pseudoPM)->deviceData;
+ 
+     if (!ppm->path) {
+ 	ppm->path = puCreateList(DD_PICK_PATH);
+ 	if (!ppm->path) {
+ 	    xfree(ppm);
+ 	    return (BadAlloc);
+ 	}
+     } else {
+ 	if (puCopyList(pRend->pickStartPath, ppm->path)) {
+ 	    puDeleteList(ppm->path);
+ 	    xfree(ppm);
+ 	    return (BadAlloc);
+ 	}
+     }
+     ppm->incl_handle = pRend->ns[DD_PICK_INCL_NS];
+     ppm->excl_handle = pRend->ns[DD_PICK_EXCL_NS];
+ 
+     if (ppm->incl_handle)
+ 	UpdateNSRefs(   ppm->incl_handle, (diResourceHandle) NULL,
+ 			PICK_RESOURCE, ADD);
+ 
+     if (ppm->excl_handle)
+ 	UpdateNSRefs(   ppm->excl_handle, (diResourceHandle) NULL,
+ 			PICK_RESOURCE, ADD);
+ 
+     /* now store the pick record */
+     ppm->type = pRec->pickType;
+     switch (ppm->type) {
+ 	case PEXPickDeviceDC_HitBox:
+ 	    bcopy((char *)&(pRec->hit_box.DC_HitBox), 
+ 	       	  (char *)&(ppm->input_rec.dc_hit_box), 
+ 		   sizeof(pexPD_DC_HitBox));
+             break;
+ 
+ 	case PEXPickDeviceNPC_HitVolume:
+ 	    bcopy((char *)&(pRec->hit_box.NPC_HitVolume), 
+ 	       	  (char *)&(ppm->input_rec.npc_hit_volume), 
+ 		   sizeof(pexPD_NPC_HitVolume));
+             break;
+     }
+ 
+ 
+     ppm->status = PEXNoPick;
+ 
+     return(Success);
+ }
+ 
+ ddpex3rtn
+ EndPickOne( pRend, pBuffer, numPickElRefs, pickStatus, betterPick)
+ /* in */
+ ddRendererPtr       pRend;    /* renderer handle */
+ /* out */
+ ddBufferPtr     pBuffer;    /* list of pick element ref */
+ ddULONG         *numPickElRefs;
+ ddUSHORT        *pickStatus;
+ ddUSHORT        *betterPick;
+ {
+     ddpex3rtn		err = Success;
+     miPickMeasureStr    *ppm;
+     int                 numbytes, i, j;
+     ddPickPath          *per;
+     pexPickElementRef   *dest;
+     ddPickPath          *sIDpp;
+ 
+     ppm = (miPickMeasureStr *) (pRend->pickstr.pseudoPM)->deviceData;
+     *numPickElRefs = 0;
+     *pickStatus = ppm->status;
+     *betterPick = 0;
+ 
+     if (ppm->status == PEXOk && ppm->path) {  /* we have a pick */
+ 
+ 	/* send back the number of objects */
+ 	*numPickElRefs = ppm->path->numObj;
+ 
+ 	/* Now, tack on the list of Element Refs to the back of the reply 
+ 	   Note that we do NOT include the length of the list. 
+ 	   The length is found in the reply itself. 
+ 	*/
+ 	numbytes = sizeof(ddPickPath) * ppm->path->numObj;
+ 
+ 	PU_CHECK_BUFFER_SIZE(pBuffer, numbytes); 
+ 	/* Copy the Pick Path to the buffer */
+ 	for (per = (ddPickPath*) ppm->path->pList,
+ 	     dest = (pexPickElementRef*) pBuffer->pBuf, i=0;
+ 	     i < ppm->path->numObj; per++, dest++, i++) {
+ 
+ 	     /* if returned structure handle is in the sIDlist
+ 	        then the pick was on a path below an immediate OC
+ 	        so return the struct id the user sent over in the BeginPick
+ 	        request, otherwise return the resource ID as normal
+ 	     */
+ 	     sIDpp = (ddPickPath *) (pRend->pickstr.sIDlist)->pList;
+ 	     for (j = 0; j < (pRend->pickstr.sIDlist)->numObj; j++, sIDpp++) {
+ 		if ((diStructHandle)(per->structure) == sIDpp->structure) {
+ 		    /* this is CORRECT, pickid is used to store the client
+ 		       provided structure id, yes it is a kludge...
+ 		    */
+ 		    dest->sid = sIDpp->pickid;
+ 		    break;
+ 		}
+ 		else
+ 		  dest->sid = ((ddStructResource*)(per->structure))->id;
+ 	     }
+ 	    dest->offset = per->offset;
+ 	    dest->pickid = per->pickid;
+ 	}
+ 
+ 	pBuffer->dataSize = numbytes; /* tells dipex how long the reply is  */
+     }
+ 
+     if (ppm->path) {
+ 	puDeleteList(ppm->path); 
+ 	ppm->path = NULL; 
+     }
+ 
+   return(err);
+ }
+ 
+ 
+ ddpex3rtn
+ PickOne( pRend)
+ /* in */
+ ddRendererPtr       pRend;    /* renderer handle */
+ {
+     ddpex3rtn		err = Success;
+     ddElementRange      range;
+     miStructPtr         pstruct;
+     miTraverserState    trav_state;
+     diPMHandle          pPM = (diPMHandle) NULL;
+     ddULONG            	offset1, offset2;
+     diStructHandle 	psh = pRend->pickstr.strHandle;
+ 
+ 
+    pstruct = (miStructPtr) (pRend->pickstr.strHandle)->deviceData;
+ 
+ 
+     /* now call the traverser to traverse this structure */
+     /* set exec_str_flag */
+     trav_state.exec_str_flag = ES_YES;
+     trav_state.p_curr_pick_el = (ddPickPath *) NULL;
+     trav_state.p_curr_sc_el = (ddElementRef *) NULL;
+     trav_state.max_depth = 0;
+     trav_state.pickId = 0;
+     trav_state.ROCoffset = 0;
+     pPM = pRend->pickstr.pseudoPM;
+ 
+     offset1 = 1;
+     offset2 =  MISTR_NUM_EL(pstruct);
+ 
+     err = traverser(pRend, psh, offset1, offset2, pPM, NULL, &trav_state);
+ 
+   return(err);
+ }
+ 
+ ddpex3rtn
+ EndPickAll( pRend, pBuffer)
+ /* in */
+ ddRendererPtr       pRend;    /* renderer handle */
+ /* out */
+ ddBufferPtr     pBuffer;    /* list of pick element ref */
+ {
+     ddpex3rtn		err = Success;
+ 
+     pexEndPickAllReply	*reply = (pexEndPickAllReply *)(pBuffer->pHead);
+     int 		i, j, k, numbytes = 0, pbytes, numObj; 
+     listofObj		*list;
+     listofObj		**listofp;
+     ddPickPath		*pp, *sIDpp;
+     ddPointer		pplist;
+     ddPickElementRef	ref;
+ 
+     reply->numPicked = (pRend->pickstr.list)->numObj;
+     reply->pickStatus = ((pRend->pickstr.list)->numObj) ?1:0;
+     reply->morePicks = pRend->pickstr.more_hits;
+ 
+     numObj = (pRend->pickstr.list)->numObj;
+     listofp = (listofObj **)(pRend->pickstr.list)->pList;
+ 
+     /* convert the pick path to a pick element ref for return */
+     for (i = 0; i < numObj; i++) {
+ 	list = listofp[0];
+ 	pbytes = list->numObj * sizeof(ddPickElementRef);
+ 	numbytes += pbytes + sizeof(CARD32);
+ 	PU_CHECK_BUFFER_SIZE(pBuffer, numbytes);
+ 	PACK_CARD32(list->numObj,  pBuffer->pBuf);
+ 	pplist = list->pList;
+ 
+ 	/* now convert each pick path to a pick element ref */
+ 	/* and pack it into the reply buffer */
+ 	for (j = 0; j < list->numObj; j++) {
+ 	  pp = (ddPickPath *) pplist;
+ 	  pplist = (ddPointer)(pp+1);
+ 	  sIDpp = (ddPickPath *) (pRend->pickstr.sIDlist)->pList;
+ 	  for (k = 0; k < (pRend->pickstr.sIDlist)->numObj; k++, sIDpp++) {
+ 	    if ((diStructHandle)(pp->structure) == sIDpp->structure) {
+ 		/* this is CORRECT, pickid is used to store the client
+ 		   provided structure id, yes it is a kludge...
+ 		*/
+ 		ref.sid = sIDpp->pickid;
+ 		break;
+ 	    }
+ 	    else
+ 		ref.sid = ((ddStructResource *)(pp->structure))->id;
+ 	  }
+ 	  ref.offset = pp->offset;
+ 	  ref.pickid = pp->pickid;
+ 	  PACK_STRUCT(ddPickElementRef, &ref, pBuffer->pBuf);
+ 	}
+ 
+ 	/* remove the list from the list of list */
+ 	puRemoveFromList( (ddPointer) &list, pRend->pickstr.list);
+ 
+ 	/* if there are more hits when doing a server side pick all
+ 	   save the last hit into the start path 
+ 	*/
+ 	if ((pRend->pickstr.more_hits == PEXMoreHits) && (i == numObj-1)
+ 	    && (pRend->pickstr.server == DD_SERVER)) 
+ 	    pRend->pickStartPath = list;
+ 	else 
+ 	    puDeleteList( list);
+ 	
+     }
+ 
+     /* if there were no more hits empty the pickStartPath */
+     if (pRend->pickstr.more_hits == PEXNoMoreHits) {
+ 	PU_EMPTY_LIST(pRend->pickStartPath);
+     }
+ 
+     pRend->pickstr.more_hits = PEXNoMoreHits;
+     pBuffer->dataSize = numbytes;
+ 
+ 
+   return(err);
+ }
+ 
+ 
+ ddpex3rtn
+ PickAll( pRend)
+ /* in */
+ ddRendererPtr       pRend;    /* renderer handle */
+ {
+     ddpex3rtn			err = Success;
+     miTraverserState      	trav_state;
+     ddULONG            		offset1, offset2, numberOCs;
+     diStructHandle 		pstruct = 0;
+     miStructPtr 		pheader;
+     ddPickPath			*pp;
+     diPMHandle            	pPM = (diPMHandle) NULL;
+     ddpex3rtn 			ValidatePickPath();
+ 
+     if (!pRend->pickStartPath)  return (PEXERR(PEXPathError));
+     err = ValidatePickPath(pRend->pickStartPath);
+     if (err != Success) return(err);
+ 
+     /* now call the traverser to traverse this structure */
+     /* set exec_str_flag */
+     trav_state.exec_str_flag = ES_FOLLOW_PICK;
+     trav_state.p_curr_pick_el = (ddPickPath *) pRend->pickStartPath->pList ;
+     trav_state.p_curr_sc_el = (ddElementRef *) NULL;
+     trav_state.max_depth = 0;
+     trav_state.pickId = 0;
+     trav_state.ROCoffset = 0;
+     pPM = pRend->pickstr.pseudoPM;
+ 
+     pp = (ddPickPath *) pRend->pickStartPath->pList ;
+     pstruct = pp->structure;
+     pheader = (miStructPtr) pstruct->deviceData;
+ 
+     offset1 = 1;
+     offset2 =  MISTR_NUM_EL(pheader);
+ 
+     err = traverser(pRend, pstruct, offset1, offset2, pPM, NULL, &trav_state);
+ 
+   return(err);
+ }
+ 
+ ddpex3rtn
+ AddPickPathToList( pRend, depth, path)
+ ddRendererPtr		pRend;		/* renderer handle */
+ int			depth;		/* pick path depth */
+ miPPLevel		*path;		/* the path 	   */
+ {
+     listofObj		*list;
+     int 		i, err;
+     ddPickPath		*patharray;
+ 
+ 
+     /* dont know what this is supposed to do */
+     if ((pRend->pickstr.list)->numObj >= pRend->pickstr.max_hits) {
+ 	pRend->pickstr.more_hits = PEXMoreHits;
+ 	return;
+     }
+     else pRend->pickstr.more_hits = PEXNoMoreHits;
+ 
+     /* allocate space to store path while reversing */
+     patharray = (ddPickPath *)  xalloc(depth * sizeof(ddPickPath));
+ 
+     /* create list to place the path into */
+     list = puCreateList(DD_PICK_PATH);
+ 
+     /* traverse the list from bottom up and copy into temp store */
+     for (i = 0; i < depth; i++){
+ 	patharray[i] = path->pp;	
+ 	path = path->up;
+     }
+ 
+     /* now store the path from top down */
+     for (i = depth-1; i >= 0; i--){
+ 	err = puAddToList((ddPointer) &patharray[i], (ddULONG) 1, list);
+ 	if (err != Success) return(err);
+     }
+ 
+     xfree(patharray);
+ 
+     err = puAddToList( (ddPointer) &list, (ddULONG) 1, pRend->pickstr.list);
+     if (err != Success) return(err);
+ 
+     if ((pRend->pickstr.send_event) && 
+ 	((pRend->pickstr.list)->numObj == pRend->pickstr.max_hits))
+ 	err = PEXMaxHitsReachedNotify( pRend->pickstr.client, pRend->rendId);
+ 
+     return(err);
+ }
+ 
+ ddpex3rtn
+ ValidatePickPath(pPath)
+     listofObj      *pPath;
+ {
+     miGenericElementPtr p_element;
+     diStructHandle  pStruct, pNextStruct;
+     miStructPtr     pstruct;
+     ddULONG         offset;
+     int             i;
+     ddPickPath     *pPickPath;
+ 
+     
+     pPickPath = (ddPickPath *) pPath->pList;
+     pNextStruct = pPickPath->structure;
+ 
+     for (i = pPath->numObj; i > 0; i--, pPickPath++) {
+ 	pStruct = pPickPath->structure;
+ 	if (pNextStruct != pStruct) return (PEXERR(PEXPathError));
+ 
+ 	pstruct = (miStructPtr) pStruct->deviceData;
+ 
+ 	offset = pPickPath->offset;
+ 	if (offset > MISTR_NUM_EL(pstruct)) return (PEXERR(PEXPathError));
+ 
+ 	/* dont bother with the leaves */
+ 	if (i == 1) break;
+ 
+ 	MISTR_FIND_EL(pstruct, offset, p_element);
+ 
+ 	if (MISTR_EL_TYPE(p_element) != PEXOCExecuteStructure)
+ 	    return (PEXERR(PEXPathError));
+ 
+ 	pNextStruct = (diStructHandle) MISTR_GET_EXSTR_STR(p_element);
+     }
+     return (Success);
+ }
+ 
*** -	Thu Jan 28 17:53:37 1993
--- mit/extensions/server/PEX/ddpex/mi/level4/miPick.c	Thu Jan 28 17:53:37 1993
***************
*** 1,6 ****
! /* $XConsortium: miPick.c,v 5.1 91/02/16 09:56:00 rws Exp $ */
  
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
--- 1,7 ----
! /* $XConsortium: miPick.c,v 5.7 92/11/17 17:34:08 hersh Exp $ */
  
  
+ 
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
***************
*** 121,128 ****
      pbuf = pBuffer->pBuf;
  
      if (mask & PEXPDPickStatus) {
! 	PACK_CARD16(pPickDevice->status, pbuf);
! 	SKIP_PADDING(pbuf,2);
      }
  
      if (mask & PEXPDPickPath) {
--- 122,128 ----
      pbuf = pBuffer->pBuf;
  
      if (mask & PEXPDPickStatus) {
! 	PACK_CARD32(pPickDevice->status, pbuf);
      }
  
      if (mask & PEXPDPickPath) {
***************
*** 131,138 ****
      }
  
      if (mask & PEXPDPickPathOrder) {
! 	PACK_CARD16(pPickDevice->pathOrder, pbuf);
! 	SKIP_PADDING(pbuf,2);
      }
  
      if (mask & PEXPDPickIncl) {
--- 131,137 ----
      }
  
      if (mask & PEXPDPickPathOrder) {
! 	PACK_CARD32(pPickDevice->pathOrder, pbuf);
      }
  
      if (mask & PEXPDPickIncl) {
***************
*** 155,168 ****
  
      /*
       * no data recs are defined, so skip this - noone should expect to
!      * get data for this if (mask & PEXPDPickDataRec) switch (dev_index)
!      * { case 0: bcopy((char *) &(MIWKS_PICK_DATA_REC_1(pPickDevice)),
!      * (char *) pbuf, MIWKS_SIZE_DATA_REC_1); pbuf +=
!      * MIWKS_SIZE_DATA_REC_1; break; case 1: bcopy((char *)
!      * &(MIWKS_PICK_DATA_REC_2(pPickDevice)), (char *) pbuf,
!      * MIWKS_SIZE_DATA_REC_2); pbuf += MIWKS_SIZE_DATA_REC_2; break; }
!      * 
!      */
      if (mask & PEXPDPickPromptEchoType) {
  	PACK_CARD32(pPickDevice->pet, pbuf);
      }
--- 154,180 ----
  
      /*
       * no data recs are defined, so skip this - noone should expect to
!      * get data for this 
!     */
!      if (mask & PEXPDPickDataRec) {
! 	/* Sun says no data records defined, this is dummy code
! 	* switch (dev_index) { 
! 	*    case 0: bcopy((char *) &(MIWKS_PICK_DATA_REC_1(pPickDevice)),
! 	*		   (char *) pbuf, MIWKS_SIZE_DATA_REC_1); 
! 	*	     pbuf += MIWKS_SIZE_DATA_REC_1; 
! 	*	     break; 
! 	*    case 1: bcopy((char *) &(MIWKS_PICK_DATA_REC_2(pPickDevice)), 
! 	*		   (char *) pbuf, MIWKS_SIZE_DATA_REC_2); 
! 	*	     pbuf += MIWKS_SIZE_DATA_REC_2; 
! 	*	     break; 
! 	* }
! 	*/
! 	/* if for some reason this bitflag is set return length
! 	   of zero bytes
! 	*/
! 	PACK_CARD32(0,pbuf);
!      }
!        
      if (mask & PEXPDPickPromptEchoType) {
  	PACK_CARD32(pPickDevice->pet, pbuf);
      }
***************
*** 170,177 ****
  	PACK_STRUCT(ddViewport,&(pPickDevice->echoVolume),pbuf);
      }
      if (mask & PEXPDPickEchoSwitch) {
! 	PACK_CARD16(pPickDevice->echoSwitch,pbuf);
! 	SKIP_PADDING(pbuf,2);
      }
      return (Success);
  }				/* InquirePickDevice */
--- 182,188 ----
  	PACK_STRUCT(ddViewport,&(pPickDevice->echoVolume),pbuf);
      }
      if (mask & PEXPDPickEchoSwitch) {
! 	PACK_CARD32(pPickDevice->echoSwitch,pbuf);
      }
      return (Success);
  }				/* InquirePickDevice */
***************
*** 199,207 ****
      register ddPointer	pbuf;
      int			dev_index;
      miPickDevice	*pPickDevice;
!     ddUSHORT		pickStatus;
!     ddUSHORT		pickPathOrder;
!     ddUSHORT		pickEchoSwitch;
      ddULONG		numPickPath;
      ddpex4rtn		err;
      extern ddpex4rtn	ValidateStructurePath();
--- 210,219 ----
      register ddPointer	pbuf;
      int			dev_index;
      miPickDevice	*pPickDevice;
!     CARD16              pickStatus;
!     CARD16              pickPathOrder;
!     CARD16              pickEchoSwitch;
!     INT16               pickPromptEchoType;
      ddULONG		numPickPath;
      ddpex4rtn		err;
      extern ddpex4rtn	ValidateStructurePath();
***************
*** 219,228 ****
  
      /* go through and check for errors first */
      if (mask & PEXPDPickStatus) {
! 	EXTRACT_CARD16(pickStatus,pbuf);
  	if (!((pickStatus == PEXNoPick) || (pickStatus == PEXOk)))
  	    return (BadValue);
- 	SKIP_PADDING(pbuf,2);
      }
  
      if (mask & PEXPDPickPath) {
--- 231,239 ----
  
      /* go through and check for errors first */
      if (mask & PEXPDPickStatus) {
! 	EXTRACT_CARD16_FROM_4B(pickStatus,pbuf);
  	if (!((pickStatus == PEXNoPick) || (pickStatus == PEXOk)))
  	    return (BadValue);
      }
  
      if (mask & PEXPDPickPath) {
***************
*** 232,241 ****
      }
  
      if (mask & PEXPDPickPathOrder) {
! 	EXTRACT_CARD16(pickPathOrder,pbuf);
  	if (!((pickPathOrder == PEXTopFirst)||(pickPathOrder == PEXBottomFirst)))
  	    return (BadValue);
- 	SKIP_PADDING(pbuf,2);
      }
      if (mask & PEXPDPickIncl)
  	SKIP_PADDING(pbuf,4);
--- 243,251 ----
      }
  
      if (mask & PEXPDPickPathOrder) {
! 	EXTRACT_CARD16_FROM_4B(pickPathOrder,pbuf);
  	if (!((pickPathOrder == PEXTopFirst)||(pickPathOrder == PEXBottomFirst)))
  	    return (BadValue);
      }
      if (mask & PEXPDPickIncl)
  	SKIP_PADDING(pbuf,4);
***************
*** 244,255 ****
  	SKIP_PADDING(pbuf,4);
  
      /*
!      * no data recs are defined, so skip this - there'd better not be any
!      * data there for these if (mask & PEXPDPickDataRec)
       */
  
      if (mask & PEXPDPickPromptEchoType) {
! 	switch (*(ddSHORT *) pbuf) {
  	    case PEXEchoPrimitive:
  	    case PEXEchoStructure:
  	    case PEXEchoNetwork:
--- 254,271 ----
  	SKIP_PADDING(pbuf,4);
  
      /*
!      * no data recs are defined, so skip the bytes if they're there  
       */
+      if (mask & PEXPDPickDataRec) {
+ 	CARD32 i, skip;
+ 	EXTRACT_CARD32(i,pbuf);
+ 	skip = (i+3)/4;
+ 	SKIP_PADDING(pbuf,skip);
+      }
  
      if (mask & PEXPDPickPromptEchoType) {
! 	EXTRACT_INT16_FROM_4B(pickPromptEchoType,pbuf);
! 	switch (pickPromptEchoType) {
  	    case PEXEchoPrimitive:
  	    case PEXEchoStructure:
  	    case PEXEchoNetwork:
***************
*** 257,263 ****
  	    default:
  		return (BadValue);
  	}
- 	SKIP_PADDING(pbuf,4);
      }
  
      if (mask & PEXPDPickEchoVolume)
--- 273,278 ----
***************
*** 264,270 ****
  	SKIP_PADDING(pbuf,sizeof(ddViewport));
  
      if (mask & PEXPDPickEchoSwitch) {
! 	EXTRACT_CARD16(pickEchoSwitch,pbuf);
  	if (!((pickEchoSwitch == PEXOff) || (pickEchoSwitch == PEXOn)))
  	    return (BadValue);
      }
--- 279,285 ----
  	SKIP_PADDING(pbuf,sizeof(ddViewport));
  
      if (mask & PEXPDPickEchoSwitch) {
! 	EXTRACT_CARD16_FROM_4B(pickEchoSwitch,pbuf);
  	if (!((pickEchoSwitch == PEXOff) || (pickEchoSwitch == PEXOn)))
  	    return (BadValue);
      }
***************
*** 343,359 ****
  
      /*
       * no data recs are defined, so skip this - there'd better not be any
!      * data there for these if (mask & PEXPDPickDataRec) { switch
!      * (dev_index) { case 0: bcopy((char *) pbuf, (char *)
!      * &(MIWKS_PICK_DATA_REC_1(pPickDevice)), MIWKS_SIZE_DATA_REC_1);
!      * pbuf += MIWKS_SIZE_DATA_REC_1; break; case 1: bcopy((char *) pbuf,
!      * (char *) &(MIWKS_PICK_DATA_REC_2(pPickDevice)),
!      * MIWKS_SIZE_DATA_REC_2); pbuf += MIWKS_SIZE_DATA_REC_2; break; } }
!      */
  
      if (mask & PEXPDPickPromptEchoType) {
! 	EXTRACT_CARD16(pPickDevice->pet,pbuf);
! 	SKIP_PADDING(pbuf,2);
      }
  
      if (mask & PEXPDPickEchoVolume) {
--- 358,384 ----
  
      /*
       * no data recs are defined, so skip this - there'd better not be any
!      * data there for these 
!     */
!      if (mask & PEXPDPickDataRec) { 
! 	/* This is dummy code from Sun, 
! 	 * I am adding code to skip bytes if present - JSH 
! 	 * switch (dev_index) { case 0: bcopy((char *) pbuf, (char *)
! 	 * &(MIWKS_PICK_DATA_REC_1(pPickDevice)), MIWKS_SIZE_DATA_REC_1);
! 	 * pbuf += MIWKS_SIZE_DATA_REC_1; break; case 1: bcopy((char *) pbuf,
! 	 * (char *) &(MIWKS_PICK_DATA_REC_2(pPickDevice)),
! 	 * MIWKS_SIZE_DATA_REC_2); pbuf += MIWKS_SIZE_DATA_REC_2; break; } 
! 	*/
  
+ 	CARD32 i, skip;
+ 	EXTRACT_CARD32(i,pbuf);
+ 	skip = (i+3)/4;
+ 	SKIP_PADDING(pbuf,skip);
+     }
+ 
      if (mask & PEXPDPickPromptEchoType) {
! 	pPickDevice->pet = pickPromptEchoType;
! 	SKIP_PADDING(pbuf,4);
      }
  
      if (mask & PEXPDPickEchoVolume) {
***************
*** 396,403 ****
      ddULONG		    start_el;
      ddULONG		    num_els;
      ddpex4rtn		    err;
-     listofObj		    *start_path;
-     extern ddpex3rtn BeginPicking();
      extern ddpex3rtn EndPicking();
      extern ddpex4rtn traverser();
  
--- 421,426 ----
***************
*** 422,456 ****
  	}
      ppm->status = PEXNoPick;
  
!     if (ppm->path->numObj)	{	/* there's a start path */
! 	trav_state.exec_str_flag = ES_FOLLOW_PICK;
! 	trav_state.p_curr_pick_el = (ddPickPath *) ppm->path->pList;
! 	trav_state.p_curr_sc_el = (ddElementRef *) NULL;
! 	/* set to follow start path */
! 	pos = NULL;
! 	pstr = (diStructHandle) trav_state.p_curr_pick_el->structure;
! 	start_el = 1;
! 	num_els = MISTR_NUM_EL((miStructPtr) pstr->deviceData);
!     } else {
! 	trav_state.exec_str_flag = ES_YES;
! 	trav_state.p_curr_pick_el = (ddPickPath *) NULL;
! 	trav_state.p_curr_sc_el = (ddElementRef *) NULL;
! 	/* set to traverse all posted structs */
! 	pos = pwks->postedStructs.postruct;
! 	pos = pos->next;
! 	pstr = pos->pstruct;
! 	start_el = 1;
! 	num_els = MISTR_NUM_EL((miStructPtr) pstr->deviceData);
!     }
  
-     /* before starting pick, copy start path and save it for later
-      * the new pick path will replace it
-      */
-     start_path = puCreateList( DD_PICK_PATH );
-     if (!start_path) 
- 	return (BadAlloc);
-     
-     puCopyList( ppm->path, start_path );
  
      BeginPicking(pwks->pRend, pPM);
  
--- 445,460 ----
  	}
      ppm->status = PEXNoPick;
  
!     trav_state.exec_str_flag = ES_YES;
!     trav_state.p_curr_pick_el = (ddPickPath *) NULL;
!     trav_state.p_curr_sc_el = (ddElementRef *) NULL;
!     /* set to traverse all posted structs */
!     pos = pwks->postedStructs.postruct;
!     pos = pos->next;
!     pstr = pos->pstruct;
!     start_el = 1;
!     num_els = MISTR_NUM_EL((miStructPtr) pstr->deviceData);
  
  
      BeginPicking(pwks->pRend, pPM);
  
***************
*** 459,464 ****
--- 463,470 ----
  	/* reset for each structure */
  	trav_state.max_depth = 0;
  	trav_state.pickId = 0;
+         trav_state.ROCoffset =  0;
+ 
  	if (MISTR_NUM_EL((miStructPtr) pstr->deviceData)) {
  	    BeginStructure(pwks->pRend, pstr->id);
  
***************
*** 467,484 ****
  
  	    EndStructure(pwks->pRend);
  	}
! 	if (pos) pos = pos->next;
! 	if ((err != Success) || (trav_state.exec_str_flag == ES_POP))
! 	    /* pop after a successful pick */
! 	    break;
      } while (pos);
  
      EndPicking(pwks->pRend);
  
!     if (err == Success ) {
!     /* now, update the structure ref counts */
!         path_update_struct_refs(start_path, (diResourceHandle) NULL,
! 				PICK_RESOURCE, REMOVE);
          path_update_struct_refs(ppm->path, (diResourceHandle) NULL,
  				PICK_RESOURCE, ADD);
      } else {
--- 473,489 ----
  
  	    EndStructure(pwks->pRend);
  	}
! 	if (pos)
! 	    if (pos = pos->next) {
! 	    	pstr = pos->pstruct;
! 	    	num_els = MISTR_NUM_EL((miStructPtr) pstr->deviceData);
! 		}
      } while (pos);
  
      EndPicking(pwks->pRend);
  
!     if (ppm->status == PEXOk) {
!       /* now, update the structure ref counts */
          path_update_struct_refs(ppm->path, (diResourceHandle) NULL,
  				PICK_RESOURCE, ADD);
      } else {
***************
*** 486,492 ****
  	return(err);
      }
  
-     puDeleteList( start_path );
      return (Success);
  }				/* UpdatePickMeasure */
  
--- 491,496 ----
***************
*** 599,609 ****
      if (ppm->devPriv) xfree(ppm->devPriv);
  
      /* go through the path and update the structures' ref. count */
!     path_update_struct_refs(	ppm->path, (diResourceHandle) NULL,
! 				PICK_RESOURCE, REMOVE);
  
      if (ppm->path) puDeleteList(ppm->path);
  
      UpdateWksRefs(ppm->pWks, (diResourceHandle) ppm, PICK_RESOURCE, REMOVE);
  
      if (ppm->incl_handle)
--- 603,614 ----
      if (ppm->devPriv) xfree(ppm->devPriv);
  
      /* go through the path and update the structures' ref. count */
!     if (ppm->path) path_update_struct_refs( ppm->path, (diResourceHandle) NULL,
! 					    PICK_RESOURCE, REMOVE);
  
      if (ppm->path) puDeleteList(ppm->path);
  
+     if (ppm->pWks)
      UpdateWksRefs(ppm->pWks, (diResourceHandle) ppm, PICK_RESOURCE, REMOVE);
  
      if (ppm->incl_handle)
***************
*** 660,667 ****
      pbuf = pBuffer->pBuf;
  
      if (itemMask & PEXPMStatus) {
! 	PACK_CARD16(ppm->status,pbuf);
! 	SKIP_PADDING(pbuf,2);
      }
      if (itemMask & PEXPMPath) {
  	PACK_CARD32(ppm->path->numObj,pbuf);
--- 665,671 ----
      pbuf = pBuffer->pBuf;
  
      if (itemMask & PEXPMStatus) {
! 	PACK_CARD32(ppm->status,pbuf);
      }
      if (itemMask & PEXPMPath) {
  	PACK_CARD32(ppm->path->numObj,pbuf);
*** -	Thu Jan 28 17:53:39 1993
--- mit/extensions/server/PEX/ddpex/mi/level4/miSC.c	Thu Jan 28 17:53:38 1993
***************
*** 1,4 ****
! /* $XConsortium: miSC.c,v 5.1 91/02/16 09:56:02 rws Exp $ */
  
  
  /***********************************************************
--- 1,4 ----
! /* $XConsortium: miSC.c,v 5.3 92/11/19 15:14:55 hersh Exp $ */
  
  
  /***********************************************************
***************
*** 73,78 ****
--- 73,80 ----
  	trav_state.p_curr_pick_el = (ddPickPath *) NULL;
  	trav_state.p_curr_sc_el = (ddElementRef *) pSC->startPath->pList;
  	trav_state.max_depth = 0;
+         trav_state.pickId = 0;
+         trav_state.ROCoffset =  0;
      } else
  	return (PEXERR(PEXPathError));
  
***************
*** 141,147 ****
  		return( BadAlloc );
  	}
  
! 	rend.immediateMode = 0;
  	/* InitRenderer does some stuff not needed for Searching
  	 * and since some of that stuff uses a drawable (and searching
  	 * doesn't have one), a work-aroundis put in around the drawable
--- 143,149 ----
  		return( BadAlloc );
  	}
  
! 	rend.immediateMode = FALSE;
  	/* InitRenderer does some stuff not needed for Searching
  	 * and since some of that stuff uses a drawable (and searching
  	 * doesn't have one), a work-aroundis put in around the drawable
*** -	Thu Jan 28 17:53:41 1993
--- mit/extensions/server/PEX/ddpex/mi/level4/miWks.c	Thu Jan 28 17:53:39 1993
***************
*** 1,4 ****
! /* $XConsortium: miWks.c,v 5.4 91/07/10 08:52:28 rws Exp $ */
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miWks.c,v 5.12 93/01/26 19:14:40 hersh Exp $ */
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 30,37 ****
--- 30,40 ----
  #include "miLUT.h"
  #include "pexUtils.h"
  #include "PEXErr.h"
+ #include "PEXprotost.h"
+ #include "pexExtract.h"
  #include "Xprotostr.h"
  #include "gcstruct.h"
+ #include "resource.h"
  
  /*  Level 4 Workstation Support */
  /* PHIGS Workstation Procedures */
***************
*** 105,110 ****
--- 108,211 ----
  	(((pws)->dynamics[(int)(dynamic)] == PEXIMM) ||		\
  		((pws)->displayUpdate == PEXVisualizeEach))
  
+ SetDoubleDrawable (pwks)
+ miWksPtr	pwks;
+ {
+      /* This routine sets the drawable pointer. It does this with or
+         without the MultiBuffer Extension
+      */
+  
+      if (pwks->hasDoubleBuffer) 
+      {
+  	/* If you have the Double Buffer do whats right for the update mode */
+  	switch (pwks->displayUpdate) {
+  	case PEXVisualizeEach:
+  	case PEXVisualizeWhenever:
+  	case PEXVisualizeNone:
+  	    pwks->pCurDrawable = pwks->doubleDrawables[pwks->curDoubleBuffer];
+  	    pwks->usingDoubleBuffer = MI_TRUE;
+  	    break;
+  	case PEXSimulateSome:
+  	case PEXVisualizeEasy:
+  	    pwks->pCurDrawable = pwks->pRend->pDrawable;
+  	    pwks->usingDoubleBuffer = MI_FALSE;
+  	    break;
+  	}
+      }
+      else 
+      {
+         /* No Double Buffer so use the renderers drawable */
+  	pwks->usingDoubleBuffer = MI_FALSE;
+  	pwks->pCurDrawable = pwks->pRend->pDrawable;
+      }
+ }
+  
+ ChangeDoubleBuffers (pwks)
+ miWksPtr	pwks;
+ {
+  
+      /* This routine does the actual work to create or delete the
+         Double Buffers. It is a no-op if there is no MultiBuffer
+         Extension, except it still has to SetDoubleBuffers to
+         insure the right drawable gets used
+      */
+  
+ #ifdef MULTIBUFFER
+  
+      if (pwks->curBufferMode == PEXDoubleBuffered && !pwks->hasDoubleBuffer)
+      {
+  	/* create the Double Buffers */
+  	int	i;
+  	int	client;
+  	int	result;
+  	XID	ids[2];
+  	extern DrawablePtr  GetBufferPointer ();
+  
+  	client = CLIENT_ID(pwks->pRend->pDrawable->id);
+  	for (i = 0; i < 2; i++)
+  	    ids[i] = FakeClientID (client);
+  	result = CreateImageBuffers (pwks->pRend->pDrawable, 2, ids,
+  			    MultibufferUpdateActionBackground,
+  			    MultibufferUpdateHintFrequent);
+  	if (result != Success)
+  	{
+  	    pwks->pCurDrawable = pwks->pRend->pDrawable;
+  	    return;
+  	}
+  	for (i = 0; i < 2; i++)
+  	    pwks->doubleDrawables[i] = GetBufferPointer (pwks->pRend->pDrawable, i);
+  	pwks->curDoubleBuffer = 1;
+  	pwks->hasDoubleBuffer = MI_TRUE;
+      }
+      else if (pwks->curBufferMode == PEXSingleBuffered && pwks->hasDoubleBuffer)
+      {
+  	/* Destroy the Double Buffers */
+  	DestroyImageBuffers (pwks->pRend->pDrawable);
+  	pwks->hasDoubleBuffer = MI_FALSE;
+      }
+ #endif
+  
+      /* With or Without MultiBuffer Call this to set the Drawable Pointer */
+      SetDoubleDrawable (pwks);
+ }
+  
+ SwapDoubleBuffers (pwks)
+ miWksPtr	pwks;
+ {
+      int	    i;
+  
+      /* This one swaps the buffers, a no-op if no MultiBuffer Extension */
+  
+ #ifdef MULTIBUFFER
+      if (pwks->usingDoubleBuffer)
+      {
+  	DisplayImageBuffers (&pwks->pCurDrawable->id, 1);
+  	pwks->curDoubleBuffer ^= 1;
+  	pwks->pCurDrawable = pwks->doubleDrawables[pwks->curDoubleBuffer];
+      }
+ #endif
+ }
+  
  
  
  /*++
***************
*** 280,286 ****
--- 381,391 ----
  	MIWKS_SETNS(pInitInfo->pHighExclSet, prend->ns[(int) DD_HIGH_EXCL_NS], pWKS);
  	MIWKS_SETNS(pInitInfo->pInvisInclSet, prend->ns[(int) DD_INVIS_INCL_NS], pWKS);
  	MIWKS_SETNS(pInitInfo->pInvisExclSet, prend->ns[(int) DD_INVIS_EXCL_NS], pWKS);
+         /* These are for Renderer Picking, not used for Wks */
+         MIWKS_SETNS(0, prend->ns[(int) DD_PICK_INCL_NS], pWKS);
+         MIWKS_SETNS(0, prend->ns[(int) DD_PICK_EXCL_NS], pWKS);
  
+ 
  	prend->hlhsrMode = PEXHlhsrOff;
  	prend->npcSubvolume = NPCInit;
  
***************
*** 298,307 ****
  	prend->tablesChanges = 0;
  	prend->namesetsChanges = 0;
  	prend->attrsChanges = 0;
! 	prend->immediateMode = MI_FALSE;
  
  	prend->pDDContext = NULL;
  
  	pwks->displayUpdate = PEXVisualizeEach;
  	pwks->visualState = PEXCorrect;
  	pwks->displaySurface = PEXEmpty;
--- 403,422 ----
  	prend->tablesChanges = 0;
  	prend->namesetsChanges = 0;
  	prend->attrsChanges = 0;
! 	prend->immediateMode = FALSE;
  
  	prend->pDDContext = NULL;
  
+ 	/* new flags added for 5.1 need to be initialized */
+ 	prend->backgroundColour.colourType = PEXIndexedColour;
+ 	prend->backgroundColour.colour.indexed.index = 0;
+ 	prend->clearI = FALSE;
+ 	prend->clearZ = TRUE;
+ 	prend->echoMode = PEXNoEcho;
+ 	prend->echoColour.colourType = PEXIndexedColour;
+ 	prend->echoColour.colour.indexed.index = 0;
+ 
+ 
  	pwks->displayUpdate = PEXVisualizeEach;
  	pwks->visualState = PEXCorrect;
  	pwks->displaySurface = PEXEmpty;
***************
*** 309,318 ****
--- 424,435 ----
  	pwks->deltaviewMask = 0;
  	pwks->wksUpdate = PEXNotPending;
  	pwks->wksMask = 0;
+ 
  	pwks->hlhsrUpdate = PEXNotPending;
  
  	pwks->bufferUpdate = PEXNotPending;
  	pwks->curBufferMode = pwks->reqBufferMode = pInitInfo->bufferMode;
+         pwks->hasDoubleBuffer = MI_FALSE;
  
  	pwks->reqNpcSubvolume = NPCInit;
  
***************
*** 412,417 ****
--- 529,539 ----
  	}
  
  
+         /* do stuff here to set up hlhsr mode */
+ 
+         /* do stuff here to set up buffer mode */
+         ChangeDoubleBuffers (pwks);
+ 
  	return (Success);
  }				/* CreatePhigsWks */
  
***************
*** 665,856 ****
  
  	/* return the info in the format encoded for the reply */
  
! 	/*
! 	 * mibcopy copies the correct size of the info into the buffer then any
! 	 * unused bytes are skipped
  	 */
  	WKS_CHECK_BITMASK(PEXPWDisplayUpdate) {
! 		mibcopy(&(pwks->displayUpdate), pbyte, sshort);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWVisualState) {
! 		mibcopy(&(pwks->visualState), pbyte, sbyte);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWDisplaySurface) {
! 		mibcopy(&(pwks->displaySurface), pbyte, sbyte);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWViewUpdate) {
! 		mibcopy(&(pwks->viewUpdate), pbyte, sbyte);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWDefinedViews) {
  		/* returns in order, highest priority view first */
  		ddOrdView      *indexer;
  
- 		mibcopy(&(pwks->views.defined_views), pbyte, sulong);
  		(*pNumValues) += pwks->views.defined_views;
! 		pbyte += 4;
  		indexer = pwks->views.highest;
  		do {
  			if (indexer->defined) {
! 				mibcopy(&indexer->first_view, pbyte, sushort);
! 				pbyte += 4;
  			}
  			indexer = indexer->lower;
  		} while (indexer != NULL);
  	}
  	WKS_CHECK_BITMASK(PEXPWWksUpdate) {
! 		mibcopy(&(pwks->wksUpdate), pbyte, sbyte);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWReqNpcSubvolume) {
! 		mibcopy(&(pwks->reqNpcSubvolume), pbyte, spexNpcSubvolume);
! 		pbyte += 24;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWCurNpcSubvolume) {
! 		mibcopy(&(pwks->pRend->npcSubvolume), pbyte, spexNpcSubvolume);
! 		pbyte += 24;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWReqWksViewport) {
! 		mibcopy(&(pwks->reqviewport), pbyte, spexViewport);
! 		pbyte += 20;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWCurWksViewport) {
! 		mibcopy(&(pwks->pRend->viewport), pbyte, spexViewport);
! 		pbyte += 20;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWHlhsrUpdate) {
! 		mibcopy(&(pwks->hlhsrUpdate), pbyte, sbyte);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWReqHlhsrMode) {
! 		mibcopy(&(pwks->reqhlhsrMode), pbyte, sshort);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWCurHlhsrMode) {
! 		mibcopy(&(pwks->pRend->hlhsrMode), pbyte, sshort);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWDrawable) {
! 		mibcopy(&(pwks->pRend->drawableId), pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWMarkerBundle) {
! 		mibcopy((PLUTID(pwks->pRend->lut[PEXMarkerBundleLUT])),
! 		      pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWTextBundle) {
! 		mibcopy((PLUTID(pwks->pRend->lut[PEXTextBundleLUT])),
! 		      pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWLineBundle) {
! 		mibcopy((PLUTID(pwks->pRend->lut[PEXLineBundleLUT])),
! 		      pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWInteriorBundle) {
! 		mibcopy((PLUTID(pwks->pRend->lut[PEXInteriorBundleLUT])),
! 		      pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWEdgeBundle) {
! 		mibcopy((PLUTID(pwks->pRend->lut[PEXEdgeBundleLUT])),
! 		      pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWColourTable) {
! 		mibcopy((PLUTID(pwks->pRend->lut[PEXColourLUT])),
! 		      pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWDepthCueTable) {
! 		mibcopy((PLUTID(pwks->pRend->lut[PEXDepthCueLUT])),
! 		      pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWLightTable) {
! 		mibcopy((PLUTID(pwks->pRend->lut[PEXLightLUT])),
! 		      pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWColourApproxTable) {
! 		mibcopy((PLUTID(pwks->pRend->lut[PEXColourApproxLUT])),
! 		      pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWPatternTable) {
! 		mibcopy((PLUTID(pwks->pRend->lut[PEXPatternLUT])),
! 		      pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWTextFontTable) {
! 		mibcopy((PLUTID(pwks->pRend->lut[PEXTextFontLUT])),
! 		      pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWHighlightIncl) {
! 		mibcopy((PNSID(pwks->pRend->ns[(int) DD_HIGH_INCL_NS])),
! 		      pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWHighlightExcl) {
! 		mibcopy((PNSID(pwks->pRend->ns[(int) DD_HIGH_EXCL_NS])),
! 		      pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWInvisibilityIncl) {
! 		mibcopy((PNSID(pwks->pRend->ns[(int) DD_INVIS_INCL_NS])),
! 		      pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWInvisibilityExcl) {
! 		mibcopy((PNSID(pwks->pRend->ns[(int) DD_INVIS_EXCL_NS])),
! 		      pbyte, sulong);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWPostedStructures) {
  		register ddOrdStruct *pos;
  
! 		mibcopy(&(pwks->postedStructs.numStructs), pbyte, sulong);
! 		pbyte += 4;
  		pos = pwks->postedStructs.postruct;
  		while (pos->next) {
! 			mibcopy(&(pos->next->pstruct->id), pbyte, sulong);
! 			pbyte += 4;
! 			mibcopy(&(pos->next->priority), pbyte, sfloat);
! 			pbyte += 4;
  			pos = pos->next;
  		}
  		(*pNumValues)++;
--- 787,931 ----
  
  	/* return the info in the format encoded for the reply */
  
! 	/*  
! 	  Took out the micopy usage cause it was a real brain dead way 
! 	  to do this. Note that this stuff NEVER checks the buffer size, 
! 	  maybe I'll add this someday  - JSH
  	 */
  	WKS_CHECK_BITMASK(PEXPWDisplayUpdate) {
! 	      PACK_CARD32(pwks->displayUpdate, pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWVisualState) {
! 	      PACK_CARD32(pwks->visualState, pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWDisplaySurface) {
! 	      PACK_CARD32(pwks->displaySurface, pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWViewUpdate) {
! 	      PACK_CARD32(pwks->viewUpdate, pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWDefinedViews) {
  		/* returns in order, highest priority view first */
  		ddOrdView      *indexer;
  
  		(*pNumValues) += pwks->views.defined_views;
! 		PACK_CARD32(pwks->views.defined_views, pbyte);
  		indexer = pwks->views.highest;
  		do {
  			if (indexer->defined) {
! 			      PACK_CARD32(indexer->first_view, pbyte);
  			}
  			indexer = indexer->lower;
  		} while (indexer != NULL);
  	}
  	WKS_CHECK_BITMASK(PEXPWWksUpdate) {
! 	      PACK_CARD32(pwks->wksUpdate, pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWReqNpcSubvolume) {
! 	      PACK_STRUCT(ddNpcSubvolume, &(pwks->reqNpcSubvolume), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWCurNpcSubvolume) {
! 	      PACK_STRUCT(ddNpcSubvolume, &(pwks->pRend->npcSubvolume), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWReqWksViewport) {
! 	      PACK_STRUCT(ddViewport, &(pwks->reqviewport), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWCurWksViewport) {
! 	      PACK_STRUCT(ddViewport, &(pwks->pRend->viewport), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWHlhsrUpdate) {
! 	      PACK_CARD32(pwks->hlhsrUpdate, pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWReqHlhsrMode) {
! 	      PACK_CARD32(pwks->reqhlhsrMode, pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWCurHlhsrMode) {
! 	      PACK_CARD32(pwks->pRend->hlhsrMode, pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWDrawable) {
! 	      PACK_CARD32(pwks->pRend->drawableId, pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWMarkerBundle) {
! 	      PACK_CARD32(*(PLUTID(pwks->pRend->lut[PEXMarkerBundleLUT])), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWTextBundle) {
! 	      PACK_CARD32(*(PLUTID(pwks->pRend->lut[PEXTextBundleLUT])), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWLineBundle) {
! 	      PACK_CARD32(*(PLUTID(pwks->pRend->lut[PEXLineBundleLUT])), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWInteriorBundle) {
! 	      PACK_CARD32(*(PLUTID(pwks->pRend->lut[PEXInteriorBundleLUT])), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWEdgeBundle) {
! 	      PACK_CARD32(*(PLUTID(pwks->pRend->lut[PEXEdgeBundleLUT])), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWColourTable) {
! 	      PACK_CARD32(*(PLUTID(pwks->pRend->lut[PEXColourLUT])), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWDepthCueTable) {
! 	      PACK_CARD32(*(PLUTID(pwks->pRend->lut[PEXDepthCueLUT])), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWLightTable) {
! 	      PACK_CARD32(*(PLUTID(pwks->pRend->lut[PEXLightLUT])), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWColourApproxTable) {
! 	      PACK_CARD32(*(PLUTID(pwks->pRend->lut[PEXColourApproxLUT])), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWPatternTable) {
! 	      PACK_CARD32(*(PLUTID(pwks->pRend->lut[PEXPatternLUT])), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWTextFontTable) {
! 	      PACK_CARD32(*(PLUTID(pwks->pRend->lut[PEXTextFontLUT])), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWHighlightIncl) {
! 	      PACK_CARD32(*(PNSID(pwks->pRend->ns[(int) DD_HIGH_INCL_NS])), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWHighlightExcl) {
! 	      PACK_CARD32(*(PNSID(pwks->pRend->ns[(int) DD_HIGH_EXCL_NS])), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWInvisibilityIncl) {
! 	      PACK_CARD32(*(PNSID(pwks->pRend->ns[(int) DD_INVIS_INCL_NS])), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWInvisibilityExcl) {
! 	      PACK_CARD32(*(PNSID(pwks->pRend->ns[(int) DD_INVIS_EXCL_NS])), pbyte);
! 	      (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWPostedStructures) {
  		register ddOrdStruct *pos;
  
! 		PACK_CARD32(pwks->postedStructs.numStructs, pbyte);
  		pos = pwks->postedStructs.postruct;
  		while (pos->next) {
! 			PACK_CARD32(pos->next->pstruct->id, pbyte);
! 			PACK_FLOAT(pos->next->priority, pbyte);
  			pos = pos->next;
  		}
  		(*pNumValues)++;
***************
*** 861,889 ****
  		 * return 0 for now - should implement num_priorities as part
  		 * of the wks
  		 */
! 		*pbyte++ = 0;
! 		*pbyte++ = 0;
! 		*pbyte++ = 0;
! 		*pbyte++ = 0;
  		(*pNumValues)++;
  	}
  
          WKS_CHECK_BITMASK( PEXPWBufferUpdate )
          {
! 	    mibcopy(&(pwks->bufferUpdate), pbyte, sbyte);
! 	    pbyte += 4;
  	    (*pNumValues)++;
          }
  
  	WKS_CHECK_BITMASK(PEXPWReqBufferMode) {
! 		mibcopy(&(pwks->reqBufferMode), pbyte, sshort);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWCurBufferMode) {
! 		mibcopy(&(pwks->curBufferMode), pbyte, sshort);
! 		pbyte += 4;
! 		(*pNumValues)++;
  	}
  	pBuffer->dataSize = needbytes;
  	ASSURE(needbytes == (pbyte - pBuffer->pBuf));
--- 936,958 ----
  		 * return 0 for now - should implement num_priorities as part
  		 * of the wks
  		 */
! 		PACK_CARD32( 0, pbyte);
  		(*pNumValues)++;
  	}
  
          WKS_CHECK_BITMASK( PEXPWBufferUpdate )
          {
! 	    PACK_CARD32( pwks->bufferUpdate, pbyte);
  	    (*pNumValues)++;
          }
  
  	WKS_CHECK_BITMASK(PEXPWReqBufferMode) {
! 	    PACK_CARD32( pwks->reqBufferMode, pbyte);
! 	    (*pNumValues)++;
  	}
  	WKS_CHECK_BITMASK(PEXPWCurBufferMode) {
! 	    PACK_CARD32( pwks->curBufferMode, pbyte);
! 	    (*pNumValues)++;
  	}
  	pBuffer->dataSize = needbytes;
  	ASSURE(needbytes == (pbyte - pBuffer->pBuf));
***************
*** 1021,1027 ****
  
      if (pDraw->class == InputOnly)	/* from dix dispatch.c */
  	return (BadMatch);
!     else {			/* pixmap: fill the rectangle ???? */
  	GCPtr           pGC;
  	extern GCPtr    CreateScratchGC();
  	extern int	ChangeGC();
--- 1090,1097 ----
  
      if (pDraw->class == InputOnly)	/* from dix dispatch.c */
  	return (BadMatch);
!     else if (!pwks->usingDoubleBuffer) {/* pixmap: fill the rectangle ???? */
! 
  	GCPtr           pGC;
  	extern GCPtr    CreateScratchGC();
  	extern int	ChangeGC();
***************
*** 1124,1132 ****
--- 1194,1205 ----
  	pwks->curBufferMode = pwks->reqBufferMode;
  	pwks->bufferUpdate = PEXNotPending;
  	/* do stuff here to effect change in buffer mode */
+         ChangeDoubleBuffers (pwks);
      }
      err = miTraverse(pWKS);
  
+     SwapDoubleBuffers (pwks);
+ 
      /* Set visual_state to Correct */
      pwks->visualState = PEXCorrect;
      /* display Surface is set in miTraverse */
***************
*** 1197,1202 ****
--- 1270,1283 ----
  	/* now redraw picture without updating any state */
  	miTraverse(pWKS);	/* ignore errors */
  
+ 
+  	/*
+  	 * The clip list must be emptied so that subsequent workstation
+  	 * updates redraw the entire display surface.
+  	 */
+ 
+  	pwks->pRend->clipList->numObj = 0;
+ 
  	return (Success);
  }				/* RedrawClipRegion */
  
***************
*** 1339,1344 ****
--- 1420,1426 ----
  	for (i = 0; i < SI_UPDATE_NUM; i++) {
  		if (mode == miDisplayUpdateModeET[type][i].index) {
  			pwks->displayUpdate = mode;
+                         SetDoubleDrawable (pwks);
  			if (mode == PEXVisualizeEach)
  
  				/*
***************
*** 1402,1415 ****
  
  /* no check for z when using drawable */
  #define PT_IN_LIMIT(prend, lim, pt) 				\
-     ((prend)->viewport.useDrawable ? 				\
-      ( (pt)->x >= (prend)->pDrawable->x && 			\
-        (pt)->x <= ((prend)->pDrawable->width - (prend)->pDrawable->x) \
-     && (pt)->y >= (prend)->pDrawable->y && 			\
-        (pt)->y <= ((prend)->pDrawable->height - (prend)->pDrawable->y) ):\
       ( (pt)->x >= (lim)->minval.x && (pt)->x <= (lim)->maxval.x \
      && (pt)->y >= (lim)->minval.y && (pt)->y <= (lim)->maxval.y \
!     && (pt)->z >= (lim)->minval.z && (pt)->z <= (lim)->maxval.z ))
  
  /*++
   |
--- 1484,1492 ----
  
  /* no check for z when using drawable */
  #define PT_IN_LIMIT(prend, lim, pt) 				\
       ( (pt)->x >= (lim)->minval.x && (pt)->x <= (lim)->maxval.x \
      && (pt)->y >= (lim)->minval.y && (pt)->y <= (lim)->maxval.y \
!     && (pt)->z >= (lim)->minval.z && (pt)->z <= (lim)->maxval.z )
  
  /*++
   |
***************
*** 1856,1864 ****
--- 1933,1944 ----
  	if ((mode == PEXSingleBuffered) || (mode == PEXDoubleBuffered)) {
  		pwks->reqBufferMode = mode;
  		if (WKSIMMEDIATE(pwks, BUFFER_MODIFY_DYNAMIC))
+                 {
  			pwks->curBufferMode = mode;
  		/* bufferUpdate doesn't change */
  		/* do stuff here to effect change in buffer mode */
+                         ChangeDoubleBuffers (pwks);
+                 }
  		else {
  			/* don't update display */
  			pwks->bufferUpdate = PEXPending;
***************
*** 2012,2019 ****
  	ErrorF("\nPostStructure %d\n", pStruct->id);
  #endif
  
! 	if (err = miAddStructToOrdList(pStruct, &(pwks->postedStructs), priority)
! 	    == MI_ALLOCERR)
  		return (BadAlloc);
  
  	if (err == MI_SUCCESS) {/* the structure was added */
--- 2092,2099 ----
  	ErrorF("\nPostStructure %d\n", pStruct->id);
  #endif
  
! 	if ((err = miAddStructToOrdList(pStruct, &(pwks->postedStructs), 
! 			                           priority)) == MI_ALLOCERR)
  		return (BadAlloc);
  
  	if (err == MI_SUCCESS) {/* the structure was added */
*** -	Thu Jan 28 17:53:43 1993
--- mit/extensions/server/PEX/ddpex/mi/level4/miStruct.c	Thu Jan 28 17:53:42 1993
***************
*** 1,4 ****
! /* $XConsortium: miStruct.c,v 5.2 91/07/01 08:41:33 rws Exp $ */
  
  
  /***********************************************************
--- 1,4 ----
! /* $XConsortium: miStruct.c,v 5.11 92/11/09 18:57:46 hersh Exp $ */
  
  
  /***********************************************************
***************
*** 589,595 ****
  	 * length
  	 */
  	*pLength = MISTR_LENGTH(pheader);
! 	*pHasRefs = MISTR_NUM_REFS(pheader);
  	return (Success);
  }				/* InquireStructureInfo */
  
--- 589,595 ----
  	 * length
  	 */
  	*pLength = MISTR_LENGTH(pheader);
! 	*pHasRefs = MISTR_NUM_PARENTS(pheader) != 0;
  	return (Success);
  }				/* InquireStructureInfo */
  
***************
*** 636,641 ****
--- 636,649 ----
  		offset1 = offset2;
  		offset2 = i;
  	}
+ 
+ 	if (offset1 == 0)
+ 		if (offset2 == 0)
+ 			return(Success);
+ 		else
+ 			offset1 = 1;
+ 
+ 
  	/* make sure buffer is large enough */
  	needbytes = (offset2 - offset1 + 1) * peisize;
  	PU_CHECK_BUFFER_SIZE(pBuffer, needbytes);
***************
*** 907,922 ****
  	*pb++ = depth;
  	pref = (ddElementRef *) pPath->pList;
  	if (which == MI_DESCENDANTS) {
! 		pref += (pathPart == PEXTopPart) ? 0 :
! 			pPath->numObj - depth;
! 
! 		mibcopy(pref, pb, listsize);
  	} else {
! 		pref += ((pathPart == PEXTopPart) ? pPath->numObj - 1 :
! 			 depth - 1);
! 		pbref = (ddElementRef *) pb;
! 		while (depth--)
! 			*pbref++ = *pref--;
  	}
  	(*pNumLists)++;
  	pBuffer->pBuf += listsize + 4;
--- 915,937 ----
  	*pb++ = depth;
  	pref = (ddElementRef *) pPath->pList;
  	if (which == MI_DESCENDANTS) {
! 		if (pathPart == PEXTopPart)
! 			mibcopy(pref, pb, listsize);
! 		else {
! 			pbref = (ddElementRef *) pb;
! 			pref += pPath->numObj - 1;
! 			while (depth--)
! 				*pbref++ = *pref--;
! 		}
  	} else {
! 		if (pathPart == PEXBottomPart)
! 			mibcopy(pref, pb, listsize);
! 		else {
! 			pbref = (ddElementRef *) pb;
! 			pref += pPath->numObj - 1;
! 			while (depth--)
! 				*pbref++ = *pref--;
! 		}
  	}
  	(*pNumLists)++;
  	pBuffer->pBuf += listsize + 4;
***************
*** 956,962 ****
      if (!num || ((pathPart==PEXBottomPart) && depth && (pPath->numObj==depth))) {
  	if (	(pathPart == PEXTopPart) && depth && (pPath->numObj > depth)
  	     && !path_unique(	pathPart, depth, pNumLists, pBuffer, pPath, 
! 				MI_DESCENDANTS))
  
  	    /*
  	     * if path is top first and has to be truncated to depth, don't 
--- 971,977 ----
      if (!num || ((pathPart==PEXBottomPart) && depth && (pPath->numObj==depth))) {
  	if (	(pathPart == PEXTopPart) && depth && (pPath->numObj > depth)
  	     && !path_unique(	pathPart, depth, pNumLists, pBuffer, pPath, 
! 				MI_ANCESTORS))
  
  	    /*
  	     * if path is top first and has to be truncated to depth, don't 
***************
*** 1250,1264 ****
  		offset1 = offset2;
  		offset2 = i;
  	}
  	MISTR_FIND_EL(pheader, offset1, pel);
  
  	for (i = offset1; i <= offset2; i++) {
! 	    if (MI_IS_PEX_OC(MISTR_EL_TYPE(pel)))
! 		err = (*InquireCSSElementTable[MISTR_EL_TYPE(pel)])
! 						(pel, pBuffer, &(pBuffer->pBuf));
! 	    else
! 		err = (*InquireCSSElementTable[0])
! 						(pel, pBuffer, &(pBuffer->pBuf));
  	    if (err != Success) {
  		*pNumOCs = i - offset1;
  		return (err);
--- 1265,1293 ----
  		offset1 = offset2;
  		offset2 = i;
  	}
+ 
+ 	if (offset1 == 0)
+ 		if (offset2 == 0)
+ 			return(Success);
+ 		else
+ 			offset1 = 1;
+ 
  	MISTR_FIND_EL(pheader, offset1, pel);
  
  	for (i = offset1; i <= offset2; i++) {
! 	    /* Propreitary calls (and OCNil) through 0th Table Entry */
! 	    if (MI_HIGHBIT_ON(MISTR_EL_TYPE(pel)))
! 		err = (*InquireCSSElementTable[MI_OC_PROP])
! 				      (pel, pBuffer, &(pBuffer->pBuf));
! 	    else {
! 		/* not Proprietary see if valid PEX OC */
! 		if (MI_IS_PEX_OC(MISTR_EL_TYPE(pel)))
! 		    err = (*InquireCSSElementTable[MISTR_EL_TYPE(pel)])
! 				      (pel, pBuffer, &(pBuffer->pBuf));
! 		else
! 		    err = !Success;
! 	    }
! 
  	    if (err != Success) {
  		*pNumOCs = i - offset1;
  		return (err);
***************
*** 1582,1621 ****
  
  		/*
  		 * replace iff
- 		 * 
  		 * we're not at the end
- 		 */
- 
- 		if ((preplel != MISTR_LAST_EL(pstruct))
- 
- 		/*
  		 * * and the types match
  		 */
  
  		    && (poc->elementType == MISTR_EL_TYPE(preplel))
  
! 		/*
! 		 * * and we're not at the beginning
! 		 */
  
! 		    && (preplel != MISTR_ZERO_EL(pstruct))) {
! 
! 			if (MI_IS_PEX_OC(poc->elementType))
! 			    err = (*ReplaceCSSElementTable[poc->elementType])
! 						(pStruct, preplel, poc);
! 			else
! 			    err = (*ReplaceCSSElementTable[0])
! 						(pStruct, preplel, poc);
  		} else
  		    err = !Success;
  
  		if (err != Success) {	/* create new el */
! 		    if (MI_IS_PEX_OC(poc->elementType))
! 			err = (*CreateCSSElementTable[poc->elementType])
  						(pStruct, poc, &pnewel);
! 		    else
! 			err = (*CreateCSSElementTable[0])
! 						(pStruct, poc, &pnewel);
  
  		if (err != Success) break;
  
--- 1611,1664 ----
  
  		/*
  		 * replace iff
  		 * we're not at the end
  		 * * and the types match
+ 		 * * and we're not at the beginning
+ 		 * * * and elements are the same size 
  		 */
  
+ 		if ((preplel != MISTR_LAST_EL(pstruct))
  		    && (poc->elementType == MISTR_EL_TYPE(preplel))
+ 		    && (preplel != MISTR_ZERO_EL(pstruct)) 
+ 		    && (MISTR_EL_LENGTH(preplel) == poc->length)) {
  
! 		      /*
! 		       * *  Replace calls Parse functions 
! 		       */
  
! 			/* Propreitary OC (and OCNil) through 0th Table Entry */
! 			if (MI_HIGHBIT_ON(poc->elementType))
! 			    err = (*ReplaceCSSElementTable[MI_OC_PROP])
! 						(pStruct, preplel, poc );
!                         else {
! 			    /* not Proprietary see if valid PEX OC */
! 			    if (MI_IS_PEX_OC(poc->elementType))
! 			      err = (*ReplaceCSSElementTable[poc->elementType])
! 						    (pStruct, preplel, poc);
! 			    else {
! 			      /* Bad Element Type Exit Now */
! 			      err = !Success;
! 			      break;
! 			    }
! 			}
  		} else
+ 		    /* Bad Replace */
  		    err = !Success;
  
  		if (err != Success) {	/* create new el */
! 		    /* Propreitary OC (and OCNil) through 0th Table Entry */
! 		    if (MI_HIGHBIT_ON(poc->elementType))
! 			err = (*CreateCSSElementTable[MI_OC_PROP])
  						(pStruct, poc, &pnewel);
! 		    else {
! 			/* not Proprietary see if valid PEX OC */
! 			if (MI_IS_PEX_OC(poc->elementType))
! 			    err = (*CreateCSSElementTable[poc->elementType])
! 						    (pStruct, poc, &pnewel);
! 			else
! 			    /* Bad Element Type */
! 			    err = !Success;
! 		    }
  
  		if (err != Success) break;
  
***************
*** 1643,1654 ****
  	    for (   count = 0, poc = pOCs, pprevel = MISTR_CURR_EL_PTR(pstruct);
  		    numOCs > 0;
  		    numOCs--, pprevel = pnewel, poc += poc->length) {
- 		if (MI_IS_PEX_OC(poc->elementType))
- 		    err = (*CreateCSSElementTable[poc->elementType])
- 					(pStruct, poc, &pnewel);
- 		else
- 		    err = (*CreateCSSElementTable[0]) (pStruct, poc, &pnewel);
  
  		if (err != Success) break;
  
  		count++;
--- 1686,1706 ----
  	    for (   count = 0, poc = pOCs, pprevel = MISTR_CURR_EL_PTR(pstruct);
  		    numOCs > 0;
  		    numOCs--, pprevel = pnewel, poc += poc->length) {
  
+ 		/* Propreitary OC (and OCNil) through 0th Table Entry */
+ 		if (MI_HIGHBIT_ON(poc->elementType))
+ 		    err = (*CreateCSSElementTable[MI_OC_PROP]) 
+ 						 (pStruct, poc, &pnewel);
+ 		else {
+ 		    /* not Proprietary see if valid PEX OC */
+ 		    if (MI_IS_PEX_OC(poc->elementType))
+ 			err = (*CreateCSSElementTable[poc->elementType])
+ 					    (pStruct, poc, &pnewel);
+ 		    else
+ 			/* Bad Element Type */
+ 			err = !Success;
+ 		}
+ 
  		if (err != Success) break;
  
  		count++;
***************
*** 1673,1679 ****
      if (err != Success) {
  	*ppErr = (pexOutputCommandError *)Xalloc(sizeof(pexOutputCommandError));
  	(*ppErr)->type = 0;
! 	(*ppErr)->errorCode = PEXOutputCommandError;
  	(*ppErr)->resourceId = pStruct->id;
  	(*ppErr)->opcode = poc->elementType;
  	(*ppErr)->numCommands = count;
--- 1725,1731 ----
      if (err != Success) {
  	*ppErr = (pexOutputCommandError *)Xalloc(sizeof(pexOutputCommandError));
  	(*ppErr)->type = 0;
! 	(*ppErr)->errorCode = PEX_ERROR_CODE(PEXOutputCommandError);
  	(*ppErr)->resourceId = pStruct->id;
  	(*ppErr)->opcode = poc->elementType;
  	(*ppErr)->numCommands = count;
***************
*** 1915,1926 ****
  	pdestprev = &pfirst;
  
  	for (i = src_low, count = 0; i <= src_high; i++) {
! 		if (MI_IS_PEX_OC(MISTR_EL_TYPE(psrcel)))
  			err4 = (*CopyCSSElementTable[MISTR_EL_TYPE(psrcel)])
  				(psrcel, pDestStruct, &pdestel);
! 		else
! 			err4 = (*CopyCSSElementTable[0])
! 				(psrcel, pDestStruct, &pdestel);
  
  		if (err4 != Success)
  			break;
--- 1967,1986 ----
  	pdestprev = &pfirst;
  
  	for (i = src_low, count = 0; i <= src_high; i++) {
! 
! 		/* Propreitary OC (and OCNil) through 0th Table Entry */
! 		if (MI_HIGHBIT_ON(MISTR_EL_TYPE(psrcel)))
! 			err4 = (*CopyCSSElementTable[MI_OC_PROP])
! 				(psrcel, pDestStruct, &pdestel);
! 		else {
! 		    /* not Proprietary see if valid PEX OC */
! 		    if (MI_IS_PEX_OC(MISTR_EL_TYPE(psrcel)))
  			err4 = (*CopyCSSElementTable[MISTR_EL_TYPE(psrcel)])
  				(psrcel, pDestStruct, &pdestel);
! 		    else
! 			/* Bad Element Type - Problem if you get here */
! 			err4 = !Success;
! 		}
  
  		if (err4 != Success)
  			break;
***************
*** 1989,2035 ****
      execStrOC.head.length = 2;
      execStrOC.id = (pexStructure) pNewStruct;
  
!     /** Search through each of the structure's parents **/
      for (loopcount = pstruct->parents->numObj; loopcount > 0; loopcount--) {
  
! 	/*
! 	 * look through all of this structure's elements to change all 
! 	 * references to this structure the parent list is changed in loop, 
! 	 * so always get first parent
! 	 */
  	parentHandle = *(diStructHandle *) pstruct->parents->pList;
  	pparentStruct = (miStructPtr) (parentHandle)->deviceData;
  
  	/* start looking at the beginning of the parent structure */
! 	position.whence = PEXBeginning;
! 	position.offset = 0;
! 	offsetFromStart = 0;
  
! 	do {
! 	    if ((foundExecuteElement =
! 			find_execute_structure(	parentHandle, &position,
! 						pStruct, &offsetFromStart))
! 		    == PEXFound) {
  		MISTR_FIND_EL(pparentStruct, offsetFromStart, pel);
  		err = (*ReplaceCSSElementTable[PEXOCExecuteStructure])
  					(parentHandle, pel, &execStrOC);
! 		if (err != Success) return (err); }
! 
! 	    /*
! 	     * continue looking for other elements at the element
! 	     * following the last one found
! 	     */
! 	    position.whence = PEXBeginning;
! 	    position.offset = offsetFromStart + 1;
! 
! 	    /*
! 	     * if the last one found was the last element in the
! 	     * struct, don't continue
! 	     */
! 	    if (offsetFromStart == MISTR_NUM_EL(pstruct)) break;
! 
! 	} while (foundExecuteElement == PEXFound);
! 
      }
  
      /*
--- 2049,2082 ----
      execStrOC.head.length = 2;
      execStrOC.id = (pexStructure) pNewStruct;
  
!     /*
!      * Update all references to this structure by walking through the
!      * structure's parent list.  Note that if the structure is referenced
!      * more than once by a parent structure, there will be more than one
!      * occurence of the parent in the parent list.
!      */
!     
      for (loopcount = pstruct->parents->numObj; loopcount > 0; loopcount--) {
  
! 	/* The parent list changes in loop, so always get first parent */
  	parentHandle = *(diStructHandle *) pstruct->parents->pList;
  	pparentStruct = (miStructPtr) (parentHandle)->deviceData;
  
  	/* start looking at the beginning of the parent structure */
!         position.whence = PEXBeginning;
!         position.offset = 0;
!         offsetFromStart = 0;
  
!     	foundExecuteElement = find_execute_structure (parentHandle, &position,
! 		pStruct, &offsetFromStart);
! 
!     	if (foundExecuteElement == PEXFound) {
  		MISTR_FIND_EL(pparentStruct, offsetFromStart, pel);
  		err = (*ReplaceCSSElementTable[PEXOCExecuteStructure])
  					(parentHandle, pel, &execStrOC);
! 		if (err != Success) return (err);
! 	} else
! 		return (!Success);
      }
  
      /*
***************
*** 2345,2351 ****
      diStructHandle  pStruct, pNextStruct;
      miStructPtr     pstruct;
      ddULONG         offset;
!     int             i;
  
      if (pPath->type == DD_ELEMENT_REF) {
  	ddElementRef   *pSCPath;
--- 2392,2398 ----
      diStructHandle  pStruct, pNextStruct;
      miStructPtr     pstruct;
      ddULONG         offset;
!     int             i, j;
  
      if (pPath->type == DD_ELEMENT_REF) {
  	ddElementRef   *pSCPath;
***************
*** 2383,2388 ****
--- 2430,2436 ----
  	pickId = 0;
  
  	for (i = pPath->numObj; i > 0; i--, pPickPath++) {
+ 
  	    pStruct = pPickPath->structure;
  	    if (pNextStruct != pStruct) return (PEXERR(PEXPathError));
  
***************
*** 2397,2403 ****
  	     */
  	    MISTR_FIND_EL(pstruct, 1, p_element);
  
! 	    for (; offset > 0; offset--) {
  		if (MISTR_EL_TYPE(p_element) == PEXOCPickId)
  		    pickId = MISTR_GET_PICK_ID(p_element);
  		p_element = MISTR_NEXT_EL(p_element);
--- 2445,2451 ----
  	     */
  	    MISTR_FIND_EL(pstruct, 1, p_element);
  
! 	    for (j = 1; j <  offset; j++ ) {
  		if (MISTR_EL_TYPE(p_element) == PEXOCPickId)
  		    pickId = MISTR_GET_PICK_ID(p_element);
  		p_element = MISTR_NEXT_EL(p_element);
*** -	Thu Jan 28 17:53:45 1993
--- mit/extensions/server/PEX/ddpex/mi/level4/miTraverse.c	Thu Jan 28 17:53:45 1993
***************
*** 1,6 ****
! /* $XConsortium: miTraverse.c,v 5.1 91/02/16 09:56:05 rws Exp $ */
  
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
--- 1,7 ----
! /* $XConsortium: miTraverse.c,v 5.5 92/11/17 17:34:39 hersh Exp $ */
  
  
+ 
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
***************
*** 53,61 ****
  #endif				/* DDTEST */
  
  static          ddBOOL
! pickES()
  {
! /* use this to follow start_path in similar fashion that searchES is used */
      return (MI_FALSE);
  }
  
--- 54,79 ----
  #endif				/* DDTEST */
  
  static          ddBOOL
! pickES (pRend, p_trav_state, p_str, depth, curr_offset)
!     ddRendererPtr	    pRend;
!     miTraverserState    *p_trav_state;
!     diStructHandle	p_str;	        /* current structure */
!     ddSHORT		depth;		/* how far down in structures */
!     ddULONG		curr_offset;
  {
! 
!     if ((p_str->id == p_trav_state->p_curr_pick_el->structure->id) &&
! 	    (curr_offset == p_trav_state->p_curr_pick_el->offset)) {
! 
! 	  if (depth < pRend->pickStartPath->numObj) 
! 	      /* continue following start path */
! 	      p_trav_state->p_curr_pick_el++;
! 	  else 
! 	      /* at end of start path; time to start traversal */
! 	      p_trav_state->exec_str_flag = ES_YES;
! 
! 	  return(MI_TRUE);
!     }
      return (MI_FALSE);
  }
  
***************
*** 93,104 ****
      miWksPtr		    pwks = (miWksPtr) pWks->deviceData;
      ddpex4rtn		    err = Success;
      miTraverserState	    trav_state;
  
      if (    (pwks->pRend->pDrawable == NULL)
  	 || (pwks->pRend->drawableId == PEXAlreadyFreed))
  		return (BadDrawable);
  
!     if (!pwks->postedStructs.numStructs) return (Success);
  
      /* set exec_str_flag */
      trav_state.exec_str_flag = ES_YES;
--- 111,124 ----
      miWksPtr		    pwks = (miWksPtr) pWks->deviceData;
      ddpex4rtn		    err = Success;
      miTraverserState	    trav_state;
+     DrawablePtr             pRealDrawable;
  
+ 
      if (    (pwks->pRend->pDrawable == NULL)
  	 || (pwks->pRend->drawableId == PEXAlreadyFreed))
  		return (BadDrawable);
  
!     if (!pwks->postedStructs.numStructs || !pwks->pCurDrawable) return (Success);
  
      /* set exec_str_flag */
      trav_state.exec_str_flag = ES_YES;
***************
*** 105,112 ****
      trav_state.p_curr_pick_el = (ddPickPath *) NULL;
      trav_state.p_curr_sc_el = (ddElementRef *) NULL;
  
      /**  call into ddPEX level III Begin Rendering   **/
!     BeginRendering(pwks->pRend, pwks->pRend->pDrawable);
  
      /* traverse all posted structs */
      pos = pwks->postedStructs.postruct;
--- 125,136 ----
      trav_state.p_curr_pick_el = (ddPickPath *) NULL;
      trav_state.p_curr_sc_el = (ddElementRef *) NULL;
  
+     /* save drawable to be restored later */
+     pRealDrawable = pwks->pRend->pDrawable;
+     pwks->pRend->pDrawable = pwks->pCurDrawable;
+ 
      /**  call into ddPEX level III Begin Rendering   **/
!     BeginRendering(pwks->pRend, pwks->pCurDrawable);
  
      /* traverse all posted structs */
      pos = pwks->postedStructs.postruct;
***************
*** 115,121 ****
--- 139,147 ----
  	/* reset for each structure */
  	trav_state.max_depth = 0;	
  	trav_state.pickId = 0;	
+         trav_state.ROCoffset =  0;
  
+ 
  	if (MISTR_NUM_EL((miStructPtr) pos->pstruct->deviceData)) {
  	    BeginStructure(pwks->pRend, pos->pstruct->id);
  
***************
*** 134,139 ****
--- 160,167 ----
  
      EndRendering(pwks->pRend);
  
+     pwks->pRend->pDrawable = pRealDrawable;
+ 
      if (err != Success) {
  	/* do stuff here to return error */
  	return(err);
***************
*** 171,177 ****
      ddPointer		ddElement;	/* imp. dep. parsed element */
      diStructHandle	p_next_str;	/* execute structure structure */
      ddSHORT		depth;		/* how far down in structures */
!     ddULONG		pickId;
      miStructPtr		pstruct = (miStructPtr)(pStruct->deviceData);
      ddUSHORT		pickStatus, searchStatus;
      ddpex2rtn		err;
--- 199,205 ----
      ddPointer		ddElement;	/* imp. dep. parsed element */
      diStructHandle	p_next_str;	/* execute structure structure */
      ddSHORT		depth;		/* how far down in structures */
!     ddULONG		pickId, ROCoffset;
      miStructPtr		pstruct = (miStructPtr)(pStruct->deviceData);
      ddUSHORT		pickStatus, searchStatus;
      ddpex2rtn		err;
***************
*** 178,184 ****
--- 206,215 ----
      ddPickPath		*pl;
      ddElementRef	*sl;
      int			zap;
+     miPPLevel		myPickLevel, *pp;
+     int			i;
  
+ 
      if (pPM)
  	ppm = (miPickMeasureStr *) pPM->deviceData;
      else
***************
*** 192,201 ****
      depth = p_trav_state->max_depth;
      /* same for pick id */
      pickId = p_trav_state->pickId;
- 
      MISTR_FIND_EL(pstruct, startel, p_element);
      currOffset = startel;
  
      /* do stuff for following search start path */
      if (pSC) {
          /* if following start path, and its at the last element_ref
--- 223,239 ----
      depth = p_trav_state->max_depth;
      /* same for pick id */
      pickId = p_trav_state->pickId;
      MISTR_FIND_EL(pstruct, startel, p_element);
      currOffset = startel;
  
+     /* when calling traverser from ROC ROCoffset may be non-zero
+        to account for prior ROCs, all other times this should
+        be 0 and we set it to 0 here so recursion doesn't mess
+        up the offsets when processing execute structure
+     */
+     ROCoffset = p_trav_state->ROCoffset;
+     p_trav_state->ROCoffset = 0;
+ 
      /* do stuff for following search start path */
      if (pSC) {
          /* if following start path, and its at the last element_ref
***************
*** 209,214 ****
--- 247,260 ----
      	p_trav_state->exec_str_flag = ES_YES;
      }
  
+     /* do stuff for following pick start path */
+     if (pPM) {
+         if ( (p_trav_state->exec_str_flag == ES_FOLLOW_PICK) &&
+              (depth == pRend->pickStartPath->numObj) &&
+ 	     (currOffset > p_trav_state->p_curr_pick_el->offset) )
+ 	  p_trav_state->exec_str_flag = ES_YES;
+     }
+ 
      while (currOffset <= stopel) {
  	ddElement = (ddPointer) (&(p_element->element));
  	
***************
*** 224,230 ****
  
  		p_next_str = ((diStructHandle) MISTR_GET_EXSTR_STR(p_element));
  		if (p_trav_state->exec_str_flag == ES_FOLLOW_PICK)
! 		    go = pickES();
  		else if (p_trav_state->exec_str_flag == ES_FOLLOW_SEARCH)
  		    go = searchES(pSC, p_trav_state, pStruct, depth, currOffset);
  		else if (p_trav_state->exec_str_flag == ES_YES)
--- 270,276 ----
  
  		p_next_str = ((diStructHandle) MISTR_GET_EXSTR_STR(p_element));
  		if (p_trav_state->exec_str_flag == ES_FOLLOW_PICK)
! 		    go = pickES (pRend, p_trav_state, pStruct, depth, currOffset);
  		else if (p_trav_state->exec_str_flag == ES_FOLLOW_SEARCH)
  		    go = searchES(pSC, p_trav_state, pStruct, depth, currOffset);
  		else if (p_trav_state->exec_str_flag == ES_YES)
***************
*** 235,240 ****
--- 281,296 ----
  		if (go) {
  
  		    BeginStructure(pRend, p_next_str->id);
+ 
+ 		    /* build the pick path as we descend the hierarchy */
+ 		    if (pPM) {
+ 			myPickLevel.up = p_trav_state->p_pick_path;
+ 			myPickLevel.pp.structure = pStruct;
+ 			myPickLevel.pp.offset = currOffset + ROCoffset;
+ 			myPickLevel.pp.pickid = pickId;
+ 			p_trav_state->p_pick_path = &myPickLevel;
+ 		    }
+ 
  		    err = traverser(	pRend, p_next_str, (ddULONG) 1,
  					MISTR_NUM_EL((miStructPtr) p_next_str->deviceData),
  					pPM, pSC, p_trav_state);
***************
*** 243,270 ****
  		}
  
  		/*
! 		 * Now, if doing picking and a pick has happened, continue 
! 		 * popping out of the traversal and setting the pick path.  These
! 		 * assume that the obj list is large enough, and it should since
! 		 * it was checked when the traversal ended and started popping
! 		 * out of the recusion
! 		 */
! 		if (pPM && (p_trav_state->exec_str_flag == ES_POP)) {
  
- 		    pl = (ddPickPath *) ppm->path->pList;
  
- 		    if (ppm->pathOrder == PEXTopPart)
- 			zap = depth -1;
- 		    else	/* order is BottomPart */
- 			zap = p_trav_state->max_depth - depth;
- 
- 		    pl[zap].structure = pStruct;
- 		    pl[zap].offset = currOffset;
- 		    pl[zap].pickid = pickId;
- 
- 		    return (Success);
- 		}
- 
  		/* do the same for searching, replacing the start
  		 * path with the found path 
  		 */
--- 299,312 ----
  		}
  
  		/*
! 		 * We built the candidate pick path when it was found. We
! 		 * do nothing on the way out - except restore pointer.
! 	       */
! 	       if (pPM) {
! 		   p_trav_state->p_pick_path = myPickLevel.up; 
! 	       }
  
  
  		/* do the same for searching, replacing the start
  		 * path with the found path 
  		 */
***************
*** 372,380 ****
  		    }
  		    if (pPM) {
  			InquirePickStatus(pRend, &pickStatus, p_trav_state);
- 			ppm->status = pickStatus;
  			if (pickStatus == PEXOk) {
  
  			    pl = (ddPickPath *) ppm->path->pList;
  
  			    /*
--- 414,432 ----
  		    }
  		    if (pPM) {
  			InquirePickStatus(pRend, &pickStatus, p_trav_state);
  			if (pickStatus == PEXOk) {
+                           if (pRend->pickstr.state == DD_PICK_ALL) {
+ 			      myPickLevel.up = p_trav_state->p_pick_path;
+ 			      myPickLevel.pp.structure = pStruct;
+ 			      myPickLevel.pp.offset = currOffset + ROCoffset;
+ 			      myPickLevel.pp.pickid = pickId;
  
+ 			      AddPickPathToList( pRend, depth, &myPickLevel);
+ 			      ppm->status = pickStatus;
+ 
+                           } else {
+ 
+ 
  			    pl = (ddPickPath *) ppm->path->pList;
  
  			    /*
***************
*** 400,416 ****
  			     * depending on whether the top/bottom part was
  			     * requested
  			     */
! 			    if (ppm->pathOrder == PEXTopPart)
  				zap = depth - 1;
  			    else	
  				zap = p_trav_state->max_depth - depth;
  
  			    pl[zap].structure = pStruct;
! 			    pl[zap].offset = currOffset;
  			    pl[zap].pickid = pickId;
  
! 			    p_trav_state->exec_str_flag = ES_POP;
! 			    return (Success);
  			}
  		    }
  		}
--- 452,484 ----
  			     * depending on whether the top/bottom part was
  			     * requested
  			     */
! 			    if (ppm->pathOrder == PEXTopFirst)
  				zap = depth - 1;
  			    else	
  				zap = p_trav_state->max_depth - depth;
  
  			    pl[zap].structure = pStruct;
! 			    pl[zap].offset = currOffset + ROCoffset;
  			    pl[zap].pickid = pickId;
  
! 			    /*
! 			     * we want to continue on, so we do not want to
! 			     * pop off to use the recursion.
! 			     * follow the linked list down
! 			     */
! 			    pp = p_trav_state->p_pick_path;
! 			    for (i = depth-1; i > 0; i-- ) {		
! 			       if (ppm->pathOrder == PEXTopFirst)
! 				   zap = i - 1;
! 			       else	
! 				   zap = p_trav_state->max_depth - i;
! 			      
! 			       pl[zap] = pp->pp; /* structure assignment */
! 			       pp = pp->up;
! 			    }
! 			    ppm->status = pickStatus;
! 
! 			  }
  			}
  		    }
  		}
***************
*** 455,460 ****
--- 523,541 ----
          
  	}
  
+ 	/* do stuff for following search start path */
+ 	if (pPM) {
+ 	    /* if following start path, and its at the last pick_path 
+ 	     * in the start path, and its after the last element in
+ 	     * the pick_path, then its at the end of the start
+ 	     * path and searching should begin
+ 	     */
+ 	    if ( (p_trav_state->exec_str_flag == ES_FOLLOW_PICK) &&
+ 		 (depth == pRend->pickStartPath->numObj) &&
+ 		 (currOffset >= p_trav_state->p_curr_pick_el->offset) )
+ 	      p_trav_state->exec_str_flag = ES_YES;
+ 	}
+ 
  	/* go on to the next element */
  	currOffset++;
  	p_element = MISTR_NEXT_EL(p_element);
***************
*** 482,487 ****
--- 563,571 ----
  	trav_state.p_curr_pick_el = NULL;
  	trav_state.p_curr_sc_el = NULL;
  	trav_state.max_depth = 0;
+         trav_state.pickId = 0;
+         trav_state.ROCoffset =  0;
+ 
  	err = traverser(    pRend, pstruct, (ddULONG)0, 
  			    MISTR_NUM_EL((miStructPtr)pstruct->deviceData), 
  			    (diPMHandle)NULL, (ddSCStr *)NULL, &trav_state);
*** -	Thu Jan 28 17:53:47 1993
--- mit/extensions/server/PEX/ddpex/mi/level4/css_plain.c	Thu Jan 28 17:53:46 1993
***************
*** 1,4 ****
! /* $XConsortium: css_plain.c,v 5.1 91/02/16 09:56:09 rws Exp $ */
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
--- 1,4 ----
! /* $XConsortium: css_plain.c,v 5.4 91/12/26 18:15:31 hersh Exp $ */
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  
***************
*** 30,36 ****
   */
  
  #include "ddpex.h"
- #include "miStruct.h"
  #include "miStrMacro.h"
  
  extern ocTableType ParseOCTable[];
--- 30,35 ----
***************
*** 44,50 ****
  
  #define PEX_EL_TYPE(POC) ((ddElementInfo *)(POC))->elementType
  
- #define OC_RANGE(ELTYPE) ((PEXOCAll < (ELTYPE) ) && ( PEXMaxOC >=(ELTYPE)))
  
  ddpex4rtn
  createCSS_Plain(pStruct, pPEXOC, ppCSSElement)
--- 43,48 ----
***************
*** 61,72 ****
  
  	/*
  	 * Parse into server native format
  	 */
! 	if (OC_RANGE(PEX_EL_TYPE(pPEXOC)))
  		err = (*ParseOCTable[PEX_EL_TYPE(pPEXOC)])
  			(pPEXOC, ppCSSElement);
! 	else
! 		err = (*ParseOCTable[0]) (pPEXOC, ppCSSElement);
  	if (err != Success)
  		return (PEXERR(PEXOutputCommandError));
  
--- 59,73 ----
  
  	/*
  	 * Parse into server native format
+ 	 * If we make it here OC is either proprietary or valid PEXOC
+ 	 * still need to check proprietary to avoid Null Function Ptrs
  	 */
! 	if (MI_HIGHBIT_ON(PEX_EL_TYPE(pPEXOC)))
! 		err = (*ParseOCTable[MI_OC_PROP]) (pPEXOC, ppCSSElement);
! 	else
  		err = (*ParseOCTable[PEX_EL_TYPE(pPEXOC)])
  			(pPEXOC, ppCSSElement);
! 
  	if (err != Success)
  		return (PEXERR(PEXOutputCommandError));
  
***************
*** 98,105 ****
  
  	/*
  	 * Free the parsed format
  	 */
! 	(*DestroyOCTable[(int) (pCSSElement->element.elementType)])
  		(pCSSElement);
  
  	return (err);
--- 99,113 ----
  
  	/*
  	 * Free the parsed format
+ 	 * If we make it here OC is either proprietary or valid PEXOC
+ 	 * still need to check proprietary to avoid Null Function Ptrs
+ 	 * even though we use the same destroy routine
  	 */
! 
! 	if (MI_HIGHBIT_ON(pCSSElement->element.elementType))
! 	    (*DestroyOCTable[MI_OC_PROP]) (pCSSElement);
! 	else 
! 	    (*DestroyOCTable[(int) (pCSSElement->element.elementType)])
  		(pCSSElement);
  
  	return (err);
***************
*** 118,125 ****
  
  	*ppDestCSSElement = (miGenericElementPtr) NULL;
  
! 	err = (*CopyOCTable[(int) (pSrcCSSElement->element.elementType)])
! 		(pSrcCSSElement, ppDestCSSElement);
  	if (err != Success)
  		return (err);
  
--- 126,142 ----
  
  	*ppDestCSSElement = (miGenericElementPtr) NULL;
  
! 	/*
! 	 * If we make it here OC is either proprietary or valid PEXOC
! 	 * still need to check proprietary to avoid Null Function Ptrs
! 	*/
! 	if (MI_HIGHBIT_ON(pSrcCSSElement->element.elementType))
! 	    err = (*CopyOCTable[MI_OC_PROP])
! 		    (pSrcCSSElement, ppDestCSSElement);
! 	else 
! 	    err = (*CopyOCTable[(int) (pSrcCSSElement->element.elementType)])
! 		    (pSrcCSSElement, ppDestCSSElement);
! 
  	if (err != Success)
  		return (err);
  
***************
*** 143,150 ****
  {
  	ddpex4rtn       err = Success;
  
! 	err = (*ReplaceOCTable[(int) (pCSSElement->element.elementType)])
! 		(pPEXOC, &pCSSElement);
  
  	if (err == Success) {
  		pCSSElement->pStruct = pStruct;
--- 160,174 ----
  {
  	ddpex4rtn       err = Success;
  
! 	/*
! 	 * If we make it here OC is either proprietary or valid PEXOC
! 	 * still need to check proprietary to avoid Null Function Ptrs
! 	*/
! 	if (MI_HIGHBIT_ON(pCSSElement->element.elementType))
! 	    err = (*ReplaceOCTable[MI_OC_PROP]) (pPEXOC, &pCSSElement);
! 	else 
! 	    err = (*ReplaceOCTable[(int) (pCSSElement->element.elementType)])
! 		    (pPEXOC, &pCSSElement);
  
  	if (err == Success) {
  		pCSSElement->pStruct = pStruct;
***************
*** 162,168 ****
  {
  	ddpex4rtn       err = Success;
  
! 	err = (*InquireOCTable[(int) (pCSSElement->element.elementType)])
! 		(pCSSElement, pBuf, ppPEXOC);
  	return (err);
  }
--- 186,199 ----
  {
  	ddpex4rtn       err = Success;
  
! 	/*
! 	 * If we make it here OC is either proprietary or valid PEXOC
! 	 * still need to check proprietary to avoid Null Function Ptrs
! 	*/
! 	if (MI_HIGHBIT_ON(pCSSElement->element.elementType))
! 	    err = (*InquireOCTable[MI_OC_PROP]) (pCSSElement, pBuf, ppPEXOC);
! 	else 
! 	    err = (*InquireOCTable[(int) (pCSSElement->element.elementType)])
! 		    (pCSSElement, pBuf, ppPEXOC);
  	return (err);
  }
*** -	Thu Jan 28 17:53:48 1993
--- mit/extensions/server/PEX/ddpex/mi/level4/css_tbls.c	Thu Jan 28 17:53:48 1993
***************
*** 1,4 ****
! /* $XConsortium: css_tbls.c,v 5.1 91/02/16 09:56:11 rws Exp $ */
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: css_tbls.c,v 5.3 92/08/12 15:32:12 hersh Exp $ */
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 47,53 ****
  extern ddpex4rtn inquireCSS_Exec_Struct();
  
  cssTableType    CreateCSSElementTable[] = {
! 	createCSS_Plain,	/* 0 All */
  	createCSS_Plain,	/* 1 MarkerType */
  	createCSS_Plain,	/* 2 MarkerScale */
  	createCSS_Plain,	/* 3 MarkerColourIndex */
--- 47,53 ----
  extern ddpex4rtn inquireCSS_Exec_Struct();
  
  cssTableType    CreateCSSElementTable[] = {
! 	createCSS_Plain,	/* 0 Propietary */
  	createCSS_Plain,	/* 1 MarkerType */
  	createCSS_Plain,	/* 2 MarkerScale */
  	createCSS_Plain,	/* 3 MarkerColourIndex */
***************
*** 150,160 ****
  	createCSS_Plain,	/* 100 CellArray2D */
  	createCSS_Plain,	/* 101 ExtCellArray */
  	createCSS_Plain,	/* 102 Gdp */
! 	createCSS_Plain		/* 103 Gdp2D */
  };
  
  cssTableType    DestroyCSSElementTable[] = {
! 	destroyCSS_Plain,	/* 0 All */
  	destroyCSS_Plain,	/* 1 MarkerType */
  	destroyCSS_Plain,	/* 2 MarkerScale */
  	destroyCSS_Plain,	/* 3 MarkerColourIndex */
--- 150,161 ----
  	createCSS_Plain,	/* 100 CellArray2D */
  	createCSS_Plain,	/* 101 ExtCellArray */
  	createCSS_Plain,	/* 102 Gdp */
! 	createCSS_Plain,	/* 103 Gdp2D */
! 	createCSS_Plain		/* 104 Noop */
  };
  
  cssTableType    DestroyCSSElementTable[] = {
! 	destroyCSS_Plain,	/* 0 Propietary */
  	destroyCSS_Plain,	/* 1 MarkerType */
  	destroyCSS_Plain,	/* 2 MarkerScale */
  	destroyCSS_Plain,	/* 3 MarkerColourIndex */
***************
*** 257,267 ****
  	destroyCSS_Plain,	/* 100 CellArray2D */
  	destroyCSS_Plain,	/* 101 ExtCellArray */
  	destroyCSS_Plain,	/* 102 Gdp */
! 	destroyCSS_Plain	/* 103 Gdp2D */
  };
  
  cssTableType    CopyCSSElementTable[] = {
! 	copyCSS_Plain,		/* 0 All */
  	copyCSS_Plain,		/* 1 MarkerType */
  	copyCSS_Plain,		/* 2 MarkerScale */
  	copyCSS_Plain,		/* 3 MarkerColourIndex */
--- 258,269 ----
  	destroyCSS_Plain,	/* 100 CellArray2D */
  	destroyCSS_Plain,	/* 101 ExtCellArray */
  	destroyCSS_Plain,	/* 102 Gdp */
! 	destroyCSS_Plain,	/* 103 Gdp2D */
! 	destroyCSS_Plain	/* 104 Noop */
  };
  
  cssTableType    CopyCSSElementTable[] = {
! 	copyCSS_Plain,		/* 0 Propietary */
  	copyCSS_Plain,		/* 1 MarkerType */
  	copyCSS_Plain,		/* 2 MarkerScale */
  	copyCSS_Plain,		/* 3 MarkerColourIndex */
***************
*** 364,374 ****
  	copyCSS_Plain,		/* 100 CellArray2D */
  	copyCSS_Plain,		/* 101 ExtCellArray */
  	copyCSS_Plain,		/* 102 Gdp */
! 	copyCSS_Plain		/* 103 Gdp2D */
  };
  
  cssTableType    ReplaceCSSElementTable[] = {
! 	replaceCSS_Plain,	/* 0 All */
  	replaceCSS_Plain,	/* 1 MarkerType */
  	replaceCSS_Plain,	/* 2 MarkerScale */
  	replaceCSS_Plain,	/* 3 MarkerColourIndex */
--- 366,377 ----
  	copyCSS_Plain,		/* 100 CellArray2D */
  	copyCSS_Plain,		/* 101 ExtCellArray */
  	copyCSS_Plain,		/* 102 Gdp */
! 	copyCSS_Plain,		/* 103 Gdp2D */
! 	copyCSS_Plain		/* 104 Noop */
  };
  
  cssTableType    ReplaceCSSElementTable[] = {
! 	replaceCSS_Plain,	/* 0 Propietary */
  	replaceCSS_Plain,	/* 1 MarkerType */
  	replaceCSS_Plain,	/* 2 MarkerScale */
  	replaceCSS_Plain,	/* 3 MarkerColourIndex */
***************
*** 471,481 ****
  	replaceCSS_Plain,	/* 100 CellArray2D */
  	replaceCSS_Plain,	/* 101 ExtCellArray */
  	replaceCSS_Plain,	/* 102 Gdp */
! 	replaceCSS_Plain	/* 103 Gdp2D */
  };
  
  cssTableType    InquireCSSElementTable[] = {
! 	inquireCSS_Plain,	/* 0 All */
  	inquireCSS_Plain,	/* 1 MarkerType */
  	inquireCSS_Plain,	/* 2 MarkerScale */
  	inquireCSS_Plain,	/* 3 MarkerColourIndex */
--- 474,485 ----
  	replaceCSS_Plain,	/* 100 CellArray2D */
  	replaceCSS_Plain,	/* 101 ExtCellArray */
  	replaceCSS_Plain,	/* 102 Gdp */
! 	replaceCSS_Plain,	/* 103 Gdp2D */
! 	replaceCSS_Plain	/* 104 Noop */
  };
  
  cssTableType    InquireCSSElementTable[] = {
! 	inquireCSS_Plain,	/* 0 Propietary */
  	inquireCSS_Plain,	/* 1 MarkerType */
  	inquireCSS_Plain,	/* 2 MarkerScale */
  	inquireCSS_Plain,	/* 3 MarkerColourIndex */
***************
*** 578,582 ****
  	inquireCSS_Plain,	/* 100 CellArray2D */
  	inquireCSS_Plain,	/* 101 ExtCellArray */
  	inquireCSS_Plain,	/* 102 Gdp */
! 	inquireCSS_Plain	/* 103 Gdp2D */
  };
--- 582,587 ----
  	inquireCSS_Plain,	/* 100 CellArray2D */
  	inquireCSS_Plain,	/* 101 ExtCellArray */
  	inquireCSS_Plain,	/* 102 Gdp */
! 	inquireCSS_Plain,	/* 103 Gdp2D */
! 	inquireCSS_Plain	/* 104 Noop */
  };
*** -	Thu Jan 28 17:53:50 1993
--- mit/extensions/server/PEX/ddpex/mi/level4/miDynamics.c	Thu Jan 28 17:53:50 1993
***************
*** 1,4 ****
! /* $XConsortium: miDynamics.c,v 5.1 91/02/16 09:56:13 rws Exp $ */
  
  
  /***********************************************************
--- 1,4 ----
! /* $XConsortium: miDynamics.c,v 5.2 92/12/30 16:44:38 hersh Exp $ */
  
  
  /***********************************************************
***************
*** 61,67 ****
  
  	wksPtr = (miWksPtr) ((*pWKS)->deviceData);
  
! 	if (!wksPtr) break;		/* workstation has been freed */
  
  	switch (wksPtr->displayUpdate) {
  	    case PEXVisualizeEach:
--- 61,67 ----
  
  	wksPtr = (miWksPtr) ((*pWKS)->deviceData);
  
! 	if (!wksPtr) continue;		/* workstation has been freed */
  
  	switch (wksPtr->displayUpdate) {
  	    case PEXVisualizeEach:
*** -	Thu Jan 28 17:54:02 1993
--- mit/extensions/server/PEX/ddpex/mi/shared/miFont.c	Thu Jan 28 17:54:01 1993
***************
*** 1,4 ****
! /* $XConsortium: miFont.c,v 5.2 91/02/18 18:20:11 rws Exp $ */
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miFont.c,v 5.4 92/12/30 13:40:40 mor Exp $ */
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 117,123 ****
  
      /*	For now, let the default glyph be an asterisk */
      font->font_info.defaultGlyph = (CARD16)'*';
!     
      return (Success);
  
  }				  /* OpenPEXFont */
--- 117,126 ----
  
      /*	For now, let the default glyph be an asterisk */
      font->font_info.defaultGlyph = (CARD16)'*';
! 
!     /* It's a stroke font */
!     font->font_info.strokeFont = 1;
! 
      return (Success);
  
  }				  /* OpenPEXFont */
***************
*** 315,333 ****
      /* guess at a large number of bytes for the reply, and make sure
         we have this many (can always realloc later) */
      for (i=0; i<n; i++)
! 	guess_size += strlen(names[i]);
!     guess_size += n * EST_MAX_FONT_PROPS * sizeof(pexFontProp);
!     guess_size += n * (sizeof(CARD32) + sizeof(pexFontInfo));
      if (PU_BUF_TOO_SMALL(pBuffer, guess_size))
  	if (puBuffRealloc(pBuffer, guess_size) != Success) goto free_names;
  
      /* write names into reply buffer */
      pBuf = pBuffer->pBuf;
      for (i = 0; i < n; i++) {
  	len = strlen(names[i]);
  	PACK_CARD16(len, pBuf);
  	PACK_LISTOF_STRUCT(len, CARD8, names[i], pBuf);
! 	SKIP_PADDING(pBuf, PADDING(len)); }
  
  
      /* read in the font info, write it into the reply buffer */
--- 318,340 ----
      /* guess at a large number of bytes for the reply, and make sure
         we have this many (can always realloc later) */
      for (i=0; i<n; i++)
! 	guess_size += (strlen(names[i]) + 4);
!     guess_size += (sizeof(CARD32) + (n * sizeof(pexFontInfo)));
!     guess_size += (n * EST_MAX_FONT_PROPS * sizeof(pexFontProp));
      if (PU_BUF_TOO_SMALL(pBuffer, guess_size))
  	if (puBuffRealloc(pBuffer, guess_size) != Success) goto free_names;
  
      /* write names into reply buffer */
      pBuf = pBuffer->pBuf;
+     pBuffer->dataSize = 0;
      for (i = 0; i < n; i++) {
  	len = strlen(names[i]);
  	PACK_CARD16(len, pBuf);
  	PACK_LISTOF_STRUCT(len, CARD8, names[i], pBuf);
! 	SKIP_PADDING(pBuf, PADDING(sizeof(CARD16) + len));
! 	pBuffer->dataSize += sizeof(CARD16) + len +
! 	    PADDING(sizeof(CARD16) + len);
!     }
  
  
      /* read in the font info, write it into the reply buffer */
***************
*** 334,340 ****
      ddFont.deviceData = (ddPointer)&(fontData);
      fontData.properties = 0;
      PACK_CARD32(n, pBuf);
!     pBuffer->dataSize = pBuffer->pBuf - pBuffer->pHead;
      for (i = 0; i < n; i++) {
      
  	err = LoadPEXFontFile(	(ddULONG)(strlen(names[i])),
--- 341,347 ----
      ddFont.deviceData = (ddPointer)&(fontData);
      fontData.properties = 0;
      PACK_CARD32(n, pBuf);
!     pBuffer->dataSize += sizeof(CARD32);
      for (i = 0; i < n; i++) {
      
  	err = LoadPEXFontFile(	(ddULONG)(strlen(names[i])),
***************
*** 347,353 ****
  	if (PU_BUF_TOO_SMALL(pBuffer, pBuffer->dataSize))
  	    if (puBuffRealloc(pBuffer, pBuffer->dataSize) != Success)
  		goto free_names;
! 	PACK_STRUCT(pexFontInfo, ddFont.deviceData, pBuf);
  	if (fontData.font_info.numProps > 0) {
  	    PACK_LISTOF_STRUCT(	fontData.font_info.numProps, pexFontProp,
  				fontData.properties, pBuf);
--- 354,380 ----
  	if (PU_BUF_TOO_SMALL(pBuffer, pBuffer->dataSize))
  	    if (puBuffRealloc(pBuffer, pBuffer->dataSize) != Success)
  		goto free_names;
! 
! 	/*
! 	 * Now, make a pass from the first glyph to the last glyph, seeing if 
! 	 * all are defined.
! 	 */
! 	fontData.font_info.allExist = 1;
! 	ch_data = fontData.ch_data + fontData.font_info.firstGlyph;
! 	for (j = fontData.font_info.firstGlyph; 
! 	     j < fontData.num_ch && fontData.font_info.allExist;
! 	     j++, ch_data++ ) 
! 	    if (*ch_data == NULL || (*ch_data)->strokes.numLists <= 0) {
! 		fontData.font_info.allExist = 0;
! 		break; }
! 
! 	/* For now, let the default glyph be an asterisk */
! 	fontData.font_info.defaultGlyph = (CARD16)'*';
!     
! 	/* It's a stroke font */
! 	fontData.font_info.strokeFont = 1;
! 
! 	PACK_STRUCT(pexFontInfo, &(fontData.font_info), pBuf);
  	if (fontData.font_info.numProps > 0) {
  	    PACK_LISTOF_STRUCT(	fontData.font_info.numProps, pexFontProp,
  				fontData.properties, pBuf);
***************
*** 384,396 ****
   * Given the extremes of all of the character sets used in composing
   * an ISTRING, and given the extremes of the ISTRING itself, along
   * with path, expansion and alignment, calculate the correct
!  * concatenation point and alignment point.
   */
  void
! micalc_cpt_and_align(meta_font, xmin, xmax, ymin, ymax, path, exp,
! 					    pAlignment, cpt, align)
  Meta_font	    *meta_font;
! register float	     xmin, xmax, ymin, ymax;
  ddUSHORT	     path;
  ddTextAlignmentData *pAlignment;
  ddFLOAT		     exp;
--- 411,425 ----
   * Given the extremes of all of the character sets used in composing
   * an ISTRING, and given the extremes of the ISTRING itself, along
   * with path, expansion and alignment, calculate the correct
!  * concatenation point and alignment point.  The updated extreme values
!  * are returned.
   */
  void
! micalc_cpt_and_align(meta_font, extent_xmin, extent_xmax,
!     extent_ymin, extent_ymax, path, exp, pAlignment, cpt, align)
  Meta_font	    *meta_font;
! float		    *extent_xmin, *extent_xmax;
! float		    *extent_ymin, *extent_ymax;
  ddUSHORT	     path;
  ddTextAlignmentData *pAlignment;
  ddFLOAT		     exp;
***************
*** 398,403 ****
--- 427,436 ----
  register pexCoord2D *align;
  {
  
+     register float  xmin = *extent_xmin,
+                     xmax = *extent_xmax,
+                     ymin = *extent_ymin,
+                     ymax = *extent_ymax;
      pexCoord2D	    temp;
      
      /* some of the necessary info may not be calculated yet */
***************
*** 438,443 ****
--- 471,477 ----
  	    
  	case PEXPathDown:
  	    if (ymax > 0.0) {
+ 		temp.y = ymax;
  		ymax = ymin;
  		ymin = temp.y;
  	    } else {
***************
*** 570,575 ****
--- 604,614 ----
  	    break;
  	
      }
+ 
+     *extent_xmin = xmin;
+     *extent_xmax = xmax;
+     *extent_ymin = ymin;
+     *extent_ymax = ymax;
  }
  
  
***************
*** 613,619 ****
      ddFLOAT		     sp = spacing * FONT_COORD_HEIGHT;
      Meta_font		     meta_font;
      pexCoord2D		     cur, end, cpt, align;
!     register float	     xmin, xmax, ymin, ymax;
      float		     ht_scale = height / FONT_COORD_HEIGHT;
      extern unsigned long     PEXFontType;
      miTextFontEntry	    *miFontTable;
--- 652,658 ----
      ddFLOAT		     sp = spacing * FONT_COORD_HEIGHT;
      Meta_font		     meta_font;
      pexCoord2D		     cur, end, cpt, align;
!     float	     	     xmin, xmax, ymin, ymax;
      float		     ht_scale = height / FONT_COORD_HEIGHT;
      extern unsigned long     PEXFontType;
      miTextFontEntry	    *miFontTable;
***************
*** 683,692 ****
  	    mono_enc = (pexMonoEncoding *)ptr;
  	    ptr += sizeof(pexMonoEncoding);
  	    
! 	    if (mono_enc->characterSet > fontEntry->numFonts)
! 		mono_enc->characterSet = 0;
  
! 	    font_handle = fontEntry->fonts[mono_enc->characterSet];
  	    
  	    /* this is the font that this MONO_ENCODING would be rendered
  	     * with, thus we use it to base our extents on */
--- 722,732 ----
  	    mono_enc = (pexMonoEncoding *)ptr;
  	    ptr += sizeof(pexMonoEncoding);
  	    
! 	    if (mono_enc->characterSet < 1 ||
! 		mono_enc->characterSet > fontEntry->numFonts)
! 		mono_enc->characterSet = 1;
  
! 	    font_handle = fontEntry->fonts[mono_enc->characterSet - 1];
  	    
  	    /* this is the font that this MONO_ENCODING would be rendered
  	     * with, thus we use it to base our extents on */
***************
*** 758,764 ****
  		}
  	    }
  	    
! 	    ptr += PADDING(2 + mono_enc->numChars * 
  		    ((mono_enc->characterSetWidth == PEXCSByte) 
  			? sizeof(CARD8) 
  			: ((mono_enc->characterSetWidth == PEXCSShort) 
--- 798,804 ----
  		}
  	    }
  	    
! 	    ptr += PADDING(mono_enc->numChars * 
  		    ((mono_enc->characterSetWidth == PEXCSByte) 
  			? sizeof(CARD8) 
  			: ((mono_enc->characterSetWidth == PEXCSShort) 
***************
*** 770,777 ****
  	
  	if (some_characters) {
  	    
! 	    micalc_cpt_and_align(   &meta_font, xmin, xmax, ymin, ymax, path, 
! 				    expansion, pAlignment, &cpt, &align);
  						       
  	} else {
  	    /* no valid characters */
--- 810,817 ----
  	
  	if (some_characters) {
  	    
! 	    micalc_cpt_and_align( &meta_font, &xmin, &xmax, &ymin, &ymax,
! 				  path, expansion, pAlignment, &cpt, &align);
  						       
  	} else {
  	    /* no valid characters */
*** -	Thu Jan 28 17:54:03 1993
--- mit/extensions/server/PEX/ddpex/mi/shared/miNS.c	Thu Jan 28 17:54:03 1993
***************
*** 1,4 ****
! /* $XConsortium: miNS.c,v 5.1 91/02/16 09:56:17 rws Exp $ */
  
  
  /***********************************************************
--- 1,4 ----
! /* $XConsortium: miNS.c,v 5.2 91/11/15 19:39:51 hersh Exp $ */
  
  
  /***********************************************************
***************
*** 100,105 ****
--- 100,106 ----
      }
  
      pheader->nameCount = 0;
+     pheader->refCount = 0;
      pheader->freeFlag = MI_FALSE;
      MINS_EMPTY_NAMESET(pheader->names);
  
*** -	Thu Jan 28 17:54:06 1993
--- mit/extensions/server/PEX/ddpex/mi/shared/miMisc.c	Thu Jan 28 17:54:05 1993
***************
*** 1,4 ****
! /* $XConsortium: miMisc.c,v 5.3 91/07/10 09:08:10 rws Exp $ */
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miMisc.c,v 5.8 92/11/16 13:32:06 mor Exp $ */
  
  /***********************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 27,32 ****
--- 27,33 ----
  #include "mipex.h"
  #include "miInfo.h"
  #include "pexUtils.h"
+ #include "PEXprotost.h"
  
  /* pex device dependent initialization */
  ddpex43rtn
***************
*** 108,114 ****
  	SI_SUPP_MARKER_SIZES,
  	SI_BEST_COLOUR_APPROX_VALUES,
  	SI_TRANSPARENCY_SUPPORTED,
! 	SI_DOUBLE_BUFFERING_SUPPORTED
  };
  
  #define	FLOAT_INDEX(n)	 (n) - (SI_NUM_INT_IMPS + 1) 
--- 109,116 ----
  	SI_SUPP_MARKER_SIZES,
  	SI_BEST_COLOUR_APPROX_VALUES,
  	SI_TRANSPARENCY_SUPPORTED,
! 	SI_DOUBLE_BUFFERING_SUPPORTED,
! 	SI_MAX_HITS_EVENT_SUPPORTED
  };
  
  #define	FLOAT_INDEX(n)	 (n) - (SI_NUM_INT_IMPS + 1) 
***************
*** 248,253 ****
--- 250,263 ----
  	 {2, SI_PICK_DEVICE_2}}
  };
  
+ miEnumType	miPickOneMethodET[MI_MAXDRAWABLES][SI_PICK_ONE_NUM] = {
+ 	 {{1, SI_PICK_ONE_LAST}}
+ };
+ 
+ miEnumType	miPickAllMethodET[MI_MAXDRAWABLES][SI_PICK_ALL_NUM] = {
+ 	 {{1, SI_PICK_ALL_ALL}}
+ };
+ 
  miEnumType	miPolylineInterpMethodET[MI_MAXDRAWABLES][SI_LINE_INTERP_NUM] = {
  	{{1, SI_LINE_INTERP_1}}
  };
***************
*** 348,353 ****
--- 358,367 ----
  	{{0, ""}}
  };
  
+ miEnumType	miEscapeET[MI_MAXDRAWABLES][SI_ESCAPE_NUM] = {
+ 	{{1, SI_ESCAPE_1}}
+ };
+ 
  miEnumType	miRenderingColourModelET[MI_MAXDRAWABLES][SI_REND_COLOUR_NUM] = {
  	{{1, SI_REND_COLOUR_1}}
  };
***************
*** 368,374 ****
  #define PUT_BUF8(buf, value) \
             *(buf).C8++ = (value);
  
! #define PADDING(n) ( (n)&3 ? (4 - (n)&3) : 0)
  
  /* be sure k is defined before using this */
  /* size is the size of the string
--- 382,388 ----
  #define PUT_BUF8(buf, value) \
             *(buf).C8++ = (value);
  
! #define PADDING(n) ( (n)&3 ? (4 - ((n)&3)) : 0)
  
  /* be sure k is defined before using this */
  /* size is the size of the string
***************
*** 387,466 ****
          } }
  
  /* macro to count space needed for et info */
! #define COUNT_ET( num, pet ) 							\
! 	count+=4;	/* space for returned num value */			\
! 	switch (itemMask)							\
! 	{									\
! 		case PEXETIndex:	/* return index values only */		\
! 			count += (num << 1);					\
! 			/* add pad if necessary */				\
! 			if (num & 1)						\
! 				count+=2;					\
! 		break;								\
! 										\
! 		case PEXETMnemonic:	/* return mnemonics only */		\
! 			for (j=0; j<num; j++, pet++)					\
! 			{							\
! 				/* add length of string */			\
! 				count += 2;					\
! 				/* then number of chars in string */		\
! 				count +=  strlen((pet)->name);			\
! 				/* then pads for string (and its length) */	\
! 				count += PADDING(strlen((pet)->name) + 2);	\
! 			}							\
! 		break;								\
! 										\
! 		case PEXETBoth:		/* return index and mnemonic */		\
! 			for (j=0; j<num; j++, pet++)					\
! 			{							\
! 				/* add index */					\
! 				count += 2;					\
! 				/* add length of string */			\
! 				count += 2;					\
! 				/* then number of chars in string */		\
! 				count +=  strlen((pet)->name);			\
! 				/* then pads for string */			\
! 				count += PADDING( strlen((pet)->name) );	\
! 			}							\
! 		break;								\
! 										\
          }			  /* switch (itemMask) */
  
  /* macro to put hard coded et info into buffer */
  #define GET_ET( num, pet ) \
! 	/* always increment the list count and return the number of types */	\
! 	(*pNumLists)++;								\
! 	PUT_BUF32(pbuf, (num));							\
! 	/* now put in the index and/or mnemonic */				\
! 	switch (itemMask)							\
! 	{									\
! 		case PEXETIndex:	/* return index values only */		\
! 			for (j=0; j<(num); j++, pet++)					\
! 				PUT_BUF16(pbuf, (pet)->index);			\
! 			/* add pad if necessary */				\
! 			if ((num) & 1)						\
! 				PUT_BUF16(pbuf, 0);				\
! 		break;								\
! 										\
! 		case PEXETMnemonic:	/* return mnemonics only */		\
! 			for (j=0; j<(num); j++, pet++)					\
! 			{							\
! 				size = strlen( (pet)->name );			\
! 				/* PUT_STR pads end of string */		\
! 				PUT_STR(pbuf, (pet)->name, size, 0);		\
! 			}							\
! 		break;								\
! 										\
! 		case PEXETBoth:		/* return index and mnemonic */		\
! 			for (j=0; j<(num); j++, pet++)					\
! 			{							\
! 				size = strlen( (pet)->name );			\
! 				PUT_BUF16(pbuf, (pet)->index);			\
! 				/* PUT_STR pads end of string */		\
! 				PUT_STR(pbuf, (pet)->name, size, 2);		\
! 			}							\
! 		break;								\
! 										\
          }			  /* switch (itemMask) */
  
  #define	DO_ET(num, pet)			\
--- 401,480 ----
          } }
  
  /* macro to count space needed for et info */
! #define COUNT_ET( num, pet ) 						\
! 	count+=4;	/* space for returned num value */		\
! 	switch (itemMask)						\
! 	{								\
! 		case PEXETIndex:	/* return index values only */	\
! 			count += (num << 1);				\
! 			/* add pad if necessary */			\
! 			if (num & 1)					\
! 				count+=2;				\
! 		break;							\
! 									\
! 		case PEXETMnemonic:	/* return mnemonics only */	\
! 			for (j=0; j<num; j++, pet++)			\
! 			{						\
! 				/* add length of string */		\
! 				count += 2;				\
! 				/* then number of chars in string */	\
! 				count +=  strlen((pet)->name);		\
! 				/* then pads for string (and its length) */\
! 				count += PADDING(strlen((pet)->name) + 2);\
! 			}						\
! 		break;							\
! 									\
! 		case PEXETBoth:		/* return index and mnemonic */	\
! 			for (j=0; j<num; j++, pet++)			\
! 			{						\
! 				/* add index */				\
! 				count += 2;				\
! 				/* add length of string */		\
! 				count += 2;				\
! 				/* then number of chars in string */	\
! 				count +=  strlen((pet)->name);		\
! 				/* then pads for string */		\
! 				count += PADDING( strlen((pet)->name) );\
! 			}						\
! 		break;							\
! 									\
          }			  /* switch (itemMask) */
  
  /* macro to put hard coded et info into buffer */
  #define GET_ET( num, pet ) \
! 	/* always increment the list count and return the number of types */\
! 	(*pNumLists)++;							\
! 	PUT_BUF32(pbuf, (num));						\
! 	/* now put in the index and/or mnemonic */			\
! 	switch (itemMask)						\
! 	{								\
! 		case PEXETIndex:	/* return index values only */	\
! 			for (j=0; j<(num); j++, pet++)			\
! 				PUT_BUF16(pbuf, (pet)->index);		\
! 			/* add pad if necessary */			\
! 			if ((num) & 1)					\
! 				PUT_BUF16(pbuf, 0);			\
! 		break;							\
! 									\
! 		case PEXETMnemonic:	/* return mnemonics only */	\
! 			for (j=0; j<(num); j++, pet++)			\
! 			{						\
! 				size = strlen( (pet)->name );		\
! 				/* PUT_STR pads end of string */	\
! 				PUT_STR(pbuf, (pet)->name, size, 0);	\
! 			}						\
! 		break;							\
! 									\
! 		case PEXETBoth:		/* return index and mnemonic */	\
! 			for (j=0; j<(num); j++, pet++)			\
! 			{						\
! 				size = strlen( (pet)->name );		\
! 				PUT_BUF16(pbuf, (pet)->index);		\
! 				/* PUT_STR pads end of string */	\
! 				PUT_STR(pbuf, (pet)->name, size, 2);	\
! 			}						\
! 		break;							\
! 									\
          }			  /* switch (itemMask) */
  
  #define	DO_ET(num, pet)			\
***************
*** 708,713 ****
--- 722,745 ----
  		DO_ET(num, pet);
  		break;
  
+ 	      case PEXETEscape:
+ 		num = SI_ESCAPE_NUM;
+ 		pet = miEscapeET[drawType];
+ 		DO_ET(num, pet);
+ 		break;
+ 
+ 	      case PEXETPickOneMethod:
+ 		num = SI_PICK_ONE_NUM;
+ 		pet = miPickOneMethodET[drawType];
+ 		DO_ET(num, pet);
+ 		break;
+ 
+ 	      case PEXETPickAllMethod:
+ 		num = SI_PICK_ALL_NUM;
+ 		pet = miPickAllMethodET[drawType];
+ 		DO_ET(num, pet);
+ 		break;
+ 
  	    }			  /* switch (*ptype) */
  
  	}			  /* for (i=0, ptype = pEnumTypeList) */
***************
*** 722,724 ****
--- 754,848 ----
      return (Success);
  }				  /* InquireEnumTypeInfo */
  
+ /*************************************************************************
+  * macro for MatchRendererTargets.
+  */
+ 
+ /* 30 is arbitrary constant */
+ #define ADD_TRIPLET(d,t,v) { int diff; \
+           if ((pexBuffer->dataSize + sizeof(pexRendererTarget)) > \
+                                                 pexBuffer->bufSize){\
+             diff = (unsigned long)p - (unsigned long)pexBuffer->pBuf; \
+             puBuffRealloc(pexBuffer,pexBuffer->bufSize + \
+                                              30*sizeof(pexRendererTarget)); \
+ 	    p = (pexRendererTarget *)(((unsigned long)pexBuffer->pBuf) +diff);\
+ 	  } \
+ 	  p->depth = (d); \
+           p->type = (t); \
+ 	  p->visualID = (v); \
+ 	  pexBuffer->dataSize += sizeof(pexRendererTarget); \
+           p++; nTargets++; \
+           if (nTargets >= maxTriplets) return (Success); \
+           }
+ /*++
+  |
+  |  Function Name:  MatchRendererTargets    
+  |
+  |  Function Description:
+  |       Handles Match Renderer Taregets Request.
+  |       Given a visualID, depth & drawable type, tell whether PEX will
+  |       render into it.  Real life: PEX does not do all drawables.
+  |
+  |  Note(s):
+  |
+  --*/
+ 			       
+ 
+ ddpex43rtn
+ MatchRendererTargets(pDraw, depth, drawType, visualID, maxTriplets, pexBuffer)
+     DrawablePtr pDraw;
+     int         depth;
+     int         drawType;
+     VisualID    visualID;
+     int         maxTriplets;
+     ddBuffer   *pexBuffer;
+ {
+     int i;
+     int nTargets = 0;
+ 
+     register ScreenPtr pScreen;
+     int idepth, ivisual;
+     DepthPtr pDepth;
+ 
+     pexRendererTarget *p = (pexRendererTarget *)pexBuffer->pBuf;
+ 
+ /*
+  * Code originally lifted from CreateWindow (x11/server/dix/window.c)
+  */
+     pScreen = pDraw->pScreen;
+ 
+     for(idepth = 0; idepth < pScreen->numDepths; idepth++) {
+ 
+       pDepth = (DepthPtr) &pScreen->allowedDepths[idepth];
+ 
+       /*
+        * if depth is wild carded, then we need to walk them all.
+        */
+       if ((depth == pDepth->depth) || (depth == 0)) {
+ 
+ 	for (ivisual = 0; ivisual < pDepth->numVids; ivisual++)	{
+ 
+ 	  /* if visual is a match or it's wildcarded then do it */
+ 	  if ((visualID == pDepth->vids[ivisual]) || (visualID == 0)) {
+ 	    /*
+              * Here is the moment of truth, this is just going to say
+              * that everything is available for PEX rendering. It is possible
+              * that vendors will want to create a global table that hangs
+              * around.  That way they can be qualified in ddpexInit().
+              * If compiled with -DMULTIBUFFER it assumes that mutli buffers
+              * are fair game.
+              */
+ 	    if ((drawType == PEXWindow) || (drawType == PEXDontCare))
+ 	      ADD_TRIPLET(pDepth->depth, PEXWindow, pDepth->vids[ivisual] );
+ 	    if ((drawType == PEXPixmap) || (drawType == PEXDontCare))
+ 	      ADD_TRIPLET(pDepth->depth, PEXPixmap, pDepth->vids[ivisual] );
+ #ifdef MULTIBUFFER
+ 	    if ((drawType == PEXBuffer) || (drawType == PEXDontCare))
+ 	      ADD_TRIPLET(pDepth->depth, PEXBuffer, pDepth->vids[ivisual] );
+ #endif	      
+ 	  }
+ 	}
+       }
+     }
+     return (Success);
+ }
*** -	Thu Jan 28 17:54:14 1993
--- mit/extensions/server/PEX/ddpex/mi/shared/miPattLUT.c	Thu Jan 28 17:54:14 1993
***************
*** 1,4 ****
! /* $XConsortium: miPattLUT.c,v 5.2 91/07/19 20:45:20 hersh Exp $ */
  
  /***********************************************************
  Copyright (c) 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miPattLUT.c,v 5.3 92/12/30 16:21:28 hersh Exp $ */
  
  /***********************************************************
  Copyright (c) 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 346,353 ****
      MILUT_NUM_ENTS(pheader) = 0;
      SET_TABLE_INFO( pheader->drawType, &(pheader->tableInfo) );
  
!     if ( (LUT_TABLE_START(pheader) = 
! 	(MI_LUT_ENTRY_STR *)xalloc(MILUT_ALLOC_ENTS(pheader) * sizeof(MI_LUT_ENTRY_STR)) ) == NULL)
      {
  	MILUT_DESTROY_HEADER(pheader);
  	return(BadAlloc);
--- 346,358 ----
      MILUT_NUM_ENTS(pheader) = 0;
      SET_TABLE_INFO( pheader->drawType, &(pheader->tableInfo) );
  
!     if (MILUT_ALLOC_ENTS(pheader) == 0)
!     {
!       LUT_TABLE_START(pheader) = NULL;
!     }
!     else if ((LUT_TABLE_START(pheader) = (MI_LUT_ENTRY_STR *)
! 		xalloc(MILUT_ALLOC_ENTS(pheader) * sizeof(MI_LUT_ENTRY_STR))) 
! 		== NULL)
      {
  	MILUT_DESTROY_HEADER(pheader);
  	return(BadAlloc);
*** -	Thu Jan 28 17:54:17 1993
--- mit/extensions/server/PEX/ddpex/mi/shared/miLUTProcs.ci	Thu Jan 28 17:54:16 1993
***************
*** 1,4 ****
! /* $XConsortium: miLUTProcs.ci,v 5.4 91/07/19 20:47:01 hersh Exp $ */
  
  /***********************************************************
  Copyright (c) 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: miLUTProcs.ci,v 5.5 92/12/30 16:21:34 hersh Exp $ */
  
  /***********************************************************
  Copyright (c) 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 65,71 ****
  
  /* get pointer to first legal entry in the table */
  #define	FIRST_ENTRY( pheader )		\
! 	LUT_TABLE_START(pheader) + MILUT_START_INDEX(pheader)
  
  #define SET_TABLE_INFO( drawType, pInfo )       \
          switch(drawType) {                               \
--- 65,71 ----
  
  /* get pointer to first legal entry in the table */
  #define	FIRST_ENTRY( pheader )		\
! 	LUT_TABLE_START(pheader)
  
  #define SET_TABLE_INFO( drawType, pInfo )       \
          switch(drawType) {                               \
***************
*** 584,591 ****
      MILUT_NUM_ENTS(pheader) = 0;
      SET_TABLE_INFO( pheader->drawType, &(pheader->tableInfo) );
  
!     if ( (LUT_TABLE_START(pheader) = 
! 	(MI_LUT_ENTRY_STR *)xalloc(MILUT_ALLOC_ENTS(pheader) * sizeof(MI_LUT_ENTRY_STR)) ) == NULL)
      {
  	MILUT_DESTROY_HEADER(pheader);
  	return(BadAlloc);
--- 584,596 ----
      MILUT_NUM_ENTS(pheader) = 0;
      SET_TABLE_INFO( pheader->drawType, &(pheader->tableInfo) );
  
!     if (MILUT_ALLOC_ENTS(pheader) == 0)
!     {
!       LUT_TABLE_START(pheader) = NULL;
!     }
!     else if ( (LUT_TABLE_START(pheader) = (MI_LUT_ENTRY_STR *)
! 		xalloc(MILUT_ALLOC_ENTS(pheader) * sizeof(MI_LUT_ENTRY_STR)) ) 
! 		== NULL)
      {
  	MILUT_DESTROY_HEADER(pheader);
  	return(BadAlloc);
*** -	Thu Jan 28 18:22:08 1993
--- mit/extensions/server/multibuf.c	Thu Jan 28 18:22:07 1993
***************
*** 24,30 ****
  
  ********************************************************/
  
! /* $XConsortium: multibuf.c,v 1.11 91/06/01 13:25:50 rws Exp $ */
  #define NEED_REPLIES
  #define NEED_EVENTS
  #include <stdio.h>
--- 24,30 ----
  
  ********************************************************/
  
! /* $XConsortium: multibuf.c,v 1.16 92/11/14 16:40:25 rws Exp $ */
  #define NEED_REPLIES
  #define NEED_EVENTS
  #include <stdio.h>
***************
*** 77,82 ****
--- 77,83 ----
  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 */
***************
*** 111,118 ****
  static unsigned char	MultibufferReqCode;
  static int		MultibufferEventBase;
  static int		MultibufferErrorBase;
! static int		MultibufferScreenIndex = -1;
! static int		MultibufferWindowIndex = -1;
  
  static int		BlockHandlerRegistered;
  static void		MultibufferBlockHandler(), MultibufferWakeupHandler();
--- 112,119 ----
  static unsigned char	MultibufferReqCode;
  static int		MultibufferEventBase;
  static int		MultibufferErrorBase;
! int			MultibufferScreenIndex = -1;
! int			MultibufferWindowIndex = -1;
  
  static int		BlockHandlerRegistered;
  static void		MultibufferBlockHandler(), MultibufferWakeupHandler();
***************
*** 123,132 ****
  
  static void		BumpTimeStamp ();
  
! static void		MultibufferExpose ();
! static void		MultibufferUpdate ();
  static void		AliasMultibuffer ();
! static void		DisposeMultibuffers ();
  static void		RecalculateMultibufferOtherEvents ();
  static int		EventSelectForMultibuffer();
  
--- 124,135 ----
  
  static void		BumpTimeStamp ();
  
! void			MultibufferExpose ();
! void			MultibufferUpdate ();
  static void		AliasMultibuffer ();
! int			CreateImageBuffers ();
! void			DestroyImageBuffers ();
! int			DisplayImageBuffers ();
  static void		RecalculateMultibufferOtherEvents ();
  static int		EventSelectForMultibuffer();
  
***************
*** 134,140 ****
   * The Pixmap associated with a buffer can be found as a resource
   * with this type
   */
! static RESTYPE		MultibufferDrawableResType;
  static void		MultibufferDrawableDelete ();
  /*
   * The per-buffer data can be found as a resource with this type.
--- 137,143 ----
   * The Pixmap associated with a buffer can be found as a resource
   * with this type
   */
! RESTYPE			MultibufferDrawableResType;
  static void		MultibufferDrawableDelete ();
  /*
   * The per-buffer data can be found as a resource with this type.
***************
*** 282,287 ****
--- 285,357 ----
      return (client->noClientException);
  }
  
+ 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;
+ 
+     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;
+     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];
+     }
+     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;
+     return Success;
+ }
+ 
  static int
  ProcCreateImageBuffers (client)
      register ClientPtr	client;
***************
*** 293,302 ****
      XID				*ids;
      int				len, nbuf;
      int				i;
!     MultibuffersPtr			pMultibuffers;
!     MultibufferPtr			pMultibuffer;
!     ScreenPtr			pScreen;
!     int				width, height, depth;
  
      REQUEST_AT_LEAST_SIZE (xMbufCreateImageBuffersReq);
      len = stuff->length - (sizeof(xMbufCreateImageBuffersReq) >> 2);
--- 363,369 ----
      XID				*ids;
      int				len, nbuf;
      int				i;
!     int				err;
  
      REQUEST_AT_LEAST_SIZE (xMbufCreateImageBuffersReq);
      len = stuff->length - (sizeof(xMbufCreateImageBuffersReq) >> 2);
***************
*** 333,397 ****
      {
  	LEGAL_NEW_RESOURCE(ids[i], client);
      }
!     pMultibuffers = (MultibuffersPtr) xalloc (sizeof (MultibuffersRec));
!     if (!pMultibuffers)
! 	return BadAlloc;
!     pMultibuffers->pWindow = pWin;
!     pMultibuffers->buffers = (MultibufferPtr) xalloc (nbuf * sizeof (MultibufferRec));
!     if (!pMultibuffers->buffers)
!     {
! 	xfree (pMultibuffers);
! 	return BadAlloc;
!     }
!     if (!AddResource (pWin->drawable.id, MultibuffersResType, (pointer) pMultibuffers))
!     {
! 	xfree (pMultibuffers->buffers);
! 	xfree (pMultibuffers);
! 	return BadAlloc;
!     }
!     width = pWin->drawable.width;
!     height = pWin->drawable.height;
!     depth = pWin->drawable.depth;
!     pScreen = pWin->drawable.pScreen;
!     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];
!     }
!     pMultibuffers->numMultibuffer = i;
!     pMultibuffers->displayedMultibuffer = -1;
!     if (i > 0)
! 	AliasMultibuffer (pMultibuffers, 0);
!     pMultibuffers->updateAction = stuff->updateAction;
!     pMultibuffers->updateHint = stuff->updateHint;
!     pMultibuffers->windowMode = MultibufferModeMono;
!     pMultibuffers->lastUpdate.months = 0;
!     pMultibuffers->lastUpdate.milliseconds = 0;
!     pMultibuffers->width = width;
!     pMultibuffers->height = height;
!     pWin->devPrivates[MultibufferWindowIndex].ptr = (pointer) pMultibuffers;
      rep.type = X_Reply;
      rep.length = 0;
      rep.sequenceNumber = client->sequence;
!     rep.numberBuffer = pMultibuffers->numMultibuffer;
      if (client->swapped)
      {
      	swaps(&rep.sequenceNumber, n);
--- 400,413 ----
      {
  	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);
***************
*** 412,418 ****
      int		    nbuf;
      XID		    *ids;
      int		    i, j;
!     CARD32	    minDelay, maxDelay;
      TimeStamp	    activateTime, bufferTime;
      
      REQUEST_AT_LEAST_SIZE (xMbufDisplayImageBuffersReq);
--- 428,434 ----
      int		    nbuf;
      XID		    *ids;
      int		    i, j;
!     CARD32	    minDelay;
      TimeStamp	    activateTime, bufferTime;
      
      REQUEST_AT_LEAST_SIZE (xMbufDisplayImageBuffersReq);
***************
*** 420,426 ****
      if (!nbuf)
  	return Success;
      minDelay = stuff->minDelay;
-     maxDelay = stuff->maxDelay;
      ids = (XID *) &stuff[1];
      ppMultibuffers = (MultibuffersPtr *) xalloc (nbuf * sizeof (MultibuffersPtr));
      pMultibuffer = (MultibufferPtr *) xalloc (nbuf * sizeof (MultibufferPtr));
--- 436,441 ----
***************
*** 482,488 ****
      REQUEST_SIZE_MATCH (xMbufDestroyImageBuffersReq);
      if (!(pWin = LookupWindow (stuff->window, client)))
  	return BadWindow;
!     DisposeMultibuffers (pWin);
      return Success;
  }
  
--- 497,503 ----
      REQUEST_SIZE_MATCH (xMbufDestroyImageBuffersReq);
      if (!(pWin = LookupWindow (stuff->window, client)))
  	return BadWindow;
!     DestroyImageBuffers (pWin);
      return Success;
  }
  
***************
*** 1072,1080 ****
  	AliasMultibuffer (ppMultibuffers[i], pMultibuffer[i] - ppMultibuffers[i]->buffers);
  	FreeScratchGC (pGC);
      }
-     return;
  }
  
  static DisplayRequestPtr    pPendingRequests;
  
  static void
--- 1087,1141 ----
  	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 DisplayRequestPtr    pPendingRequests;
  
  static void
***************
*** 1152,1162 ****
      return TRUE;
  }
  
  static void
  MultibufferBlockHandler (data, wt, LastSelectMask)
      pointer	    data;		/* unused */
      struct timeval  **wt;		/* wait time */
!     long	    *LastSelectMask;
  {
      DisplayRequestPtr	    pReq, pNext;
      unsigned long	    newdelay, olddelay;
--- 1213,1224 ----
      return TRUE;
  }
  
+ /*ARGSUSED*/
  static void
  MultibufferBlockHandler (data, wt, LastSelectMask)
      pointer	    data;		/* unused */
      struct timeval  **wt;		/* wait time */
!     long	    *LastSelectMask;	/* unused */
  {
      DisplayRequestPtr	    pReq, pNext;
      unsigned long	    newdelay, olddelay;
***************
*** 1194,1199 ****
--- 1256,1262 ----
      }
  }
  
+ /*ARGSUSED*/
  static void
  MultibufferWakeupHandler (data, i, LastSelectMask)
      pointer	    data;
***************
*** 1265,1271 ****
   * Send Expose events to interested clients
   */
  
! static void
  MultibufferExpose (pMultibuffer, pRegion)
      MultibufferPtr	pMultibuffer;
      RegionPtr	pRegion;
--- 1328,1334 ----
   * Send Expose events to interested clients
   */
  
! void
  MultibufferExpose (pMultibuffer, pRegion)
      MultibufferPtr	pMultibuffer;
      RegionPtr	pRegion;
***************
*** 1306,1312 ****
      }
  }
  
! static void
  MultibufferUpdate (pMultibuffer, time)
      MultibufferPtr	pMultibuffer;
      CARD32	time;
--- 1369,1375 ----
      }
  }
  
! void
  MultibufferUpdate (pMultibuffer, time)
      MultibufferPtr	pMultibuffer;
      CARD32	time;
***************
*** 1325,1331 ****
   * events
   */
  
! static void
  MultibufferClobber (pMultibuffer)
      MultibufferPtr	pMultibuffer;
  {
--- 1388,1394 ----
   * events
   */
  
! void
  MultibufferClobber (pMultibuffer)
      MultibufferPtr	pMultibuffer;
  {
***************
*** 1377,1384 ****
   * window
   */
  
! static void
! DisposeMultibuffers (pWin)
      WindowPtr	pWin;
  {
      FreeResourceByType (pWin->drawable.id, MultibuffersResType, FALSE);
--- 1440,1447 ----
   * window
   */
  
! void
! DestroyImageBuffers (pWin)
      WindowPtr	pWin;
  {
      FreeResourceByType (pWin->drawable.id, MultibuffersResType, FALSE);
***************
*** 1471,1477 ****
  	pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, pWin->drawable.depth);
  	if (!pPixmap)
  	{
! 	    DisposeMultibuffers (pWin);
  	    break;
  	}
  	ValidateGC (pPixmap, pGC);
--- 1534,1540 ----
  	pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, pWin->drawable.depth);
  	if (!pPixmap)
  	{
! 	    DestroyImageBuffers (pWin);
  	    break;
  	}
  	ValidateGC (pPixmap, pGC);
***************
*** 1502,1507 ****
--- 1565,1571 ----
  }
  
  /* Resource delete func for MultibufferDrawableResType */
+ /*ARGSUSED*/
  static void
  MultibufferDrawableDelete (pDrawable, id)
      DrawablePtr	pDrawable;
***************
*** 1525,1539 ****
  }
  
  /* Resource delete func for MultibufferResType */
  static void
  MultibufferDelete (pMultibuffer, id)
      MultibufferPtr	pMultibuffer;
      XID		id;
  {
!     return;
  }
  
  /* Resource delete func for MultibuffersResType */
  static void
  MultibuffersDelete (pMultibuffers, id)
      MultibuffersPtr	pMultibuffers;
--- 1589,1613 ----
  }
  
  /* Resource delete func for MultibufferResType */
+ /*ARGSUSED*/
  static void
  MultibufferDelete (pMultibuffer, id)
      MultibufferPtr	pMultibuffer;
      XID		id;
  {
!     MultibuffersPtr	pMultibuffers;
! 
!     pMultibuffers = pMultibuffer->pMultibuffers;
!     if (--pMultibuffers->refcnt == 0)
!     {
! 	FreeResourceByType (pMultibuffers->pWindow->drawable.id,
! 			    MultibuffersResType, TRUE);
! 	xfree (pMultibuffers);
!     }
  }
  
  /* Resource delete func for MultibuffersResType */
+ /*ARGSUSED*/
  static void
  MultibuffersDelete (pMultibuffers, id)
      MultibuffersPtr	pMultibuffers;
***************
*** 1541,1553 ****
  {
      int	i;
  
!     for (i = 0; i < pMultibuffers->numMultibuffer; i++)
! 	FreeResource (pMultibuffers->buffers[i].pPixmap->drawable.id, 0);
!     xfree (pMultibuffers->buffers);
!     xfree (pMultibuffers);
  }
  
  /* Resource delete func for DisplayRequestResType */
  static void
  DisplayRequestDelete (pRequest, id)
      DisplayRequestPtr	pRequest;
--- 1615,1629 ----
  {
      int	i;
  
!     if (pMultibuffers->refcnt == pMultibuffers->numMultibuffer)
!     {
! 	for (i = pMultibuffers->numMultibuffer; --i >= 0; )
! 	    FreeResource (pMultibuffers->buffers[i].pPixmap->drawable.id, 0);
!     }
  }
  
  /* Resource delete func for DisplayRequestResType */
+ /*ARGSUSED*/
  static void
  DisplayRequestDelete (pRequest, id)
      DisplayRequestPtr	pRequest;
*** -	Thu Jan 28 18:09:50 1993
--- mit/extensions/lib/PEX/archive/ar_conv.c	Thu Jan 28 18:09:50 1993
***************
*** 1,4 ****
! /* $XConsortium: ar_conv.c,v 5.3 91/07/01 16:20:00 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: ar_conv.c,v 5.4 91/12/30 18:20:16 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 37,46 ****
  
  /* For in place conversions which happen in this file */
  #define CONVERT_CARD32(swp, val) \
!     (val = ((swp)->ConvertCARD32 ? (*(swp)->ConvertCARD32)(&(val)) : (val)))
  
  #define CONVERT_CARD16(swp, val) \
!     (val = ((swp)->ConvertCARD16 ? (*(swp)->ConvertCARD16)(&(val)) : (val)))
      
      
  static pexSwap   clientSwapStructure;	
--- 37,46 ----
  
  /* For in place conversions which happen in this file */
  #define CONVERT_CARD32(swp, val) \
!     if ((swp)->ConvertCARD32)  ((*(swp)->ConvertCARD32)(&(val))) 
  
  #define CONVERT_CARD16(swp, val) \
!     if ((swp)->ConvertCARD16)  ((*(swp)->ConvertCARD16)(&(val))) 
      
      
  static pexSwap   clientSwapStructure;	
***************
*** 49,77 ****
  static int fromFormat;
  static int toFormat;
  
! extern PEXFLOAT	ConvertIEEEToVax();
! extern PEXFLOAT	SwapIEEEToVax();
! extern PEXFLOAT	ConvertVaxToIEEE();
! extern PEXFLOAT	SwapVaxToIEEE();
! extern CARD16	SwapCARD16();
! extern CARD32	SwapCARD32();
  
  typedef struct {
! 	CARD16 (*s)();		/* Function to convert a short */
! 	CARD32 (*l)();		/* Function to convert a long */
! 	PEXFLOAT  (*f)();		/* Function to convert a float */
  } ThreeFuncs;
  
  static ThreeFuncs ConversionFunction[4][4] = {
  	{   /* From Big Endian Ieee */
  	    { 0, 0, 0 },
! 	    { SwapCARD16, SwapCARD32, (PEXFLOAT (*)())SwapCARD32 },
  	    { 0, 0, ConvertIEEEToVax },
  	    { SwapCARD16, SwapCARD32, SwapIEEEToVax }
  	},
  	{
  	    /* From Big Endian DecF */
! 	    { SwapCARD16, SwapCARD32, (PEXFLOAT (*)())SwapCARD32 },
  	    { 0, 0, 0 },
  	    { SwapCARD16, SwapCARD32, SwapIEEEToVax },
  	    { 0, 0, ConvertIEEEToVax }
--- 49,77 ----
  static int fromFormat;
  static int toFormat;
  
! extern void	ConvertIEEEToVax();
! extern void	SwapIEEEToVax();
! extern void	ConvertVaxToIEEE();
! extern void	SwapVaxToIEEE();
! extern void	SwapCARD16();
! extern void	SwapCARD32();
  
  typedef struct {
! 	void (*s)();		/* Function to convert a short */
! 	void (*l)();		/* Function to convert a long */
! 	void  (*f)();		/* Function to convert a float */
  } ThreeFuncs;
  
  static ThreeFuncs ConversionFunction[4][4] = {
  	{   /* From Big Endian Ieee */
  	    { 0, 0, 0 },
! 	    { SwapCARD16, SwapCARD32, (void (*)())SwapCARD32 },
  	    { 0, 0, ConvertIEEEToVax },
  	    { SwapCARD16, SwapCARD32, SwapIEEEToVax }
  	},
  	{
  	    /* From Big Endian DecF */
! 	    { SwapCARD16, SwapCARD32, (void (*)())SwapCARD32 },
  	    { 0, 0, 0 },
  	    { SwapCARD16, SwapCARD32, SwapIEEEToVax },
  	    { 0, 0, ConvertIEEEToVax }
***************
*** 81,93 ****
  	    { 0, 0, ConvertVaxToIEEE },
  	    { SwapCARD16, SwapCARD32, SwapVaxToIEEE },
  	    { 0, 0, 0 },
! 	    { SwapCARD16, SwapCARD32, (PEXFLOAT (*)())SwapCARD32 }
  	},
  	{
  	    /* From Little Endian DecF */
  	    { SwapCARD16, SwapCARD32, SwapVaxToIEEE },
  	    { 0, 0, ConvertVaxToIEEE },
! 	    { SwapCARD16, SwapCARD32, (PEXFLOAT (*)())SwapCARD32 },
  	    { 0, 0, 0 }
  	}
  };
--- 81,93 ----
  	    { 0, 0, ConvertVaxToIEEE },
  	    { SwapCARD16, SwapCARD32, SwapVaxToIEEE },
  	    { 0, 0, 0 },
! 	    { SwapCARD16, SwapCARD32, (void (*)())SwapCARD32 }
  	},
  	{
  	    /* From Little Endian DecF */
  	    { SwapCARD16, SwapCARD32, SwapVaxToIEEE },
  	    { 0, 0, ConvertVaxToIEEE },
! 	    { SwapCARD16, SwapCARD32, (void (*)())SwapCARD32 },
  	    { 0, 0, 0 }
  	}
  };
***************
*** 172,178 ****
      register int	command;
      register CARD16	type;
      CARD16		length;
!     CARD16	      (*localswapshort)();
      extern OCFunction	cPEXOutputCmd[];
      extern OCFunction	uPEXOutputCmd[];
  
--- 172,178 ----
      register int	command;
      register CARD16	type;
      CARD16		length;
!     void	      (*localswapshort)();
      extern OCFunction	cPEXOutputCmd[];
      extern OCFunction	uPEXOutputCmd[];
  
***************
*** 195,202 ****
  	
  	    /* we are reading fram an archive so we must 'decode' */
  	    if (localswapshort != NULL) {
! 		type = (*localswapshort)(head->elementType);
! 		length = (*localswapshort)(head->length);
  	    } else {
  		type = head->elementType;
  		length = head->length;
--- 195,204 ----
  	
  	    /* we are reading fram an archive so we must 'decode' */
  	    if (localswapshort != NULL) {
! 		(*localswapshort)(head->elementType);
! 		type = head->elementType;
! 		(*localswapshort)(head->length);
! 		length = head->length;
  	    } else {
  		type = head->elementType;
  		length = head->length;
*** -	Thu Jan 28 18:09:52 1993
--- mit/extensions/lib/PEX/archive/ar_ops.c	Thu Jan 28 18:09:52 1993
***************
*** 1,4 ****
! /* $XConsortium: ar_ops.c,v 5.5 91/07/10 09:18:29 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: ar_ops.c,v 5.6 91/12/11 16:04:27 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 394,410 ****
  Ar_handle     arh;
  { 
      int nbytes;
-     short opcode;
      int fd = arh->fd;
   
      /* Find EOA element position */
      nbytes = lseek(fd, (off_t)-4, L_XTND);
   
      /* Insure the last element is EOA */
!     if (read(fd, (char *)&opcode, sizeof(short)) != sizeof(short)) 
  	return(1);
  
!     if (opcode != PHG_AR_EOA) 
  	return(1);
   
      /* Remove the EOA element.  This is written by pclosearfile. */
--- 394,410 ----
  Ar_handle     arh;
  { 
      int nbytes;
      int fd = arh->fd;
+     Phg_ar_end_archive    endar;
   
      /* Find EOA element position */
      nbytes = lseek(fd, (off_t)-4, L_XTND);
   
      /* Insure the last element is EOA */
!     if (read(fd, (char *)&endar, sizeof(endar)) != sizeof(endar))
  	return(1);
  
!     if (endar.opcode != PHG_AR_EOA) 
  	return(1);
   
      /* Remove the EOA element.  This is written by pclosearfile. */
***************
*** 477,489 ****
  phg_ar_write_eoa(fd)
  int fd;
  {
!     int opcode = PHG_AR_EOA << 16;
!  
      /* Find end of file */
      (void) lseek(fd, (off_t)0, L_XTND);
   
!     /* Write the EOA element */
!     if (write(fd, (char *)&opcode, sizeof(int)) != sizeof(int)) 
  	return(1);
   
      return(0);
--- 477,490 ----
  phg_ar_write_eoa(fd)
  int fd;
  {
!     Phg_ar_end_archive    endar;
!     
      /* Find end of file */
      (void) lseek(fd, (off_t)0, L_XTND);
   
!     endar.opcode = PHG_AR_EOA;
!     
!     if (write(fd, (char *)&endar, sizeof(endar)) != sizeof(endar))
  	return(1);
   
      return(0);
*** -	Thu Jan 28 18:10:05 1993
--- mit/extensions/lib/PEX/c_binding/cb_ar.c	Thu Jan 28 18:10:05 1993
***************
*** 1,4 ****
! /* $XConsortium: cb_ar.c,v 5.2 91/07/12 18:08:54 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cb_ar.c,v 5.3 92/12/23 10:31:13 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 416,430 ****
  	    }
  	    size += (*ar_files)->num_ar_files * sizeof(Par_file);
  	    if ( CB_STORE_SPACE( ((_Pstore *)store), size, error_ind ) ) {
  		(*ar_files)->ar_files = (Par_file *)((_Pstore *)store)->buf;
  		name_buf = (char *)
  		    ((*ar_files)->ar_files + (*ar_files)->num_ar_files);
  		for ( i = 0; i < MAX_NO_OPEN_ARFILES; i++ ) {
  		    if ( psl->ar_files[i].used ) {
! 			(*ar_files)->ar_files[i].id = psl->ar_files[i].arid;
! 			(*ar_files)->ar_files[i].name = name_buf;
  			strcpy( name_buf, psl->ar_files[i].fname );
  			name_buf += strlen( psl->ar_files[i].fname ) + 1;
  		    }
  		}
  	    }
--- 416,432 ----
  	    }
  	    size += (*ar_files)->num_ar_files * sizeof(Par_file);
  	    if ( CB_STORE_SPACE( ((_Pstore *)store), size, error_ind ) ) {
+ 		register int j = 0;
  		(*ar_files)->ar_files = (Par_file *)((_Pstore *)store)->buf;
  		name_buf = (char *)
  		    ((*ar_files)->ar_files + (*ar_files)->num_ar_files);
  		for ( i = 0; i < MAX_NO_OPEN_ARFILES; i++ ) {
  		    if ( psl->ar_files[i].used ) {
! 			(*ar_files)->ar_files[j].id = psl->ar_files[i].arid;
! 			(*ar_files)->ar_files[j].name = name_buf;
  			strcpy( name_buf, psl->ar_files[i].fname );
  			name_buf += strlen( psl->ar_files[i].fname ) + 1;
+ 			j++;
  		    }
  		}
  	    }
*** -	Thu Jan 28 18:10:07 1993
--- mit/extensions/lib/PEX/c_binding/cb_ctrl.c	Thu Jan 28 18:10:07 1993
***************
*** 1,4 ****
! /* $XConsortium: cb_ctrl.c,v 5.6 91/07/12 18:09:22 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cb_ctrl.c,v 5.7 93/01/04 16:48:54 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 56,62 ****
  merge_args( xinfo )
      Pxphigs_info	*xinfo;
  {
!     XrmDatabase		db;
  
      if ( !xinfo->rmdb ) {
  	XrmInitialize();
--- 56,62 ----
  merge_args( xinfo )
      Pxphigs_info	*xinfo;
  {
!     XrmDatabase		db = NULL;
  
      if ( !xinfo->rmdb ) {
  	XrmInitialize();
*** -	Thu Jan 28 18:10:14 1993
--- mit/extensions/lib/PEX/c_binding/cb_inp.c	Thu Jan 28 18:10:13 1993
***************
*** 1,4 ****
! /* $XConsortium: cb_inp.c,v 5.3 91/07/15 14:20:58 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cb_inp.c,v 5.7 93/01/05 14:29:13 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 35,41 ****
      (((Wst*)_wsinfo->wstype)->desc_tbl.phigs_dt.ws_category)
  
  #define DEVICE_EXISTS( _idt, _class, _num) \
!     ((_num) <= (_idt)->num_devs._class)
  
  #define LINE_BUNDLE_VALID( _lb, _dt ) \
      ( (_lb)->colour >= 0 \
--- 35,41 ----
      (((Wst*)_wsinfo->wstype)->desc_tbl.phigs_dt.ws_category)
  
  #define DEVICE_EXISTS( _idt, _class, _num) \
!     ((_num) > 0 && (_num) <= (_idt)->num_devs._class)
  
  #define LINE_BUNDLE_VALID( _lb, _dt ) \
      ( (_lb)->colour >= 0 \
***************
*** 940,946 ****
      Wst_input_wsdt			*idt;
      register int			i;
  
!     if ( idt = outin_ws_open( phg_cur_cph, ws, Pfn_req_stroke, NO_DT_NEEDED,
  		REPORT_ERROR)) {
  	if ( !DEVICE_EXISTS( idt, stroke, dev) ) {
  	    ERR_REPORT( phg_cur_cph->erh, ERR250);
--- 940,946 ----
      Wst_input_wsdt			*idt;
      register int			i;
  
!     if ( idt = input_ws_open( phg_cur_cph, ws, Pfn_req_stroke, NO_DT_NEEDED,
  		REPORT_ERROR)) {
  	if ( !DEVICE_EXISTS( idt, stroke, dev) ) {
  	    ERR_REPORT( phg_cur_cph->erh, ERR250);
***************
*** 1107,1113 ****
      Wst_defloc			*ddt;
  {
      int		status = 0;
!     Pint	err;
  
      switch ( pet ) {
  	case 1:
--- 1107,1113 ----
      Wst_defloc			*ddt;
  {
      int		status = 0;
!     Pint	err = 0;
  
      switch ( pet ) {
  	case 1:
***************
*** 1114,1132 ****
  	case 2:
  	case 3:
  	    /* No data */
! 	    status = !0;
! 	    break;
  
  	default:
  	    /* Shouldn't get here, pet should be verified before calling. */
! 	     err = ERR260;
! 	    break;
      }
  
-     if ( !status ) {
- 	ERR_REPORT( cph->erh, err);
-     }
-     return status;
  }
  
  static void
--- 1114,1127 ----
  	case 2:
  	case 3:
  	    /* No data */
! 	    return !0;
  
  	default:
  	    /* Shouldn't get here, pet should be verified before calling. */
! 	    ERR_REPORT( cph->erh, ERR260);
! 	    return 0;
      }
  
  }
  
  static void
***************
*** 1403,1417 ****
--- 1398,1419 ----
  {
      int			status = 1;
  
+     /* This is a placeholder for vendor code, commented to make picky 
+        compilers happy
      switch ( pet ) {
  	default:
  	    break;
      }
+     */
  
      if ( !status ) {
  	ERR_REPORT( cph->erh, ERR260);
  	status = 0;
  
+     } else if ( rec->low > rec->high ) {
+ 	ERR_REPORT( cph->erh, ERR260);
+ 	status = 0;
+ 
      } else if ( init < rec->low || init > rec->high ) {
  	ERR_REPORT( cph->erh, ERR261);
  	status = 0;
***************
*** 1526,1531 ****
--- 1528,1534 ----
      register int	i, size, cnt;
      register char	**strs, *strlist, *str;
      int			list_count, status = 0;
+     int			chk_flag = 0;
  
      switch ( pet ) {
  	case 1:
***************
*** 1546,1553 ****
  	    } else if ( list_count < 0 || list_count > ddt->choices ) {
  		ERR_REPORT( cph->erh, ERR260);
  
! 	    } else
! 		status = !0;
  	    break;
  
  	case 3:
--- 1549,1567 ----
  	    } else if ( list_count < 0 || list_count > ddt->choices ) {
  		ERR_REPORT( cph->erh, ERR260);
  
! 	    } else {
! 		for ( i = 0; i < list_count; i++ ) {
! 		    if ( *((rec->pets.pet_r2.prompts)+i) != 0 ||
! 			*((rec->pets.pet_r2.prompts)+i) != 1) {
! 			chk_flag = 1;
! 			ERR_REPORT( cph->erh, ERR260);
! 			break;
! 		    }
! 		}
! 
! 		if ( chk_flag == 0 )
! 		    status = !0;		
! 	    }
  	    break;
  
  	case 3:
***************
*** 1720,1729 ****
--- 1734,1746 ----
      Ppoint3	*aper;
      */
  
+     /* This is a placeholder for vendor code, commented to make picky 
+        compilers happy
      switch ( pet ) {
  	default:
  	    break;
      }
+     */
  
      if ( !status ) {
  	ERR_REPORT( cph->erh, ERR260);
***************
*** 1845,1854 ****
--- 1862,1874 ----
  {
      int		status = 1;
  
+     /* This is a placeholder for vendor code, commented to make picky 
+        compilers happy
      switch ( pet ) {
  	default:
  	    break;
      }
+     */
  
      if ( !status ) {
  	ERR_REPORT( cph->erh, ERR260);
***************
*** 2565,2571 ****
      Phg_args			cp_args;
      Wst_input_wsdt		*idt;
  
!     if (idt = input_ws_open( phg_cur_cph, ws, Pfn_INQUIRY, NO_DT_NEEDED, err)) {
  	if ( !DEVICE_EXISTS( idt, pick, dev) ) {
  	    *err = ERR250;
  	} else {
--- 2585,2591 ----
      Phg_args			cp_args;
      Wst_input_wsdt		*idt;
  
!     if (idt = outin_ws_open( phg_cur_cph, ws, Pfn_INQUIRY, NO_DT_NEEDED, err)) {
  	if ( !DEVICE_EXISTS( idt, pick, dev) ) {
  	    *err = ERR250;
  	} else {
***************
*** 2595,2601 ****
      exfilt_size = state->exclusion_filter.num_ints * sizeof(Pint);
      total_size = path_size + infilt_size + exfilt_size;
      if ( CB_STORE_SPACE( store, total_size, err ) ) {
! 	init_pick->depth = path_size;
  	init_pick->path_list = (Ppick_path_elem *)store->buf;
  	if ( path_size > 0 )
  	    bcopy( (char*)state->pick.pick_path.path_list,
--- 2615,2621 ----
      exfilt_size = state->exclusion_filter.num_ints * sizeof(Pint);
      total_size = path_size + infilt_size + exfilt_size;
      if ( CB_STORE_SPACE( store, total_size, err ) ) {
! 	init_pick->depth = state->pick.pick_path.depth;
  	init_pick->path_list = (Ppick_path_elem *)store->buf;
  	if ( path_size > 0 )
  	    bcopy( (char*)state->pick.pick_path.path_list,
***************
*** 2646,2652 ****
  	*path_order = state->order;
  	*filter = &((_Pstore *)store)->data.pick_data3.filter;
  	*init_pick = &((_Pstore *)store)->data.pick_data3.init_pick;
! 	copy_pick_data( ((_Pstore *)store), err, state, init_pick, filter );
  	if ( !*err ) {
  	    *pick_data = &((_Pstore *)store)->data.pick_data3.drec;
  	    /* Copy the data record. */
--- 2666,2672 ----
  	*path_order = state->order;
  	*filter = &((_Pstore *)store)->data.pick_data3.filter;
  	*init_pick = &((_Pstore *)store)->data.pick_data3.init_pick;
! 	copy_pick_data( ((_Pstore *)store), err, state, *init_pick, *filter );
  	if ( !*err ) {
  	    *pick_data = &((_Pstore *)store)->data.pick_data3.drec;
  	    /* Copy the data record. */
***************
*** 2689,2695 ****
  	*path_order = state->order;
  	*filter = &((_Pstore *)store)->data.pick_data.filter;
  	*init_pick = &((_Pstore *)store)->data.pick_data.init_pick;
! 	copy_pick_data( ((_Pstore *)store), err, state, init_pick, filter );
  	if ( !*err ) {
  	    *pick_data = &((_Pstore *)store)->data.pick_data.drec;
  	    /* Copy the data record. */
--- 2709,2715 ----
  	*path_order = state->order;
  	*filter = &((_Pstore *)store)->data.pick_data.filter;
  	*init_pick = &((_Pstore *)store)->data.pick_data.init_pick;
! 	copy_pick_data( ((_Pstore *)store), err, state, *init_pick, *filter );
  	if ( !*err ) {
  	    *pick_data = &((_Pstore *)store)->data.pick_data.drec;
  	    /* Copy the data record. */
*** -	Thu Jan 28 18:10:15 1993
--- mit/extensions/lib/PEX/c_binding/cb_lite.c	Thu Jan 28 18:10:15 1993
***************
*** 1,4 ****
! /* $XConsortium: cb_lite.c,v 5.2 91/02/16 09:47:52 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cb_lite.c,v 5.3 92/12/23 10:33:23 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 150,155 ****
--- 150,156 ----
      if (CB_ENTRY_CHECK(phg_cur_cph, ERR3, Pfn_set_light_src_rep)) {
      	if (PSL_WS_STATE(phg_cur_cph->psl) != PWS_ST_WSOP) {
  	    ERR_REPORT(phg_cur_cph->erh, ERR3);
+ 	    return;
  
  	} else if (!(wsinfo = phg_psl_get_ws_info( phg_cur_cph->psl, ws))) {
  	    ERR_REPORT(phg_cur_cph->erh, ERR54);
*** -	Thu Jan 28 18:10:23 1993
--- mit/extensions/lib/PEX/c_binding/cb_ws.c	Thu Jan 28 18:10:23 1993
***************
*** 1,4 ****
! /* $XConsortium: cb_ws.c,v 5.3 91/07/12 19:54:04 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cb_ws.c,v 5.6 93/01/06 10:21:11 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 740,747 ****
  
      if (wsinfo = phg_cb_ws_open(phg_cur_cph, ws, Pfn_set_hlhsr_mode)) {
  	dt = &((Wst*)wsinfo->wstype)->desc_tbl.phigs_dt;
! 	if (dt->ws_category == PCAT_MI) {
! 	    ERR_REPORT(phg_cur_cph->erh, ERR57);
  
  	} 
  	for (i = 0; i < dt->num_hlhsr_modes; i ++) {
--- 740,749 ----
  
      if (wsinfo = phg_cb_ws_open(phg_cur_cph, ws, Pfn_set_hlhsr_mode)) {
  	dt = &((Wst*)wsinfo->wstype)->desc_tbl.phigs_dt;
! 	if (!(dt->ws_category == PCAT_OUT ||
! 	      dt->ws_category == PCAT_OUTIN ||
! 	      dt->ws_category == PCAT_MO)) {
! 	    ERR_REPORT(phg_cur_cph->erh, ERR59);
  
  	} 
  	for (i = 0; i < dt->num_hlhsr_modes; i ++) {
***************
*** 1045,1050 ****
--- 1047,1060 ----
  		    ? rep->back_colr.val.ind : 1) < 0) {
  	    ERR_REPORT( phg_cur_cph->erh, ERR113);
  
+         } else if ((rep->refl_props.specular_colr.type == PINDIRECT
+              ? rep->refl_props.specular_colr.val.ind : 1) < 0) {
+              ERR_REPORT( phg_cur_cph->erh, ERR113);
+  
+         } else if ((rep->back_refl_props.specular_colr.type == PINDIRECT
+              ? rep->back_refl_props.specular_colr.val.ind : 1) < 0) {
+              ERR_REPORT( phg_cur_cph->erh, ERR113);
+ 
  	} else if ( !phg_cb_int_in_list( (Pint)rep->style,
  					dt->out_dt.num_interior_styles,
  					(Pint*)dt->out_dt.interior_styles) ||
***************
*** 1058,1064 ****
  	    ERR_REPORT( phg_cur_cph->erh, ERR112);
  
  	} else if (!CB_COLOUR_MODEL_SUPPORTED(rep->colr.type) ||
! 		   !CB_COLOUR_MODEL_SUPPORTED(rep->back_colr.type)) {
  	    ERR_REPORT( phg_cur_cph->erh, ERR110);
  
  	} else if (!CB_INT_SHADING_SUPPORTED(rep->shad_meth) ||
--- 1068,1079 ----
  	    ERR_REPORT( phg_cur_cph->erh, ERR112);
  
  	} else if (!CB_COLOUR_MODEL_SUPPORTED(rep->colr.type) ||
! 		   !CB_COLOUR_MODEL_SUPPORTED(rep->back_colr.type) ||
! 		   !CB_COLOUR_MODEL_SUPPORTED(
! 			  rep->refl_props.specular_colr.type) ||
! 		   !CB_COLOUR_MODEL_SUPPORTED(
! 			  rep->back_refl_props.specular_colr.type)) {
! 	    
  	    ERR_REPORT( phg_cur_cph->erh, ERR110);
  
  	} else if (!CB_INT_SHADING_SUPPORTED(rep->shad_meth) ||
***************
*** 2571,2580 ****
  
      } else {
  	dt = &((Wst*)wsinfo->wstype)->desc_tbl.phigs_dt;
! 	if ( !(dt->ws_category == PCAT_OUT || 
! 	       dt->ws_category == PCAT_OUTIN ||
! 	       dt->ws_category == PCAT_MO) ) {
! 	    *error_ind = ERR59;
  
  	} else {
  	    cp_args.data.idata = ws;
--- 2586,2593 ----
  
      } else {
  	dt = &((Wst*)wsinfo->wstype)->desc_tbl.phigs_dt;
! 	if ( dt->ws_category == PCAT_MI) {
! 	    *error_ind = ERR57;
  
  	} else {
  	    cp_args.data.idata = ws;
*** -	Thu Jan 28 18:10:25 1993
--- mit/extensions/lib/PEX/c_binding/cb_wst.c	Thu Jan 28 18:10:25 1993
***************
*** 1,4 ****
! /* $XConsortium: cb_wst.c,v 5.8 91/08/23 17:15:53 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cb_wst.c,v 5.9 93/01/04 15:52:13 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 2784,2790 ****
      } else if ( dt->ws_category == PCAT_MO ) {
  	*error_ind = ERR62;
  
!     } else if ( index > dt->out_dt.num_predefined_depth_cue_indices) {
  	*error_ind = ERR102;
  
      } else if ( index < 0 ) {
--- 2784,2790 ----
      } else if ( dt->ws_category == PCAT_MO ) {
  	*error_ind = ERR62;
  
!     } else if ( index >= dt->out_dt.num_predefined_depth_cue_indices) {
  	*error_ind = ERR102;
  
      } else if ( index < 0 ) {
***************
*** 3108,3114 ****
      } else if ( dt->ws_category == PCAT_MO ) {
  	*error_ind = ERR62;
  
!     } else if ( index > dt->out_dt.num_predefined_colr_mapping_indices) {
  	*error_ind = ERR102;
  
      } else if ( index < 0 ) {
--- 3108,3114 ----
      } else if ( dt->ws_category == PCAT_MO ) {
  	*error_ind = ERR62;
  
!     } else if ( index >= dt->out_dt.num_predefined_colr_mapping_indices) {
  	*error_ind = ERR102;
  
      } else if ( index < 0 ) {
*** -	Thu Jan 28 18:10:27 1993
--- mit/extensions/lib/PEX/c_binding/cb_xfut.c	Thu Jan 28 18:10:27 1993
***************
*** 1,4 ****
! /* $XConsortium: cb_xfut.c,v 5.4 91/07/22 19:14:52 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cb_xfut.c,v 5.6 92/02/24 17:18:28 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 243,251 ****
      } else {
  	*error_ind = 0;
  	w = 1.0 / w;
! 	r->x = w * (m[0][0] * p->x + m[0][1] * p->y + m[0][2] * p->z + m[0][3]);
! 	r->y = w * (m[1][0] * p->x + m[1][1] * p->y + m[1][2] * p->z + m[1][3]);
! 	r->z = w * (m[2][0] * p->x + m[2][1] * p->y + m[2][2] * p->z + m[2][3]);
      }
  }
  
--- 243,281 ----
      } else {
  	*error_ind = 0;
  	w = 1.0 / w;
! 	if (r != p) {
! 	    r->x = w * (m[0][0] * p->x +
! 			m[0][1] * p->y +
! 			m[0][2] * p->z +
! 			m[0][3]);
! 	    r->y = w * (m[1][0] * p->x +
! 			m[1][1] * p->y +
! 			m[1][2] * p->z +
! 			m[1][3]);
! 	    r->z = w * (m[2][0] * p->x +
! 			m[2][1] * p->y +
! 			m[2][2] * p->z +
! 			m[2][3]);
! 	} else {
! 	    Ppoint3 t;
! 
! 	    t.x =  w * (m[0][0] * p->x +
! 			m[0][1] * p->y +
! 			m[0][2] * p->z +
! 			m[0][3]);
! 	    t.y =  w * (m[1][0] * p->x +
! 			m[1][1] * p->y +
! 			m[1][2] * p->z +
! 			m[1][3]);
! 	    t.z =  w * (m[2][0] * p->x +
! 			m[2][1] * p->y +
! 			m[2][2] * p->z +
! 			m[2][3]);
! 
! 	    r->x = t.x;
! 	    r->y = t.y;
! 	    r->z = t.z;
! 	}
      }
  }
  
***************
*** 268,275 ****
      } else {
  	*error_ind = 0;
  	w = 1.0 / w;
! 	r->x = w * (m[0][0] * p->x + m[0][1] * p->y + m[0][2]);
! 	r->y = w * (m[1][0] * p->x + m[1][1] * p->y + m[1][2]);
      }
  }
  
--- 298,319 ----
      } else {
  	*error_ind = 0;
  	w = 1.0 / w;
! 	if (p != r) {
! 	    r->x = w * (m[0][0] * p->x +
! 			m[0][1] * p->y + m[0][2]);
! 	    r->y = w * (m[1][0] * p->x +
! 			m[1][1] * p->y + m[1][2]);
! 	} else {
! 	    Ppoint t;
! 
! 	    t.x =  w * (m[0][0] * p->x +
! 		        m[0][1] * p->y + m[0][2]);
! 	    t.y =  w * (m[1][0] * p->x +
! 		        m[1][1] * p->y + m[1][2]);
! 
! 	    r->x = t.x;
! 	    r->y = t.y;
! 	}
      }
  }
  
***************
*** 419,425 ****
  	*error_ind = 0;
  	build_transform3( pt, shift, x_ang, y_ang, z_ang, scale, xform);
  	/* Assuming pre-multiplication of old by new. */
! 	phg_mat_mul(result, m, xform);
      }
  }
  
--- 463,469 ----
  	*error_ind = 0;
  	build_transform3( pt, shift, x_ang, y_ang, z_ang, scale, xform);
  	/* Assuming pre-multiplication of old by new. */
! 	phg_mat_mul(result, xform, m);
      }
  }
  
***************
*** 442,448 ****
  	*error_ind = 0;
  	build_transform( pt, shift, angle, scale, xform);
  	/* Assuming pre-multiplication of old by new. */
! 	phg_mat_mul_3x3(result, m, xform);
      }
  }
  
--- 486,492 ----
  	*error_ind = 0;
  	build_transform( pt, shift, angle, scale, xform);
  	/* Assuming pre-multiplication of old by new. */
! 	phg_mat_mul_3x3(result, xform, m);
      }
  }
  
*** -	Thu Jan 28 18:10:31 1993
--- mit/extensions/lib/PEX/c_binding/cb_stru.c	Thu Jan 28 18:10:30 1993
***************
*** 1,4 ****
! /* $XConsortium: cb_stru.c,v 5.2 91/07/12 20:20:57 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cb_stru.c,v 5.4 93/01/05 14:33:59 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 649,654 ****
--- 649,658 ----
      if ( !CB_ENTRY_CHECK( phg_cur_cph, 0, Pfn_INQUIRY)) {
  	*error_ind = ERR2;
  
+     } else if ( element == 0) {
+ 	*error_ind = 0;
+ 	*data = (Pelem_data *) 0;
+ 
      } else if ( element < 0) {
  	*error_ind = ERR202;
  
***************
*** 870,875 ****
--- 874,882 ----
  
      if ( ! CB_ENTRY_CHECK(phg_cur_cph, 0, Pfn_INQUIRY)) {
  	*error_ind = ERR2;
+ 
+     } else if ( ceil < 1 || ceil > sp->num_elem_refs ) {
+ 	*error_ind = ERR204;
  
      } else {
  	args->ref_pt = *ref;
*** -	Thu Jan 28 18:10:45 1993
--- mit/extensions/lib/PEX/cp/cpx_clnt.c	Thu Jan 28 18:10:45 1993
***************
*** 1,4 ****
! /* $XConsortium: cpx_clnt.c,v 5.7 91/07/15 18:19:50 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cpx_clnt.c,v 5.9 92/01/28 11:38:46 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 26,31 ****
--- 26,34 ----
  
  /* CPX code that is used only in the client process. */
  
+ #define NEED_EVENTS
+ 
+ #include <X11/Xlibint.h>
  #include "phg.h"
  #include "cp.h"
  #include "ar.h"
*** -	Thu Jan 28 18:10:47 1993
--- mit/extensions/lib/PEX/cp/cp_ccom.c	Thu Jan 28 18:10:47 1993
***************
*** 1,4 ****
! /* $XConsortium: cp_ccom.c,v 5.18 91/07/26 20:11:11 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cp_ccom.c,v 5.19 92/08/10 20:46:50 eswu Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 1336,1342 ****
--- 1336,1347 ----
      }
      tmpnam(name.sun_path);
      name.sun_family = AF_UNIX;
+ #ifdef BSD44SOCKETS /* unlikely */
+     name.sun_len = strlen(name.sun_path);
+     socket_size = SUN_LEN(&name);
+ #else
      socket_size = sizeof(name.sun_family) + strlen(name.sun_path) + 1;
+ #endif
      if (bind(fd, &name, socket_size) < 0 ||
  	listen(fd, 1) < 0 ||
  	connect(sv[0], &name, socket_size) < 0 ||
***************
*** 1374,1379 ****
--- 1379,1387 ----
  
      /* Port number of 6100 is arbitrary, (100 above the X server port). */
      bzero ((char *)&insock, sizeof (insock));
+ #ifdef BSD44SOCKETS /* unlikely */
+     insock.sin_len = sizeof(insock);
+ #endif
      insock.sin_family = AF_INET;
      port_num = 6100;
      insock.sin_port = htons((unsigned short)(port_num));
***************
*** 1414,1424 ****
--- 1422,1449 ----
  #endif
  
  #ifdef DEBUG
+ 
+ #ifdef BSD44SOCKETS
  #define Connect(fd,addr) {\
      struct sockaddr_un	un_addr; \
  \
      strcpy (un_addr.sun_path, addr);\
+     un_addr.sun_len = strlen(un_addr.sun_path);\
+     un_addr.sun_family = AF_UNIX;\
      fd = socket (AF_UNIX, SOCK_STREAM, 0);\
+     if (connect (fd, &un_addr, SUN_LEN(&un_addr)))\
+     {\
+ 	perror ("phigsmon connect");\
+ 	abort ();\
+     }\
+ }
+ #else /* !BSD44SOCKETS */
+ #define Connect(fd,addr) {\
+     struct sockaddr_un	un_addr; \
+ \
+     strcpy (un_addr.sun_path, addr);\
+     un_addr.sun_family = AF_UNIX;\
+     fd = socket (AF_UNIX, SOCK_STREAM, 0);\
      if (connect (fd, &un_addr, sizeof (short) + strlen (addr)))\
      {\
  	perror ("phigsmon connect");\
***************
*** 1425,1430 ****
--- 1450,1457 ----
  	abort ();\
      }\
  }
+ #endif /* !BSD44SOCKETS */
+ 
      Connect (cph->data.client.sfd, DEBUG_PHIGSMON_SOCKET_COMMAND);
      Connect (cph->erh->data.client.sfd, DEBUG_PHIGSMON_SOCKET_ERROR);
      if (read (cph->data.client.sfd, &pid, sizeof (pid)) != sizeof (pid))
*** -	Thu Jan 28 18:10:50 1993
--- mit/extensions/lib/PEX/cp/cpa_css.c	Thu Jan 28 18:10:50 1993
***************
*** 1,4 ****
! /* $XConsortium: cpa_css.c,v 5.4 91/07/17 19:00:54 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cpa_css.c,v 5.7 92/12/29 21:21:41 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 888,897 ****
  		return;	/* can't create the new structure */
  	    }
  	}
!     }
!     (void)PEXChangeStructureRefs(  css_srvr->display,
  	    old->xid, new->xid );
!     CPA_FLUSH( css_srvr );
  }
  
  
--- 888,897 ----
  		return;	/* can't create the new structure */
  	    }
  	}
! 	(void)PEXChangeStructureRefs(  css_srvr->display,
  	    old->xid, new->xid );
! 	CPA_FLUSH( css_srvr );
!     }
  }
  
  
***************
*** 903,909 ****
  {
      Ws			*ws;
      pexBitmask		mask[PEXMSGetWksInfo];
!     pexEnumTypeIndex	old_modes[MAX_NO_OPEN_WS];
      int			cur;
  
      /* First need to set workstation update states to avoid an intermediate
--- 903,909 ----
  {
      Ws			*ws;
      pexBitmask		mask[PEXMSGetWksInfo];
!     CARD32              old_modes[MAX_NO_OPEN_WS];
      int			cur;
  
      /* First need to set workstation update states to avoid an intermediate
***************
*** 940,946 ****
  	if ( ws->css_srvr == css_srvr ) {
  	    if ( old_modes[cur] == PEXVisualizeEach )
  		(void)PEXSetDisplayUpdateMode( ws->display, ws->rid,
! 		    old_modes[cur] );
  	    cur++;
  	}
      }
--- 940,946 ----
  	if ( ws->css_srvr == css_srvr ) {
  	    if ( old_modes[cur] == PEXVisualizeEach )
  		(void)PEXSetDisplayUpdateMode( ws->display, ws->rid,
! 		    (pexEnumTypeIndex) old_modes[cur] );
  	    cur++;
  	}
      }
***************
*** 1079,1091 ****
      PEX_CONV_FROM_Ppoint3(&args->ref_pt, pex_pt)
      pex_dist = (PEXFLOAT *)(pex_pt + 1);
      *pex_dist = args->distance;
!     card16_p = (CARD16 *)(pex_dist + 1);
!     *card16_p = args->ceiling;
!     card8_p = (CARD8 *)(card16_p + 2);
!     *card8_p = PEX_CONV_FROM_Pclip(args->mclip_flag);
  
      /* Convert the start path. */
!     card32_p = (CARD32 *)(card8_p + 4); /* info + padding */
      if ( args->start_path.num_elem_refs <= 0 )
  	*card32_p = 0;
      else {
--- 1079,1092 ----
      PEX_CONV_FROM_Ppoint3(&args->ref_pt, pex_pt)
      pex_dist = (PEXFLOAT *)(pex_pt + 1);
      *pex_dist = args->distance;
!     card32_p = (CARD32 *)(pex_dist + 1);
!     *card32_p = (CARD32)args->ceiling;
!     card32_p++;
!     *card32_p = (args->mclip_flag == PIND_CLIP) ?
! 	(CARD32) PEXClip : (CARD32) PEXNoClip;
  
      /* Convert the start path. */
!     card32_p++;
      if ( args->start_path.num_elem_refs <= 0 )
  	*card32_p = 0;
      else {
*** -	Thu Jan 28 18:10:51 1993
--- mit/extensions/lib/PEX/cp/cpa_ws.c	Thu Jan 28 18:10:51 1993
***************
*** 1,4 ****
! /* $XConsortium: cpa_ws.c,v 5.5 91/07/15 15:37:46 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cpa_ws.c,v 5.6 91/10/01 03:00:18 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 120,128 ****
      else {
  	st->def_mode = ws->out_ws.def_mode;
  	st->mod_mode = ws->out_ws.mod_mode;
! 	st->state = PEX_CONV_TO_Pvisualrep( *(CARD8 *)buf );
  	buf += 4;
! 	st->display_surf = PEX_CONV_TO_Pdisp_surf_empty( *(CARD8 *)buf );
      }
  }
  
--- 120,128 ----
      else {
  	st->def_mode = ws->out_ws.def_mode;
  	st->mod_mode = ws->out_ws.mod_mode;
! 	st->state = PEX_CONV_TO_Pvisualrep( *(CARD32 *)buf );
  	buf += 4;
! 	st->display_surf = PEX_CONV_TO_Pdisp_surf_empty( *(CARD32 *)buf );
      }
  }
  
***************
*** 391,401 ****
      if ( !PEXGetWksInfo( ws->display, ws->rid, mask, &buf ))
  	ret->err = ERR900;	/* TODO: Use phg_pex_errno. */
      else {
! 	hlhsr_mode->state = PEX_CONV_TO_Pupdatest( *(CARD8*)buf );
  	buf += 4;
! 	hlhsr_mode->req_mode = PEX_CONV_PEX_HLHSR_MODE( *(CARD16 *)buf );
  	buf += 4;
! 	hlhsr_mode->cur_mode = PEX_CONV_PEX_HLHSR_MODE( *(CARD16 *)buf );
      }
  }
  
--- 391,401 ----
      if ( !PEXGetWksInfo( ws->display, ws->rid, mask, &buf ))
  	ret->err = ERR900;	/* TODO: Use phg_pex_errno. */
      else {
! 	hlhsr_mode->state = PEX_CONV_TO_Pupdatest( *(CARD32*)buf );
  	buf += 4;
! 	hlhsr_mode->req_mode = PEX_CONV_PEX_HLHSR_MODE( *(CARD32 *)buf );
  	buf += 4;
! 	hlhsr_mode->cur_mode = PEX_CONV_PEX_HLHSR_MODE( *(CARD32 *)buf );
      }
  }
  
***************
*** 595,601 ****
  {
      caddr_t		buf;
      CARD32		count;
!     pexTableIndex	*indices;
  
      register	int	i;
      register	Pint	*list;
--- 595,601 ----
  {
      caddr_t		buf;
      CARD32		count;
!     CARD32       	*indices;
  
      register	int	i;
      register	Pint	*list;
***************
*** 614,620 ****
  	    ret->err = ERR900;	/* TODO: use phg_pex_errno. */
  	else {
  	    count = *(CARD32 *)buf;
! 	    indices = (pexTableIndex *)(buf + 4);
  	    if ( count > 0 &&
  		    !PHG_SCRATCH_SPACE( &ws->scratch, count * sizeof(Pint)) )
  		ret->err = ERR900;
--- 614,620 ----
  	    ret->err = ERR900;	/* TODO: use phg_pex_errno. */
  	else {
  	    count = *(CARD32 *)buf;
! 	    indices = (CARD32 *)(buf + 4);
  	    if ( count > 0 &&
  		    !PHG_SCRATCH_SPACE( &ws->scratch, count * sizeof(Pint)) )
  		ret->err = ERR900;
***************
*** 621,630 ****
  	    else {
  		ret->data.int_list.num_ints = count;
  		ret->data.int_list.ints = list = (Pint *)ws->scratch.buf;
! 		/* View entries come back as CARD16-s interspersed with
! 		 * two bytes of padding.
  		 */
! 		for ( i = 0; i < count; i++, list++, indices += 2 )
  		    *list = *indices;
  	    }
  	}
--- 621,629 ----
  	    else {
  		ret->data.int_list.num_ints = count;
  		ret->data.int_list.ints = list = (Pint *)ws->scratch.buf;
! 		/* View entries come back as CARD32s
  		 */
! 		for ( i = 0; i < count; i++, list++, indices++ )
  		    *list = *indices;
  	    }
  	}
*** -	Thu Jan 28 18:10:54 1993
--- mit/extensions/lib/PEX/cp/cpx_util.c	Thu Jan 28 18:10:54 1993
***************
*** 1,4 ****
! /* $XConsortium: cpx_util.c,v 5.3 91/07/24 16:48:53 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cpx_util.c,v 5.4 93/01/05 14:28:01 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 115,124 ****
      Cp_handle		cph;
  {
      register	Cpx_css_srvr	*css_srvr;
  
!     CPX_FOR_ALL_SERVERS(cph,css_srvr) {
  	destroy_css_srvr( cph, css_srvr );
      }
      cph->css_srvr_list = (Cpx_css_srvr *)NULL;
  }
  
--- 115,129 ----
      Cp_handle		cph;
  {
      register	Cpx_css_srvr	*css_srvr;
+     register    Cpx_css_srvr    *n_css_srvr;
  
!     css_srvr = cph->css_srvr_list;
!     while ( css_srvr ) {
! 	n_css_srvr = css_srvr->next;
  	destroy_css_srvr( cph, css_srvr );
+ 	css_srvr = n_css_srvr;
      }
+ 
      cph->css_srvr_list = (Cpx_css_srvr *)NULL;
  }
  
*** -	Thu Jan 28 18:10:56 1993
--- mit/extensions/lib/PEX/cp/phigsmon.c	Thu Jan 28 18:10:56 1993
***************
*** 1,4 ****
! /* $XConsortium: phigsmon.c,v 5.8 91/06/19 10:46:34 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: phigsmon.c,v 5.9 92/08/10 20:46:54 eswu Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 380,391 ****
--- 380,409 ----
      
  
  #ifdef DEBUG
+ #ifdef BSD44SOCKETS
  #define Make(rendezvous,addr) {\
  	struct sockaddr_un	un_addr; \
   \
  	unlink (addr); \
  	strcpy (un_addr.sun_path, addr); \
+ 	un_addr.sun_len = strlen(un_addr.sun_path); \
+ 	un_addr.sun_family = AF_UNIX; \
  	rendezvous = socket (AF_UNIX, SOCK_STREAM, 0); \
+ 	if (bind (rendezvous, &un_addr, SUN_LEN(&un_addr)) == -1) \
+ 	{ \
+ 	    perror ("phigs debug bind"); \
+ 	    abort (); \
+ 	} \
+ 	listen (rendezvous, 5); \
+ }
+ #else
+ #define Make(rendezvous,addr) {\
+ 	struct sockaddr_un	un_addr; \
+  \
+ 	unlink (addr); \
+ 	strcpy (un_addr.sun_path, addr); \
+ 	un_addr.sun_family = AF_UNIX; \
+ 	rendezvous = socket (AF_UNIX, SOCK_STREAM, 0); \
  	if (bind (rendezvous, &un_addr, sizeof (short) + strlen (addr)) == -1) \
  	{ \
  	    perror ("phigs debug bind"); \
***************
*** 393,398 ****
--- 411,417 ----
  	} \
  	listen (rendezvous, 5); \
  }
+ #endif
  
  #define Get(fd,rendezvous) { \
  	struct sockaddr_un	un_addr; \
*** -	Thu Jan 28 18:11:02 1993
--- mit/extensions/lib/PEX/cp/cpa_clnt.c	Thu Jan 28 18:11:02 1993
***************
*** 1,4 ****
! /* $XConsortium: cpa_clnt.c,v 5.2 91/04/04 21:05:51 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cpa_clnt.c,v 5.4 92/01/28 11:42:39 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 24,31 ****
--- 24,34 ----
  
  ******************************************************************/
  
+ #define NEED_EVENTS
+ 
  #include <sys/types.h>
  #include <sys/stat.h>
+ #include <X11/Xlibint.h>
  #include "phg.h"
  #include "cp.h"
  #include "cp_priv.h"
*** -	Thu Jan 28 18:11:03 1993
--- mit/extensions/lib/PEX/cp/cpx_pm.c	Thu Jan 28 18:11:03 1993
***************
*** 1,4 ****
! /* $XConsortium: cpx_pm.c,v 5.1 91/02/16 09:48:43 rws Exp $ */
  
  /***********************************************************
  Copyright (c) 1989,1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: cpx_pm.c,v 5.2 93/01/05 14:33:11 mor Exp $ */
  
  /***********************************************************
  Copyright (c) 1989,1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 90,96 ****
      f[(int)CP_FUNC_OP_INQ_INP_DEV_STATE]	= phg_cp_inq_inp_dev_state;
      f[(int)CP_FUNC_OP_INQ_REPRESENTATION]	= phg_cpx_inq_rep;
      f[(int)CP_FUNC_OP_INQ_VIEW_REP]		= phg_cpx_inq_view_rep;
!     f[(int)CP_FUNC_OP_INQ_HLHSR_MODE]		= phg_cpx_set_hlhsr_mode;
      f[(int)CP_FUNC_OP_INQ_DISP_UPDATE_STATE]	= phg_cpx_inq_disp_update_state;
      f[(int)CP_FUNC_OP_INQ_COLOUR_MODEL]	= phg_cpx_inq_colour_model;
      f[(int)CP_FUNC_OP_INQ_WS_XFORM]		= phg_cpx_inq_ws_xform;
--- 90,96 ----
      f[(int)CP_FUNC_OP_INQ_INP_DEV_STATE]	= phg_cp_inq_inp_dev_state;
      f[(int)CP_FUNC_OP_INQ_REPRESENTATION]	= phg_cpx_inq_rep;
      f[(int)CP_FUNC_OP_INQ_VIEW_REP]		= phg_cpx_inq_view_rep;
!     f[(int)CP_FUNC_OP_INQ_HLHSR_MODE]		= phg_cpx_inq_hlhsr_mode;
      f[(int)CP_FUNC_OP_INQ_DISP_UPDATE_STATE]	= phg_cpx_inq_disp_update_state;
      f[(int)CP_FUNC_OP_INQ_COLOUR_MODEL]	= phg_cpx_inq_colour_model;
      f[(int)CP_FUNC_OP_INQ_WS_XFORM]		= phg_cpx_inq_ws_xform;
*** -	Thu Jan 28 18:11:30 1993
--- mit/extensions/lib/PEX/error/error.c	Thu Jan 28 18:11:30 1993
***************
*** 1,4 ****
! /* $XConsortium: error.c,v 5.1 91/02/16 09:48:50 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: error.c,v 5.2 92/01/30 09:01:39 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 126,132 ****
      fprintf( stderr, "X Error: error code = %d, request code = %d,\
  minor code = %d\nresource id = %d, serial = %d, last request = %d\n",
      error->error_code, error->request_code, error->minor_code,
!     error->resourceid, error->serial, display->request );
      return 1; /* ? */
  }
  
--- 126,132 ----
      fprintf( stderr, "X Error: error code = %d, request code = %d,\
  minor code = %d\nresource id = %d, serial = %d, last request = %d\n",
      error->error_code, error->request_code, error->minor_code,
!     error->resourceid, error->serial, NextRequest(display)-1 );
      return 1; /* ? */
  }
  
*** -	Thu Jan 28 18:12:18 1993
--- mit/extensions/lib/PEX/include/ws.h	Thu Jan 28 18:12:18 1993
***************
*** 1,4 ****
! /* $XConsortium: ws.h,v 5.2 91/03/29 10:45:38 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: ws.h,v 5.3 92/10/15 16:23:08 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 27,32 ****
--- 27,33 ----
  #define PHG_WS_H_INCLUDED
  
  #include "ws_inp.h"
+ #include <X11/extensions/multibuf.h>
  
  /* The maximum number of views for client-side workstations. */
  #define WS_MAX_VIEWS	20
***************
*** 243,248 ****
--- 244,254 ----
      Pupd_st		hlhsr_mode_pending;	/* new hlhsr mode is pending */
      int			req_hlhsr_mode;		/* requested hlhsr mode */
      int			cur_hlhsr_mode;		/* current hlhsr mode */
+     /* Double Buffer Stuff */
+     int                 front;                  /* index of front drawable */
+     int                 back;                  /* index of back drawable */
+     int                 has_double_buffer;     /* Boolean for buffer presence */
+     Multibuffer         double_drawable[2];    /* the two buffers */
  } Wsb_output_ws;
  
  typedef struct {
*** -	Thu Jan 28 18:12:19 1993
--- mit/extensions/lib/PEX/include/ws_type.h	Thu Jan 28 18:12:19 1993
***************
*** 1,4 ****
! /* $XConsortium: ws_type.h,v 5.4 91/07/24 14:42:39 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: ws_type.h,v 5.6 92/01/27 21:19:48 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 41,48 ****
  #define WST_MAX_NUM_LOCATOR_DEVS	3
  #define WST_MAX_NUM_STROKE_DEVS		3
  #define WST_MAX_NUM_PICK_DEVS		3
! #define WST_MAX_NUM_VALUATOR_DEVS	6
! #define WST_MAX_NUM_CHOICE_DEVS		1
  #define WST_MAX_NUM_STRING_DEVS		1
  
  /* The below constant is the maximum number of prompt/echo types any one
--- 41,48 ----
  #define WST_MAX_NUM_LOCATOR_DEVS	3
  #define WST_MAX_NUM_STROKE_DEVS		3
  #define WST_MAX_NUM_PICK_DEVS		3
! #define WST_MAX_NUM_VALUATOR_DEVS	12
! #define WST_MAX_NUM_CHOICE_DEVS		3
  #define WST_MAX_NUM_STRING_DEVS		1
  
  /* The below constant is the maximum number of prompt/echo types any one
***************
*** 482,488 ****
  extern caddr_t		phg_wst_get_attr();
  extern caddr_t 		phg_wst_init();
  extern void 		phg_wst_destroy();
- extern caddr_t		phg_wst_set();
  extern Wst		*phg_wst_create();
  extern int 		phg_wst_copy();
  extern void		phg_wst_copy_buf_pointers();
--- 482,487 ----
*** -	Thu Jan 28 18:12:22 1993
--- mit/extensions/lib/PEX/include/ar.h	Thu Jan 28 18:12:22 1993
***************
*** 1,4 ****
! /* $XConsortium: ar.h,v 5.5 91/04/04 15:17:54 hersh Exp $ */
  
  /***********************************************************
  Copyright (c) 1988-1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: ar.h,v 5.6 91/12/11 16:05:26 hersh Exp $ */
  
  /***********************************************************
  Copyright (c) 1988-1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 121,126 ****
--- 121,131 ----
      CARD8	pad;
      /* List of char(length) */
  } Phg_ar_begin_archive;
+ 
+ typedef struct {
+     CARD16	opcode;		/* Always EOA */
+     CARD8	pad[2];
+ } Phg_ar_end_archive;
  
  typedef struct {
      CARD16	opcode;		/* Always BSE */
*** -	Thu Jan 28 18:12:48 1993
--- mit/extensions/lib/PEX/input/sin_ws.c	Thu Jan 28 18:12:48 1993
***************
*** 1,4 ****
! /* $XConsortium: sin_ws.c,v 5.1 91/02/16 09:49:44 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: sin_ws.c,v 5.2 92/12/28 15:24:08 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 360,365 ****
--- 360,367 ----
          }
          SIN_DISABLE_BREAK( ws);
  	scratch_event.dev_class = SIN_TO_PHIGS_CLASS( dev->class);
+ 	scratch_event.wsid = dev->wsid;
+ 	scratch_event.dev_num = dev->num;
  	(*ws->ops.send_request)( ws->wsh, &scratch_event, 1);
      } 
  
*** -	Thu Jan 28 18:13:09 1993
--- mit/extensions/lib/PEX/pex/pex_pick.c	Thu Jan 28 18:13:09 1993
***************
*** 1,4 ****
! /* $XConsortium: pex_pick.c,v 5.1 91/02/16 09:49:56 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pex_pick.c,v 5.2 93/01/27 16:06:53 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 27,44 ****
  /*
   *   PEX Picking functions:
   *
!  *   Section 11.1 -- Pick Device Descriptors
   *	PEXGetPickDevice()	    
   *	PEXChangePickDevice()	    
   *
!  *   Section 11.2 -- Pick Measure Resource Management 
   *	PEXCreatePickMeasure()	    
   *	PEXDeletePickMeasure()	    -- access via macro in phigspex.h
-  *
-  *   Section 11.3 -- Pick Measure Inquiry
   *	PEXGetPickMeasure()	    
-  *
-  *   Section 11.4 -- Pick Operations
   *	PEXUpdatePickMeasure()	    
   *
   */
--- 27,48 ----
  /*
   *   PEX Picking functions:
   *
!  *   SECTION 7 -- RENDERER PICKING
!  *
!  *   Section 7.1 -- Pick One
!  *	PEXBeginPickOne()
!  *	PEXEndPickOne()
!  *
!  *   SECTION 12 -- WORKSTATION PICKING
!  *
!  *   Section 12.1 -- Pick Device Descriptors
   *	PEXGetPickDevice()	    
   *	PEXChangePickDevice()	    
   *
!  *   Section 12.2 -- Pick Measure
   *	PEXCreatePickMeasure()	    
   *	PEXDeletePickMeasure()	    -- access via macro in phigspex.h
   *	PEXGetPickMeasure()	    
   *	PEXUpdatePickMeasure()	    
   *
   */
***************
*** 45,50 ****
--- 49,139 ----
  
  #include "pex_priv.h"
  
+ 
+ 
+ /*
+  * Section 7.1 -- Pick One
+  */
+ 
+ int PEXBeginPickOne (display, rdr_id, drawable, struct_id, method,
+ 	pickrec_bytes, pickrec)
+ 
+ Display		*display;
+ pexRenderer	rdr_id;
+ Drawable	drawable;
+ CARD32		struct_id;
+ int		method;
+ CARD32		pickrec_bytes;
+ CARD8		pickrec[];
+ 
+ {
+     int				status = 0;
+     Pex_srvr_info		*srvr;
+     pexBeginPickOneReq		*req;
+     Pex_data_vec		vec[1];
+ 
+     if (srvr = PexEntryCheck (display, 1)) {
+ 	LOCK_DISPLAY (display);
+ 	vec[0].size = pickrec_bytes;
+ 	vec[0].padding = PADDING (vec[0].size);
+ 	vec[0].data = (char *) pickrec;
+ 	PEX_VAR_REQUEST (BeginPickOne, display, PEX_OPCODE (srvr),
+ 		vec[0].size + vec[0].padding, req);
+ 	PEX_FP_FORMAT (req->fpFormat);
+ 	req->method = method;
+ 	req->rdr = rdr_id;
+ 	req->drawable = drawable;
+ 	req->sid = struct_id;
+ 	PEX_LOAD_VAR_REQUEST_DATA (display, 1, vec);
+ 	status = 1;
+ 	UNLOCK_DISPLAY (display);
+     }
+     PEX_SYNC_HANDLE (display);
+     return status;
+ }
+ 
+ 
+ int PEXEndPickOne (display, rdr_id, better_pick, elements, num_elements)
+ 
+ Display			*display;
+ pexRenderer		rdr_id;
+ int			*better_pick;
+ pexPickElementRef	**elements;
+ int			*num_elements;
+ 
+ {
+     int				status = 0;
+     unsigned			size;
+     Pex_srvr_info		*srvr;
+     pexEndPickOneReq	    	*req;
+     pexEndPickOneReply		reply;
+     
+     if (srvr = PexEntryCheck (display, 1)) {
+ 	LOCK_DISPLAY (display);
+ 	PEX_REQUEST (EndPickOne, display, PEX_OPCODE (srvr), req);
+ 	req->rdr = rdr_id;
+ 	
+ 	status = _XReply (display, (xReply *) &reply, 0, xFalse);
+ 	if (status) {
+ 	    *better_pick = reply.betterPick;
+ 	    *num_elements = reply.numPickElRefs;
+ 	    if ((size = reply.length * sizeof(CARD32)) > 0) {
+ 		if (*elements = (pexPickElementRef *) PEX_SCRATCH (srvr, size))
+ 		    _XRead (display, (char *) *elements, (long) size);
+ 		else {
+ 		    status = 0;
+ 		    PexClearReply (display, reply.length);
+ 		}
+ 	    }
+ 	}
+ 	UNLOCK_DISPLAY (display);
+     }
+     PEX_SYNC_HANDLE (display);
+     return status;    
+ }
+ 
+ 
+ 
  /*
   * Section 11.1 -- Pick Device Descriptors
   */
*** -	Thu Jan 28 18:13:24 1993
--- mit/extensions/lib/PEX/util/ut_ntfy.c	Thu Jan 28 18:13:23 1993
***************
*** 1,4 ****
! /* $XConsortium: ut_ntfy.c,v 5.6 91/08/22 19:51:44 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: ut_ntfy.c,v 5.7 91/12/03 17:02:47 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 260,271 ****
  sig_dispatcher(signal_num)
  int		     signal_num;
  {
!     register	 notify_list	*curr;
  	
      curr = notify_list_array[signal_num - 1];	
      while (curr) {
! 	(*curr->sig_handler)(curr->client_id, signal_num);
! 	curr = curr->next;
      }
  #if defined(SYSV) || defined(SVR4)
      /* Have to reinstall the signal handler. */
--- 260,273 ----
  sig_dispatcher(signal_num)
  int		     signal_num;
  {
!     register	 notify_list	*curr, *tmp;
  	
      curr = notify_list_array[signal_num - 1];	
      while (curr) {
! 	/* curr can get corrupted, so save the next value */
! 	tmp = curr->next;
! 	(*curr->sig_handler)(curr->client_id, signal_num, 0);
! 	curr = tmp;
      }
  #if defined(SYSV) || defined(SVR4)
      /* Have to reinstall the signal handler. */
*** -	Thu Jan 28 18:13:29 1993
--- mit/extensions/lib/PEX/util/utx_conv.c	Thu Jan 28 18:13:27 1993
***************
*** 1,4 ****
! /* $XConsortium: utx_conv.c,v 5.7 91/08/26 12:35:38 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: utx_conv.c,v 5.11 92/12/29 17:11:16 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 1498,1504 ****
      register	caddr_t			buf;
      register	Phg_ret_ws_tran3	*ws_xform;
  {
!     ws_xform->state = PEX_CONV_TO_Pupdatest(*(CARD8 *)buf);
      buf += 4;
      ws_xform->req_window.x_min = ((pexNpcSubvolume *)buf)->minval.x;
      ws_xform->req_window.y_min = ((pexNpcSubvolume *)buf)->minval.y;
--- 1498,1504 ----
      register	caddr_t			buf;
      register	Phg_ret_ws_tran3	*ws_xform;
  {
!     ws_xform->state = PEX_CONV_TO_Pupdatest(*(CARD32 *)buf);
      buf += 4;
      ws_xform->req_window.x_min = ((pexNpcSubvolume *)buf)->minval.x;
      ws_xform->req_window.y_min = ((pexNpcSubvolume *)buf)->minval.y;
***************
*** 2424,2430 ****
  		PEX_CONV_TO_Pcullmode(RHEADER(CullingMode)->cullMode);
  	    break;
  	case PEXOCModelClip:
! 	    ed->clip_ind = PEX_CONV_TO_Pclip(RHEADER(ModelClip)->onoff);
  	    break;
  
  	/* All these contain just a colour. */
--- 2424,2431 ----
  		PEX_CONV_TO_Pcullmode(RHEADER(CullingMode)->cullMode);
  	    break;
  	case PEXOCModelClip:
! 	    ed->clip_ind = (RHEADER(ModelClip)->onoff == PEXClip) ?
! 		PIND_CLIP : PIND_NO_CLIP;
  	    break;
  
  	/* All these contain just a colour. */
***************
*** 3977,3983 ****
  		= PEX_CONV_FROM_Pcullmode((Pcull_mode)ed->cullmode);
  	    break;
  	case PELEM_MODEL_CLIP_IND:
! 	    HEADER(ModelClip)->onoff = PEX_CONV_FROM_Pclip(ed->clip_ind);
  	    break;
  	case PELEM_EDGE_FLAG:
  	    HEADER(SurfaceEdgeFlag)->onoff = PEX_CONV_FROM_Pedgef(ed->edgef);
--- 3978,3985 ----
  		= PEX_CONV_FROM_Pcullmode((Pcull_mode)ed->cullmode);
  	    break;
  	case PELEM_MODEL_CLIP_IND:
! 	    HEADER(ModelClip)->onoff = (ed->clip_ind == PIND_CLIP) ?
! 		PEXClip : PEXNoClip;
  	    break;
  	case PELEM_EDGE_FLAG:
  	    HEADER(SurfaceEdgeFlag)->onoff = PEX_CONV_FROM_Pedgef(ed->edgef);
*** -	Thu Jan 28 18:13:36 1993
--- mit/extensions/lib/PEX/ws/wsx_lut.c	Thu Jan 28 18:13:35 1993
***************
*** 1,4 ****
! /* $XConsortium: wsx_lut.c,v 5.2 91/04/19 18:50:31 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: wsx_lut.c,v 5.3 93/01/05 14:32:27 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 1236,1242 ****
  		&& phg_ut_htab_get_entry( htab, 1, (caddr_t *)NULL ) ) {
  	    index = 1;
  	} else {
! 	    ret->err = ERR101;
  	    return;
  	}
      }
--- 1236,1247 ----
  		&& phg_ut_htab_get_entry( htab, 1, (caddr_t *)NULL ) ) {
  	    index = 1;
  	} else {
! 	    if ( type == PINQ_REALIZED && ( rep_type == PHG_ARGS_PTREP ||
! 		rep_type == PHG_ARGS_EXTPTREP ) ) {
! 		ret->err = ERR109;
! 	    } else {
! 		ret->err = ERR101;
! 	    }
  	    return;
  	}
      }
*** -	Thu Jan 28 18:13:38 1993
--- mit/extensions/lib/PEX/ws/wsa_pm.c	Thu Jan 28 18:13:38 1993
***************
*** 1,4 ****
! /* $XConsortium: wsa_pm.c,v 5.2 91/04/05 17:30:37 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: wsa_pm.c,v 5.3 92/12/21 10:22:54 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 151,158 ****
       * regions, send them down to PEXRedrawClipRegion, and repaint any
       * input echoes on the window.
       */
!     if ( num_rects = phg_wsx_build_exposure_rects( display, window, ws,
! 	    first_event, &pex_rects, &x_rects ) > 0 ) {
  	(void)PEXRedrawClipRegion(display, ws->rid,
  	    (CARD32)num_rects, pex_rects);
  	if ( WS_ANY_INP_DEV_ACTIVE(ws) && ws->input_repaint )
--- 151,158 ----
       * regions, send them down to PEXRedrawClipRegion, and repaint any
       * input echoes on the window.
       */
!     if ( (num_rects = phg_wsx_build_exposure_rects( display, window, ws,
! 	    first_event, &pex_rects, &x_rects)) > 0 ) {
  	(void)PEXRedrawClipRegion(display, ws->rid,
  	    (CARD32)num_rects, pex_rects);
  	if ( WS_ANY_INP_DEV_ACTIVE(ws) && ws->input_repaint )
*** -	Thu Jan 28 18:13:39 1993
--- mit/extensions/lib/PEX/ws/wsa.c	Thu Jan 28 18:13:39 1993
***************
*** 1,4 ****
! /* $XConsortium: wsa.c,v 5.2 91/04/05 17:30:41 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: wsa.c,v 5.3 91/10/01 02:55:24 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 154,160 ****
      pexViewRep		pvr;
      pexViewRep		view_zero;
      CARD32		count;
!     pexTableIndex	*indices;
      pexBitmask		mask[PEXMSGetWksInfo];
      caddr_t		buf;
      Hash_table		htab;
--- 154,160 ----
      pexViewRep		pvr;
      pexViewRep		view_zero;
      CARD32		count;
!     CARD32              *indices;
      pexBitmask		mask[PEXMSGetWksInfo];
      caddr_t		buf;
      Hash_table		htab;
***************
*** 199,205 ****
  
      } else {
  	count = *(CARD32 *)buf;
! 	indices = (pexTableIndex *)(buf + 4);
  	for ( i = 0; i < count; i++ ) {
  	    if ( !phg_ut_htab_add_entry( ws->out_ws.htab.view, (int)indices[i],
  		    (caddr_t)NULL ) ) {
--- 199,205 ----
  
      } else {
  	count = *(CARD32 *)buf;
! 	indices = (CARD32 *)(buf + 4);
  	for ( i = 0; i < count; i++ ) {
  	    if ( !phg_ut_htab_add_entry( ws->out_ws.htab.view, (int)indices[i],
  		    (caddr_t)NULL ) ) {
*** -	Thu Jan 28 18:13:41 1993
--- mit/extensions/lib/PEX/ws/wsb.c	Thu Jan 28 18:13:40 1993
***************
*** 1,4 ****
! /* $XConsortium: wsb.c,v 5.3 91/07/12 20:26:27 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: wsb.c,v 5.8 93/01/27 16:07:36 mor Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 346,352 ****
      CARD32		size, *rid_list;
      pexTableIndex	start;
      pexBitmask		pmask[PEXMSPipeline], rmask;
!     CARD16		*card16_p;
      pexReflectionAttr	*refl_attr, *bf_refl_attr;
      pexFloatColour	*spec_colr, *bf_spec_colr;
      pexViewport		*vp;
--- 346,352 ----
      CARD32		size, *rid_list;
      pexTableIndex	start;
      pexBitmask		pmask[PEXMSPipeline], rmask;
!     CARD32		*card32_p;
      pexReflectionAttr	*refl_attr, *bf_refl_attr;
      pexFloatColour	*spec_colr, *bf_spec_colr;
      pexViewport		*vp;
***************
*** 383,390 ****
      bf_spec_colr = (pexFloatColour *)(bf_refl_attr + 1);
      *bf_spec_colr = *spec_colr;
      PEX_BITSET(pmask,PEXPCCullingMode); size += sizeof(CARD32);
!     card16_p = (CARD16 *)(bf_spec_colr + 1);
!     *card16_p = 0;
      (void)PEXChangePipelineContext( ws->display, ws->out_ws.model.b.pipeline,
  	pmask, size, (char *)ws->scratch.buf );
  
--- 383,390 ----
      bf_spec_colr = (pexFloatColour *)(bf_refl_attr + 1);
      *bf_spec_colr = *spec_colr;
      PEX_BITSET(pmask,PEXPCCullingMode); size += sizeof(CARD32);
!     card32_p = (CARD32 *)(bf_spec_colr + 1);
!     *card32_p = 0;
      (void)PEXChangePipelineContext( ws->display, ws->out_ws.model.b.pipeline,
  	pmask, size, (char *)ws->scratch.buf );
  
***************
*** 430,437 ****
      rmask |= PEXRDInvisibilityExcl; size += sizeof(CARD32);
  	*rid_list++ = ws->out_ws.nset.invis_excl;
      rmask |= PEXRDHlhsrMode; size += sizeof(CARD32);
! 	card16_p = (CARD16 *)rid_list++;
! 	*card16_p = (CARD16)PEX_CONV_PHIGS_HLHSR_MODE(PHIGS_HLHSR_MODE_NONE);
      rmask |= PEXRDViewport; size += sizeof(pexViewport);
  	vp = (pexViewport *)rid_list++;
  	vp->minval.x = ws->out_ws.model.b.req_ws_viewport.x_min;
--- 430,436 ----
      rmask |= PEXRDInvisibilityExcl; size += sizeof(CARD32);
  	*rid_list++ = ws->out_ws.nset.invis_excl;
      rmask |= PEXRDHlhsrMode; size += sizeof(CARD32);
! 	*rid_list++ = (CARD32)PEX_CONV_PHIGS_HLHSR_MODE(PHIGS_HLHSR_MODE_NONE);
      rmask |= PEXRDViewport; size += sizeof(pexViewport);
  	vp = (pexViewport *)rid_list++;
  	vp->minval.x = ws->out_ws.model.b.req_ws_viewport.x_min;
***************
*** 456,462 ****
--- 455,464 ----
      pexBitmask		dyn_tbls, dyn_nsets, dyn_attrs;
      Pint		err;
      CARD16		*card16_p;
+     Drawable            draw;
+     int                 numbufs, mbuf_event_base, mbuf_error_base;;
  
+ 
      /* Create the LUTs, renderer and pipeline context. */
      if ( !phg_wsx_create_LUTs( ws, 1, &err ) ) {
  	ERR_BUF( ws->erh, err );
***************
*** 479,487 ****
      }
      */
  
      /* Create the renderer, initializing the necessary attributes. */
      ws->rid = XAllocID(ws->display);
!     (void)PEXCreateRenderer( ws->display, ws->rid, ws->drawable_id,
  	(pexBitmask)0, (CARD32)0, (char *)NULL );
  
      /* Make an inquiry to see if the create worked. */
--- 481,524 ----
      }
      */
  
+     /* Check the Workstation buffer mode and do the double buffer
+        create here if necessary This is simpler than on the workstation
+        since this PHIGS implementation only lets the Double Buffers
+        be created when the workstation is created, so no change action
+        need be done
+     */
+ 
+     /* initialize the local drawable variable */
+     draw = ws->drawable_id;
+     ws->out_ws.model.b.has_double_buffer = FALSE;
+ 
+     if (ws->type->desc_tbl.xwin_dt.buffer_mode == PHIGS_BUF_DOUBLE) {
+       if (XmbufQueryExtension(ws->display, &mbuf_event_base, &mbuf_error_base)){
+ 
+         /* the Multi-Buffer extension is there */
+         numbufs = XmbufCreateBuffers(ws->display, ws->drawable_id, 2,
+                      MultibufferUpdateActionBackground,
+                      MultibufferUpdateHintFrequent,
+                      &ws->out_ws.model.b.double_drawable[0]);
+         if  (numbufs == 2) {
+           /* got the buffers OK */
+           ws->out_ws.model.b.front = 0;
+           ws->out_ws.model.b.back = 1;
+           ws->out_ws.model.b.has_double_buffer = TRUE;
+           draw = ws->out_ws.model.b.double_drawable[1];
+           /* this isn't implemented yet
+             XmbufClearBufferArea(ws->display, draw, 0, 0, 0, 0, False);
+           */
+         } else
+           /* buffers didn't get created correctly, bag them  */
+           XmbufDestroyBuffers(ws->display, ws->drawable_id);
+       }
+     }
+ 
+ 
      /* Create the renderer, initializing the necessary attributes. */
      ws->rid = XAllocID(ws->display);
!     (void)PEXCreateRenderer( ws->display, ws->rid, draw,
  	(pexBitmask)0, (CARD32)0, (char *)NULL );
  
      /* Make an inquiry to see if the create worked. */
***************
*** 774,781 ****
--- 811,826 ----
  
      /* Other pending data */
      if ( owsb->hlhsr_mode_pending == PUPD_PEND) {
+ 	 CARD32     new_mode;
+ 
  	 owsb->cur_hlhsr_mode = owsb->req_hlhsr_mode;
  	 owsb->hlhsr_mode_pending = PUPD_NOT_PEND;
+ 
+ 	 new_mode = (CARD32)PEX_CONV_PHIGS_HLHSR_MODE(owsb->cur_hlhsr_mode);
+          (void)PEXChangeRenderer( ws->display, ws->rid,
+                                  (pexBitmask)PEXRDHlhsrMode,
+                                  (CARD32)sizeof(CARD32), (char *)&new_mode);
+ 
      }
  
      /* Make it all take effect. */
***************
*** 791,800 ****
      XRectangle	*exposure_rects;	/* may be NULL */
  {
      Wsb_output_ws	*owsb = &ws->out_ws.model.b;
  
      register int	i;
  
!     if( clear_control == PFLAG_ALWAYS || owsb->surf_state == PSURF_NOT_EMPTY ) {
  	/* TODO: Need a way to "clear" the window that uses the zero-th
  	 * entry in the WS colour table and runs it through colour mapping.
  	 */
--- 836,851 ----
      XRectangle	*exposure_rects;	/* may be NULL */
  {
      Wsb_output_ws	*owsb = &ws->out_ws.model.b;
+     int                 tmp;
+     Drawable            draw;
  
      register int	i;
  
!     /* assuming this stuff does clear then don't do it when using Double Buff
!        since the swap will take care of that
!     */
!     if ((clear_control == PFLAG_ALWAYS || owsb->surf_state == PSURF_NOT_EMPTY)
!        && !ws->out_ws.model.b.has_double_buffer) {
  	/* TODO: Need a way to "clear" the window that uses the zero-th
  	 * entry in the WS colour table and runs it through colour mapping.
  	 */
***************
*** 809,816 ****
      }
      owsb->surf_state = PSURF_EMPTY;
  
!     phg_wsb_traverse_all_postings( ws );
  
      /* Redraw input prompts & echos of any active input devices. */
      if ( ws->input_repaint && WS_ANY_INP_DEV_ACTIVE(ws) )
  	(ws->input_repaint)( ws, num_rects, exposure_rects );
--- 860,881 ----
      }
      owsb->surf_state = PSURF_EMPTY;
  
!     /* set the drawable correctly */
!     if (ws->out_ws.model.b.has_double_buffer)
!         draw = ws->out_ws.model.b.double_drawable[ws->out_ws.model.b.back];
!     else  /* single buffer */
!         draw = ws->drawable_id;
  
+     phg_wsb_traverse_all_postings( ws, draw );
+ 
+     /* now swap the buffers and update the drawable indices */
+     if (ws->out_ws.model.b.has_double_buffer) {
+           XmbufDisplayBuffers(ws->display, 1, &draw, 0, 0);
+           tmp = ws->out_ws.model.b.front;
+           ws->out_ws.model.b.front  = ws->out_ws.model.b.back;
+           ws->out_ws.model.b.back = tmp;
+     }
+ 
      /* Redraw input prompts & echos of any active input devices. */
      if ( ws->input_repaint && WS_ANY_INP_DEV_ACTIVE(ws) )
  	(ws->input_repaint)( ws, num_rects, exposure_rects );
***************
*** 820,827 ****
  
  
  void
! phg_wsb_traverse_all_postings( ws )
      Ws		*ws;
  {
      register Wsb_output_ws	*owsb = &ws->out_ws.model.b;
      register Ws_post_str	*post_str, *end;
--- 885,893 ----
  
  
  void
! phg_wsb_traverse_all_postings( ws, draw )
      Ws		*ws;
+     Drawable            draw;
  {
      register Wsb_output_ws	*owsb = &ws->out_ws.model.b;
      register Ws_post_str	*post_str, *end;
***************
*** 831,837 ****
  	/* Set up for complete traversal. */
  	post_str = owsb->posted.lowest.higher;
  	end = &(owsb->posted.highest);
! 	PEXBeginRendering( ws->display, ws->rid, ws->drawable_id );
  	while ( post_str != end ) {
  	    phg_wsb_traverse_net( ws, post_str->structh );
  	    post_str = post_str->higher;
--- 897,903 ----
  	/* Set up for complete traversal. */
  	post_str = owsb->posted.lowest.higher;
  	end = &(owsb->posted.highest);
! 	PEXBeginRendering( ws->display, ws->rid, draw);
  	while ( post_str != end ) {
  	    phg_wsb_traverse_net( ws, post_str->structh );
  	    post_str = post_str->higher;
***************
*** 1885,1891 ****
  {
       /* Calculate the inverse xform, if necessary. */
      if ( view->npc_to_wc_state == WS_INV_NOT_CURRENT ) {
! 	phg_mat_mul( view->npc_to_wc, view->vom, view->vmm );
  	phg_mat_inv( view->npc_to_wc );
  	view->npc_to_wc_state = WS_INV_CURRENT;
      }
--- 1951,1957 ----
  {
       /* Calculate the inverse xform, if necessary. */
      if ( view->npc_to_wc_state == WS_INV_NOT_CURRENT ) {
! 	phg_mat_mul( view->npc_to_wc, view->vmm, view->vom );
  	phg_mat_inv( view->npc_to_wc );
  	view->npc_to_wc_state = WS_INV_CURRENT;
      }
***************
*** 1927,1933 ****
      }
  
      view = &ws->out_ws.model.b.views[view_index];
!     phg_mat_mul( wc_to_npc, view->vom, view->vmm );
      if ( !phg_tranpts3( wc_to_npc, *num_pts, wc_pts, npc_pts ) ) {
  	*num_pts = 0;
  	return 0;
--- 1993,1999 ----
      }
  
      view = &ws->out_ws.model.b.views[view_index];
!     phg_mat_mul( wc_to_npc, view->vmm, view->vom );
      if ( !phg_tranpts3( wc_to_npc, *num_pts, wc_pts, npc_pts ) ) {
  	*num_pts = 0;
  	return 0;
***************
*** 2173,2186 ****
      pexDeviceCoord      *dc_pt;
      Ppick		*pick;
  {
!     /* Picking not supported by the SI for client-side structure storage.
!      * But this is where the pick detection code would go if it did do it.
!      */
  
!     /* Make the resolution look like a no-pick. */
!     pick->status = PIN_STATUS_NONE;
!     pick->pick_path.depth = 0;
!     pick->pick_path.path_list = (Ppick_path_elem *)NULL;
      return 1;
  }
  
--- 2239,2383 ----
      pexDeviceCoord      *dc_pt;
      Ppick		*pick;
  {
!     register Wsb_output_ws	*owsb = &ws->out_ws.model.b;
!     register Ws_post_str	*post_str, *end;
!     pexDeviceCoord2D		dc_vol[2];
!     Ppoint			npc_pt[2];
!     pexPickElementRef		*pickPath;
!     int				pickDepth;
!     int				betterPick, i;
  
!     CARD32			pickDataBytes;
! 
!     struct {
! 	pexEnumTypeIndex pickType;
! 	CARD16		 unused;
! 	union {
! 	    pexPD_DC_HitBox	dcHitBox;
! 	    pexPD_NPC_HitVolume npcHitVolume;
! 	} pickRec;
!     } pickData;
!     
!     WSB_CHECK_POSTED (&owsb->posted)
! 
!     if (WSB_SOME_POSTED (&owsb->posted)) {
! 
! 	/*
! 	 * Use pick rendering to get the pick results.  Call BeginPickOne, do
! 	 * a complete traversal (starting with highest priority structure,
! 	 * then call EndPickOne to get the pick results.
! 	 */
! 
! 	if (dev->dev_type == PEXPickDeviceDC_HitBox) {
! 
! 	    pickData.pickType = PEXPickDeviceDC_HitBox;
! 
! 	    pickData.pickRec.dcHitBox.position.x = dc_pt->x;
! 	    pickData.pickRec.dcHitBox.position.y = dc_pt->y;
! 	    pickData.pickRec.dcHitBox.distance = dev->ap_size;
! 
! 	    pickDataBytes = 4 + sizeof (pexPD_DC_HitBox);
! 
! 	} else {
! 
! 	    pickData.pickType = PEXPickDeviceNPC_HitVolume;
! 
! 	    dc_vol[0].x = dc_pt->x - dev->ap_size;
! 	    dc_vol[0].y = dc_pt->y - dev->ap_size;
! 	    dc_vol[1].x = dc_pt->x + dev->ap_size;
! 	    dc_vol[1].y = dc_pt->y + dev->ap_size;
! 
! 	    WS_DC_TO_NPC2 (&owsb->ws_xform, &dc_vol[0], &npc_pt[0])
! 	    WS_DC_TO_NPC2 (&owsb->ws_xform, &dc_vol[1], &npc_pt[1])
! 
! 	    pickData.pickRec.npcHitVolume.minval.x = npc_pt[0].x;
! 	    pickData.pickRec.npcHitVolume.minval.y = npc_pt[0].y;
! 	    pickData.pickRec.npcHitVolume.maxval.x = npc_pt[1].x;
! 	    pickData.pickRec.npcHitVolume.maxval.y = npc_pt[1].y;
! 	    pickData.pickRec.npcHitVolume.minval.z = owsb->ws_window.z_min;
! 	    pickData.pickRec.npcHitVolume.maxval.z = owsb->ws_window.z_max;
! 
! 	    pickDataBytes = 4 + sizeof (pexPD_NPC_HitVolume);
! 	}
! 
! 	PEXChangeRenderer (ws->display, ws->rid,
! 		(pexBitmask) PEXRDPickInclusion, (CARD32) sizeof (pexNameSet),
! 		(char *) &(dev->filter.incl));
! 
! 	PEXChangeRenderer (ws->display, ws->rid,
! 		(pexBitmask) PEXRDPickExclusion, (CARD32) sizeof (pexNameSet),
! 		(char *) &(dev->filter.excl));
! 
! 
! 	PEXBeginPickOne (ws->display, ws->rid, ws->drawable_id, -1,
! 		PEXLast, pickDataBytes, &pickData);
! 
! 	post_str = owsb->posted.highest.lower;
! 	end = &(owsb->posted.lowest);
! 
! 	while (post_str != end) {
! 	    phg_wsb_traverse_net (ws, post_str->structh);
! 	    post_str = post_str->lower;
! 	}
! 
! 	PEXEndPickOne (ws->display, ws->rid, &betterPick,
! 	    &pickPath, &pickDepth);
!     }
! 
! 
!     if (!pickDepth) {
! 
!     	pick->status = PIN_STATUS_NONE;
!     	pick->pick_path.depth = 0;
!     	pick->pick_path.path_list = (Ppick_path_elem *) NULL;
! 
!     } else {
! 
! 	/*
! 	 * The protocol pick element ref data structure has its fields
! 	 * layed out in a different order than the PHIGS data structure.
! 	 * We must repack the data into PHIGS format.
! 	 */
! 
! 	for (i = 1; i < pickDepth; i++) {
! 	    Ppick_path_elem *dst = (Ppick_path_elem *) &pickPath[i];
! 	    pexPickElementRef src;
! 
! 	    src = pickPath[i];
! 	    dst->struct_id = src.sid;
! 	    dst->pick_id = src.pickid;
! 	    dst->elem_pos = src.offset;
! 	}
! 
! 	/*
! 	 * order = bottom first?
! 	 */
! 
! 	if (dev->order == PORDER_BOTTOM_FIRST) {
! 	    int			head, tail;
! 	    pexPickElementRef 	temp;
! 
! 	    head = 1;
! 	    tail = pickDepth - 1;
! 
! 	    for (i = 0; i < (pickDepth - 1) / 2; i++) {
! 		temp = pickPath[head];
! 		pickPath[head] = pickPath[tail];
! 		pickPath[tail] = temp;
! 		head++;
! 		tail--;
! 	    }
! 	}
! 
! 	/*
! 	 * return status and pick path
! 	 */
! 
! 	pick->status = PIN_STATUS_OK;
! 	pick->pick_path.depth = pickDepth - 1;
! 	pick->pick_path.path_list = (Ppick_path_elem *) &(pickPath[1]);
!     }
! 
      return 1;
  }
  
*** -	Thu Jan 28 18:13:46 1993
--- mit/extensions/lib/PEX/ws/wsa_inp.c	Thu Jan 28 18:13:46 1993
***************
*** 1,4 ****
! /* $XConsortium: wsa_inp.c,v 5.2 91/04/05 17:27:23 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: wsa_inp.c,v 5.3 91/10/01 02:55:55 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 193,199 ****
      if ( !PEXGetPickMeasure( ws->display, dev->measure, mask[0], &buf ) )
  	return 0;	/* TODO: use phg_pex_errno */
  
!     *status = *((CARD16 *)buf);
      *depth = *((CARD32 *)(buf + sizeof(CARD32)));
      *path = (pexPickPath *)(buf + 2 * sizeof(CARD32));
  
--- 193,199 ----
      if ( !PEXGetPickMeasure( ws->display, dev->measure, mask[0], &buf ) )
  	return 0;	/* TODO: use phg_pex_errno */
  
!     *status = (CARD16) *((CARD32 *)buf);
      *depth = *((CARD32 *)(buf + sizeof(CARD32)));
      *path = (pexPickPath *)(buf + 2 * sizeof(CARD32));
  
***************
*** 220,246 ****
  
      /* Set the device data and create a pick measure for this interaction. */
      mask |= PEXPDPickStatus;
!     card16_p = (CARD16 *)buf; buf += sizeof(CARD32);
!     *card16_p = dev->pick.status == PIN_STATUS_OK ? PEXOk : PEXNoPick;
  
      mask |= PEXPDPickPathOrder;
!     card16_p = (CARD16 *)buf; buf += sizeof(CARD32);
!     *card16_p = dev->order == PORDER_TOP_FIRST ? PEXTopFirst : PEXBottomFirst;
  
      mask |= PEXPDPickIncl;
!     xid_p = (XID *)buf; buf += sizeof(CARD32);
      *xid_p = dev->filter.incl;
  
      mask |= PEXPDPickExcl;
!     xid_p = (XID *)buf; buf += sizeof(CARD32);
      *xid_p = dev->filter.excl;
  
      mask |= PEXPDPickPromptEchoType;
!     int16_p = (INT16 *)buf; buf += sizeof(CARD32);
!     *int16_p = dev->pet;
  
      mask |= PEXPDPickEchoVolume;
!     ev = (pexViewport *)buf; buf += sizeof(pexViewport);
      ev->minval.x = dev->e_volume.x_min;
      ev->minval.y = dev->e_volume.y_min;
      ev->minval.z = dev->e_volume.z_min;
--- 220,251 ----
  
      /* Set the device data and create a pick measure for this interaction. */
      mask |= PEXPDPickStatus;
!     card32_p = (CARD32 *)buf; 
!     *card32_p = dev->pick.status == PIN_STATUS_OK ? PEXOk : PEXNoPick;
!     buf += sizeof(CARD32);
  
      mask |= PEXPDPickPathOrder;
!     card32_p = (CARD32 *)buf; 
!     *card32_p = dev->order == PORDER_TOP_FIRST ? PEXTopFirst : PEXBottomFirst;
!     buf += sizeof(CARD32);
  
      mask |= PEXPDPickIncl;
!     xid_p = (XID *)buf; 
      *xid_p = dev->filter.incl;
+     buf += sizeof(CARD32);
  
      mask |= PEXPDPickExcl;
!     xid_p = (XID *)buf; 
      *xid_p = dev->filter.excl;
+     buf += sizeof(CARD32);
  
      mask |= PEXPDPickPromptEchoType;
!     card32_p = (CARD32 *)buf; 
!     *card32_p = (CARD32)dev->pet;
!     buf += sizeof(CARD32);
  
      mask |= PEXPDPickEchoVolume;
!     ev = (pexViewport *)buf; 
      ev->minval.x = dev->e_volume.x_min;
      ev->minval.y = dev->e_volume.y_min;
      ev->minval.z = dev->e_volume.z_min;
***************
*** 248,257 ****
      ev->maxval.y = dev->e_volume.y_max;
      ev->maxval.z = dev->e_volume.z_max;
      ev->useDrawable = 0;
  
      mask |= PEXPDPickEchoSwitch;
!     card16_p = (CARD16 *)buf; buf += sizeof(CARD32);
!     *card16_p = dev->esw == PSWITCH_ECHO ? PEXEcho : PEXNoEcho;
  
      (void)PEXChangePickDevice( ws->display, ws->rid, dev->dev_type, mask,
  															(CARD32)sizeof(buffer), buffer );
--- 253,264 ----
      ev->maxval.y = dev->e_volume.y_max;
      ev->maxval.z = dev->e_volume.z_max;
      ev->useDrawable = 0;
+     buf += sizeof(pexViewport);
  
      mask |= PEXPDPickEchoSwitch;
!     card32_p = (CARD32 *)buf; 
!     *card32_p = dev->esw == PSWITCH_ECHO ? PEXEcho : PEXNoEcho;
!     buf += sizeof(CARD32);
  
      (void)PEXChangePickDevice( ws->display, ws->rid, dev->dev_type, mask,
  															(CARD32)sizeof(buffer), buffer );
*** -	Thu Jan 28 18:16:25 1993
--- mit/extensions/lib/PEX/ws_type/wstx_ini.c	Thu Jan 28 18:16:25 1993
***************
*** 1,4 ****
! /* $XConsortium: wstx_ini.c,v 5.5 91/07/24 14:43:18 hersh Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: wstx_ini.c,v 5.8 92/05/29 14:29:22 rws Exp $ */
  
  /***********************************************************
  Copyright 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 239,247 ****
      assure(in_ws_dt->num_devs.stroke <= WST_MAX_NUM_STROKE_DEVS);
      in_ws_dt->num_devs.pick = 1;
      assure(in_ws_dt->num_devs.pick <= WST_MAX_NUM_PICK_DEVS);
!     in_ws_dt->num_devs.val = 6;
      assure(in_ws_dt->num_devs.val <= WST_MAX_NUM_VALUATOR_DEVS);
!     in_ws_dt->num_devs.choice = 1;
      assure(in_ws_dt->num_devs.choice <= WST_MAX_NUM_CHOICE_DEVS);
      in_ws_dt->num_devs.string = 1;
      assure(in_ws_dt->num_devs.string <= WST_MAX_NUM_STRING_DEVS);
--- 239,247 ----
      assure(in_ws_dt->num_devs.stroke <= WST_MAX_NUM_STROKE_DEVS);
      in_ws_dt->num_devs.pick = 1;
      assure(in_ws_dt->num_devs.pick <= WST_MAX_NUM_PICK_DEVS);
!     in_ws_dt->num_devs.val = 12;
      assure(in_ws_dt->num_devs.val <= WST_MAX_NUM_VALUATOR_DEVS);
!     in_ws_dt->num_devs.choice = 3;
      assure(in_ws_dt->num_devs.choice <= WST_MAX_NUM_CHOICE_DEVS);
      in_ws_dt->num_devs.string = 1;
      assure(in_ws_dt->num_devs.string <= WST_MAX_NUM_STRING_DEVS);
***************
*** 357,362 ****
--- 357,373 ----
  	    switch ( i ) {
  		default:
  		case 1: val->type = WST_VAL_TYPE_SLIDER; break;
+ 		case 2: val->type = WST_VAL_TYPE_SLIDER; break;
+ 		case 3: val->type = WST_VAL_TYPE_SLIDER; break;
+ 		case 4: val->type = WST_VAL_TYPE_SLIDER; break;
+ 		case 5: val->type = WST_VAL_TYPE_SLIDER; break;
+ 		case 6: val->type = WST_VAL_TYPE_SLIDER; break;
+ 		case 7: val->type = WST_VAL_TYPE_SLIDER; break;
+ 		case 8: val->type = WST_VAL_TYPE_SLIDER; break;
+ 		case 9: val->type = WST_VAL_TYPE_SLIDER; break;
+ 		case 10: val->type = WST_VAL_TYPE_SLIDER; break;
+ 		case 11: val->type = WST_VAL_TYPE_SLIDER; break;
+ 		case 12: val->type = WST_VAL_TYPE_SLIDER; break;
  	    }
  	    switch ( val->type ) {
  		case WST_VAL_TYPE_SLIDER:
***************
*** 384,389 ****
--- 395,402 ----
  	    switch ( i ) {
  		default:
  		case 1: cho->type = WST_CHOICE_TYPE_LIST; break;
+ 		case 2: cho->type = WST_CHOICE_TYPE_LIST; break;
+ 		case 3: cho->type = WST_CHOICE_TYPE_LIST; break;
  	    }
  	    switch ( cho->type ) {
  		case WST_CHOICE_TYPE_LIST:
***************
*** 570,575 ****
--- 583,593 ----
      }
  }
  
+ /* This is stupid, atoms don't go away when the client exits, and here we
+  * are always creating an atom which is usually never used.  Moreover,
+  * process id is not unique when clients come from multiple machines.
+  * Why does this silliness exist? -rws
+  */
  static char*
  get_cmap_prop_atom( wst, display ) 
     Wst			*wst;
***************
*** 576,593 ****
     Display		*display;
  {
      static char cmap_prop_name[PHIGS_MAX_NAME_LEN + 1];
-     Atom	api_map;
-     XStandardColormap	std;
      int		pid;
  
      pid = getpid();
      sprintf (cmap_prop_name, "PEX_SI_RGB_API_MAP_%d", pid); 
!     api_map = XInternAtom( display, cmap_prop_name, False );
!     std.colormap = 0;
!     XChangeProperty( display, DefaultRootWindow(display), api_map,
! 	XA_RGB_COLOR_MAP, 32, PropModeReplace, (unsigned char *)&std,
! 	sizeof(XStandardColormap)/4 );
!     return( (char *)api_map );
  }
  
  static void
--- 594,604 ----
     Display		*display;
  {
      static char cmap_prop_name[PHIGS_MAX_NAME_LEN + 1];
      int		pid;
  
      pid = getpid();
      sprintf (cmap_prop_name, "PEX_SI_RGB_API_MAP_%d", pid); 
!     return (char *)XInternAtom( display, cmap_prop_name, False );
  }
  
  static void
***************
*** 771,776 ****
--- 782,791 ----
      char	*name_buf = NULL, *class_buf;
      unsigned	size, name_len, class_len;
  
+     if (!rmdb) {
+ 	(void) XGetDefault (display, name, "hackToGetDefaults");
+ 	rmdb = XrmGetDatabase (display);
+     }
      if ( rmdb ) {
  	/* Set up for getting resource database values. */
  	name_len = strlen( name );
*** /tmp/da2309	Fri Jan 29 13:34:29 1993
--- mit/extensions/test/InsPEX/include/wdt.h	Fri Jan 29 13:34:28 1993
***************
*** 1,5 ****
  
! /* $XConsortium: wdt.h,v 5.4 91/07/24 18:44:18 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989,1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,5 ----
  
! /* $XConsortium: wdt.h,v 5.6 91/11/26 16:01:32 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989,1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 557,564 ****
  
  Pint  num_locator_dev = 3;
  Pint  num_stroke_dev = 1;
! Pint  num_valuator_dev = 1;
! Pint  num_choice_dev = 1;
  Pint  num_pick_dev = 1;
  Pint  num_string_dev = 1;
  
--- 557,564 ----
  
  Pint  num_locator_dev = 3;
  Pint  num_stroke_dev = 1;
! Pint  num_valuator_dev = 12;
! Pint  num_choice_dev = 3;
  Pint  num_pick_dev = 1;
  Pint  num_string_dev = 1;
  
***************
*** 668,693 ****
  	2. valuator data records are ommited, since they will not be verified 
  */
  
! Pint list_valuator_dev_num [] = {1};
! Pfloat list_valuator_def_init_value[] = {0.0};
! Pint list_valuator_num_pet[] = {2};
! Pint list_valuator_list_pet[][10] = { {1,-1} };
  #ifdef PHIGS_WS_TYPE_X_TOOL
! Plimit list_valuator_def_echo_area[] = { {0.0,600.0, 0.0,600.0} };
  #endif
  #ifdef PHIGS_WS_TYPE_X_DRAWABLE
! Plimit list_valuator_def_echo_area[] = { {0.0,WIN_WIDTH,0.0,WIN_HEIGHT} };
  #endif
  
! Pint list_valuator3_dev_num [] = {1};
! Pfloat list_valuator3_def_init_value[] = {0.0};
! Pint list_valuator3_num_pet[] = {2};
! Pint list_valuator3_list_pet[][10] = { {1,-1} };
  #ifdef PHIGS_WS_TYPE_X_TOOL
! Plimit3 list_valuator3_def_echo_volume[] = { {0.0,600.0, 0.0,600.0, 0.0,1.0} };
  #endif
  #ifdef PHIGS_WS_TYPE_X_DRAWABLE
! Plimit3 list_valuator3_def_echo_volume[] = { {0.0,WIN_WIDTH,0.0,WIN_HEIGHT,0.0,1.0} };
  #endif
  /*
    default data for every logical device of class stroke(3):
--- 668,715 ----
  	2. valuator data records are ommited, since they will not be verified 
  */
  
! Pint list_valuator_dev_num [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
! Pfloat list_valuator_def_init_value[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
! Pint list_valuator_num_pet[] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
! Pint list_valuator_list_pet[][10] = { {1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1} };
  #ifdef PHIGS_WS_TYPE_X_TOOL
! Plimit list_valuator_def_echo_area[] = { {0.0,600.0, 0.0,600.0} ,
! {0.0,600.0, 0.0,600.0} , {0.0,600.0, 0.0,600.0} , {0.0,600.0, 0.0,600.0} ,
! {0.0,600.0, 0.0,600.0} , {0.0,600.0, 0.0,600.0} , {0.0,600.0, 0.0,600.0} ,
! {0.0,600.0, 0.0,600.0} , {0.0,600.0, 0.0,600.0} , {0.0,600.0, 0.0,600.0} ,
! {0.0,600.0, 0.0,600.0} , {0.0,600.0, 0.0,600.0} };
  #endif
  #ifdef PHIGS_WS_TYPE_X_DRAWABLE
! Plimit list_valuator_def_echo_area[] = { {0.0,WIN_WIDTH,0.0,WIN_HEIGHT},
! {0.0,WIN_WIDTH,0.0,WIN_HEIGHT}, {0.0,WIN_WIDTH,0.0,WIN_HEIGHT},
! {0.0,WIN_WIDTH,0.0,WIN_HEIGHT}, {0.0,WIN_WIDTH,0.0,WIN_HEIGHT},
! {0.0,WIN_WIDTH,0.0,WIN_HEIGHT}, {0.0,WIN_WIDTH,0.0,WIN_HEIGHT},
! {0.0,WIN_WIDTH,0.0,WIN_HEIGHT}, {0.0,WIN_WIDTH,0.0,WIN_HEIGHT},
! {0.0,WIN_WIDTH,0.0,WIN_HEIGHT}, {0.0,WIN_WIDTH,0.0,WIN_HEIGHT},
! {0.0,WIN_WIDTH,0.0,WIN_HEIGHT} };
  #endif
  
! Pint list_valuator3_dev_num [] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
! Pfloat list_valuator3_def_init_value[] = {0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
! Pint list_valuator3_num_pet[] = {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2};
! Pint list_valuator3_list_pet[][10] = { {1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1},{1,-1} };
  #ifdef PHIGS_WS_TYPE_X_TOOL
! Plimit3 list_valuator3_def_echo_volume[] = { {0.0,600.0, 0.0,600.0, 0.0,1.0},
! {0.0,600.0, 0.0,600.0, 0.0,1.0}, {0.0,600.0, 0.0,600.0, 0.0,1.0},
! {0.0,600.0, 0.0,600.0, 0.0,1.0}, {0.0,600.0, 0.0,600.0, 0.0,1.0},
! {0.0,600.0, 0.0,600.0, 0.0,1.0}, {0.0,600.0, 0.0,600.0, 0.0,1.0},
! {0.0,600.0, 0.0,600.0, 0.0,1.0}, {0.0,600.0, 0.0,600.0, 0.0,1.0},
! {0.0,600.0, 0.0,600.0, 0.0,1.0}, {0.0,600.0, 0.0,600.0, 0.0,1.0},
! {0.0,600.0, 0.0,600.0, 0.0,1.0} };
  #endif
  #ifdef PHIGS_WS_TYPE_X_DRAWABLE
! Plimit3 list_valuator3_def_echo_volume[] = { {0.0,WIN_WIDTH,0.0,WIN_HEIGHT,0.0,1.0},
! {0.0,WIN_WIDTH,0.0,WIN_HEIGHT,0.0,1.0}, {0.0,WIN_WIDTH,0.0,WIN_HEIGHT,0.0,1.0},
! {0.0,WIN_WIDTH,0.0,WIN_HEIGHT,0.0,1.0}, {0.0,WIN_WIDTH,0.0,WIN_HEIGHT,0.0,1.0},
! {0.0,WIN_WIDTH,0.0,WIN_HEIGHT,0.0,1.0}, {0.0,WIN_WIDTH,0.0,WIN_HEIGHT,0.0,1.0},
! {0.0,WIN_WIDTH,0.0,WIN_HEIGHT,0.0,1.0}, {0.0,WIN_WIDTH,0.0,WIN_HEIGHT,0.0,1.0},
! {0.0,WIN_WIDTH,0.0,WIN_HEIGHT,0.0,1.0}, {0.0,WIN_WIDTH,0.0,WIN_HEIGHT,0.0,1.0},
! {0.0,WIN_WIDTH,0.0,WIN_HEIGHT,0.0,1.0} };
  #endif
  /*
    default data for every logical device of class stroke(3):
*** /tmp/da3294	Fri Jan 29 13:35:42 1993
--- mit/extensions/test/InsPEX/testcases/dispctl/dcviewrep.pi	Fri Jan 29 13:35:42 1993
***************
*** 1,5 ****
  
! /* $XConsortium: dcviewrep.pi,v 5.1 91/02/16 10:02:13 rws Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,5 ----
  
! /* $XConsortium: dcviewrep.pi,v 5.2 91/11/26 14:58:53 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 86,92 ****
  dynmod = i_get_ws_dyn_mod(1,"view representation modification");
  if (dynmod == PDYN_IRG) # if reference mod's dynamic modification is IRG
  	# verify that view rep 
! 	im_confirm_viewrep(PUPD_PENDING,oldviewrep3,newviewrep3,"before updatews");
  	# verify that visual rep state is PVISUAL_ST_DEFER
  	im_confirm_visual_rep(1,PVISUAL_ST_DEFER,
    		"failed: visual rep=%d,expected PVISUAL_ST_DEFER before updatews\n");
--- 86,92 ----
  dynmod = i_get_ws_dyn_mod(1,"view representation modification");
  if (dynmod == PDYN_IRG) # if reference mod's dynamic modification is IRG
  	# verify that view rep 
! 	im_confirm_viewrep(PUPD_PEND,oldviewrep3,newviewrep3,"before updatews");
  	# verify that visual rep state is PVISUAL_ST_DEFER
  	im_confirm_visual_rep(1,PVISUAL_ST_DEFER,
    		"failed: visual rep=%d,expected PVISUAL_ST_DEFER before updatews\n");
***************
*** 97,103 ****
  
  if (dynmod == PDYN_CBS) # if reference mod's dynamic modification is CBS
  	# verify that view rep 
! 	im_confirm_viewrep(PUPD_PENDING,oldviewrep3,newviewrep3,"before updatews");
  	# verify that visual rep state is PVISUAL_ST_SIMULATED
  	im_confirm_visual_rep(1,PVISUAL_ST_SIMULATED,
    		"failed: visual rep=%d,expected PVISUAL_ST_SIMULATED before updatews\n");
--- 97,103 ----
  
  if (dynmod == PDYN_CBS) # if reference mod's dynamic modification is CBS
  	# verify that view rep 
! 	im_confirm_viewrep(PUPD_PEND,oldviewrep3,newviewrep3,"before updatews");
  	# verify that visual rep state is PVISUAL_ST_SIMULATED
  	im_confirm_visual_rep(1,PVISUAL_ST_SIMULATED,
    		"failed: visual rep=%d,expected PVISUAL_ST_SIMULATED before updatews\n");
***************
*** 105,111 ****
  
  if (dynmod == PDYN_IMM) # if reference mod's dynamic modification is IMM
  	# verify that view rep 
! 	im_confirm_viewrep(PUPD_NOT_PENDING,newviewrep3,newviewrep3,"before updatews");
  	# verify that visual rep state is PVISUAL_ST_CORRECT
  	im_confirm_visual_rep(1,PVISUAL_ST_CORRECT,
    		"failed: visual rep=%d,expected PVISUAL_ST_CORRECT before updatews\n");
--- 105,111 ----
  
  if (dynmod == PDYN_IMM) # if reference mod's dynamic modification is IMM
  	# verify that view rep 
! 	im_confirm_viewrep(PUPD_NOT_PEND,newviewrep3,newviewrep3,"before updatews");
  	# verify that visual rep state is PVISUAL_ST_CORRECT
  	im_confirm_visual_rep(1,PVISUAL_ST_CORRECT,
    		"failed: visual rep=%d,expected PVISUAL_ST_CORRECT before updatews\n");
***************
*** 117,127 ****
  i_pause();
  
  #OPERATION: update workstation with PERFORM
! pupd_ws(1,PUPD_PERFORM);
  
  #VERIFICATION: 
  # verify that view rep 
! im_confirm_viewrep(PUPD_NOT_PENDING,newviewrep3,newviewrep3,"after updatews");
  
  #verify visual rep state is PVISUAL_ST_CORRECT
  im_confirm_visual_rep(1,PVISUAL_ST_CORRECT,
--- 117,127 ----
  i_pause();
  
  #OPERATION: update workstation with PERFORM
! pupd_ws(1,PFLAG_PERFORM);
  
  #VERIFICATION: 
  # verify that view rep 
! im_confirm_viewrep(PUPD_NOT_PEND,newviewrep3,newviewrep3,"after updatews");
  
  #verify visual rep state is PVISUAL_ST_CORRECT
  im_confirm_visual_rep(1,PVISUAL_ST_CORRECT,
*** /tmp/da3330	Fri Jan 29 13:35:43 1993
--- mit/extensions/test/InsPEX/testcases/dispctl/dispupst1.pi	Fri Jan 29 13:35:43 1993
***************
*** 1,5 ****
  
! /* $XConsortium: dispupst1.pi,v 5.1 91/02/16 10:02:14 rws Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,5 ----
  
! /* $XConsortium: dispupst1.pi,v 5.2 91/11/26 14:59:05 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 42,48 ****
  pinq_disp_upd_st(1, &err, &defmode, &modmode, &sur, &vis);
  
  foreach @defmode (
! 	PDEFER_ASAP;PDEFER_WAIT;PASIT;PDEFER_BNIG;PDEFER_BNIL;
  	)
  	foreach @modmode (
  		PMODE_UQUM;PMODE_NIVE;PMODE_UWOR;
--- 42,48 ----
  pinq_disp_upd_st(1, &err, &defmode, &modmode, &sur, &vis);
  
  foreach @defmode (
! 	PDEFER_ASAP;PDEFER_WAIT;PDEFER_ASTI;PDEFER_BNIG;PDEFER_BNIL;
  	)
  	foreach @modmode (
  		PMODE_UQUM;PMODE_NIVE;PMODE_UWOR;
*** /tmp/da3366	Fri Jan 29 13:35:44 1993
--- mit/extensions/test/InsPEX/testcases/dispctl/dispupst2.pi	Fri Jan 29 13:35:44 1993
***************
*** 1,5 ****
  
! /* $XConsortium: dispupst2.pi,v 5.1 91/02/16 10:02:14 rws Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,5 ----
  
! /* $XConsortium: dispupst2.pi,v 5.2 91/11/26 14:59:07 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 70,77 ****
  
  	#  Verify the current workstation window has old values,
  	#  the requested workstation window has new values, and
! 	#  update state is PUPD_PENDING
! 	im_confirm_wsxform(PUPD_PENDING,
  		newwin,oldwin,vport,vport,"before updatews");
  
  	if (dynmod == PDYN_IRG) # if the ws xform's dynamic modification is IRG
--- 70,77 ----
  
  	#  Verify the current workstation window has old values,
  	#  the requested workstation window has new values, and
! 	#  update state is PUPD_PEND
! 	im_confirm_wsxform(PUPD_PEND,
  		newwin,oldwin,vport,vport,"before updatews");
  
  	if (dynmod == PDYN_IRG) # if the ws xform's dynamic modification is IRG
***************
*** 102,108 ****
  
  	#OPERATIONS: update display
  
! 	pupd_ws(1, PUPD_PERFORM );
  
  	#VERIFICATIONS: 
  
--- 102,108 ----
  
  	#OPERATIONS: update display
  
! 	pupd_ws(1, PFLAG_PERFORM );
  
  	#VERIFICATIONS: 
  
***************
*** 112,119 ****
  
  	#  Verify the current workstation window has new values,
  	#  the requested workstation window has new values, and
! 	#  update state is PUPD_NOT_PENDING
! 	im_confirm_wsxform(PUPD_NOT_PENDING,
  		newwin,newwin,vport,vport,"after updatews");
  
  	#  Verify the picture by sampling pixels at the expected locations. 
--- 112,119 ----
  
  	#  Verify the current workstation window has new values,
  	#  the requested workstation window has new values, and
! 	#  update state is PUPD_NOT_PEND
! 	im_confirm_wsxform(PUPD_NOT_PEND,
  		newwin,newwin,vport,vport,"after updatews");
  
  	#  Verify the picture by sampling pixels at the expected locations. 
***************
*** 123,129 ****
  	i_pause();
  	#CLEANUP: set ws window to default values
  	pset_ws_win(1, &oldwin);
! 	pupd_ws(1, PUPD_PERFORM );
  
  end
  
--- 123,129 ----
  	i_pause();
  	#CLEANUP: set ws window to default values
  	pset_ws_win(1, &oldwin);
! 	pupd_ws(1, PFLAG_PERFORM );
  
  end
  
*** /tmp/da3402	Fri Jan 29 13:35:46 1993
--- mit/extensions/test/InsPEX/testcases/dispctl/dispupst3.pi	Fri Jan 29 13:35:45 1993
***************
*** 1,5 ****
  
! /* $XConsortium: dispupst3.pi,v 5.1 91/02/16 10:02:15 rws Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,5 ----
  
! /* $XConsortium: dispupst3.pi,v 5.2 91/11/26 14:59:09 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 80,87 ****
  			"failed: state of visual rep = %d, expected PVISUAL_ST_CORRECT\n");
  	#  Verify the current workstation window has old values,
  	#  the requested workstation window has new values, and
! 	#  update state is PUPD_NOT_PENDING
! 	im_confirm_wsxform(PUPD_NOT_PENDING,newwin,newwin,vport,vport,
  		"before updatews");
  
  	#  Verify the picture by sampling pixels at the expected locations. 
--- 80,87 ----
  			"failed: state of visual rep = %d, expected PVISUAL_ST_CORRECT\n");
  	#  Verify the current workstation window has old values,
  	#  the requested workstation window has new values, and
! 	#  update state is PUPD_NOT_PEND
! 	im_confirm_wsxform(PUPD_NOT_PEND,newwin,newwin,vport,vport,
  		"before updatews");
  
  	#  Verify the picture by sampling pixels at the expected locations. 
***************
*** 91,97 ****
  	#CLEANUP: set ws window to default values
  
  		pset_ws_win(1, &oldwin);
! 		pupd_ws(1,PUPD_PERFORM);
  
  		end
  	end
--- 91,97 ----
  	#CLEANUP: set ws window to default values
  
  		pset_ws_win(1, &oldwin);
! 		pupd_ws(1,PFLAG_PERFORM);
  
  		end
  	end
*** /tmp/da3508	Fri Jan 29 13:35:50 1993
--- mit/extensions/test/InsPEX/testcases/dispctl/dcinvis.pi	Fri Jan 29 13:35:49 1993
***************
*** 1,5 ****
  
! /* $XConsortium: dcinvis.pi,v 5.1 91/02/16 10:02:18 rws Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,5 ----
  
! /* $XConsortium: dcinvis.pi,v 5.2 91/11/26 14:59:11 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 99,105 ****
  i_pause();
  
  #OPERATION: update workstation with PERFORM
! pupd_ws(1,PUPD_PERFORM);
  
  #VERIFICATION: 
  #verify visual rep state is PVISUAL_ST_CORRECT
--- 99,105 ----
  i_pause();
  
  #OPERATION: update workstation with PERFORM
! pupd_ws(1,PFLAG_PERFORM);
  
  #VERIFICATION: 
  #verify visual rep state is PVISUAL_ST_CORRECT
*** /tmp/da4807	Fri Jan 29 13:36:59 1993
--- mit/extensions/test/InsPEX/testcases/input/pick1.pi	Fri Jan 29 13:36:59 1993
***************
*** 1,4 ****
! /* $XConsortium: pick1.pi,v 5.1 91/02/16 10:03:23 rws Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: pick1.pi,v 5.2 92/02/24 16:02:29 mor Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 55,64 ****
  
  # retrieve default data
  pinq_pick_st(1,1,PINQ_SET,store,&err,&inqmode,&inqswitch,&filter,&inqstatus,
! 	&inqpath, &inqpet, &inqearea, &data, &inqorder);
  im_ifneq(err,0,"ERROR: %d in pinq_pick_st\n",err);
  pinq_pick_st3(1,1,PINQ_SET,store3,&err,&inqmode,&inqswitch,&filter,&inqstatus,
! 	&inqpath, &inqpet, &inqevol, &data3, &inqorder3);
  im_ifneq(err,0,"ERROR: %d in pinq_pick_st3\n",err);
  
  # operation: initialize pick device
--- 55,64 ----
  
  # retrieve default data
  pinq_pick_st(1,1,PINQ_SET,store,&err,&inqmode,&inqswitch,&filter,&inqstatus,
! 	&pinqpath, &inqpet, &inqearea, &data, &inqorder);
  im_ifneq(err,0,"ERROR: %d in pinq_pick_st\n",err);
  pinq_pick_st3(1,1,PINQ_SET,store3,&err,&inqmode,&inqswitch,&filter,&inqstatus,
! 	&pinqpath, &inqpet, &inqevol, &data3, &inqorder3);
  im_ifneq(err,0,"ERROR: %d in pinq_pick_st3\n",err);
  
  # operation: initialize pick device
***************
*** 67,73 ****
  # verify: inquire pick states and verify against the expected values
  
  pinq_pick_st(1,1,PINQ_SET,store,&err,&inqmode,&inqswitch,&filter,&inqstatus,
! 	&inqpath, &inqpet, &inqearea, &inqdata, &inqorder);
  im_ifneq(err,0,"ERROR: %d in pinq_pick_st\n",err);
  
  im_ifneq(inqstatus,PIN_STATUS_OK,
--- 67,73 ----
  # verify: inquire pick states and verify against the expected values
  
  pinq_pick_st(1,1,PINQ_SET,store,&err,&inqmode,&inqswitch,&filter,&inqstatus,
! 	&pinqpath, &inqpet, &inqearea, &inqdata, &inqorder);
  im_ifneq(err,0,"ERROR: %d in pinq_pick_st\n",err);
  
  im_ifneq(inqstatus,PIN_STATUS_OK,
***************
*** 80,86 ****
  status = i_compare_Plimit(inqearea,earea);
  im_ifneq(status,1,"failed: pick init echo area != expected\n",NULL);
  
! status = i_compare_Ppick_path(inqpath,path1);
  im_ifneq(status,1,"failed: pick init path != expected\n",NULL);
  
  # test sample pick
--- 80,86 ----
  status = i_compare_Plimit(inqearea,earea);
  im_ifneq(status,1,"failed: pick init echo area != expected\n",NULL);
  
! status = i_compare_Ppick_path(*pinqpath,path1);
  im_ifneq(status,1,"failed: pick init path != expected\n",NULL);
  
  # test sample pick
***************
*** 99,105 ****
  # verify: inquire pick(3) states and verify against the expected values
  
  pinq_pick_st3(1,1,PINQ_SET,store3,&err,&inqmode,&inqswitch,&filter,&inqstatus,
! 	&inqpath, &inqpet,&inqevol, &inqdata3, &inqorder);
  im_ifneq(err,0,"ERROR: %d in pinq_pick_st3\n",err);
  
  im_ifneq(inqstatus,PIN_STATUS_OK,
--- 99,105 ----
  # verify: inquire pick(3) states and verify against the expected values
  
  pinq_pick_st3(1,1,PINQ_SET,store3,&err,&inqmode,&inqswitch,&filter,&inqstatus,
! 	&pinqpath, &inqpet,&inqevol, &inqdata3, &inqorder);
  im_ifneq(err,0,"ERROR: %d in pinq_pick_st3\n",err);
  
  im_ifneq(inqstatus,PIN_STATUS_OK,
***************
*** 112,118 ****
  status = i_compare_Plimit3(inqevol,evol);
  im_ifneq(status,1,"failed: pick3 init echo volume != expected\n",NULL);
  
! status = i_compare_Ppick_path(inqpath,path2);
  im_ifneq(status,1,"failed: pick3 init path != expected\n",NULL);
  
  
--- 112,118 ----
  status = i_compare_Plimit3(inqevol,evol);
  im_ifneq(status,1,"failed: pick3 init echo volume != expected\n",NULL);
  
! status = i_compare_Ppick_path(*pinqpath,path2);
  im_ifneq(status,1,"failed: pick3 init path != expected\n",NULL);
  
  
*** /tmp/da5985	Fri Jan 29 13:38:04 1993
--- mit/extensions/test/InsPEX/testcases/nurbs/nurbss3.pi	Fri Jan 29 13:38:03 1993
***************
*** 1,5 ****
  
! /* $XConsortium: nurbss3.pi,v 5.1 91/02/16 10:03:51 rws Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,5 ----
  
! /* $XConsortium: nurbss3.pi,v 5.2 91/11/26 15:50:38 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 129,135 ****
  pset_indiv_asf(PASPECT_INT_SHAD_METH,PASF_BUNDLED);
  pset_indiv_asf(PASPECT_REFL_PROPS,PASF_BUNDLED);
  pset_indiv_asf(PASPECT_BACK_INT_STYLE,PASF_BUNDLED);
! pset_indiv_asf(PASPECT_BACK_INT_COLR_INDEX,PASF_BUNDLED);
  pset_indiv_asf(PASPECT_BACK_INT_REFL_EQN,PASF_BUNDLED);
  pset_indiv_asf(PASPECT_BACK_INT_SHAD_METH,PASF_BUNDLED);
  pset_indiv_asf(PASPECT_BACK_REFL_PROPS,PASF_BUNDLED);
--- 129,135 ----
  pset_indiv_asf(PASPECT_INT_SHAD_METH,PASF_BUNDLED);
  pset_indiv_asf(PASPECT_REFL_PROPS,PASF_BUNDLED);
  pset_indiv_asf(PASPECT_BACK_INT_STYLE,PASF_BUNDLED);
! pset_indiv_asf(PASPECT_BACK_INT_COLR,PASF_BUNDLED);
  pset_indiv_asf(PASPECT_BACK_INT_REFL_EQN,PASF_BUNDLED);
  pset_indiv_asf(PASPECT_BACK_INT_SHAD_METH,PASF_BUNDLED);
  pset_indiv_asf(PASPECT_BACK_REFL_PROPS,PASF_BUNDLED);
*** /tmp/da6386	Fri Jan 29 13:38:32 1993
--- mit/extensions/test/InsPEX/testcases/plinedata/pldata2.pi	Fri Jan 29 13:38:32 1993
***************
*** 1,4 ****
! /* $XConsortium: pldata2.pi,v 5.1 91/02/16 10:03:36 rws Exp $ */
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
  
--- 1,4 ----
! /* $XConsortium: pldata2.pi,v 5.2 91/11/26 15:27:19 hersh Exp $ */
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
  
***************
*** 108,114 ****
  	ppolyline_set3_data(PVERT_COORD_COLOUR, PMODEL_RGB, 2, set_lower_left);
  
  	# dotdash in lower right
! 	pset_linetype(PLINE_DOT_DASH);
  	ppolyline_set3_data(PVERT_COORD_COLOUR, PMODEL_RGB, 2, set_lower_right);
  
  	# compose the image name and description, compare images
--- 108,114 ----
  	ppolyline_set3_data(PVERT_COORD_COLOUR, PMODEL_RGB, 2, set_lower_left);
  
  	# dotdash in lower right
! 	pset_linetype(PLINE_DASH_DOT);
  	ppolyline_set3_data(PVERT_COORD_COLOUR, PMODEL_RGB, 2, set_lower_right);
  
  	# compose the image name and description, compare images
*** /tmp/da6457	Fri Jan 29 13:38:34 1993
--- mit/extensions/test/InsPEX/testcases/plinedata/pldata4.pi	Fri Jan 29 13:38:34 1993
***************
*** 1,4 ****
! /* $XConsortium: pldata4.pi,v 5.1 91/02/16 10:03:38 rws Exp $ */
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
  
--- 1,4 ----
! /* $XConsortium: pldata4.pi,v 5.2 91/11/26 15:27:32 hersh Exp $ */
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
  
***************
*** 109,115 ****
  ppolyline_set3_data(PVERT_COORD, NULL, 2, set_lower_left);
  
  # light blue dotdash in lower right - direct colour
! pset_linetype(PLINE_DOT_DASH);
  pset_line_colr(&lightblue);
  ppolyline_set3_data(PVERT_COORD, NULL, 2, set_lower_right);
  
--- 109,115 ----
  ppolyline_set3_data(PVERT_COORD, NULL, 2, set_lower_left);
  
  # light blue dotdash in lower right - direct colour
! pset_linetype(PLINE_DASH_DOT);
  pset_line_colr(&lightblue);
  ppolyline_set3_data(PVERT_COORD, NULL, 2, set_lower_right);
  
*** /tmp/da6570	Fri Jan 29 13:38:42 1993
--- mit/extensions/test/InsPEX/testcases/poly/polyline2.pi	Fri Jan 29 13:38:41 1993
***************
*** 1,4 ****
! # $XConsortium: polyline2.pi,v 5.1 91/02/16 10:00:34 rws Exp $
  ## polyline2 - test /*WARNING: parameters changed */ ppolyline with all various combinations of widths and
  ## line types.
  
--- 1,4 ----
! # $XConsortium: polyline2.pi,v 5.2 91/11/26 14:49:41 hersh Exp $
  ## polyline2 - test /*WARNING: parameters changed */ ppolyline with all various combinations of widths and
  ## line types.
  
***************
*** 18,24 ****
  foreach @linetype @typename (PLINE_SOLID; "solid";
  			     PLINE_DASH;  "dash";
  			     PLINE_DOT;   "dot";
! 			     PLINE_DOT_DASH; "dotdash")
  
  	pset_linetype(@linetype);
  
--- 18,24 ----
  foreach @linetype @typename (PLINE_SOLID; "solid";
  			     PLINE_DASH;  "dash";
  			     PLINE_DOT;   "dot";
! 			     PLINE_DASH_DOT; "dotdash")
  
  	pset_linetype(@linetype);
  
*** /tmp/da6641	Fri Jan 29 13:38:44 1993
--- mit/extensions/test/InsPEX/testcases/poly/polyline4.pi	Fri Jan 29 13:38:44 1993
***************
*** 1,4 ****
! # $XConsortium: polyline4.pi,v 5.1 91/02/16 10:00:36 rws Exp $
  ## polyline4- test ppolyline with all combinations of widths and
  ## line types - based on polyline2, but ordering differently to
  ## work around bug.
--- 1,4 ----
! # $XConsortium: polyline4.pi,v 5.2 91/11/26 14:49:53 hersh Exp $
  ## polyline4- test ppolyline with all combinations of widths and
  ## line types - based on polyline2, but ordering differently to
  ## work around bug.
***************
*** 18,24 ****
  
  foreach @linetype @typename (PLINE_DASH;  "dash";
  			     PLINE_DOT;   "dot";
! 			     PLINE_DOT_DASH; "dotdash";
  			     PLINE_SOLID; "solid";)
  
  	pset_linetype(@linetype);
--- 18,24 ----
  
  foreach @linetype @typename (PLINE_DASH;  "dash";
  			     PLINE_DOT;   "dot";
! 			     PLINE_DASH_DOT; "dotdash";
  			     PLINE_SOLID; "solid";)
  
  	pset_linetype(@linetype);
*** /tmp/da7140	Fri Jan 29 13:39:06 1993
--- mit/extensions/test/InsPEX/testcases/rep/viewrep.pi	Fri Jan 29 13:39:05 1993
***************
*** 1,4 ****
! /* $XConsortium: viewrep.pi,v 5.1 91/02/16 10:04:29 rws Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: viewrep.pi,v 5.2 91/11/26 15:52:56 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 63,72 ****
  
  err = i_bogus_error();
  pinq_view_rep(1,1,&err,&updatest,&cur_rep,&req_rep);
! im_ifneq(e,0,"ERROR: %d in pinq_view_rep",e);
  
! im_ifneq(updatest,PUPD_NOT_PENDING,
! 	"failed: display update state != PUPD_NOT_PENDING\n",NULL);
  
  status = i_compare_Pview_rep3(cur_rep,viewrep3);
  im_ifneq(status,1,"failed: current view representation != expected\n",NULL);
--- 63,72 ----
  
  err = i_bogus_error();
  pinq_view_rep(1,1,&err,&updatest,&cur_rep,&req_rep);
! im_ifneq(err,0,"ERROR: %d in pinq_view_rep",err);
  
! im_ifneq(updatest,PUPD_NOT_PEND,
! 	"failed: display update state != PUPD_NOT_PEND\n",NULL);
  
  status = i_compare_Pview_rep3(cur_rep,viewrep3);
  im_ifneq(status,1,"failed: current view representation != expected\n",NULL);
*** /tmp/da7680	Fri Jan 29 13:39:36 1993
--- mit/extensions/test/InsPEX/testcases/shared/armacro.pi	Fri Jan 29 13:39:36 1993
***************
*** 1,5 ****
  
! /* $XConsortium: armacro.pi,v 5.1 91/02/16 10:02:49 rws Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,5 ----
  
! /* $XConsortium: armacro.pi,v 5.2 91/11/26 15:00:37 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 78,84 ****
  	#
  	# verify type of first element in structure
  	#
! 	if (structstatus == PSTRUCT_STATUS_NON_EMPTY)
  		err = i_bogus_error();
          	pinq_elem_type_size(@str, 1, &err, &actualtype, &elemsize);
  		im_ifneq(err,0,"ERROR: %d in pinq_elem_type_size\n",err);
--- 78,84 ----
  	#
  	# verify type of first element in structure
  	#
! 	if (structstatus == PSTRUCT_STATUS_NOT_EMPTY)
  		err = i_bogus_error();
          	pinq_elem_type_size(@str, 1, &err, &actualtype, &elemsize);
  		im_ifneq(err,0,"ERROR: %d in pinq_elem_type_size\n",err);
*** /tmp/da8613	Fri Jan 29 13:40:36 1993
--- mit/extensions/test/InsPEX/testcases/strcon/strstat1.pi	Fri Jan 29 13:40:35 1993
***************
*** 1,5 ****
  
! /* $XConsortium: strstat1.pi,v 5.1 91/02/16 10:01:00 rws Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,5 ----
  
! /* $XConsortium: strstat1.pi,v 5.2 91/11/26 14:51:34 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 52,58 ****
  pset_line_colr_ind(3);
  ppolyline(&lines1);
  pclose_struct();
! im_confirm_struct_status(2, PSTRUCT_STATUS_NON_EMPTY, "failed: struct status %d should have been PSTRUCT_STATUS_NON_EMPTY\n");
  
  
  tendtest();
--- 52,58 ----
  pset_line_colr_ind(3);
  ppolyline(&lines1);
  pclose_struct();
! im_confirm_struct_status(2, PSTRUCT_STATUS_NOT_EMPTY, "failed: struct status %d should have been PSTRUCT_STATUS_NOT_EMPTY\n");
  
  
  tendtest();
*** /tmp/da0676	Fri Jan 29 13:42:28 1993
--- mit/extensions/test/InsPEX/testcases/utils/comptran.pi	Fri Jan 29 13:42:27 1993
***************
*** 1,4 ****
! /* $XConsortium: comptran.pi,v 5.1 91/02/16 10:01:03 rws Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: comptran.pi,v 5.2 91/11/26 14:53:00 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 59,65 ****
--- 59,67 ----
  	# INITIALIZE: 2D scale and translate vectors
  	xlate = I_Pvec(@tx,@ty);
  	scale = I_Pvec(@sx,@sy);
+         ref   = I_Ppoint(@rx,@ry);
  
+ 
  	# OPERATION: pbuild_tran_matrix
  	err = i_bogus_error();
  	pcompose_tran_matrix(mtx1,&ref,&xlate,@zang,&scale,&err,mtx2);
***************
*** 79,84 ****
--- 81,87 ----
  	# INITIALIZE: 3D scale and translate vectors
  	xlate3 = I_Pvec3(@tx,@ty,@tz);
  	scale3 = I_Pvec3(@sx,@sy,@sz);
+         ref3   = I_Ppoint3(@rx,@ry,@rz);
  
  	# OPERATION: pbuild_tran_matrix3
  	err = i_bogus_error();
*** /tmp/da1244	Fri Jan 29 13:42:56 1993
--- mit/extensions/test/InsPEX/testcases/xform/viewxf1.pi	Fri Jan 29 13:42:56 1993
***************
*** 1,4 ****
! /* $XConsortium: viewxf1.pi,v 5.1 91/02/16 10:01:36 rws Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: viewxf1.pi,v 5.2 91/11/26 14:54:15 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 70,76 ****
  	im_ifneq(err,0,"ERROR: %d in peval_view_ori_matrix3\n",err);
  	viewrep3 = I_Pview_rep3(orientmtx3,mapmtx3,cliplimit3,PIND_CLIP,PIND_CLIP,PIND_CLIP);
  	pset_view_rep3(1,1,&viewrep3);
! pupd_ws(1,PUPD_PERFORM);
  	im_confirm_line3(xdisplay,xwindow,1,1,xaxis3,5,1,
  		"failed: 3D: %s, a line is missing\n",@text);
  	im_confirm_line3(xdisplay,xwindow,1,1,yaxis3,5,1,
--- 70,76 ----
  	im_ifneq(err,0,"ERROR: %d in peval_view_ori_matrix3\n",err);
  	viewrep3 = I_Pview_rep3(orientmtx3,mapmtx3,cliplimit3,PIND_CLIP,PIND_CLIP,PIND_CLIP);
  	pset_view_rep3(1,1,&viewrep3);
! pupd_ws(1,PFLAG_PERFORM);
  	im_confirm_line3(xdisplay,xwindow,1,1,xaxis3,5,1,
  		"failed: 3D: %s, a line is missing\n",@text);
  	im_confirm_line3(xdisplay,xwindow,1,1,yaxis3,5,1,
*** /tmp/da1385	Fri Jan 29 13:43:01 1993
--- mit/extensions/test/InsPEX/testcases/xform/wsxf1.pi	Fri Jan 29 13:43:01 1993
***************
*** 1,4 ****
! /* $XConsortium: wsxf1.pi,v 5.1 91/02/16 10:01:39 rws Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: wsxf1.pi,v 5.2 91/11/26 14:54:44 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 52,64 ****
  # OPERATION and VERIFICATION begins:
  # testing 2D case
  # verify default ws transformation
! im_confirm_wsxform(PUPD_NOT_PENDING,wswindow,wswindow,wsviewport,wsviewport,
  	"failed: default ws window,viewport(2D) != exp\n");
  
  # set and inquire ws transformation 
  pset_ws_win(1,&wswindow);
  pset_ws_vp(1,&wsviewport);
! im_confirm_wsxform(PUPD_NOT_PENDING,wswindow,wswindow,wsviewport,wsviewport,
  	"failed: set and inquire ws window,viewport(2D) != exp\n");
  
  # CLEANUP and re-SETUP: close ws and re-open ws
--- 52,64 ----
  # OPERATION and VERIFICATION begins:
  # testing 2D case
  # verify default ws transformation
! im_confirm_wsxform(PUPD_NOT_PEND,wswindow,wswindow,wsviewport,wsviewport,
  	"failed: default ws window,viewport(2D) != exp\n");
  
  # set and inquire ws transformation 
  pset_ws_win(1,&wswindow);
  pset_ws_vp(1,&wsviewport);
! im_confirm_wsxform(PUPD_NOT_PEND,wswindow,wswindow,wsviewport,wsviewport,
  	"failed: set and inquire ws window,viewport(2D) != exp\n");
  
  # CLEANUP and re-SETUP: close ws and re-open ws
***************
*** 70,82 ****
  
  # testing 3D case
  # verify default ws transformation3
! im_confirm_wsxform3(PUPD_NOT_PENDING,wswindow3,wswindow3,wsviewport3,wsviewport3,
  	"failed: default ws window,viewport(3D) != exp\n");
  
  # set and inquire ws transformation3 
  pset_ws_win3(1,&wswindow3);
  pset_ws_vp3(1,&wsviewport3);
! im_confirm_wsxform3(PUPD_NOT_PENDING,wswindow3,wswindow3,wsviewport3,wsviewport3,
  	"failed: set and inquire ws window,viewport(3D): inq != exp\n");
  
  tendtest()
--- 70,82 ----
  
  # testing 3D case
  # verify default ws transformation3
! im_confirm_wsxform3(PUPD_NOT_PEND,wswindow3,wswindow3,wsviewport3,wsviewport3,
  	"failed: default ws window,viewport(3D) != exp\n");
  
  # set and inquire ws transformation3 
  pset_ws_win3(1,&wswindow3);
  pset_ws_vp3(1,&wsviewport3);
! im_confirm_wsxform3(PUPD_NOT_PEND,wswindow3,wswindow3,wsviewport3,wsviewport3,
  	"failed: set and inquire ws window,viewport(3D): inq != exp\n");
  
  tendtest()
*** /tmp/da1421	Fri Jan 29 13:43:02 1993
--- mit/extensions/test/InsPEX/testcases/xform/wsxf2.pi	Fri Jan 29 13:43:02 1993
***************
*** 1,4 ****
! /* $XConsortium: wsxf2.pi,v 5.1 91/02/16 10:01:40 rws Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,4 ----
! /* $XConsortium: wsxf2.pi,v 5.2 91/11/26 14:54:26 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 57,69 ****
  # set 2D and inquire 3D ws transformation 
  pset_ws_win(1,&wswindow1);
  pset_ws_vp(1,&wsviewport1);
! im_confirm_wsxform3(PUPD_NOT_PENDING,wswindow31,wswindow31,wsviewport31,wsviewport31,
  	"failed: set(2D) and inquire(3D) ws window,viewport != exp\n");
  
  # set 3D and inquire 2D ws transformation 
  pset_ws_win3(1,&wswindow32);
  pset_ws_vp3(1,&wsviewport32);
! im_confirm_wsxform(PUPD_NOT_PENDING,wswindow2,wswindow2,wsviewport2,wsviewport2,
  	"failed: set(3D) and inquire(2D) ws window,viewport != exp\n");
  
  tendtest()
--- 57,69 ----
  # set 2D and inquire 3D ws transformation 
  pset_ws_win(1,&wswindow1);
  pset_ws_vp(1,&wsviewport1);
! im_confirm_wsxform3(PUPD_NOT_PEND,wswindow31,wswindow31,wsviewport31,wsviewport31,
  	"failed: set(2D) and inquire(3D) ws window,viewport != exp\n");
  
  # set 3D and inquire 2D ws transformation 
  pset_ws_win3(1,&wswindow32);
  pset_ws_vp3(1,&wsviewport32);
! im_confirm_wsxform(PUPD_NOT_PEND,wswindow2,wswindow2,wsviewport2,wsviewport2,
  	"failed: set(3D) and inquire(2D) ws window,viewport != exp\n");
  
  tendtest()
*** /tmp/da1597	Fri Jan 29 13:43:08 1993
--- mit/extensions/test/InsPEX/testcases/xform/primxf1.pi	Fri Jan 29 13:43:07 1993
***************
*** 1,5 ****
  
! /* $XConsortium: primxf1.pi,v 5.2 91/07/24 18:47:42 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,5 ----
  
! /* $XConsortium: primxf1.pi,v 5.3 91/11/26 14:54:35 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 70,76 ****
  view = I_Plimit3(0.0,1.0,0.0,1.0,0.0,1.0);
  cliplimit = I_Plimit3(0.0,1.0,0.0,1.0,0.0,1.0);
  prp = I_Ppoint3(0.0,0.0,4.0);
! viewmap = I_Pview_map3(win,view,PPERPECTIVE,prp,0.0,0.0,1.0);
  peval_view_map_matrix3(&viewmap,&err,mapmtx);
  im_ifneq(err,0,"ERROR: %d in pevalviewmappingtrix3\n",err);
  viewrep = I_Pview_rep3(xlate_mtx,mapmtx,cliplimit,PIND_CLIP,PIND_CLIP,PIND_CLIP);
--- 70,76 ----
  view = I_Plimit3(0.0,1.0,0.0,1.0,0.0,1.0);
  cliplimit = I_Plimit3(0.0,1.0,0.0,1.0,0.0,1.0);
  prp = I_Ppoint3(0.0,0.0,4.0);
! viewmap = I_Pview_map3(win,view,PTYPE_PERSPECT,prp,0.0,0.0,1.0);
  peval_view_map_matrix3(&viewmap,&err,mapmtx);
  im_ifneq(err,0,"ERROR: %d in pevalviewmappingtrix3\n",err);
  viewrep = I_Pview_rep3(xlate_mtx,mapmtx,cliplimit,PIND_CLIP,PIND_CLIP,PIND_CLIP);
*** /tmp/da2046	Fri Jan 29 13:43:46 1993
--- mit/extensions/test/InsPEX/tools/newt/looper.yacc	Fri Jan 29 13:43:45 1993
***************
*** 1,5 ****
  
! /* $XConsortium: looper.yacc,v 5.3 91/05/04 23:18:31 keith Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,5 ----
  
! /* $XConsortium: looper.yacc,v 5.4 91/11/26 14:42:32 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 408,415 ****
  
  		    /* iterate over the loop */
  		    for ( ; i <= end; i+=increment) {
! 			set_val(func->fun.forl.loopvar->name,
! 				sprintf(numstring, "%d", i));
                          N_execute(func->fun.forl.body,curflag);
  		    }
  		}
--- 408,415 ----
  
  		    /* iterate over the loop */
  		    for ( ; i <= end; i+=increment) {
! 			sprintf(numstring, "%d", i);
! 			set_val(func->fun.forl.loopvar->name,numstring);
                          N_execute(func->fun.forl.body,curflag);
  		    }
  		}
*** /tmp/da2327	Fri Jan 29 13:43:56 1993
--- mit/extensions/test/InsPEX/tools/newt/ipp.c	Fri Jan 29 13:43:55 1993
***************
*** 1,7 ****
  
  
  
! /* $XConsortium: ipp.c,v 5.1 91/02/16 09:59:55 rws Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989,1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
--- 1,7 ----
  
  
  
! /* $XConsortium: ipp.c,v 5.2 92/02/25 10:16:07 mor Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989,1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 562,567 ****
--- 562,568 ----
  {
  	int i;
  
+ 	fprintf(dotcfp, "#define XLIB_ILLEGAL_ACCESS\n");
  	fprintf(dotcfp, "#include \"%s\"\n",doth);
  	if (icount) {
  		for (i=0;i<icount;++i)
*** /tmp/da2616	Fri Jan 29 13:44:10 1993
--- mit/extensions/test/InsPEX/tools/pexint/pexapi.m	Fri Jan 29 13:44:10 1993
***************
*** 1,5 ****
  
! /* $XConsortium: pexapi.m,v 5.3 91/07/24 18:40:25 hersh Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
--- 1,5 ----
  
! /* $XConsortium: pexapi.m,v 5.4 92/02/24 15:57:23 mor Exp $ */
  
  /*****************************************************************
  Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
***************
*** 284,292 ****
  void
  pinq_choice_st(Pint,Pint,Pstore,Pint*,Pop_mode*,Pecho_switch*,Pin_status*,Pint*,Pint*,Plimit*,Pchoice_data**)
  void
! pinq_pick_st3(Pint,Pint,Pinq_type,Pstore,Pint*,Pop_mode*,Pecho_switch*,Pfilter**,Pin_status*,Ppick_path**,Pint*,Plimit3*,Ppath_order*,Ppick_data3**)
  void
! pinq_pick_st(Pint,Pint,Pinq_type,Pstore,Pint*,Pop_mode*,Pecho_switch*,Pfilter**,Pin_status*,Ppick_path**,Pint*,Plimit*,Ppath_order*,Ppick_data**)
  void
  pinq_string_st3(Pint,Pint,Pstore,Pint*,Pop_mode*,Pecho_switch*,char**,Pint*,Plimit3*,Pstring_data3**)
  void
--- 284,292 ----
  void
  pinq_choice_st(Pint,Pint,Pstore,Pint*,Pop_mode*,Pecho_switch*,Pin_status*,Pint*,Pint*,Plimit*,Pchoice_data**)
  void
! pinq_pick_st3(Pint,Pint,Pinq_type,Pstore,Pint*,Pop_mode*,Pecho_switch*,Pfilter**,Pin_status*,Ppick_path**,Pint*,Plimit3*,Ppick_data3**,Ppath_order*)
  void
! pinq_pick_st(Pint,Pint,Pinq_type,Pstore,Pint*,Pop_mode*,Pecho_switch*,Pfilter**,Pin_status*,Ppick_path**,Pint*,Plimit*,Ppick_data**,Ppath_order*)
  void
  pinq_string_st3(Pint,Pint,Pstore,Pint*,Pop_mode*,Pecho_switch*,char**,Pint*,Plimit3*,Pstring_data3**)
  void
*** /tmp/da27045	Tue Feb  2 15:43:00 1993
--- mit/extensions/test/InsPEX/tools/pexint/Makefile	Tue Feb  2 15:43:00 1993
***************
*** 1,5 ****
  
! # $XConsortium: Makefile,v 5.6 91/07/08 18:19:12 hersh Exp $
  ###################################################################
  # Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
  # 
--- 1,5 ----
  
! # $XConsortium: Makefile,v 5.7 93/01/04 18:18:39 hersh Exp $
  ###################################################################
  # Copyright (c) 1989, 1990, 1991,1990 by Sun Microsystems, Inc. and the X Consortium.
  # 
***************
*** 51,57 ****
  NEWTDIR = $$INSPEXHOME/tools/newt
  CFLAGS = $(DEBUGOPT) $(I_CFLAGS) $(CPPFLAGS) -I$(XINCDIR) -I$(PEXINCDIR) -I$(SRCDIR)
  LDFLAGS = $(DEBUGOPT) $(I_LDFLAGS) -L$(PEXLIBDIR) -L$(XLIBDIR) 
! LIBS = ../../../../lib/PEX/libphigs.a -lX11 -lm -ll
  
  SRC = Makefile NewTvararg.h computils.c computils.h computils.m \
  	config.h datautils.c datautils.h datautils.m imath.h \
--- 51,57 ----
  NEWTDIR = $$INSPEXHOME/tools/newt
  CFLAGS = $(DEBUGOPT) $(I_CFLAGS) $(CPPFLAGS) -I$(XINCDIR) -I$(PEXINCDIR) -I$(SRCDIR)
  LDFLAGS = $(DEBUGOPT) $(I_LDFLAGS) -L$(PEXLIBDIR) -L$(XLIBDIR) 
! LIBS = ../../../../lib/PEX/libphigs.a -lX11 -lm -ll -lXext
  
  SRC = Makefile NewTvararg.h computils.c computils.h computils.m \
  	config.h datautils.c datautils.h datautils.m imath.h \
*** /tmp/da28825	Tue Feb  2 16:32:30 1993
--- mit/extensions/test/InsPEX/testcases/shared/Makefile	Tue Feb  2 16:32:30 1993
***************
*** 1,4 ****
! # $XConsortium: Makefile,v 5.6 91/02/19 20:38:16 hersh Exp $
  ###################################################################
  # Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  # 
--- 1,4 ----
! # $XConsortium: Makefile,v 5.7 93/01/04 18:19:19 hersh Exp $
  ###################################################################
  # Copyright (c) 1989, 1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  # 
***************
*** 42,48 ****
  INSPEXINCLUDE = -I$(INSPEXHOME)/tools/pexint -I$(INSPEXDEST)/include
  PEXLIB = -L$(PEXLIBDIR)  -L$(XLIBDIR)
  INSPEXLIB = -L$(INSPEXDEST)/lib
! LIBS = $(INSPEXDEST)/lib/libinspex.a $(PEXLIBDIR)/libphigs.a -lX11 -lm 
  
  LDFLAGS = -g $(I_LDFLAGS) $(PEXLIB) $(INSPEXLIB) $(LIBS)
  CFLAGS = -g  $(I_CFLAGS) $(CPPFLAGS) $(PEXINCLUDE) $(INSPEXINCLUDE)
--- 42,48 ----
  INSPEXINCLUDE = -I$(INSPEXHOME)/tools/pexint -I$(INSPEXDEST)/include
  PEXLIB = -L$(PEXLIBDIR)  -L$(XLIBDIR)
  INSPEXLIB = -L$(INSPEXDEST)/lib
! LIBS = $(INSPEXDEST)/lib/libinspex.a $(PEXLIBDIR)/libphigs.a -lX11 -lm -lXext
  
  LDFLAGS = -g $(I_LDFLAGS) $(PEXLIB) $(INSPEXLIB) $(LIBS)
  CFLAGS = -g  $(I_CFLAGS) $(CPPFLAGS) $(PEXINCLUDE) $(INSPEXINCLUDE)
