#if defined(sun) && defined(i386) && defined(SVR4) && !defined(__EXTENSIONS__)
#define __EXTENSIONS__
#endif
#include <X11/extensions/Printstr.h>
#include <X11/Xlibint.h>
#include <X11/Xos.h>
#include "XpExtUtil.h"
#include <limits.h>
#ifndef WIN32
#define X_INCLUDE_PWD_H
#define XOS_USE_XLIB_LOCKING
#include <X11/Xos_r.h>
#endif
#include <limits.h>
typedef struct {
int event_base_return;
XPContext context;
} _XpDiscardJobRec;
static Bool _XpDiscardJob(Display *dpy, XEvent *event, XPointer arg)
{
_XpDiscardJobRec *disrec = (_XpDiscardJobRec *) arg;
if (event->type != disrec->event_base_return + XPPrintNotify)
return False;
if (disrec->context != ((XPPrintEvent *) event)->context)
return False;
if ((((XPPrintEvent *) event)->detail == XPEndJobNotify) ||
(((XPPrintEvent *) event)->detail == XPEndDocNotify) ||
(((XPPrintEvent *) event)->detail == XPEndPageNotify)) {
return False;
}
return True;
}
void
XpStartJob (
Display *dpy,
XPSaveData save_data
)
{
xPrintStartJobReq *req;
XExtDisplayInfo *info = (XExtDisplayInfo *) xp_find_display (dpy);
XPContext context;
{
char *joa;
char *PwName;
#ifndef WIN32
#ifdef X_NEEDS_PWPARAMS
_Xgetpwparams pwparams;
#endif
struct passwd *pw;
pw = _XGetpwuid(getuid(),pwparams);
if (pw && (PwName = pw->pw_name)) {
#else
if ((PwName = getenv("USERNAME"))) {
#endif
joa = (char *) Xmalloc( strlen( PwName ) + 20 );
sprintf( joa, "*job-owner: %s", PwName );
context = XpGetContext( dpy );
XpSetAttributes( dpy, context, XPJobAttr, joa, XPAttrMerge );
Xfree( joa );
}
}
if (XpCheckExtInit(dpy, XP_INITIAL_RELEASE) == -1)
return;
LockDisplay (dpy);
GetReq(PrintStartJob,req);
req->reqType = info->codes->major_opcode;
req->printReqType = X_PrintStartJob;
req->saveData = (CARD8) save_data;
UnlockDisplay (dpy);
SyncHandle ();
}
void
XpEndJob (
Display *dpy
)
{
xPrintEndJobReq *req;
XExtDisplayInfo *info = (XExtDisplayInfo *) xp_find_display (dpy);
if (XpCheckExtInit(dpy, XP_INITIAL_RELEASE) == -1)
return;
LockDisplay (dpy);
GetReq(PrintEndJob,req);
req->reqType = info->codes->major_opcode;
req->printReqType = X_PrintEndJob;
req->cancel = False;
UnlockDisplay (dpy);
SyncHandle ();
}
void
XpCancelJob (
Display *dpy,
Bool discard
)
{
xPrintEndJobReq *req;
XExtDisplayInfo *info = (XExtDisplayInfo *) xp_find_display (dpy);
_XpDiscardJobRec disrec;
XEvent event;
if (XpCheckExtInit(dpy, XP_INITIAL_RELEASE) == -1)
return;
LockDisplay (dpy);
GetReq(PrintEndJob,req);
req->reqType = info->codes->major_opcode;
req->printReqType = X_PrintEndJob;
req->cancel = True;
UnlockDisplay (dpy);
SyncHandle ();
if (discard) {
disrec.event_base_return = info->codes->first_event;
disrec.context = XpGetContext(dpy);
while (XCheckIfEvent(dpy, &event, _XpDiscardJob, (XPointer) &disrec))
{
}
}
}