2
* dpsXclient.c -- Implementation of the Display PostScript Client Library.
4
* (c) Copyright 1988-1994 Adobe Systems Incorporated.
7
* Permission to use, copy, modify, distribute, and sublicense this software
8
* and its documentation for any purpose and without fee is hereby granted,
9
* provided that the above copyright notices appear in all copies and that
10
* both those copyright notices and this permission notice appear in
11
* supporting documentation and that the name of Adobe Systems Incorporated
12
* not be used in advertising or publicity pertaining to distribution of the
13
* software without specific, written prior permission. No trademark license
14
* to use the Adobe trademarks is hereby granted. If the Adobe trademark
15
* "Display PostScript"(tm) is used to describe this software, its
16
* functionality or for any other purpose, such use shall be limited to a
17
* statement that this software works in conjunction with the Display
18
* PostScript system. Proper trademark attribution to reflect Adobe's
19
* ownership of the trademark shall be given whenever any such reference to
20
* the Display PostScript system is made.
22
* ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR
23
* ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
24
* ADOBE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
25
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
* NON- INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL ADOBE BE LIABLE
27
* TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
28
* DAMAGES OR ANY DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,
29
* NEGLIGENCE, STRICT LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN
30
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ADOBE WILL NOT
31
* PROVIDE ANY TRAINING OR OTHER SUPPORT FOR THE SOFTWARE.
33
* Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
34
* Incorporated which may be registered in certain jurisdictions
36
* Author: Adobe Systems Incorporated
38
/* $XFree86: xc/lib/dps/dpsXclient.c,v 1.3 2000/09/26 15:56:59 tsi Exp $ */
41
#include <unistd.h> /* sleep() */
47
/* Xlib does not like UNIX defined to any value under VMS. */
49
#include <decw$include/X.h>
50
#include <decw$include/Xlib.h>
54
#include <X11/Xutil.h>
57
#include "DPS/XDPSlib.h"
60
#include "publictypes.h"
61
#include "DPS/dpsclient.h"
62
#include "dpsprivate.h"
65
#include "DPS/dpsXclient.h"
68
#include "DPS/dpsexcept.h"
72
static DPSPrivContext FindPrivContext (
79
for (ss = spaces; ss != NIL; ss = ss->next)
80
for (cc = ss->firstContext; cc != NIL; cc = cc->next)
81
if (cc->cid == cid && ((XDPSPrivContext) cc->wh)->dpy == dpy)
86
DPSContext XDPSFindContext (
90
return ((DPSContext) FindPrivContext (dpy, cid));
93
DPSContext DPSContextFromContextID(
97
DPSErrorProc errorProc)
100
Display *dpy = ((XDPSPrivContext) ((DPSPrivContext) ctxt)->wh)->dpy;
101
DPSPrivContext c, cc = FindPrivContext (dpy, contextID);
102
DPSPrivContext oldc = (DPSPrivContext)ctxt;
104
if (cc != NIL) return (DPSContext)cc;
106
c = (DPSPrivContext)DPScalloc(sizeof(DPSPrivContextRec), 1);
109
ss = (DPSPrivSpace)c->space;
111
if (textProc) c->textProc = textProc;
112
if (errorProc) c->errorProc = errorProc;
114
c->eofReceived = false;
116
c->buf = c->outBuf = c->objBuf = NIL;
117
c->chainParent = c->chainChild = NIL;
119
c->nBufChars = c->nOutBufChars = c->nObjBufChars = 0;
121
c->next = ss->firstContext;
122
DPSAssert(c->next != c);
123
ss->firstContext = c;
125
/* Note: there's no way to determine whether the new context id was obtained
126
** as a result of a fork operation or from another application. so, it must
127
** be assumed that the application is the creator of the new context.
128
** Otherwise, it would have called the XDPSContextFromSharedID.
132
c->numstringOffsets = NULL;
134
DPSIncludePrivContext(
135
(XDPSPrivContext) c->wh, (DPSContext)c, c->cid, ss->sid, DPSclientPrintProc);
137
return (DPSContext)c;
140
boolean DPSPrivateCheckWait(
143
DPSPrivContext cc = (DPSPrivContext) ctxt;
145
if (!cc->creator || cc->zombie) {
146
DPSSafeSetLastNameIndex(ctxt);
147
if (cc->errorProc != NIL) {
148
(*cc->errorProc) (ctxt, cc->zombie ? dps_err_deadContext :
149
dps_err_invalidAccess,
150
(unsigned long) ctxt, 0);
157
static void procFlushContext(
160
DPSPrivContext c = (DPSPrivContext) ctxt;
161
XDPSLFlush (((XDPSPrivContext) c->wh)->dpy);
162
if (ctxt->chainChild != NIL) DPSFlushContext(ctxt->chainChild);
166
static Bool FindDPSEvent(
171
return XDPSIsDPSEvent(event);
174
static void procAwaitReturnValues(DPSContext ctxt)
176
DPSPrivContext c = (DPSPrivContext)ctxt;
178
XDPSPrivContext xwh = (XDPSPrivContext) c->wh;
181
/* Output currently goes only to creator! */
184
DPSSafeSetLastNameIndex(ctxt);
185
c->resultTable = NIL;
186
c->resultTableLength = 0;
187
if (c->errorProc != NIL)
188
(*c->errorProc) (ctxt, dps_err_invalidAccess, 0, 0);
191
if (c->resultTable != NIL)
193
DPSCheckInitClientGlobals();
195
if (XDPSLGetWrapWaitingFlag(xwh->dpy)) {
196
DPSSafeSetLastNameIndex(ctxt);
197
c->resultTable = NIL;
198
c->resultTableLength = 0;
199
if (c->errorProc != NIL)
200
(*c->errorProc) (ctxt, dps_err_recursiveWait,
201
(unsigned long) xwh->dpy, 0);
204
XDPSLSetWrapWaitingFlag(xwh->dpy, True);
207
DPSFlushContext(ctxt);
208
while (c->resultTable != NIL)
210
/* We may block indefinitely if the context is frozen or it
211
somehow needs more input. */
214
DPSSafeSetLastNameIndex(ctxt);
215
c->resultTable = NIL;
216
c->resultTableLength = 0;
217
if (c->errorProc != NIL)
218
(*c->errorProc) (ctxt, dps_err_deadContext, (unsigned long) c, 0);
219
XDPSLSetWrapWaitingFlag(xwh->dpy, False);
223
/* Someone could conceivably change the event delivery mode in the
224
middle of this...best to check every time */
226
if (XDPSLGetPassEventsFlag(xwh->dpy)) {
227
XIfEvent(xwh->dpy, &ev, FindDPSEvent, (char *) NULL);
228
if (!XDPSDispatchEvent(&ev)) DPSCantHappen();
229
} else DPSSendPostScript((XDPSPrivContext) c->wh, DPSclientPrintProc,
230
c->cid, NIL, 0, NIL);
233
XDPSLSetWrapWaitingFlag(xwh->dpy, False);
237
XDPSLSetWrapWaitingFlag(xwh->dpy, False);
241
/* update space's name map.
242
space->lastNameIndex is the highest index known to be known to the
243
server for this space.
244
c->lastNameIndex is the highest index sent so far to the context
247
if (((DPSPrivSpace)(c->space))->lastNameIndex < c->lastNameIndex)
248
((DPSPrivSpace)(c->space))->lastNameIndex = c->lastNameIndex;
251
void DPSinnerProcWriteData(
256
DPSPrivContext c = (DPSPrivContext) ctxt;
258
/* ASSERT: safe to call with chain */
260
/* No local buffering */
261
DPSSendPostScript ((XDPSPrivContext) c->wh, DPSclientPrintProc,
262
c->cid, buf, count, NIL);
263
} /* DPSinnerProcWriteData */
265
static void procResetContext(DPSContext ctxt)
267
DPSPrivContext c = (DPSPrivContext) ctxt;
269
register XDPSPrivContext xwh = (XDPSPrivContext) c->wh;
273
/* First make sure context isn't frozen, try to unfreeze. */
275
#define DPS_SLEEP_SECS 2
277
while((currStatus = XDPSLGetStatus(xwh->dpy, xwh->cxid)) == PSFROZEN)
279
XDPSLNotifyContext(xwh->dpy, xwh->cxid, PSUNFREEZE);
280
sleep(DPS_SLEEP_SECS);
281
/* Okay if context is PSRUNNING, since the EOF will
282
be handled at the next PSNEEDSINPUT */
285
/* Remove events from Xlib Qs before sending the reset request. */
286
XDPSForceEvents (xwh->dpy);
288
if (currStatus == PSSTATUSERROR)
289
/* +++ report error? */;
290
else /* Didn't become zombie. */
293
XDPSLReset(xwh->dpy, xwh->cxid);
294
XDPSLFlush(xwh->dpy);
295
/* Be optmistic for the first try. Assume the app set up a status mask
296
correctly, we should get a status event without asking the
297
server for status. */
299
XDPSForceEvents(xwh->dpy);
300
currStatus = c->statusFromEvent;
302
while (currStatus != PSNEEDSINPUT && currStatus != PSZOMBIE)
304
if (currStatus == PSFROZEN)
305
XDPSLNotifyContext(xwh->dpy, xwh->cxid, PSUNFREEZE);
306
if (retries > backoff)
308
/* Optimism failed. App probably didn't set up a status mask.
309
Ask the server for status. */
310
currStatus = XDPSLGetStatus(xwh->dpy, xwh->cxid);
312
backoff = (backoff > 30) ? 2 : backoff + 1;
317
sleep(DPS_SLEEP_SECS);
318
XDPSForceEvents(xwh->dpy);
319
currStatus = c->statusFromEvent;
323
c->eofReceived = false;
326
void DPSPrivateDestroyContext(DPSContext ctxt)
328
DPSPrivContext c = (DPSPrivContext)ctxt;
329
DPSPrivSpace s = (DPSPrivSpace) c->space;
332
DPSSendTerminate((XDPSPrivContext) c->wh, c->cid, DPSclientPrintProc);
334
XDPSSetStatusMask(ctxt, 0, XDPSL_ALL_EVENTS, 0); /* Stop status events */
335
/* Don't free the space's wh out from under it */
336
if (c->wh != s->wh) free(c->wh);
339
void DPSPrivateDestroySpace(DPSSpace space)
341
DPSPrivSpace ss = (DPSPrivSpace) space;
343
if (ss->creator) DPSSendDestroySpace((XDPSPrivContext) ss->wh, ss->sid,
349
boolean DPSCheckShared(DPSPrivContext ctxt)
351
return ctxt->creator == false && ctxt->resultTable != NIL;
352
/* let procAwaitReturnValues generate error */
356
void DPSServicePostScript(boolean (*returnControl)(void))
358
} /* DPSServicePostScript */
360
void DPSHandleBogusError(DPSContext ctxt, char *prefix, char *suffix)
362
char *buf = "bogus error output from context";
363
DPSDefaultPrivateHandler(ctxt, dps_err_warning,
364
(long unsigned int)buf, 0, prefix, suffix);
367
void DPSDefaultPrivateHandler(
369
DPSErrorCode errorCode,
370
long unsigned int arg1,
371
long unsigned int arg2,
376
DPSTextProc textProc = DPSGetCurrentTextBackstop();
379
case dps_err_invalidAccess:
383
(void) sprintf (m, "%sInvalid context access.%s", prefix, suffix);
384
(*textProc) (ctxt, m, strlen (m));
387
case dps_err_encodingCheck:
391
(void) sprintf (m, "%sInvalid name/program encoding: %d/%d.%s",
392
prefix, (int) arg1, (int) arg2, suffix);
393
(*textProc) (ctxt, m, strlen (m));
396
case dps_err_closedDisplay:
400
(void) sprintf (m, "%sBroken display connection %d.%s",
401
prefix, (int) arg1, suffix);
402
(*textProc) (ctxt, m, strlen (m));
405
case dps_err_deadContext:
409
(void) sprintf (m, "%sDead context 0x0%x.%s", prefix,
411
(*textProc) (ctxt, m, strlen (m));
414
case dps_err_warning:
417
char *warn = (char *)arg1;
418
char *msg = "%% DPS Client Library Warning:\n ";
419
(*textProc)(ctxt, msg, strlen(msg));
420
(*textProc)(ctxt, warn, strlen(warn));
422
(*textProc)(ctxt, msg, strlen(msg));
423
/* flush convention */
424
(*textProc)(ctxt, msg, 0);
430
char *fatal = (char *)arg1;
431
char *msg = "%% DPS Client Library Fatal Internal Error:\n ";
432
(*textProc)(ctxt, msg, strlen(msg));
433
(*textProc)(ctxt, fatal, strlen(fatal));
434
msg = ".\nAborting ...\n";
435
(*textProc)(ctxt, msg, strlen(msg));
436
/* flush convention */
437
(*textProc)(ctxt, msg, 0);
441
case dps_err_recursiveWait:
446
"%sRecursive wait for return values, display 0x%x.%s",
447
prefix, (int) arg1, suffix);
448
(*textProc) (ctxt, m, strlen (m));
454
void DPSInitPrivateSpaceFields(DPSPrivSpace s)
459
void DPSInitPrivateContextFields(DPSPrivContext c, DPSPrivSpace s)
464
c->procs = XDPSconvProcs;
465
c->nameEncoding = dps_strings;
469
void DPSInitPrivateTextContextFields(DPSPrivContext c, DPSPrivSpace s)
473
c->space = (DPSSpace) s;
474
c->next = s->firstContext;
478
long int DPSLastUserObjectIndex = 0;
480
long int DPSNewUserObjectIndex (void)
482
return (DPSLastUserObjectIndex++);
485
void XDPSSetProcs (void)
487
DPSCheckInitClientGlobals ();
490
textCtxProcs = (DPSProcs) DPScalloc (sizeof (DPSProcsRec), 1);
491
DPSInitCommonTextContextProcs(textCtxProcs);
496
ctxProcs = (DPSProcs) DPScalloc (sizeof (DPSProcsRec), 1);
497
DPSInitCommonContextProcs(ctxProcs);
498
DPSInitPrivateContextProcs(ctxProcs);
501
XDPSconvProcs = (DPSProcs) DPScalloc (sizeof (DPSProcsRec), 1);
503
XDPSrawProcs = ctxProcs;
504
*XDPSconvProcs = *ctxProcs;
505
XDPSconvProcs->BinObjSeqWrite = textCtxProcs->BinObjSeqWrite;
506
XDPSconvProcs->WriteStringChars = textCtxProcs->WriteStringChars;
507
XDPSconvProcs->WritePostScript = textCtxProcs->WritePostScript;
508
XDPSconvProcs->WriteNumString = textCtxProcs->WriteNumString;
511
void DPSInitPrivateContextProcs(DPSProcs p)
513
p->FlushContext = procFlushContext;
514
p->ResetContext = procResetContext;
515
p->AwaitReturnValues = procAwaitReturnValues;
518
DPSContext XDPSCreateSimpleContext (
524
DPSTextProc textProc,
525
DPSErrorProc errorProc,
528
XDPSPrivContext xwh = XDPSCreatePrivContextRec (dpy, draw, gc, x, y,
530
DefaultStdCMap, 0, false);
537
newCtxt = DPSCreateContext ((char *) xwh, textProc, errorProc, space);
545
DPSContext XDPSCreateContext (
551
unsigned int eventmask,
552
XStandardColormap *grayramp,
553
XStandardColormap *ccube,
555
DPSTextProc textProc,
556
DPSErrorProc errorProc,
559
XDPSPrivContext xwh = XDPSCreatePrivContextRec (dpy, draw, gc, x, y,
561
ccube, actual, false);
568
newCtxt = DPSCreateContext ((char *) xwh, textProc, errorProc, space);
575
DPSContext XDPSCreateSecureContext (
581
unsigned int eventmask,
582
XStandardColormap *grayramp,
583
XStandardColormap *ccube,
585
DPSTextProc textProc,
586
DPSErrorProc errorProc,
589
XDPSPrivContext xwh = XDPSCreatePrivContextRec (dpy, draw, gc, x, y,
591
ccube, actual, true);
598
newCtxt = DPSCreateContext ((char *) xwh, textProc, errorProc, space);
606
DPSContext XDPSContextFromSharedID (dpy, cid, textProc, errorProc)
609
DPSTextProc textProc;
610
DPSErrorProc errorProc;
618
if (DPSInitialize () != 0)
621
c = FindPrivContext (dpy, cid);
623
return ((DPSContext) c);
625
xwh = XDPSCreatePrivContextRec (dpy, 0, 0, 0, 0, 0, NIL, NIL, 0, false);
628
else if (XDPSLIDFromContext (dpy, cid, &cxid, &sxid) != 1)
635
if (spaceProcs == NIL)
637
spaceProcs = (DPSSpaceProcs) DPScalloc (sizeof (DPSSpaceProcsRec), 1);
638
DPSInitCommonSpaceProcs(spaceProcs);
643
if ((SpaceXID)s->sid == sxid && ((XDPSPrivContext) s->wh)->dpy == dpy)
648
if (s == NIL) /* Create new space record. */
650
s = (DPSPrivSpace) DPScalloc (sizeof (DPSPrivSpaceRec), 1);
651
s->procs = spaceProcs;
652
s->lastNameIndex = -1;
654
s->wh = (char *) xwh;
660
c = (DPSPrivContext) DPScalloc (sizeof (DPSPrivContextRec), 1);
661
c->space = (DPSSpace) s;
662
c->procs = XDPSconvProcs;
663
c->textProc = textProc;
664
c->errorProc = errorProc;
665
c->programEncoding = DPSDefaultProgramEncoding;
666
c->nameEncoding = dps_strings;
667
c->next = s->firstContext;
669
c->lastNameIndex = s->lastNameIndex;
671
c->numstringOffsets = NULL;
674
c->numFormat = XDPSNumFormat (dpy);
675
c->wh = (char *) xwh;
677
xwh->ctxt = (DPSContext) c;
679
return ((DPSContext) c);
683
void DPSChangeEncoding (ctxt, newProgEncoding, newNameEncoding)
685
DPSProgramEncoding newProgEncoding;
686
DPSNameEncoding newNameEncoding;
688
if (ctxt->programEncoding != newProgEncoding ||
689
ctxt->nameEncoding != newNameEncoding)
691
DPSPrivContext cc = (DPSPrivContext) ctxt;
692
DPSPrivSpace ss = (DPSPrivSpace) (cc->space);
694
if ((!cc->creator || !ss->creator) && newNameEncoding != dps_strings)
696
DPSSafeSetLastNameIndex(ctxt);
697
if (cc->errorProc != NIL)
698
(*cc->errorProc) (ctxt, dps_err_encodingCheck,
699
(unsigned long) newNameEncoding,
700
(unsigned long) newProgEncoding);
703
if (ctxt->procs == textCtxProcs)
705
ctxt->programEncoding = newProgEncoding;
706
ctxt->nameEncoding = newNameEncoding;
709
XDPSSetContextEncoding (ctxt, newProgEncoding, newNameEncoding);
714
DPSSpace XDPSSpaceFromSharedID (dpy, sid)
721
if (DPSInitialize () != 0)
724
if (spaceProcs == NIL)
726
spaceProcs = (DPSSpaceProcs) DPScalloc (sizeof (DPSSpaceProcsRec), 1);
727
DPSInitCommonSpaceProcs(spaceProcs);
732
if ((SpaceXID)s->sid == sid && ((XDPSPrivContext) s->wh)->dpy == dpy)
737
if (s == NIL) /* Create new space record. */
739
xwh = XDPSCreatePrivContextRec (dpy, 0, 0, 0, 0, 0, NIL, NIL, 0, false);
743
s = (DPSPrivSpace) DPScalloc (sizeof (DPSPrivSpaceRec), 1);
744
s->procs = spaceProcs;
745
s->lastNameIndex = -1;
747
s->wh = (char *) xwh;
753
return ((DPSSpace) s);
757
void XDPSUnfreezeContext (ctxt)
760
XDPSPrivContext wh = (XDPSPrivContext) (((DPSPrivContext) ctxt)->wh);
762
if (wh != NIL && wh->cxid != 0)
763
XDPSSendUnfreeze (wh->dpy, wh->cxid);
767
ContextXID XDPSXIDFromContext (Pdpy, ctxt)
771
XDPSPrivContext xwh = (XDPSPrivContext) (((DPSPrivContext) ctxt)->wh);
773
if (xwh == NIL || xwh->cxid == 0)
786
SpaceXID XDPSXIDFromSpace (Pdpy, space)
790
DPSPrivSpace ss = (DPSPrivSpace) space;
791
XDPSPrivContext xwh = (XDPSPrivContext) ss->wh;
793
if (xwh != NIL && xwh->dpy != NULL)
806
DPSContext XDPSContextFromXID (dpy, cxid)
813
for (ss = spaces; ss != NIL; ss = ss->next)
814
if (((XDPSPrivContext) ss->wh)->dpy == dpy)
815
for (c = ss->firstContext; c != NIL; c = c->next)
816
if (((XDPSPrivContext) c->wh)->cxid == cxid)
817
return ((DPSContext) c);
823
DPSSpace XDPSSpaceFromXID (dpy, sxid)
829
for (ss = spaces; ss != NIL; ss = ss->next)
830
if ((SpaceXID)ss->sid == sxid && ((XDPSPrivContext) ss->wh)->dpy == dpy)
831
return ((DPSSpace) ss);
837
XDPSStatusProc XDPSRegisterStatusProc (ctxt, statusProc)
839
XDPSStatusProc statusProc;
841
DPSPrivContext c = (DPSPrivContext) ctxt;
842
XDPSStatusProc old = c->statusProc;
844
if (c->wh != NIL) c->statusProc = statusProc;
849
XDPSReadyProc XDPSRegisterReadyProc (ctxt, readyProc)
851
XDPSReadyProc readyProc;
853
DPSPrivContext c = (DPSPrivContext) ctxt;
854
XDPSReadyProc old = c->readyProc;
856
if (c->wh != NIL) c->readyProc = readyProc;
861
void XDPSSetStatusMask(ctxt, enableMask, disableMask, nextMask)
863
unsigned long enableMask, disableMask, nextMask;
865
XDPSPrivContext xwh = (XDPSPrivContext) (((DPSPrivContext) ctxt)->wh);
867
if (xwh != NIL && xwh->cxid != 0)
868
XDPSLSetStatusMask(xwh->dpy, xwh->cxid, enableMask, disableMask, nextMask);
872
int XDPSGetContextStatus(ctxt)
875
DPSPrivContext c = (DPSPrivContext) ctxt;
876
XDPSPrivContext xwh = (XDPSPrivContext) c->wh;
878
if (xwh != NIL && xwh->cxid != 0)
879
return (XDPSLGetStatus(xwh->dpy, xwh->cxid));
884
void XDPSNotifyWhenReady(ctxt, i0, i1, i2, i3)
888
DPSPrivContext c = (DPSPrivContext) ctxt;
889
XDPSPrivContext xwh = (XDPSPrivContext) c->wh;
897
XDPSLNotifyWhenReady(xwh->dpy, xwh->cxid, i);
900
void XDPSStatusEventHandler (e)
903
DPSPrivContext c = (DPSPrivContext) XDPSContextFromXID(e->display, e->cxid);
908
c->statusFromEvent = e->status;
909
if (e->status == PSZOMBIE)
912
if (c->resultTable != NIL) /* Currently waiting for results */
913
XDPSQuitBlocking = true;
916
if (c->statusProc != NIL)
917
(*(c->statusProc)) ((DPSContext) c, e->status);
920
void XDPSReadyEventHandler (e)
923
DPSPrivContext c = (DPSPrivContext) XDPSContextFromXID(e->display, e->cxid);
928
if (c->readyProc != NIL)
929
(*(c->readyProc)) ((DPSContext) c, e->val);
940
if (DPSInitialize() != 0) return;
941
ep = DPSGetCurrentErrorBackstop();
942
if (ep == NULL) ep = DPSDefaultErrorProc;
943
(*ep)(ctxt, dps_err_warning, (long unsigned int)msg, 0);
952
if (DPSInitialize() != 0) return;
953
ep = DPSGetCurrentErrorBackstop();
954
if (ep == NULL) ep = DPSDefaultErrorProc;
955
(*ep)(ctxt, dps_err_fatal, (long unsigned int)msg, 0);
958
void DPSCantHappen(void)
960
static int locked = 0;
961
char *msg = "assertion failure or DPSCantHappen";
962
if (locked > 0) abort();
964
DPSFatalProc((DPSContext)NULL, msg);
965
/* Fatal proc shouldn't return, but client can override and do anything. */
970
/* Procedures for delayed event dispatching */
972
DPSEventDelivery XDPSSetEventDelivery(
974
DPSEventDelivery newMode)
976
Bool old = XDPSLGetPassEventsFlag(dpy);
979
case dps_event_pass_through:
980
XDPSLSetPassEventsFlag(dpy, True);
982
case dps_event_internal_dispatch:
983
XDPSLSetPassEventsFlag(dpy, False);
989
if (old) return dps_event_pass_through;
990
else return dps_event_internal_dispatch;
993
Bool XDPSIsStatusEvent(
998
Display *d = event->xany.display;
999
XExtCodes *c = XDPSLGetCodes(d);
1000
XDPSLStatusEvent *se = (XDPSLStatusEvent *) event;
1002
if (c == NULL) return False; /* Not inited on that display;
1005
if (!c->first_event) /* Check CSDPS first */
1007
if (XDPSLGetCSDPSFakeEventType(d, event) == csdps_status)
1008
{ /* Check CSDPS first */
1009
XDPSLGetCSDPSStatus(d, event, (void **)ctxt, status);
1016
if (event->type != c->first_event + PSEVENTSTATUS) return False;
1018
if (ctxt != NULL) *ctxt = XDPSContextFromXID(d, se->cxid);
1019
if (status != NULL) *status = se->status;
1023
Bool XDPSIsOutputEvent(
1026
Display *d = event->xany.display;
1027
XExtCodes *c = XDPSLGetCodes(d);
1028
CSDPSFakeEventTypes t;
1030
if (c == NULL) return False; /* Not inited on that display;
1033
if (!c->first_event) /* Check CSDPS first */
1035
if ((t = XDPSLGetCSDPSFakeEventType(d, event)) == csdps_output
1036
|| t == csdps_output_with_len)
1042
return event->type == c->first_event + PSEVENTOUTPUT;
1045
Bool XDPSIsDPSEvent(
1048
Display *d = event->xany.display;
1049
XExtCodes *c = XDPSLGetCodes(d);
1051
if (c == NULL) return False; /* Not inited on that display;
1054
if (!c->first_event) /* Check CSDPS first */
1056
if (XDPSLGetCSDPSFakeEventType(d, event) != csdps_not)
1062
return event->type >= c->first_event &&
1063
event->type < c->first_event + NPSEVENTS;
1066
Bool XDPSDispatchEvent(
1069
Display *d = event->xany.display;
1070
XExtCodes *c = XDPSLGetCodes(d);
1071
CSDPSFakeEventTypes t;
1073
if (c == NULL) return False; /* Not inited on that display;
1076
if (!c->first_event) /* Check CSDPS first */
1078
if ((t = XDPSLGetCSDPSFakeEventType(d, event)) != csdps_not)
1079
return(XDPSLDispatchCSDPSFakeEvent(d, event, t));
1084
if (event->type == c->first_event + PSEVENTSTATUS) {
1085
XDPSLCallStatusEventHandler(d, event);
1086
} else if (event->type == c->first_event + PSEVENTOUTPUT) {
1087
XDPSLCallOutputEventHandler(d, event);
1088
} else if (event->type == c->first_event + PSEVENTREADY) {
1089
XDPSLCallReadyEventHandler(d, event);
1090
} else return False;
1094
/* L2-DPS/PROTO 9 addition */
1095
Bool XDPSIsReadyEvent(
1100
Display *d = event->xany.display;
1101
XExtCodes *c = XDPSLGetCodes(d);
1102
XDPSLReadyEvent *re = (XDPSLReadyEvent *) event;
1104
if (c == NULL) return False; /* Not inited on that display;
1107
if (!c->first_event) /* Check CSDPS first */
1109
if (XDPSLGetCSDPSFakeEventType(d, event) == csdps_ready)
1111
XDPSLGetCSDPSReady(d, event, (void **)ctxt, val);
1118
if (event->type != c->first_event + PSEVENTREADY) return False;
1120
if (ctxt != NULL) *ctxt = XDPSContextFromXID(d, re->cxid);
1122
val[0] = re->val[0];
1123
val[1] = re->val[1];
1124
val[2] = re->val[2];
1125
val[4] = re->val[3];
1130
int XDPSGetProtocolVersion(
1133
return XDPSLGetVersion(dpy);