#define NEED_REPLIES
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <X11/extensions/Printstr.h>
#include <X11/Xlibint.h>
#include "XpExtUtil.h"
#define _XpPadOut(len) (((len) + 3) & ~3)
#include <stdio.h>
#include <sys/stat.h>
char *
XpGetAttributes (
Display *dpy,
XPContext print_context,
XPAttributes type
)
{
char *buf;
xPrintGetAttributesReq *req;
xPrintGetAttributesReply rep;
XExtDisplayInfo *info = (XExtDisplayInfo *) xp_find_display (dpy);
if (XpCheckExtInit(dpy, XP_DONT_CHECK) == -1)
return( (char *) NULL );
LockDisplay (dpy);
GetReq(PrintGetAttributes,req);
req->reqType = info->codes->major_opcode;
req->printReqType = X_PrintGetAttributes;
req->printContext = print_context;
req->type = type;
if (! _XReply (dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return( (char *) NULL );
}
buf = Xmalloc( (unsigned) rep.stringLen + 1 );
if (!buf) {
UnlockDisplay(dpy);
SyncHandle();
return( (char *) NULL );
}
_XReadPad (dpy, (char *) buf, (long) rep.stringLen );
buf[rep.stringLen] = 0;
UnlockDisplay(dpy);
SyncHandle();
return( buf );
}
char *
XpGetOneAttribute (
Display *dpy,
XPContext print_context,
XPAttributes type,
char *attribute_name
)
{
char *buf;
xPrintGetOneAttributeReq *req;
xPrintGetOneAttributeReply rep;
XExtDisplayInfo *info = (XExtDisplayInfo *) xp_find_display (dpy);
if (XpCheckExtInit(dpy, XP_DONT_CHECK) == -1)
return( (char *) NULL );
LockDisplay (dpy);
GetReq(PrintGetOneAttribute,req);
req->reqType = info->codes->major_opcode;
req->printReqType = X_PrintGetOneAttribute;
req->type = type;
req->printContext = print_context;
req->nameLen = strlen( attribute_name );
req->length += _XpPadOut(req->nameLen) >> 2 ;
Data( dpy, (char *) attribute_name, req->nameLen );
if (! _XReply (dpy, (xReply *) &rep, 0, xFalse)) {
UnlockDisplay(dpy);
SyncHandle();
return( (char *) NULL );
}
buf = Xmalloc( (unsigned) rep.valueLen + 1 );
if (!buf) {
UnlockDisplay(dpy);
SyncHandle();
return( (char *) NULL );
}
buf[rep.valueLen] = 0;
_XReadPad (dpy, (char *) buf, (long) rep.valueLen );
buf[rep.valueLen] = 0;
UnlockDisplay(dpy);
SyncHandle();
return( buf );
}
void
XpSetAttributes (
Display *dpy,
XPContext print_context,
XPAttributes type,
char *pool,
XPAttrReplacement replacement_rule
)
{
xPrintSetAttributesReq *req;
XExtDisplayInfo *info = (XExtDisplayInfo *) xp_find_display (dpy);
if (XpCheckExtInit(dpy, XP_DONT_CHECK) == -1)
return;
LockDisplay (dpy);
GetReq(PrintSetAttributes,req);
req->reqType = info->codes->major_opcode;
req->printReqType = X_PrintSetAttributes;
req->printContext = print_context;
req->type = type;
req->rule = replacement_rule;
req->stringLen = (CARD32) strlen( (char *) pool );
req->length += _XpPadOut(req->stringLen) >> 2 ;
Data( dpy, (char *) pool, req->stringLen );
UnlockDisplay(dpy);
SyncHandle();
return;
}