824N/A/*
824N/A * dpsclient.c -- Implementation of the Display PostScript Client Library.
824N/A *
824N/A * (c) Copyright 1988-1994 Adobe Systems Incorporated.
824N/A * All rights reserved.
824N/A *
824N/A * Permission to use, copy, modify, distribute, and sublicense this software
824N/A * and its documentation for any purpose and without fee is hereby granted,
824N/A * provided that the above copyright notices appear in all copies and that
824N/A * both those copyright notices and this permission notice appear in
824N/A * supporting documentation and that the name of Adobe Systems Incorporated
824N/A * not be used in advertising or publicity pertaining to distribution of the
824N/A * software without specific, written prior permission. No trademark license
824N/A * to use the Adobe trademarks is hereby granted. If the Adobe trademark
824N/A * "Display PostScript"(tm) is used to describe this software, its
824N/A * functionality or for any other purpose, such use shall be limited to a
824N/A * statement that this software works in conjunction with the Display
824N/A * PostScript system. Proper trademark attribution to reflect Adobe's
824N/A * ownership of the trademark shall be given whenever any such reference to
824N/A * the Display PostScript system is made.
824N/A *
824N/A * ADOBE MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THE SOFTWARE FOR
824N/A * ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
824N/A * ADOBE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
824N/A * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
824N/A * NON- INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL ADOBE BE LIABLE
824N/A * TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL
824N/A * DAMAGES OR ANY DAMAGES WHATSOEVER WHETHER IN AN ACTION OF CONTRACT,
824N/A * NEGLIGENCE, STRICT LIABILITY OR ANY OTHER ACTION ARISING OUT OF OR IN
824N/A * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ADOBE WILL NOT
824N/A * PROVIDE ANY TRAINING OR OTHER SUPPORT FOR THE SOFTWARE.
824N/A *
824N/A * Adobe, PostScript, and Display PostScript are trademarks of Adobe Systems
824N/A * Incorporated which may be registered in certain jurisdictions
824N/A *
824N/A * Author: Adobe Systems Incorporated
824N/A */
824N/A/* $XFree86$ */
824N/A
824N/A#include <stdlib.h>
824N/A#include <stdio.h>
824N/A#include <ctype.h>
824N/A#include <string.h>
824N/A
824N/A#include "dpsXpriv.h"
824N/A#include "DPS/dpsclient.h"
824N/A#include "dpsprivate.h"
824N/A#include "dpsdict.h"
824N/A#include "DPS/dpsexcept.h"
824N/A#include "dpsassert.h"
824N/A
824N/A#ifdef XDPS
824N/A#include "dpsXint.h"
824N/A#endif /* XDPS */
824N/A
824N/A#if defined(SVR4) || defined(SYSV) || defined(SystemV)
824N/A#define os_bcopy(f,t,c) memcpy(t,f,c)
824N/A#else
824N/A#define os_bcopy(f,t,c) bcopy(f,t,c)
824N/A#endif
824N/A
824N/A#if !IEEEFLOAT
824N/Aextern void IEEEHighToNative(/* FloatRep *from, real *to */);
824N/A/* Converts from IEEE high-byte-first real to native real. */
824N/A
824N/Aextern void NativeToIEEEHigh(/* real *from, FloatRep *to */);
824N/A/* Converts from native real to IEEE high-byte-first real. */
824N/A
824N/Aextern void IEEELowToNative(/* FloatRep *from, real *to */);
824N/A/* Converts from IEEE low-byte-first real to native real. */
824N/A
824N/Aextern void NativeToIEEELow(/* real *from, FloatRep *to */);
824N/A/* Converts from native real to IEEE low-byte-first real. */
824N/A#endif /* !IEEEFLOAT */
824N/A
824N/Atypedef union { /* 32 bit number representations */
824N/A unsigned int u;
824N/A int i;
824N/A float f;
824N/A unsigned char bytes[4];
824N/A /* raw bytes, in whatever order they appear in memory */
824N/A } Swap32Rec;
824N/A
824N/Atypedef union { /* 16 bit number representations */
824N/A unsigned short u;
824N/A short i;
824N/A unsigned char bytes[2];
824N/A } Swap16Rec;
824N/A
824N/A#if SWAPBITS
824N/A#define Copy4SrcLo(src, dst)\
824N/A (((Swap32Rec *) dst)->bytes[0] = ((Swap32Rec *) src)->bytes[0], \
824N/A ((Swap32Rec *) dst)->bytes[1] = ((Swap32Rec *) src)->bytes[1], \
824N/A ((Swap32Rec *) dst)->bytes[2] = ((Swap32Rec *) src)->bytes[2], \
824N/A ((Swap32Rec *) dst)->bytes[3] = ((Swap32Rec *) src)->bytes[3] )
824N/A#define Copy4SrcHi(src, dst)\
824N/A (((Swap32Rec *) dst)->bytes[0] = ((Swap32Rec *) src)->bytes[3], \
824N/A ((Swap32Rec *) dst)->bytes[1] = ((Swap32Rec *) src)->bytes[2], \
824N/A ((Swap32Rec *) dst)->bytes[2] = ((Swap32Rec *) src)->bytes[1], \
824N/A ((Swap32Rec *) dst)->bytes[3] = ((Swap32Rec *) src)->bytes[0] )
824N/A#define Copy2SrcLo(src, dst)\
824N/A (((Swap16Rec *) dst)->bytes[0] = ((Swap16Rec *) src)->bytes[0], \
824N/A ((Swap16Rec *) dst)->bytes[1] = ((Swap16Rec *) src)->bytes[1] )
824N/A#define Copy2SrcHi(src, dst)\
824N/A (((Swap16Rec *) dst)->bytes[0] = ((Swap16Rec *) src)->bytes[1], \
824N/A ((Swap16Rec *) dst)->bytes[1] = ((Swap16Rec *) src)->bytes[0] )
824N/A#else /* SWAPBITS */
824N/A#define Copy4SrcHi(src, dst)\
824N/A (((Swap32Rec *) dst)->bytes[0] = ((Swap32Rec *) src)->bytes[0], \
824N/A ((Swap32Rec *) dst)->bytes[1] = ((Swap32Rec *) src)->bytes[1], \
824N/A ((Swap32Rec *) dst)->bytes[2] = ((Swap32Rec *) src)->bytes[2], \
824N/A ((Swap32Rec *) dst)->bytes[3] = ((Swap32Rec *) src)->bytes[3] )
824N/A#define Copy4SrcLo(src, dst)\
824N/A (((Swap32Rec *) dst)->bytes[0] = ((Swap32Rec *) src)->bytes[3], \
824N/A ((Swap32Rec *) dst)->bytes[1] = ((Swap32Rec *) src)->bytes[2], \
824N/A ((Swap32Rec *) dst)->bytes[2] = ((Swap32Rec *) src)->bytes[1], \
824N/A ((Swap32Rec *) dst)->bytes[3] = ((Swap32Rec *) src)->bytes[0] )
824N/A#define Copy2SrcHi(src, dst)\
824N/A (((Swap16Rec *) dst)->bytes[0] = ((Swap16Rec *) src)->bytes[0], \
824N/A ((Swap16Rec *) dst)->bytes[1] = ((Swap16Rec *) src)->bytes[1] )
824N/A#define Copy2SrcLo(src, dst)\
824N/A (((Swap16Rec *) dst)->bytes[0] = ((Swap16Rec *) src)->bytes[1], \
824N/A ((Swap16Rec *) dst)->bytes[1] = ((Swap16Rec *) src)->bytes[0] )
824N/A#endif /* SWAPBITS */
824N/A
824N/A
824N/A#define DPS_ERR_TAG 250
824N/A
824N/A#define CONTEXTBUFFERSIZE 256
824N/A#define MAXQUEUEDBUFFERS 5
824N/A
824N/ADPSContext DPSGlobalContext;
824N/A
824N/AGlobals DPSglobals = NULL;
824N/A
824N/Achar *DPScalloc(integer e, integer n)
824N/A{
824N/A char *p;
824N/A while (!(p = (char *)calloc(e, n))) {
824N/A DPSOutOfMemory();
824N/A }
824N/A return p;
824N/A}
824N/A
824N/A
824N/A
824N/Avoid DPSSafeSetLastNameIndex(DPSContext ctxt)
824N/A{
824N/A /* we're about to call the error handler, so roll back the
824N/A lastNameIndex to the last known valid index */
824N/A DPSCheckInitClientGlobals();
824N/A if (ctxt != dummyCtx && ctxt->space != NIL)
824N/A ((DPSPrivContext)ctxt)->lastNameIndex = ((DPSPrivSpace)(ctxt->space))->lastNameIndex;
824N/A}
824N/A
824N/Avoid DPSCheckInitClientGlobals(void)
824N/A{
824N/A if (!DPSglobals) {
824N/A DPSglobals = (Globals)DPScalloc(sizeof(GlobalsRec), 1);
824N/A globLastNameIndex = -1;
824N/A }
824N/A}
824N/A
824N/A/**************************************************************/
824N/A/* Procedures that support the DPSCreateContext context procs */
824N/A/**************************************************************/
824N/A
824N/A/* ARGSUSED */
824N/Astatic void ReleaseInput(
824N/A char *unused, char *buffer)
824N/A{
824N/A ContextBuffer cb = (ContextBuffer)buffer;
824N/A if (cb == NIL) return;
824N/A cb->next = contextBuffers;
824N/A contextBuffers = cb;
824N/A queuedBuffers--;
824N/A}
824N/A
824N/A/* ARGSUSED */
824N/Astatic void StuffResultVal(
824N/A DPSContext ctxt,
824N/A DPSResults result,
824N/A integer tag,
824N/A DPSBinObj obj)
824N/A{
824N/A
824N/A integer type = obj->attributedType & ~DPS_EXEC;
824N/A integer nObjs = 1;
824N/A
824N/A /* check if array */
824N/A if (type == DPS_ARRAY) {
824N/A nObjs = obj->length;
824N/A if (nObjs < 1) return;
824N/A if (result->count == -1 && nObjs != 1) {
824N/A DPSSafeSetLastNameIndex(ctxt);
824N/A if (ctxt->errorProc != NIL)
824N/A (*ctxt->errorProc)(ctxt, dps_err_resultTypeCheck, (long unsigned)obj, 0);
824N/A return;
824N/A }
824N/A obj = (DPSBinObj) ((char *)obj + obj->val.arrayVal);
824N/A type = obj->attributedType & ~DPS_EXEC;
824N/A }
824N/A
824N/A do {
824N/A integer bump = 0;
824N/A if (result->count == 0) return;
824N/A switch (result->type) {
824N/A case dps_tBoolean:
824N/A if (type == DPS_BOOL) {
824N/A int *b = (int *) result->value;
824N/A *b = (int) obj->val.booleanVal;
824N/A bump = sizeof(int);
824N/A }
824N/A break;
824N/A case dps_tFloat: {
824N/A float *f = (float *) result->value;
824N/A if (type == DPS_REAL) {
824N/A *f = obj->val.realVal;
824N/A bump = sizeof(float);
824N/A }
824N/A else if (type == DPS_INT) {
824N/A *f = (float) obj->val.integerVal;
824N/A bump = sizeof(float);
824N/A }
824N/A break;
824N/A }
824N/A case dps_tDouble: {
824N/A double *d = (double *) result->value;
824N/A if (type == DPS_REAL) {
824N/A *d = (double) obj->val.realVal;
824N/A bump = sizeof(double);
824N/A }
824N/A else if (type == DPS_INT) {
824N/A *d = (double) obj->val.integerVal;
824N/A bump = sizeof(double);
824N/A }
824N/A break;
824N/A }
824N/A case dps_tShort:
824N/A if (type == DPS_INT) {
824N/A short *s = (short *) result->value;
824N/A *s = (short) obj->val.integerVal;
824N/A bump = sizeof(short);
824N/A }
824N/A break;
824N/A case dps_tUShort:
824N/A if (type == DPS_INT) {
824N/A unsigned short *us = (unsigned short *) result->value;
824N/A *us = (unsigned short) obj->val.integerVal;
824N/A bump = sizeof(unsigned short);
824N/A }
824N/A break;
824N/A case dps_tInt:
824N/A if (type == DPS_INT) {
824N/A int *i = (int *) result->value;
824N/A *i = (int) obj->val.integerVal;
824N/A bump = sizeof(int);
824N/A }
824N/A break;
824N/A case dps_tUInt:
824N/A if (type == DPS_INT) {
824N/A unsigned int *ui = (unsigned int *) result->value;
824N/A *ui = (unsigned int) obj->val.integerVal;
824N/A bump = sizeof(unsigned int);
824N/A }
824N/A break;
824N/A case dps_tLong:
824N/A if (type == DPS_INT) {
824N/A long int *li = (long int *) result->value;
824N/A *li = obj->val.integerVal;
824N/A bump = sizeof(long int);
824N/A }
824N/A break;
824N/A case dps_tULong:
824N/A if (type == DPS_INT) {
824N/A unsigned long *u = (unsigned long *) result->value;
824N/A *u = (unsigned long) obj->val.integerVal;
824N/A bump = sizeof(unsigned long);
824N/A }
824N/A break;
824N/A case dps_tChar:
824N/A case dps_tUChar:
824N/A if (nObjs != 1) {
824N/A DPSSafeSetLastNameIndex(ctxt);
824N/A if (ctxt->errorProc != NIL)
824N/A (*ctxt->errorProc)(ctxt, dps_err_resultTypeCheck, (long unsigned)obj, 0);
824N/A }
824N/A else if (type == DPS_STRING) {
824N/A if (result->count == -1) {
824N/A /* char * result, copy first, ignore subsequent, null terminate */
824N/A os_bcopy(((integer)(obj->val.stringVal)) + (char *)obj,
824N/A result->value, obj->length);
824N/A (result->value)[obj->length] = '\0';
824N/A result->count = 0;
824N/A }
824N/A else {
824N/A unsigned slen;
824N/A if (result->count >= (int) obj->length) {
824N/A /* copy entire string into char array */
824N/A slen = obj->length;
824N/A }
824N/A else if (result->count > 0) {
824N/A /* copy partial string into char array */
824N/A slen = result->count;
824N/A }
824N/A else return; /* ignore string result, no room left */
824N/A os_bcopy(((integer)(obj->val.stringVal)) + (char *)obj,
824N/A result->value, slen);
824N/A result->value += slen;
824N/A result->count -= slen;
824N/A }
824N/A return;
824N/A }
824N/A break;
824N/A
824N/A default:
824N/A DPSSafeSetLastNameIndex(ctxt);
824N/A if (ctxt->errorProc != NIL)
824N/A (*ctxt->errorProc)(ctxt, dps_err_resultTypeCheck, (long unsigned)obj, 0);
824N/A } /* switch (result->type) */
824N/A
824N/A if (bump == 0) {
824N/A DPSSafeSetLastNameIndex(ctxt);
824N/A if (ctxt->errorProc != NIL)
824N/A (*ctxt->errorProc)(ctxt, dps_err_resultTypeCheck, (long unsigned)obj, 0);
824N/A return;
824N/A }
824N/A if (result->count != -1) {
824N/A result->count--;
824N/A result->value += bump;
824N/A }
824N/A obj += 1;
824N/A nObjs--;
824N/A } while (nObjs > 0); /* do */
824N/A
824N/A} /* StuffResultVal */
824N/A
824N/A
824N/Astatic void NumFormatFromTokenType(
824N/A unsigned char t,
824N/A DPSNumFormat *numFormat)
824N/A{
824N/A switch (t) {
824N/A case DPS_HI_IEEE:
824N/A *numFormat = dps_ieee;
824N/A break;
824N/A case DPS_LO_IEEE:
824N/A *numFormat = dps_ieee;
824N/A break;
824N/A case DPS_HI_NATIVE:
824N/A *numFormat = dps_native;
824N/A break;
824N/A case DPS_LO_NATIVE:
824N/A *numFormat = dps_native;
824N/A break;
824N/A default: DPSCantHappen();
824N/A }
824N/A}
824N/A
824N/A
824N/A#if !IEEEFLOAT
824N/A/* called to deal with results from the server */
824N/Astatic void ConvSeqInPlace(nObjs, currObj, base, tokenType)
824N/A integer nObjs;
824N/A DPSBinObj currObj;
824N/A char *base;
824N/A unsigned char tokenType;
824N/A{
824N/A DPSNumFormat numFormat;
824N/A
824N/A NumFormatFromTokenType(tokenType, &numFormat);
824N/A
824N/A while (nObjs--) {
824N/A unsigned char t = currObj->attributedType & 0x07f;
824N/A integer i;
824N/A switch (t) {
824N/A case DPS_REAL: {
824N/A float f;
824N/A if (numFormat == dps_ieee) {
824N/A if (DPSDefaultByteOrder == dps_hiFirst)
824N/A IEEEHighToNative(&currObj->val.realVal, &f);
824N/A else
824N/A IEEELowToNative(&currObj->val.realVal, &f);
824N/A }
824N/A else break; /* switch */
824N/A currObj->val.realVal = f;
824N/A break;
824N/A }
824N/A case DPS_ARRAY:
824N/A if (currObj->length > 0)
824N/A ConvSeqInPlace(currObj->length, (DPSBinObj)(base + currObj->val.arrayVal), base, tokenType);
824N/A break;
824N/A case DPS_NAME:
824N/A case DPS_STRING:
824N/A break;
824N/A default:;
824N/A } /* end switch */
824N/A ++currObj;
824N/A } /* end while */
824N/A}
824N/A#endif /* !IEEEFLOAT */
824N/A
824N/Aboolean DPSKnownContext(DPSContext ctxt)
824N/A{
824N/A DPSPrivContext cc, c = (DPSPrivContext) ctxt;
824N/A DPSPrivSpace ss;
824N/A for (ss = spaces; ss != NIL; ss = ss->next)
824N/A for (cc = ss->firstContext; cc != NIL; cc = cc->next)
824N/A if (cc == c) return true;
824N/A return false;
824N/A}
824N/A
824N/Aboolean DPSKnownSpace(DPSSpace space)
824N/A{
824N/A DPSPrivSpace ss, s = (DPSPrivSpace) space;
824N/A for (ss = spaces; ss != NIL; ss = ss->next)
824N/A if (ss == s) return true;
824N/A return false;
824N/A}
824N/A
824N/Avoid DPSclientPrintProc (
824N/A DPSContext ctxt,
824N/A char *buf,
824N/A unsigned nch)
824N/A{
824N/A DPSPrivContext cc = (DPSPrivContext) ctxt;
824N/A
824N/A#define DPS_SEQ_MIN 2
824N/A
824N/A DPSCheckInitClientGlobals();
824N/A if (cc == NIL) cc = (DPSPrivContext)dummyCtx;
824N/A if (cc == NIL) return;
824N/A
824N/A if (nch == 0) { /* this is an EOF */
824N/A DPSAssertWarn(buf == NIL, cc, "non-nil output buffer with 0 length");
824N/A cc->eofReceived = true;
824N/A if (cc->objBuf) {
824N/A /* we were buffering; drop buffered chars on the floor */
824N/A free(cc->objBuf);
824N/A cc->objBuf = NIL;
824N/A cc->nObjBufChars = 0;
824N/A }
824N/A }
824N/A while (nch > 0) {
824N/A char *oldBuf = NIL;
824N/A unsigned oldNch = 0;
824N/A unsigned n;
824N/A if (cc->objBuf) { /* we're buffering */
824N/A unsigned long int m;
824N/A char *b = cc->objBuf + cc->nObjBufChars;
824N/A integer minSize;
824N/A while (cc->nObjBufChars < DPS_SEQ_MIN) {
824N/A if (nch == 0) return;
824N/A *b++ = *buf++;
824N/A ++cc->nObjBufChars;
824N/A --nch;
824N/A }
824N/A b = cc->objBuf;
824N/A minSize = (*(b+1) == 0) ? DPS_EXT_HEADER_SIZE : DPS_HEADER_SIZE;
824N/A if (cc->nObjBufChars < minSize) {
824N/A if (nch + cc->nObjBufChars < (unsigned) minSize) {
824N/A os_bcopy(buf, b + cc->nObjBufChars, nch);
824N/A cc->nObjBufChars += nch;
824N/A return;
824N/A }
824N/A else {
824N/A os_bcopy(buf, b + cc->nObjBufChars, minSize - cc->nObjBufChars);
824N/A buf += minSize - cc->nObjBufChars;
824N/A nch -= minSize - cc->nObjBufChars;
824N/A cc->nObjBufChars = minSize;
824N/A }
824N/A }
824N/A
824N/A if (minSize == DPS_HEADER_SIZE) {
824N/A unsigned short *sizeP = (unsigned short *)(cc->objBuf+2);
824N/A m = *sizeP;
824N/A }
824N/A else {
824N/A unsigned long *extSizeP = (unsigned long *)(cc->objBuf+4);
824N/A m = *extSizeP;
824N/A }
824N/A
824N/A /* here with m = BOS total length in bytes, b = cc->objBuf */
824N/A cc->objBuf = (char *)realloc(b, m);
824N/A
824N/A if (nch + cc->nObjBufChars < m) {
824N/A os_bcopy(buf, cc->objBuf + cc->nObjBufChars, nch);
824N/A cc->nObjBufChars += nch;
824N/A return;
824N/A }
824N/A else {
824N/A os_bcopy(buf, cc->objBuf + cc->nObjBufChars, m - cc->nObjBufChars);
824N/A buf += m - cc->nObjBufChars;
824N/A nch -= m - cc->nObjBufChars;
824N/A cc->nObjBufChars = m;
824N/A }
824N/A /* we're here only if cc->objBuf contains a complete BOS */
824N/A oldBuf = buf;
824N/A oldNch = nch;
824N/A buf = cc->objBuf;
824N/A nch = cc->nObjBufChars;
824N/A cc->objBuf = NIL;
824N/A cc->nObjBufChars = 0;
824N/A } /* if we're buffering */
824N/A
824N/A /* dispose of any plain text. If no binary conversion, all output
824N/A is plain text */
824N/A if (cc->contextFlags & DPS_FLAG_NO_BINARY_CONVERSION) n = nch;
824N/A else {
824N/A for (n = 0; n < nch &&
824N/A ((unsigned char) buf[n] < 128 || (unsigned char) buf[n] > 159); n++);
824N/A }
824N/A if ((n > 0) && (cc->textProc != NIL)) {
824N/A (*cc->textProc)((DPSContext)cc, buf, n);
824N/A }
824N/A buf += n;
824N/A nch -= n;
824N/A
824N/A if (nch != 0) {
824N/A /* here with the next binary object sequence from a server */
824N/A DPSExtendedBinObjSeq bos;
824N/A DPSExtendedBinObjSeqRec bosRec;
824N/A DPSBinObj firstObj;
824N/A unsigned t;
824N/A unsigned long int m;
824N/A unsigned minSize;
824N/A
824N/A if (nch < DPS_SEQ_MIN) {
824N/A /* gotta buffer it */
824N/A DPSAssertWarn(nch == 1 && !oldBuf, cc, "illegal binary output from context (oldBuf)");
824N/A cc->objBuf = (char *)DPScalloc(DPS_EXT_HEADER_SIZE, 1);
824N/A cc->nObjBufChars = nch;
824N/A *cc->objBuf = *buf;
824N/A return;
824N/A }
824N/A /* check for quadbyte alignment */
824N/A if ((long int)buf & (MIN_POINTER_ALIGN - 1)) {
824N/A /* not aligned, we gotta copy the buffer */
824N/A /* we assert that we can't have an oldBuf if we're not aligned,
824N/A since we only get an oldBuf if we copied to a new buffer,
824N/A and we have already tested nch to be at least DPS_SEQ_MIN */
824N/A DPSAssertWarn(!oldBuf && nch > 1, cc, "return values garbled (oldBuf||nch<DPS_SEQ_MIN");
824N/A /* copy DPS_SEQ_MIN bytes, so we can use existing buffering code */
824N/A cc->objBuf = (char *)DPScalloc(DPS_EXT_HEADER_SIZE, 1);
824N/A cc->nObjBufChars = DPS_SEQ_MIN;
824N/A os_bcopy(buf, cc->objBuf, cc->nObjBufChars);
824N/A buf += DPS_SEQ_MIN;
824N/A nch -= DPS_SEQ_MIN;
824N/A /* now go to top of loop and go through the buffer update code */
824N/A continue;
824N/A }
824N/A bos = (DPSExtendedBinObjSeq) buf;
824N/A t = bos->tokenType;
824N/A minSize = (bos->escape == 0) ? DPS_EXT_HEADER_SIZE : DPS_HEADER_SIZE;
824N/A if (nch < minSize) {
824N/A /* gotta buffer it */
824N/A char *tb;
824N/A DPSAssertWarn(!oldBuf, cc, "return values garbled (oldBuf)");
824N/A tb = cc->objBuf = (char *)DPScalloc(minSize, 1);
824N/A cc->nObjBufChars = nch;
824N/A while (nch--) *tb++ = *buf++;
824N/A return;
824N/A }
824N/A else if (minSize == DPS_HEADER_SIZE) {
824N/A /* this is not an extended BOS */
824N/A DPSBinObjSeq seqHead = (DPSBinObjSeq) buf;
824N/A bos = &bosRec;
824N/A bos->tokenType = t;
824N/A bos->nTopElements = seqHead->nTopElements;
824N/A bos->length = seqHead->length;
824N/A firstObj = &(seqHead->objects[0]);
824N/A }
824N/A else firstObj = &(bos->objects[0]);
824N/A m = bos->length;
824N/A if (nch < m) {
824N/A /* gotta buffer it */
824N/A DPSAssertWarn(!oldBuf, cc, "return values garbled (oldBuf&&nch<m");
824N/A cc->objBuf = (char *)DPScalloc(bos->length, 1);
824N/A cc->nObjBufChars = nch;
824N/A os_bcopy(buf, cc->objBuf, nch);
824N/A return;
824N/A }
824N/A DPSAssertWarn(bos->nTopElements == 1, cc, "illegal binary output detected (bos->nTopElements!=1)");
824N/A#if !IEEEFLOAT
824N/A if (t != DPS_DEF_TOKENTYPE)
824N/A ConvSeqInPlace(1, firstObj, firstObj, bos->tokenType);
824N/A#endif /* !IEEEFLOAT */
824N/A t = firstObj->tag;
824N/A if (t == DPS_ERR_TAG) {
824N/A cc->resultTable = NIL;
824N/A DPSSafeSetLastNameIndex((DPSContext)cc);
824N/A DURING
824N/A if (cc->errorProc != NIL)
824N/A (*cc->errorProc)((DPSContext)cc, dps_err_ps, (unsigned long)buf, m);
824N/A HANDLER
824N/A if (oldBuf) free(buf);
824N/A RERAISE;
824N/A END_HANDLER
824N/A }
824N/A else { /* dispatch this result */
824N/A if (!cc->resultTable || t > cc->resultTableLength) {
824N/A if (cc->chainParent == NIL && cc->errorProc != NIL) {
824N/A DPSSafeSetLastNameIndex((DPSContext)cc);
824N/A (*cc->errorProc)((DPSContext)cc, dps_err_resultTagCheck, (unsigned long)buf, m);
824N/A }
824N/A }
824N/A else if (t == cc->resultTableLength) {
824N/A cc->resultTable = NIL;
824N/A }
824N/A else {
824N/A StuffResultVal((DPSContext)cc, &cc->resultTable[t], t, firstObj);
824N/A }
824N/A }
824N/A if (!oldBuf)
824N/A buf += m;
824N/A nch -= m;
824N/A } /* if (nch != 0) ... the next binary object sequence from a server */
824N/A if (oldBuf) {
824N/A DPSAssertWarn(nch == 0, cc, "some return values/data lost (nch)");
824N/A free(buf);
824N/A buf = oldBuf;
824N/A nch = oldNch;
824N/A }
824N/A } /* while (nch > 0) */
824N/A
824N/A} /* DPSclientPrintProc */
824N/A
824N/A/**************************************/
824N/A/* Context procs for DPSCreateContext */
824N/A/**************************************/
824N/A
824N/A
824N/Astatic void procWaitContext(DPSContext ctxt)
824N/A{
824N/A typedef struct {
824N/A unsigned char tokenType;
824N/A unsigned char topLevelCount;
824N/A unsigned short int nBytes;
824N/A
824N/A DPSBinObjGeneric obj0;
824N/A DPSBinObjGeneric obj1;
824N/A DPSBinObjGeneric obj2;
824N/A DPSBinObjGeneric obj3;
824N/A } DPSQ;
824N/A static DPSQ dpsF = {
824N/A DPS_DEF_TOKENTYPE, 4, sizeof(DPSQ),
824N/A {DPS_LITERAL|DPS_INT, 0, 0, -23}, /* arbitrary int */
824N/A {DPS_LITERAL|DPS_INT, 0, 0, 0}, /* termination tag = 0 */
824N/A {DPS_EXEC|DPS_NAME, 0, DPSSYSNAME, 119}, /* printobject */
824N/A {DPS_EXEC|DPS_NAME, 0, DPSSYSNAME, 70}, /* flush */
824N/A }; /* DPSQ */
824N/A DPSResultsRec DPSR;
824N/A
824N/A if (DPSPrivateCheckWait(ctxt)) return;
824N/A
824N/A ctxt->resultTable = &DPSR; /* must be non-null for handler to work */
824N/A ctxt->resultTableLength = 0; /* same value as termination tag */
824N/A DPSBinObjSeqWrite(ctxt, (char *) &dpsF,sizeof(DPSQ));
824N/A DPSAwaitReturnValues(ctxt);
824N/A}
824N/A
824N/Astatic void procUpdateNameMap(DPSContext ctxt)
824N/A{
824N/A integer i;
824N/A DPSPrivContext c = (DPSPrivContext) ctxt;
824N/A DPSPrivSpace s = (DPSPrivSpace) ctxt->space;
824N/A DPSContext children = ctxt->chainChild;
824N/A
824N/A /* unlink context from chain temporarily, so DPSPrintf can be called */
824N/A if (children != NIL) ctxt->chainChild = NIL;
824N/A DURING
824N/A for (i = s->lastNameIndex+1; i <= globLastNameIndex; i++)
824N/A DPSPrintf(ctxt, "%d /%s defineusername\n", i, userNames[i]);
824N/A HANDLER
824N/A if (children != NIL) ctxt->chainChild = children;
824N/A RERAISE;
824N/A END_HANDLER
824N/A c->lastNameIndex = globLastNameIndex;
824N/A if (children != NIL) {
824N/A /* update any children */
824N/A ctxt->chainChild = children;
824N/A DPSUpdateNameMap(ctxt->chainChild);
824N/A }
824N/A}
824N/A
824N/Astatic void procWriteData(
824N/A DPSContext ctxt,
824N/A char *buf,
824N/A unsigned int count)
824N/A{
824N/A /* safe to call with chain */
824N/A DPSinnerProcWriteData(ctxt, buf, count);
824N/A if (ctxt->chainChild != NIL) DPSWriteData(ctxt->chainChild, buf, count);
824N/A}
824N/A
824N/Astatic void procBinObjSeqWrite(
824N/A DPSContext ctxt,
824N/A char *buf,
824N/A unsigned int count)
824N/A{
824N/A if (((DPSPrivContext)ctxt)->lastNameIndex < globLastNameIndex) DPSUpdateNameMap(ctxt);
824N/A DPSinnerProcWriteData(ctxt, buf, count);
824N/A if (ctxt->chainChild != NIL) DPSBinObjSeqWrite(ctxt->chainChild, buf, count);
824N/A}
824N/A
824N/Astatic void procWriteStringChars(
824N/A DPSContext ctxt,
824N/A char *buf,
824N/A unsigned int count)
824N/A{
824N/A DPSinnerProcWriteData(ctxt, buf, count);
824N/A if (ctxt->chainChild != NIL) DPSWriteStringChars(ctxt->chainChild, buf, count);
824N/A}
824N/A
824N/Astatic void procWritePostScript(
824N/A DPSContext ctxt,
824N/A char *buf,
824N/A unsigned int count)
824N/A{
824N/A DPSinnerProcWriteData(ctxt, buf, count);
824N/A if (ctxt->chainChild != NIL) DPSWritePostScript(ctxt->chainChild, buf, count);
824N/A}
824N/A
824N/Astatic void innerProcWriteNumstring(
824N/A DPSContext ctxt,
824N/A DPSDefinedType type,
824N/A char *data,
824N/A unsigned int size,
824N/A int scale,
824N/A void (*writeProc)(DPSContext, char *, unsigned))
824N/A{
824N/A unsigned char HNumHeader[4];
824N/A register int i;
824N/A#define NBUFSIZE 10
824N/A int ibuf[NBUFSIZE]; /* This needs to be a 32 bit datatype */
824N/A
824N/A HNumHeader[0] = 149;
824N/A switch (type) {
824N/A case dps_tLong:
824N/A HNumHeader[1] = (DPS_DEF_TOKENTYPE % 2) * 128 + scale;
824N/A break;
824N/A
824N/A case dps_tInt:
824N/A HNumHeader[1] = ((sizeof(int) >= 4) ? 0 : 32)
824N/A + ((DPS_DEF_TOKENTYPE % 2) * 128) + scale;
824N/A break;
824N/A
824N/A case dps_tShort:
824N/A HNumHeader[1] = 32 + ((DPS_DEF_TOKENTYPE % 2) * 128) + scale;
824N/A break;
824N/A
824N/A case dps_tFloat:
824N/A HNumHeader[1] = 48 + ((DPS_DEF_TOKENTYPE % 2) * 128)
824N/A + ((DPS_DEF_TOKENTYPE >= 130) ? 1 : 0);
824N/A break;
824N/A
824N/A default:
824N/A break;
824N/A }
824N/A
824N/A HNumHeader[(DPS_DEF_TOKENTYPE % 2) ? 2 : 3] = (unsigned char) size;
824N/A HNumHeader[(DPS_DEF_TOKENTYPE % 2) ? 3 : 2] = (unsigned char) (size >> 8);
824N/A
824N/A (*writeProc)(ctxt, (char *)HNumHeader, 4);
824N/A
824N/A switch (type) {
824N/A case dps_tLong:
824N/A if (sizeof(long) == 4) {
824N/A (*writeProc)(ctxt, (char *) data, size * 4);
824N/A } else {
824N/A while (size > 0) {
824N/A for (i = 0; i < NBUFSIZE && (unsigned) i < size; i++) {
824N/A ibuf[i] = ((long *) data)[i];
824N/A }
824N/A (*writeProc)(ctxt, (char *) ibuf,
824N/A 4 * (size < NBUFSIZE ? size : NBUFSIZE));
824N/A size -= NBUFSIZE;
824N/A }
824N/A }
824N/A break;
824N/A
824N/A case dps_tInt:
824N/A (*writeProc)(ctxt, (char *) data, size * sizeof(int));
824N/A break;
824N/A
824N/A case dps_tShort:
824N/A (*writeProc)(ctxt, (char *) data, size * sizeof(short));
824N/A break;
824N/A
824N/A case dps_tFloat:
824N/A (*writeProc)(ctxt, (char *) data, size * sizeof(float));
824N/A
824N/A default:
824N/A break;
824N/A }
824N/A} /* innerProcWriteNumstring */
824N/A
824N/Astatic void procWriteNumstring(
824N/A DPSContext ctxt,
824N/A DPSDefinedType type,
824N/A char *data,
824N/A unsigned int size,
824N/A int scale)
824N/A{
824N/A innerProcWriteNumstring(ctxt, type, data, size, scale, DPSinnerProcWriteData);
824N/A if (ctxt->chainChild != NIL) DPSWriteNumString(ctxt->chainChild, type, data, size, scale);
824N/A}
824N/A
824N/Astatic void writeTypedObjectArray(
824N/A DPSContext ctxt,
824N/A DPSDefinedType type,
824N/A char *array,
824N/A unsigned int length)
824N/A{
824N/A
824N/A#define DPSMAX_SEQ 10
824N/A unsigned int i;
824N/A DPSPrivContext c = (DPSPrivContext)(ctxt);
824N/A static DPSBinObjGeneric bboolObj[DPSMAX_SEQ] = {
824N/A {DPS_LITERAL | DPS_BOOL, 0,0,0},
824N/A {DPS_LITERAL | DPS_BOOL, 0,0,0},
824N/A {DPS_LITERAL | DPS_BOOL, 0,0,0},
824N/A {DPS_LITERAL | DPS_BOOL, 0,0,0},
824N/A {DPS_LITERAL | DPS_BOOL, 0,0,0},
824N/A {DPS_LITERAL | DPS_BOOL, 0,0,0},
824N/A {DPS_LITERAL | DPS_BOOL, 0,0,0},
824N/A {DPS_LITERAL | DPS_BOOL, 0,0,0},
824N/A {DPS_LITERAL | DPS_BOOL, 0,0,0},
824N/A {DPS_LITERAL | DPS_BOOL, 0,0,0},
824N/A };
824N/A static DPSBinObjReal rrealObj[DPSMAX_SEQ] = {
824N/A {DPS_LITERAL | DPS_REAL, 0,0,0},
824N/A {DPS_LITERAL | DPS_REAL, 0,0,0},
824N/A {DPS_LITERAL | DPS_REAL, 0,0,0},
824N/A {DPS_LITERAL | DPS_REAL, 0,0,0},
824N/A {DPS_LITERAL | DPS_REAL, 0,0,0},
824N/A {DPS_LITERAL | DPS_REAL, 0,0,0},
824N/A {DPS_LITERAL | DPS_REAL, 0,0,0},
824N/A {DPS_LITERAL | DPS_REAL, 0,0,0},
824N/A {DPS_LITERAL | DPS_REAL, 0,0,0},
824N/A {DPS_LITERAL | DPS_REAL, 0,0,0},
824N/A };
824N/A static DPSBinObjGeneric iintObj[DPSMAX_SEQ] = {
824N/A {DPS_LITERAL | DPS_INT, 0,0,0},
824N/A {DPS_LITERAL | DPS_INT, 0,0,0},
824N/A {DPS_LITERAL | DPS_INT, 0,0,0},
824N/A {DPS_LITERAL | DPS_INT, 0,0,0},
824N/A {DPS_LITERAL | DPS_INT, 0,0,0},
824N/A {DPS_LITERAL | DPS_INT, 0,0,0},
824N/A {DPS_LITERAL | DPS_INT, 0,0,0},
824N/A {DPS_LITERAL | DPS_INT, 0,0,0},
824N/A {DPS_LITERAL | DPS_INT, 0,0,0},
824N/A {DPS_LITERAL | DPS_INT, 0,0,0},
824N/A };
824N/A
824N/A if (DPSCheckShared(c)) return;
824N/A
824N/A switch (type) {
824N/A case dps_tChar:
824N/A case dps_tUChar:
824N/A DPSCantHappen();
824N/A break;
824N/A
824N/A case dps_tBoolean: {
824N/A while (length > 0) {
824N/A for (i = 0; i < MIN(DPSMAX_SEQ, length); i++) {
824N/A bboolObj[i].val = *((int *)array);
824N/A array += sizeof(int);
824N/A }
824N/A DPSWritePostScript(ctxt, (char *) bboolObj, sizeof(DPSBinObjGeneric) * i);
824N/A length -= i;
824N/A }
824N/A break;
824N/A }
824N/A
824N/A case dps_tFloat: {
824N/A while (length > 0) {
824N/A for (i = 0; i < MIN(DPSMAX_SEQ, length); i++) {
824N/A rrealObj[i].realVal = *((float *)array);
824N/A array += sizeof(float);
824N/A }
824N/A DPSWritePostScript(ctxt, (char *) rrealObj, sizeof(DPSBinObjReal) * i);
824N/A length -= i;
824N/A }
824N/A break;
824N/A }
824N/A
824N/A case dps_tDouble: {
824N/A while (length > 0) {
824N/A for (i = 0; i < MIN(DPSMAX_SEQ, length); i++) {
824N/A rrealObj[i].realVal = *((double *)array);
824N/A array += sizeof(double);
824N/A }
824N/A DPSWritePostScript(ctxt, (char *) rrealObj, sizeof(DPSBinObjReal) * i);
824N/A length -= i;
824N/A }
824N/A break;
824N/A }
824N/A
824N/A case dps_tShort: {
824N/A while (length > 0) {
824N/A for (i = 0; i < MIN(DPSMAX_SEQ, length); i++) {
824N/A iintObj[i].val = *((short *)array);
824N/A array += sizeof(short);
824N/A }
824N/A DPSWritePostScript(ctxt, (char *) iintObj, sizeof(DPSBinObjGeneric) * i);
824N/A length -= i;
824N/A }
824N/A break;
824N/A }
824N/A
824N/A case dps_tUShort: {
824N/A while (length > 0) {
824N/A for (i = 0; i < MIN(DPSMAX_SEQ, length); i++) {
824N/A iintObj[i].val = *((unsigned short *)array);
824N/A array += sizeof(unsigned short);
824N/A }
824N/A DPSWritePostScript(ctxt, (char *) iintObj, sizeof(DPSBinObjGeneric) * i);
824N/A length -= i;
824N/A }
824N/A break;
824N/A }
824N/A
824N/A case dps_tInt: {
824N/A while (length > 0) {
824N/A for (i = 0; i < MIN(DPSMAX_SEQ, length); i++) {
824N/A iintObj[i].val = *((int *)array);
824N/A array += sizeof(int);
824N/A }
824N/A DPSWritePostScript(ctxt, (char *) iintObj, sizeof(DPSBinObjGeneric) * i);
824N/A length -= i;
824N/A }
824N/A break;
824N/A }
824N/A
824N/A case dps_tUInt: {
824N/A while (length > 0) {
824N/A for (i = 0; i < MIN(DPSMAX_SEQ, length); i++) {
824N/A iintObj[i].val = *((unsigned int *)array);
824N/A array += sizeof(unsigned int);
824N/A }
824N/A DPSWritePostScript(ctxt, (char *) iintObj, sizeof(DPSBinObjGeneric) * i);
824N/A length -= i;
824N/A }
824N/A break;
824N/A }
824N/A
824N/A case dps_tLong: {
824N/A while (length > 0) {
824N/A for (i = 0; i < MIN(DPSMAX_SEQ, length); i++) {
824N/A iintObj[i].val = *((long *)array);
824N/A array += sizeof(long);
824N/A }
824N/A DPSWritePostScript(ctxt, (char *) iintObj, sizeof(DPSBinObjGeneric) * i);
824N/A length -= i;
824N/A }
824N/A break;
824N/A }
824N/A
824N/A case dps_tULong: {
824N/A while (length > 0) {
824N/A for (i = 0; i < MIN(DPSMAX_SEQ, length); i++) {
824N/A iintObj[i].val = *((unsigned long *)array);
824N/A array += sizeof(unsigned long);
824N/A }
824N/A DPSWritePostScript(ctxt, (char *) iintObj, sizeof(DPSBinObjGeneric) * i);
824N/A length -= i;
824N/A }
824N/A break;
824N/A
824N/A
824N/A }
824N/A
824N/A default:;
824N/A }
824N/A} /* writeTypedObjectArray */
824N/A
824N/Astatic void procDestroyContext(DPSContext ctxt)
824N/A{
824N/A DPSPrivContext c = (DPSPrivContext)ctxt, cc, prev;
824N/A DPSPrivSpace ss = (DPSPrivSpace)(c->space);
824N/A
824N/A if (c->buf != NIL) {
824N/A ContextBuffer b = (ContextBuffer)(c->buf);
824N/A b->next = contextBuffers;
824N/A contextBuffers = b;
824N/A c->buf = NIL;
824N/A }
824N/A if (c->objBuf != NIL) {
824N/A free(c->objBuf);
824N/A c->objBuf = NIL;
824N/A }
824N/A
824N/A DPSUnchainContext(ctxt);
824N/A
824N/A prev = NIL;
824N/A DPSAssert(ss != NIL);
824N/A for (cc = ss->firstContext; (cc != NIL) && (cc != c); cc = cc->next)
824N/A prev = cc;
824N/A DPSAssert(cc != NIL);
824N/A DPSAssert(cc != prev);
824N/A if (prev == NIL) ss->firstContext = cc->next;
824N/A else {
824N/A prev->next = cc->next;
824N/A DPSAssert(prev->next != prev);
824N/A }
824N/A
824N/A DPSPrivateDestroyContext(ctxt);
824N/A free(c);
824N/A}
824N/A
824N/Astatic void procDestroySpace(DPSSpace space)
824N/A{
824N/A DPSPrivSpace ns, prevS, ss = (DPSPrivSpace)space;
824N/A integer sid = ss->sid;
824N/A
824N/A while (ss->firstContext != NIL)
824N/A DPSDestroyContext((DPSContext)(ss->firstContext));
824N/A
824N/A prevS = NIL;
824N/A for (ns = spaces; (ns != NIL) && (ns->sid != sid); ns = ns->next)
824N/A prevS = ns;
824N/A DPSAssert(ns != NIL);
824N/A DPSAssert(ns == ss);
824N/A if (prevS == NIL) spaces = ns->next;
824N/A else {
824N/A prevS->next = ns->next;
824N/A DPSAssert(prevS->next != prevS);
824N/A }
824N/A
824N/A DPSPrivateDestroySpace(space);
824N/A free(ss);
824N/A}
824N/A
824N/Astatic void procInterrupt(DPSContext ctxt)
824N/A{
824N/A DPSPrivContext c = (DPSPrivContext)ctxt;
824N/A DPSSendInterrupt((XDPSPrivContext)c->wh, c->cid, DPSclientPrintProc);
824N/A if (ctxt->chainChild != NIL) DPSInterruptContext(ctxt->chainChild);
824N/A}
824N/A
824N/A
824N/A/****************************************************************/
824N/A/* Procedures that support the DPSCreateTextContext context procs */
824N/A/****************************************************************/
824N/A
824N/A/* precondition: (c >= 129 && c <= 159), which means that c is the
824N/A first byte of either a binary token or a binary object sequence */
824N/A
824N/Astatic boolean IsBinaryToken(unsigned char c)
824N/A{
824N/A return (c != DPS_HI_IEEE && c != DPS_LO_IEEE
824N/A && c != DPS_HI_NATIVE && c != DPS_LO_NATIVE);
824N/A}
824N/A
824N/A/* returns the number of initial bytes of a given goody that are
824N/A required to figure out how many bytes are needed for the entire goody */
824N/A
824N/Astatic unsigned GetHdrNBytes(unsigned char *t)
824N/A{
824N/A if (!IsBinaryToken(*t)) {
824N/A if (*(++t) == 0) return DPS_EXT_HEADER_SIZE;
824N/A else return DPS_HEADER_SIZE;
824N/A }
824N/A switch (*t) {
824N/A case 137:
824N/A case 142:
824N/A return(2);
824N/A case 143:
824N/A case 144:
824N/A return(3);
824N/A case 149:
824N/A return(4);
824N/A default:
824N/A if (*t > 149 && *t < 160) return(1); /* unassigned */
824N/A else return(1);
824N/A }
824N/A}
824N/A
824N/A
824N/Astatic void WriteHomogeneousArrayAsASCII(
824N/A DPSContext ctxt,
824N/A register unsigned char *buf)
824N/A{
824N/A Swap32Rec n32;
824N/A Swap16Rec n16;
824N/A register unsigned char *b;
824N/A
824N/A unsigned char r = *buf++;
824N/A float f;
824N/A boolean hi = (r < 128);
824N/A
824N/A if (!hi) r -= 128;
824N/A DPSPrintf(ctxt, "[ ");
824N/A b = n16.bytes;
824N/A if (hi) {Copy2SrcHi(buf, b);} else {Copy2SrcLo(buf, b);}
824N/A buf += 2;
824N/A if (r < 32) /* 32-bit fixed */
824N/A while (n16.u--) {
824N/A b = n32.bytes;
824N/A if (hi) {Copy4SrcHi(buf, b);} else {Copy4SrcLo(buf, b);}
824N/A if (r == 0)
824N/A DPSPrintf(ctxt, "%d ", n32.i);
824N/A else {
824N/A f = n32.i; /* convert to float */
824N/A n32.f = f / (1 << r); /* scale */
824N/A DPSPrintf(ctxt, "%g ", n32.f);
824N/A }
824N/A buf += 4;
824N/A }
824N/A else if (r < 48) { /* 16-bit fixed */
824N/A unsigned l = n16.u;
824N/A r -= 32;
824N/A while (l--) {
824N/A b = n16.bytes;
824N/A if (hi) {Copy2SrcHi(buf, b);} else {Copy2SrcLo(buf, b);}
824N/A if (r == 0)
824N/A DPSPrintf(ctxt, "%d ", n16.i);
824N/A else {
824N/A f = n16.i; /* convert to float */
824N/A n32.f = f / (1 << r); /* scale */
824N/A DPSPrintf(ctxt, "%g ", n32.f);
824N/A }
824N/A buf += 2;
824N/A }
824N/A }
824N/A else if (r == 48) /* 32-bit IEEE */
824N/A while (n16.u--) {
824N/A#if IEEEFLOAT
824N/A b = n32.bytes;
824N/A if (hi) {Copy4SrcHi(buf, b);} else {Copy4SrcLo(buf, b);}
824N/A#else /* IEEEFLOAT */
824N/A if (hi) IEEEHighToNative(buf, &n32.f);
824N/A else IEEELowToNative(buf, &n32.f);
824N/A#endif /* IEEEFLOAT */
824N/A DPSPrintf(ctxt, "%g ", n32.f);
824N/A buf += 4;
824N/A }
824N/A else if (r == 49) /* 32-bit native */
824N/A while (n16.u--) {
824N/A b = n32.bytes;
824N/A *b++ = *buf++,*b++ = *buf++,*b++ = *buf++,*b = *buf++;
824N/A DPSPrintf(ctxt, "%g ", n32.f);
824N/A }
824N/A else DPSCantHappen();
824N/A DPSPrintf(ctxt, "\n] ");
824N/A} /* WriteHomogeneousArrayAsASCII */
824N/A
824N/A/* returns the number of bytes needed for the entire goody. buf points
824N/A to enough initial bytes of the goody to figure this out (see above). */
824N/A
824N/Astatic integer GetNBytes(register unsigned char *buf)
824N/A{
824N/A unsigned short int nBytes;
824N/A register unsigned char *r = (unsigned char *)&nBytes;
824N/A
824N/A switch (*buf) {
824N/A case DPS_HI_IEEE:
824N/A case DPS_HI_NATIVE:
824N/A if (*(buf+1) == 0) {
824N/A unsigned int nb;
824N/A r = (unsigned char *)&nb;
824N/A buf += 4;
824N/A Copy4SrcHi(buf, r);
824N/A return(nb);
824N/A }
824N/A else {
824N/A buf += 2;
824N/A Copy2SrcHi(buf, r);
824N/A }
824N/A break;
824N/A case DPS_LO_IEEE:
824N/A case DPS_LO_NATIVE:
824N/A if (*(buf+1) == 0) {
824N/A unsigned int nb;
824N/A r = (unsigned char *)&nb;
824N/A buf += 4;
824N/A Copy4SrcLo(buf, r);
824N/A return(nb);
824N/A }
824N/A else {
824N/A buf += 2;
824N/A Copy2SrcLo(buf, r);
824N/A }
824N/A break;
824N/A case 132:
824N/A case 133:
824N/A case 138:
824N/A case 139:
824N/A case 140:
824N/A nBytes = 5; break;
824N/A case 134:
824N/A case 135:
824N/A nBytes = 3; break;
824N/A case 136:
824N/A case 141:
824N/A case 145:
824N/A case 146:
824N/A case 147:
824N/A case 148:
824N/A nBytes = 2; break;
824N/A case 137: {
824N/A unsigned int l = *(buf+1);
824N/A if (l < 32) {nBytes = 6; break;}
824N/A if (l < 48) {nBytes = 4; break;}
824N/A if (l-128 < 32) {nBytes = 6; break;}
824N/A if (l-128 < 48) {nBytes = 4; break;}
824N/A DPSCantHappen();
824N/A }
824N/A case 142:
824N/A nBytes = *(buf+1);
824N/A nBytes += 2;
824N/A break;
824N/A case 143:
824N/A buf++;
824N/A Copy2SrcHi(buf, r);
824N/A nBytes += 3;
824N/A break;
824N/A case 144:
824N/A buf++;
824N/A Copy2SrcLo(buf, r);
824N/A nBytes += 3;
824N/A break;
824N/A case 149: {
824N/A unsigned char scale = *(buf+1);
824N/A buf += 2;
824N/A if (scale < 128)
824N/A Copy2SrcHi(buf, r);
824N/A else {
824N/A scale -= 128;
824N/A Copy2SrcLo(buf, r);
824N/A }
824N/A if (scale < 32)
824N/A nBytes *= 4;
824N/A else if (scale < 48)
824N/A nBytes *= 2;
824N/A else
824N/A nBytes *= 4;
824N/A nBytes += 4;
824N/A break;
824N/A }
824N/A default: nBytes = 1; /* unassigned */
824N/A }
824N/A return(nBytes);
824N/A}
824N/A
824N/Astatic void WriteSeqAsAscii(
824N/A DPSContext ctxt,
824N/A char *base,
824N/A DPSBinObj currObj,
824N/A unsigned int nObjs,
824N/A unsigned char tokenType,
824N/A int *numstringOffsets)
824N/A{
824N/A integer nLineObjs = 0;
824N/A DPSNumFormat numFormat;
824N/A float f;
824N/A long int i;
824N/A unsigned short int length;
824N/A
824N/A /* NOTE: It's ok to call DPSPrintf (which calls DPSWritePostScript)
824N/A from here since we are only sending text, so there's no problem
824N/A with re-entering DPSWritePostScript. Caller guarantees
824N/A that this context has no children. */
824N/A
824N/A NumFormatFromTokenType(tokenType, &numFormat);
824N/A
824N/A while (nObjs--) {
824N/A unsigned char type = currObj->attributedType & ~DPS_EXEC;
824N/A boolean lit = ((currObj->attributedType & DPS_EXEC) == 0);
824N/A
824N/A switch (type) {
824N/A case DPS_NULL:
824N/A break;
824N/A case DPS_BOOL:
824N/A i = currObj->val.booleanVal;
824N/A if (i)
824N/A DPSPrintf(ctxt, "true ");
824N/A else
824N/A DPSPrintf(ctxt, "false ");
824N/A break;
824N/A case DPS_INT:
824N/A i = currObj->val.integerVal;
824N/A DPSPrintf(ctxt, "%d ", i);
824N/A break;
824N/A case DPS_REAL:
824N/A#if IEEEFLOAT
824N/A f = currObj->val.realVal;
824N/A#else /* IEEEFLOAT */
824N/A if (numFormat != DPSDefaultNumFormat)
824N/A#if SWAPBITS
824N/A IEEELowToNative(&currObj->val.realVal, &f);
824N/A#else /* SWAPBITS */
824N/A IEEEHighToNative(&currObj->val.realVal, &f);
824N/A#endif /* SWAPBITS */
824N/A else
824N/A f = currObj->val.realVal;
824N/A#endif /* IEEEFLOAT */
824N/A
824N/A DPSPrintf(ctxt, "%g ", f);
824N/A break;
824N/A case DPS_NAME: {
824N/A char *p = 0;
824N/A integer index;
824N/A
824N/A index = currObj->val.nameVal;
824N/A length = currObj->length;
824N/A
824N/A if (lit) DPSPrintf(ctxt, "/");
824N/A
824N/A if (length == DPSSYSNAME) { /* system name index */
824N/A if (index <= DPS_LAST_COMMON_SYSNAME) {
824N/A if (!lit && (ctxt->contextFlags & DPS_FLAG_USE_ABBREVS)) {
824N/A p = DPSGetSysnameAbbrev(index);
824N/A if (p == NULL) p = DPSSysNames[index];
824N/A } else p = DPSSysNames[index];
824N/A } else if (DPS_FIRST_AUX_SYSNAME <= index
824N/A && index <= DPS_LAST_AUX_SYSNAME)
824N/A p = DPSSysNamesAux[index - DPS_FIRST_AUX_SYSNAME];
824N/A else DPSCantHappen();
824N/A length = strlen(p);
824N/A }
824N/A else if (length == 0) { /* user name index */
824N/A p = DPSNameFromIndex(index);
824N/A length = strlen(p);
824N/A }
824N/A else
824N/A p = base + index;
824N/A
824N/A DPSWriteData(ctxt, p, length);
824N/A DPSPrintf(ctxt, " ");
824N/A break;
824N/A }
824N/A case DPS_ARRAY:
824N/A DPSPrintf(ctxt, (lit ? "[ " : "{ "));
824N/A WriteSeqAsAscii(
824N/A ctxt,
824N/A base,
824N/A (DPSBinObj)(base+currObj->val.arrayVal),
824N/A currObj->length,
824N/A tokenType, numstringOffsets);
824N/A DPSPrintf(ctxt, (lit ? " ] " : " } "));
824N/A break;
824N/A case DPS_MARK:
824N/A if (lit)
824N/A DPSPrintf(ctxt, "/mark ");
824N/A else
824N/A DPSPrintf(ctxt, "mark ");
824N/A break;
824N/A case DPS_STRING: {
824N/A char *p;
824N/A int j;
824N/A i = currObj->val.stringVal;
824N/A length = currObj->length;
824N/A p = base + i;
824N/A if (numstringOffsets != NULL) {
824N/A for (j = 2; j < numstringOffsets[1] &&
824N/A numstringOffsets[j] != i; j++) ;
824N/A if (numstringOffsets[j] == i) {
824N/A DPSAssert(*(unsigned char *) p++ == 149);
824N/A WriteHomogeneousArrayAsASCII(ctxt, (unsigned char *) p);
824N/A break;
824N/A }
824N/A }
824N/A DPSPrintf(ctxt, "(");
824N/A#ifdef VMS
824N/A WriteVMSStringBody(ctxt, p, length); /* write this */
824N/A#else /* VMS */
824N/A /* render string bytes correctly */
824N/A while (length--) {
824N/A char c = *p++;
824N/A if (c == '(' || c == ')' || c == '\\')
824N/A DPSPrintf(ctxt, "\\%c", c);
824N/A else if (c == '\n')
824N/A DPSPrintf(ctxt, "\\n");
824N/A else if (!(isascii(c) && isprint(c)))
824N/A DPSPrintf(ctxt, "\\%03.3o", (unsigned char) c);
824N/A else DPSWriteData(ctxt, &c, 1);
824N/A }
824N/A#endif /* VMS */
824N/A DPSPrintf(ctxt, ") ");
824N/A break;
824N/A }
824N/A default: DPSCantHappen();
824N/A }
824N/A
824N/A currObj++;
824N/A if (++nLineObjs == 15) {
824N/A nLineObjs = 0;
824N/A DPSPrintf(ctxt, "\n ");
824N/A }
824N/A } /* end while */
824N/A
824N/A DPSPrintf(ctxt, "\n");
824N/A
824N/A} /* WriteSeqAsAscii */
824N/A
824N/Astatic void ConvertAndWriteSeqAsData(
824N/A DPSContext ctxt,
824N/A char *bosBuf,
824N/A int pass)
824N/A{
824N/A DPSPrivContext cc = (DPSPrivContext) ctxt;
824N/A DPSExtendedBinObjSeq bos;
824N/A DPSExtendedBinObjSeqRec bosRec;
824N/A DPSNumFormat numFormat;
824N/A unsigned int offset, firstCharOffset;
824N/A unsigned int nameOffset;
824N/A unsigned int len = 0;
824N/A DPSBinObj currObj;
824N/A integer headSize;
824N/A char *seqBase;
824N/A
824N/A if (*(bosBuf+1) != 0) {
824N/A /* not an extended BOS */
824N/A DPSBinObjSeq seqHead = (DPSBinObjSeq) bosBuf;
824N/A bos = &bosRec;
824N/A bos->tokenType = seqHead->tokenType;
824N/A bos->escape = seqHead->nTopElements;
824N/A bos->nTopElements = seqHead->nTopElements;
824N/A bos->length = seqHead->length;
824N/A currObj = &(seqHead->objects[0]);
824N/A seqBase = (char *) &(seqHead->objects[0]);
824N/A headSize = DPS_HEADER_SIZE;
824N/A }
824N/A else {
824N/A bos = (DPSExtendedBinObjSeq) bosBuf;
824N/A currObj = &(bos->objects[0]);
824N/A seqBase = (char *) &(bos->objects[0]);
824N/A headSize = DPS_EXT_HEADER_SIZE;
824N/A }
824N/A firstCharOffset = bos->length - headSize;
824N/A nameOffset = firstCharOffset;
824N/A
824N/A /* Caller guarantees that this context has no children,
824N/A so it is okay to call DPSWriteData */
824N/A
824N/A NumFormatFromTokenType(bos->tokenType, &numFormat);
824N/A
824N/A /* Pass 0: If we're expanding name indices, find all name objects,
824N/A lookup their strings, sum the lengths.
824N/A Write the modified sequence header regardless.
824N/A Pass 1: we're converting indices to strings and/or
824N/A converting numbers. Write each modified object, and
824N/A subsidiary strings.
824N/A Pass 2: Find all name objects, lookup and write the strings. */
824N/A
824N/A if (pass == 0 && ctxt->nameEncoding != dps_strings)
824N/A /* we're just converting numbers, so skip while loop */
824N/A offset = firstCharOffset;
824N/A else
824N/A offset = 0;
824N/A
824N/A while (offset < firstCharOffset) {
824N/A DPSBinObjRec newObj;
824N/A unsigned char type = (currObj->attributedType & ~DPS_EXEC);
824N/A
824N/A newObj = *currObj;
824N/A
824N/A#if !IEEEFLOAT
824N/A if (type == DPS_REAL) {
824N/A if (numFormat != cc->numFormat) {
824N/A if (numFormat == dps_ieee) {
824N/A if (DPSDefaultByteOrder == dps_loFirst)
824N/A IEEELowToNative(&currObj->val.realVal, &newObj.val.realVal);
824N/A else
824N/A IEEEHighToNative(&currObj->val.realVal, &newObj.val.realVal);
824N/A }
824N/A else { /* numFormat is native */
824N/A if (DPSDefaultByteOrder == dps_loFirst)
824N/A NativeToIEEELow(&currObj->val.realVal, &newObj.val.realVal);
824N/A else
824N/A NativeToIEEEHigh(&currObj->val.realVal, &newObj.val.realVal);
824N/A }
824N/A }
824N/A }
824N/A#endif /* !IEEEFLOAT */
824N/A
824N/A if (type == DPS_STRING && newObj.length > 0) {
824N/A /* keep track of where strings start */
824N/A firstCharOffset = ((unsigned) newObj.val.stringVal < firstCharOffset)
824N/A ? newObj.val.stringVal : firstCharOffset;
824N/A }
824N/A if (type == DPS_NAME) {
824N/A if (newObj.length == DPSSYSNAME) { /* system name index, never expand to string body */
824N/A if (pass != 1) goto next_obj;
824N/A }
824N/A else if (newObj.length == 0) { /* user name index */
824N/A register char *p = DPSNameFromIndex(newObj.val.nameVal);
824N/A switch (pass) {
824N/A case 0: len += strlen(p); goto next_obj;
824N/A case 1:
824N/A if (ctxt->nameEncoding == dps_strings) {
824N/A newObj.length = strlen(p);
824N/A newObj.val.nameVal = nameOffset;
824N/A nameOffset += newObj.length;
824N/A }
824N/A break;
824N/A case 2: DPSWriteData(ctxt, p, strlen(p)); goto next_obj;
824N/A default:;
824N/A }
824N/A }
824N/A else { /* name is already a string */
824N/A /* keep track of where strings start */
824N/A firstCharOffset = ((unsigned) newObj.val.nameVal < firstCharOffset)
824N/A ? newObj.val.nameVal : firstCharOffset;
824N/A }
824N/A } /* end if type == DPS_NAME */
824N/A if (pass == 1) {
824N/A DPSWriteData(ctxt, (char *) &newObj, sizeof(newObj));
824N/A }
824N/A
824N/Anext_obj:
824N/A offset += sizeof(newObj);
824N/A ++currObj;
824N/A } /* end while */
824N/A
824N/A /* finish pass */
824N/A switch (pass) {
824N/A case 0: {
824N/A unsigned char t;
824N/A /* write modified seqHead */
824N/A if (DPSDefaultByteOrder == dps_hiFirst && cc->numFormat == dps_ieee)
824N/A t = DPS_HI_IEEE;
824N/A else if (DPSDefaultByteOrder == dps_loFirst && cc->numFormat == dps_ieee)
824N/A t = DPS_LO_IEEE;
824N/A else if (DPSDefaultByteOrder == dps_hiFirst && cc->numFormat == dps_native)
824N/A t = DPS_HI_NATIVE;
824N/A else
824N/A t = DPS_LO_NATIVE;
824N/A DPSWriteData(ctxt, (char *) &t, 1);
824N/A if (headSize == DPS_HEADER_SIZE) {
824N/A unsigned short int nBytes;
824N/A unsigned char c = bos->nTopElements;
824N/A /* write top level count */
824N/A DPSWriteData(ctxt, (char *) &c, 1);
824N/A /* write nBytes */
824N/A nBytes = (ctxt->nameEncoding == dps_strings) ? bos->length + len :
824N/A bos->length;
824N/A DPSWriteData(ctxt, (char *)&nBytes, 2);
824N/A }
824N/A else {
824N/A unsigned int nBytes;
824N/A /* write escape code & top level count */
824N/A DPSWriteData(ctxt, (char *)&bos->escape, 3);
824N/A /* write nBytes */
824N/A nBytes = (ctxt->nameEncoding == dps_strings) ? bos->length + len :
824N/A bos->length;
824N/A DPSWriteData(ctxt, (char *)&nBytes, 4);
824N/A }
824N/A break;
824N/A }
824N/A case 1: {
824N/A char *stringStart = seqBase + firstCharOffset;
824N/A DPSWriteData(ctxt, stringStart, (bos->length - headSize - firstCharOffset));
824N/A break;
824N/A }
824N/A default:;
824N/A }
824N/A
824N/A} /* ConvertAndWriteSeqAsData */
824N/A
824N/A#define MIN16 -32768
824N/A#define MAX16 32767
824N/A
824N/A/* TestHomogeneous will return a non-negative representation code 'r'
824N/A if all of the array elements are "integers", or all are "reals".
824N/A Will return -1 for any other case. */
824N/A
824N/Astatic integer TestHomogeneous(
824N/A DPSBinObj aryObj,
824N/A unsigned short length,
824N/A DPSNumFormat numFormat)
824N/A{
824N/A integer tmp, r = -1;
824N/A
824N/A while (length--) {
824N/A switch (aryObj->attributedType & ~DPS_EXEC) {
824N/A case DPS_INT:
824N/A#if SWAPBITS
824N/A tmp = (aryObj->val.integerVal < MIN16
824N/A || aryObj->val.integerVal > MAX16) ? 128 : 128+32;
824N/A#else /* SWAPBITS */
824N/A tmp = (aryObj->val.integerVal < MIN16
824N/A || aryObj->val.integerVal > MAX16) ? 0 : 32;
824N/A#endif /* SWAPBITS */
824N/A if ((r == -1) || ((r & 0x07F) == 32 && (tmp & 0x07F) == 0))
824N/A r = tmp; /* first element, or was 16-bit => bump to 32-bit */
824N/A else if ((r & 0x07F) == 0 && (tmp & 0x07F) == 32)
824N/A goto bump_obj; /* is 32-bit => stay 32-bit */
824N/A else if (r != tmp)
824N/A return(-1);
824N/A /* else fall thru, r == tmp */
824N/A break;
824N/A case DPS_REAL:
824N/A#if SWAPBITS
824N/A tmp = (numFormat == dps_ieee) ? 128+48 : 128+49;
824N/A#else /* SWAPBITS */
824N/A tmp = (numFormat == dps_ieee) ? 48 : 49;
824N/A#endif /* SWAPBITS */
824N/A if (r == -1)
824N/A r = tmp;
824N/A else if (r != tmp) return(-1);
824N/A break;
824N/A default: return(-1);
824N/A }
824N/Abump_obj:
824N/A ++aryObj;
824N/A }
824N/A return(r);
824N/A} /* TestHomogeneous */
824N/A
824N/Astatic void WriteSeqAsTokens(
824N/A DPSContext ctxt,
824N/A char *base,
824N/A DPSBinObj currObj,
824N/A unsigned int nObjs,
824N/A unsigned char tokenType,
824N/A int *numstringOffsets)
824N/A{
824N/A int nLineObjs = 0;
824N/A DPSNumFormat numFormat;
824N/A unsigned short length;
824N/A Swap32Rec n32;
824N/A Swap16Rec n16;
824N/A unsigned char c;
824N/A
824N/A#define PB(byte) c = (byte),DPSWriteData(ctxt, (char *) &c, 1)
824N/A#if SWAPBITS
824N/A#define WTT(byte) PB((byte)+1)
824N/A#else /* SWAPBITS */
824N/A#define WTT(byte) PB(byte)
824N/A#endif /* SWAPBITS */
824N/A
824N/A NumFormatFromTokenType(tokenType, &numFormat);
824N/A
824N/A while (nObjs--) {
824N/A unsigned char type = currObj->attributedType & ~DPS_EXEC;
824N/A boolean lit = ((currObj->attributedType & DPS_EXEC) == 0);
824N/A
824N/A switch (type) {
824N/A case DPS_NULL:
824N/A break;
824N/A case DPS_BOOL:
824N/A PB(141); /* boolean */
824N/A if (currObj->val.booleanVal)
824N/A PB(true);
824N/A else
824N/A PB(false);
824N/A break;
824N/A case DPS_INT:
824N/A n32.i = currObj->val.integerVal;
824N/A if (n32.i < MIN16 || n32.i > MAX16) {
824N/A WTT(132); /* 32-bit int */
824N/A DPSWriteData(ctxt, (char *) n32.bytes, 4);
824N/A }
824N/A else if (n32.i < -128 || n32.i > 127) {
824N/A WTT(134); /* 16-bit int */
824N/A n16.i = n32.i;
824N/A DPSWriteData(ctxt, (char *) n16.bytes, 2);
824N/A }
824N/A else {
824N/A WTT(136); /* 8-bit int */
824N/A PB(n32.i);
824N/A }
824N/A break;
824N/A case DPS_REAL:
824N/A#if IEEEFLOAT
824N/A WTT(138); /* 32-bit IEEE float */
824N/A#else /* IEEEFLOAT */
824N/A if (numFormat != DPSDefaultNumFormat)
824N/A /* then it must be IEEE */
824N/A WTT(138); /* 32-bit IEEE float */
824N/A else
824N/A PB(140); /* 32-bit native float */
824N/A#endif /* IEEEFLOAT */
824N/A
824N/A DPSWriteData(ctxt, (char *) &currObj->val.realVal, 4);
824N/A break;
824N/A case DPS_NAME: {
824N/A char *p = 0;
824N/A integer index = currObj->val.nameVal;
824N/A
824N/A length = currObj->length;
824N/A if (length == DPSSYSNAME) {/* system name index */
824N/A if (index >= 0 && index < 256) {
824N/A if (lit)
824N/A PB(145); /* literal system name */
824N/A else
824N/A PB(146); /* exec. system name */
824N/A PB(index);
824N/A goto next_obj;
824N/A }
824N/A else if (DPS_FIRST_AUX_SYSNAME <= index
824N/A && index <= DPS_LAST_AUX_SYSNAME)
824N/A p = DPSSysNamesAux[index - DPS_FIRST_AUX_SYSNAME];
824N/A else DPSCantHappen();
824N/A length = strlen(p);
824N/A }
824N/A else if (length == 0) { /* user name index */
824N/A if (ctxt->nameEncoding == dps_indexed && index < 256) {
824N/A if (lit)
824N/A PB(147); /* literal user name index */
824N/A else
824N/A PB(148); /* executable user name index */
824N/A PB(index);
824N/A goto next_obj;
824N/A }
824N/A else {
824N/A p = DPSNameFromIndex(index);
824N/A length = strlen(p);
824N/A }
824N/A }
824N/A else
824N/A p = base + index;
824N/A if (lit) DPSPrintf(ctxt, "/");
824N/A DPSWriteData(ctxt, p, length);
824N/A DPSPrintf(ctxt, " ");
824N/A break;
824N/A }
824N/A case DPS_ARRAY: {
824N/A DPSBinObj aryObj = (DPSBinObj)(base+currObj->val.arrayVal);
824N/A integer r;
824N/A length = currObj->length;
824N/A if (lit && (r = TestHomogeneous(aryObj, length, numFormat)) != -1) {
824N/A PB(149); /* homogeneous number array */
824N/A PB(r);
824N/A DPSWriteData(ctxt, (char *) &length, 2);
824N/A if (r > 127) r -= 128;
824N/A while (length--) {
824N/A switch (r) {
824N/A case 0:
824N/A DPSWriteData(ctxt, (char *) &aryObj->val.integerVal, 4);
824N/A break;
824N/A case 32:
824N/A n16.i = aryObj->val.integerVal;
824N/A DPSWriteData(ctxt, (char *) n16.bytes, 2);
824N/A break;
824N/A case 48:
824N/A case 49:
824N/A DPSWriteData(ctxt, (char *) &aryObj->val.realVal, 4);
824N/A break;
824N/A default: DPSCantHappen();
824N/A }
824N/A ++aryObj;
824N/A }
824N/A }
824N/A else {
824N/A DPSPrintf(ctxt, (lit ? "[ " : "{ "));
824N/A WriteSeqAsTokens(ctxt, base, aryObj, length, tokenType,
824N/A numstringOffsets);
824N/A DPSPrintf(ctxt, (lit ? " ] " : " } "));
824N/A }
824N/A break; }
824N/A case DPS_MARK:
824N/A if (lit)
824N/A DPSPrintf(ctxt, "/mark ");
824N/A else
824N/A DPSPrintf(ctxt, "mark ");
824N/A break;
824N/A case DPS_STRING: {
824N/A char *p = base + currObj->val.stringVal;
824N/A int i;
824N/A if (numstringOffsets != NULL) {
824N/A for (i = 2; i < numstringOffsets[1] &&
824N/A numstringOffsets[i] != currObj->val.stringVal; i++) ;
824N/A if (numstringOffsets[i] == currObj->val.stringVal) {
824N/A DPSAssert(*(unsigned char *) p == 149);
824N/A DPSWriteData(ctxt, p, length);
824N/A break;
824N/A }
824N/A }
824N/A length = currObj->length;
824N/A if (length < 256) {
824N/A PB(142); /* short string */
824N/A PB(length);
824N/A }
824N/A else {
824N/A WTT(143); /* long string */
824N/A DPSWriteData(ctxt, (char *) &length, 2);
824N/A }
824N/A DPSWriteData(ctxt, p, length);
824N/A break;
824N/A }
824N/A default: DPSCantHappen();
824N/A }
824N/Anext_obj:
824N/A ++currObj;
824N/A if (++nLineObjs == 15) {
824N/A nLineObjs = 0;
824N/A DPSPrintf(ctxt, "\n ");
824N/A }
824N/A } /* end while */
824N/A
824N/A DPSPrintf(ctxt, "\n");
824N/A} /* WriteSeqAsTokens */
824N/A
824N/Astatic void WriteTokenAsAscii(
824N/A DPSContext ctxt,
824N/A register unsigned char *buf)
824N/A{
824N/A Swap32Rec n32;
824N/A Swap16Rec n16;
824N/A register unsigned char *b;
824N/A
824N/A switch (*buf++) {
824N/A case 132: /* 32-bit int, hi */
824N/A b = n32.bytes;
824N/A Copy4SrcHi(buf, b);
824N/A DPSPrintf(ctxt, "%d ", n32.i);
824N/A break;
824N/A case 133: /* 32-bit int, lo */
824N/A b = n32.bytes;
824N/A Copy4SrcLo(buf, b);
824N/A DPSPrintf(ctxt, "%d ", n32.i);
824N/A break;
824N/A case 134: /* 16-bit int, hi */
824N/A b = n16.bytes;
824N/A Copy2SrcHi(buf, b);
824N/A DPSPrintf(ctxt, "%d ", n16.i);
824N/A break;
824N/A case 135: /* 16-bit int, lo */
824N/A b = n16.bytes;
824N/A Copy2SrcLo(buf, b);
824N/A DPSPrintf(ctxt, "%d ", n16.i);
824N/A break;
824N/A case 136: /* 8-bit int, signed */
824N/A n32.i = (char) *buf;
824N/A DPSPrintf(ctxt, "%d ", n32.i);
824N/A break;
824N/A case 137: { /* 16 or 32-bit fixed */
824N/A unsigned char r = *buf++;
824N/A float f = 0.0;
824N/A boolean hi = (r < 128);
824N/A
824N/A if (!hi) r -= 128;
824N/A if (r < 32) { /* 32-bit */
824N/A b = n32.bytes;
824N/A if (hi) {Copy4SrcHi(buf, b);} else {Copy4SrcLo(buf, b);}
824N/A if (r == 0) {
824N/A DPSPrintf(ctxt, "%d ", n32.i);
824N/A break;
824N/A }
824N/A else {
824N/A f = n32.i; /* convert to float */
824N/A goto do_scale;
824N/A }
824N/A }
824N/A else if (r < 48) { /* 16-bit */
824N/A b = n16.bytes;
824N/A if (hi) {Copy2SrcHi(buf, b);} else {Copy2SrcLo(buf, b);};
824N/A if (r == 0) {
824N/A DPSPrintf(ctxt, "%d ", n16.i);
824N/A break;
824N/A }
824N/A else {
824N/A r -= 32;
824N/A f = n16.i; /* convert to float */
824N/A goto do_scale;
824N/A }
824N/A }
824N/A else DPSCantHappen();
824N/Ado_scale:
824N/A n32.f = f / (1 << r); /* scale */
824N/A DPSPrintf(ctxt, "%g ", n32.f);
824N/A break;
824N/A }
824N/A case 138: /* 32-bit IEEE float, hi */
824N/A#if IEEEFLOAT
824N/A b = n32.bytes;
824N/A Copy4SrcHi(buf, b);
824N/A#else /* IEEEFLOAT */
824N/A IEEEHighToNative(buf, &n32.f);
824N/A#endif /* IEEEFLOAT */
824N/A DPSPrintf(ctxt, "%g ", n32.f);
824N/A break;
824N/A case 139: /* 32-bit IEEE float, lo */
824N/A#if IEEEFLOAT
824N/A b = n32.bytes;
824N/A Copy4SrcLo(buf, b);
824N/A#else /* IEEEFLOAT */
824N/A IEEELowToNative(buf, &n32.f);
824N/A#endif /* IEEEFLOAT */
824N/A DPSPrintf(ctxt, "%g ", n32.f);
824N/A break;
824N/A case 140: /* 32-bit native float */
824N/A b = n32.bytes;
824N/A *b++ = *buf++,*b++ = *buf++,*b++ = *buf++,*b = *buf;
824N/A DPSPrintf(ctxt, "%g ", n32.f);
824N/A break;
824N/A case 141: /* boolean */
824N/A if (*buf)
824N/A DPSPrintf(ctxt, "true ");
824N/A else
824N/A DPSPrintf(ctxt, "false ");
824N/A break;
824N/A case 142: /* short string */
824N/A DPSPrintf(ctxt, "(");
824N/A n16.u = *buf++;
824N/A goto share_str_code;
824N/A case 143: /* long string, hi */
824N/A b = n16.bytes;
824N/A Copy2SrcHi(buf, b);
824N/A DPSPrintf(ctxt, "(");
824N/A buf += 2;
824N/A goto share_str_code;
824N/A case 144: /* long string, lo */
824N/A b = n16.bytes;
824N/A Copy2SrcLo(buf, b);
824N/A DPSPrintf(ctxt, "(");
824N/A buf += 2;
824N/Ashare_str_code:
824N/A#ifdef VMS
824N/A WriteVMSStringBody(ctxt, buf, n16.u); /* write this */
824N/A#else /* VMS */
824N/A /* render string bytes correctly */
824N/A while (n16.u--) {
824N/A unsigned char c = *buf++;
824N/A if (c == '(' || c == ')' || c == '\\')
824N/A DPSPrintf(ctxt, "\\%c", c);
824N/A else if (c == '\n')
824N/A DPSPrintf(ctxt, "\\n");
824N/A else if (!(isascii(c) && isprint(c)))
824N/A DPSPrintf(ctxt, "\\%03.3o", c);
824N/A else DPSWriteData(ctxt, (char *) &c, 1);
824N/A }
824N/A#endif /* VMS */
824N/A DPSPrintf(ctxt, ") ");
824N/A break;
824N/A case 145: /* literal system name index */
824N/A DPSPrintf(ctxt, "/%s ", DPSSysNames[*buf]);
824N/A break;
824N/A case 146: /* executable system name index */
824N/A DPSPrintf(ctxt, "%s ", DPSSysNames[*buf]);
824N/A break;
824N/A case 147: /* literal user name index */
824N/A DPSPrintf(ctxt, "/%s ", DPSNameFromIndex(*buf));
824N/A break;
824N/A case 148: /* executable user name index */
824N/A DPSPrintf(ctxt, "%s ", DPSNameFromIndex(*buf));
824N/A break;
824N/A case 149: { /* homogeneous number array */
824N/A WriteHomogeneousArrayAsASCII(ctxt, buf);
824N/A break;
824N/A }
824N/A default:; /* unassigned */
824N/A }
824N/A} /* WriteTokenAsAscii */
824N/A
824N/A
824N/A/* WriteEntireGoody converts an entire binary token or binary object
824N/A sequence as specified by ctxt's encoding parameters. Write the
824N/A converted bytes via DPSWriteData. buf points to the complete goody. */
824N/A
824N/Astatic void WriteEntireGoody(
824N/A DPSContext ctxt,
824N/A unsigned char *buf,
824N/A int *numstringOffsets)
824N/A{
824N/A
824N/A DPSExtendedBinObjSeq bos = (DPSExtendedBinObjSeq) buf;
824N/A DPSExtendedBinObjSeqRec bosRec;
824N/A DPSBinObj currObj;
824N/A DPSPrivContext cc = (DPSPrivContext) ctxt;
824N/A
824N/A if (IsBinaryToken(*buf)) {
824N/A /* only supported conversion is binary token to ASCII */
824N/A WriteTokenAsAscii(ctxt, buf);
824N/A if (numstringOffsets) numstringOffsets[1] = 2;
824N/A return;
824N/A }
824N/A
824N/A if (bos->escape != 0) {
824N/A /* not extended BOS */
824N/A DPSBinObjSeq seqHead = (DPSBinObjSeq) buf;
824N/A bos = &bosRec;
824N/A bos->tokenType = seqHead->tokenType;
824N/A bos->escape = seqHead->nTopElements;
824N/A bos->nTopElements = seqHead->nTopElements;
824N/A bos->length = seqHead->length;
824N/A currObj = &(seqHead->objects[0]);
824N/A }
824N/A else currObj = &(bos->objects[0]);
824N/A
824N/A switch (ctxt->programEncoding) {
824N/A case dps_binObjSeq:
824N/A if (ctxt->nameEncoding == dps_strings) {
824N/A /* takes three passes to do conversions */
824N/A ConvertAndWriteSeqAsData(ctxt, (char *) buf, 0);
824N/A ConvertAndWriteSeqAsData(ctxt, (char *) buf, 1);
824N/A ConvertAndWriteSeqAsData(ctxt, (char *) buf, 2);
824N/A }
824N/A else if (bos->tokenType != DPS_DEF_TOKENTYPE
824N/A || cc->numFormat != DPSDefaultNumFormat) {
824N/A /* first pass just writes modified seqHead */
824N/A ConvertAndWriteSeqAsData(ctxt, (char *) buf, 0);
824N/A /* second pass converts numbers and writes the sequence */
824N/A ConvertAndWriteSeqAsData(ctxt, (char *) buf, 1);
824N/A }
824N/A else DPSWriteData(ctxt, (char *) buf, bos->length);
824N/A break;
824N/A case dps_ascii:
824N/A case dps_encodedTokens: {
824N/A
824N/A if (ctxt->programEncoding == dps_ascii)
824N/A {
824N/A WriteSeqAsAscii(
824N/A ctxt, (char *)currObj, currObj, bos->nTopElements,
824N/A bos->tokenType, numstringOffsets);
824N/A }
824N/A else
824N/A WriteSeqAsTokens(
824N/A ctxt, (char *)currObj, currObj, bos->nTopElements,
824N/A bos->tokenType, numstringOffsets);
824N/A DPSWriteData(ctxt, "\n", 1);
824N/A break;
824N/A }
824N/A default:;
824N/A }
824N/A if (numstringOffsets) numstringOffsets[1] = 2;
824N/A} /* WriteEntireGoody */
824N/A
824N/A
824N/A/**************************************/
824N/A/* Context procs for DPSCreateTextContext */
824N/A/**************************************/
824N/A
824N/Astatic void textWriteData(DPSContext ctxt, char *buf, unsigned int nch)
824N/A{
824N/A (*ctxt->textProc)(ctxt, buf, nch);
824N/A if (ctxt->chainChild != NIL) DPSWriteData(ctxt->chainChild, buf, nch);
824N/A}
824N/A
824N/Astatic void textFlushContext(DPSContext ctxt)
824N/A{
824N/A if (ctxt->chainChild != NIL) DPSFlushContext(ctxt->chainChild);
824N/A}
824N/A
824N/Astatic void textInterruptContext(DPSContext ctxt)
824N/A{
824N/A if (ctxt->chainChild != NIL) DPSInterruptContext(ctxt->chainChild);
824N/A}
824N/A
824N/Astatic void textDestroyContext(DPSContext ctxt)
824N/A{
824N/A DPSPrivContext c = (DPSPrivContext)ctxt;
824N/A
824N/A DPSUnchainContext(ctxt);
824N/A
824N/A free(c);
824N/A}
824N/A
824N/Astatic void textInnerWritePostScript(
824N/A DPSContext ctxt, char *buf, unsigned int nch)
824N/A{
824N/A DPSPrivContext cc = (DPSPrivContext)ctxt;
824N/A while (nch > 0) {
824N/A char *oldBuf = NIL;
824N/A integer oldNch = 0;
824N/A unsigned n;
824N/A if (cc->outBuf) { /* we're buffering */
824N/A unsigned m;
824N/A integer bst;
824N/A if (!IsBinaryToken(cc->outBuf[0]) && cc->nOutBufChars < DPS_SEQ_MIN) {
824N/A char *tb = cc->outBuf + cc->nOutBufChars;
824N/A integer nn = DPS_SEQ_MIN - cc->nOutBufChars;
824N/A DPSAssert(nn == 1);
824N/A cc->nOutBufChars += nn;
824N/A nch -= nn;
824N/A *tb++ = *buf++;
824N/A }
824N/A bst = GetHdrNBytes((unsigned char *) cc->outBuf);
824N/A /* # bytes needed to determine size */
824N/A if (cc->nOutBufChars < bst) {
824N/A char *b = cc->outBuf;
824N/A if (nch + cc->nOutBufChars < (unsigned) bst) {
824N/A os_bcopy(buf, cc->outBuf + cc->nOutBufChars, nch);
824N/A cc->nOutBufChars += nch;
824N/A return;
824N/A }
824N/A os_bcopy(buf, b + cc->nOutBufChars, bst - cc->nOutBufChars);
824N/A buf += bst - cc->nOutBufChars;
824N/A nch -= bst - cc->nOutBufChars;
824N/A cc->nOutBufChars = bst;
824N/A m = GetNBytes((unsigned char *) cc->outBuf);
824N/A cc->outBuf = (char *)DPScalloc(m, 1);
824N/A os_bcopy(b, cc->outBuf, bst);
824N/A free(b);
824N/A }
824N/A else m = GetNBytes((unsigned char *) cc->outBuf);
824N/A
824N/A /* here with size of entire goody in m and outBuf set up */
824N/A if (nch + cc->nOutBufChars < m) {
824N/A os_bcopy(buf, cc->outBuf + cc->nOutBufChars, nch);
824N/A cc->nOutBufChars += nch;
824N/A return;
824N/A }
824N/A os_bcopy(buf, cc->outBuf + cc->nOutBufChars, m - cc->nOutBufChars);
824N/A buf += m - cc->nOutBufChars;
824N/A nch -= m - cc->nOutBufChars;
824N/A cc->nOutBufChars = m;
824N/A oldBuf = buf;
824N/A oldNch = nch;
824N/A buf = cc->outBuf;
824N/A nch = cc->nOutBufChars;
824N/A cc->outBuf = NIL;
824N/A cc->nOutBufChars = 0;
824N/A } /* if (cc->outBuf) */
824N/A
824N/A /* dispose of any plain text. If no binary conversion, all output
824N/A is plain text */
824N/A if (cc->contextFlags & DPS_FLAG_NO_BINARY_CONVERSION) n = nch;
824N/A else {
824N/A for (n = 0; n < nch &&
824N/A ((unsigned char) buf[n] < 128 || (unsigned char) buf[n] > 159); n++);
824N/A }
824N/A if (n > 0) {
824N/A /* Assumes below that any error proc called uses dpsexcept.h
824N/A if it rips control away */
824N/A DURING
824N/A DPSWriteData((DPSContext)cc, buf, n);
824N/A HANDLER
824N/A if (oldBuf) free(buf);
824N/A RERAISE;
824N/A END_HANDLER
824N/A }
824N/A buf += n;
824N/A nch -= n;
824N/A
824N/A if (nch != 0) {
824N/A /* here with the next binary object sequence or encoded token */
824N/A unsigned m = 0;
824N/A integer bst;
824N/A if (!IsBinaryToken(buf[0]) && nch < DPS_SEQ_MIN) {
824N/A /* gotta buffer it */
824N/A DPSAssertWarn(nch == 1 && !oldBuf, cc, "problem converting binary token/sequence (nch!=1||oldBuf)");
824N/A cc->outBuf = (char *)DPScalloc(DPS_EXT_HEADER_SIZE, 1);
824N/A cc->nOutBufChars = nch;
824N/A cc->outBuf[0] = *buf;
824N/A return;
824N/A }
824N/A bst = GetHdrNBytes((unsigned char *) buf);
824N/A if (nch < (unsigned)bst || nch < (m = GetNBytes((unsigned char *) buf))) {
824N/A /* gotta buffer it */
824N/A DPSAssertWarn(!oldBuf, cc, "problem converting binary token/sequence (oldBuf)");
824N/A if (nch < (unsigned) bst) {
824N/A cc->outBuf = (char *)DPScalloc(bst, 1);
824N/A }
824N/A else {
824N/A cc->outBuf = (char *)DPScalloc(m, 1);
824N/A }
824N/A cc->nOutBufChars = nch;
824N/A os_bcopy(buf, cc->outBuf, nch);
824N/A return;
824N/A }
824N/A
824N/A /* Assumes below that any error proc called uses dpsexcept.h
824N/A if it rips control away */
824N/A DURING
824N/A WriteEntireGoody(ctxt, (unsigned char *) buf, cc->numstringOffsets);
824N/A HANDLER
824N/A if (oldBuf) {
824N/A DPSAssertWarn(nch == m, cc, "some converted PostScript language may be lost during error recovery (nch!=m)");
824N/A free(buf);
824N/A }
824N/A RERAISE;
824N/A END_HANDLER
824N/A
824N/A if (oldBuf) {
824N/A DPSAssertWarn(nch == m, cc, "some converted PostScript language may be lost (nch!=m)");
824N/A free(buf);
824N/A buf = oldBuf;
824N/A nch = oldNch;
824N/A oldBuf = NIL;
824N/A }
824N/A else {
824N/A buf += m;
824N/A nch -= m;
824N/A }
824N/A } /* if (nch != 0) */
824N/A } /* while (nch > 0) */
824N/A} /* textInnerWritePostScript */
824N/A
824N/Astatic void textWritePostScript(
824N/A DPSContext ctxt, char *buf, unsigned int nch)
824N/A{
824N/A DPSContext children = ctxt->chainChild;
824N/A /* disconnect temporarily so that high level procs can
824N/A be called safely */
824N/A if (children != NIL) ctxt->chainChild = NIL;
824N/A DURING
824N/A textInnerWritePostScript(ctxt, buf, nch);
824N/A HANDLER
824N/A if (children != NIL) ctxt->chainChild = children;
824N/A RERAISE;
824N/A END_HANDLER
824N/A if (children != NIL) {
824N/A ctxt->chainChild = children;
824N/A DPSWritePostScript(ctxt->chainChild, buf, nch);
824N/A }
824N/A}
824N/A
824N/Astatic void textWriteStringChars(
824N/A DPSContext ctxt, char *buf, unsigned int nch)
824N/A{
824N/A DPSContext children = ctxt->chainChild;
824N/A
824N/A if (DPSCheckShared((DPSPrivContext)ctxt)) return;
824N/A /* disconnect temporarily so that high level procs can
824N/A be called safely */
824N/A if (children != NIL) ctxt->chainChild = NIL;
824N/A DURING
824N/A textInnerWritePostScript(ctxt, buf, nch);
824N/A HANDLER
824N/A if (children != NIL) ctxt->chainChild = children;
824N/A RERAISE;
824N/A END_HANDLER
824N/A if (children != NIL) {
824N/A ctxt->chainChild = children;
824N/A DPSWriteStringChars(ctxt->chainChild, buf, nch);
824N/A }
824N/A}
824N/A
824N/Astatic void textBinObjSeqWrite(
824N/A DPSContext ctxt, char *buf, unsigned int nch)
824N/A{
824N/A DPSContext children = ctxt->chainChild;
824N/A DPSPrivContext c = (DPSPrivContext) ctxt;
824N/A
824N/A if (DPSCheckShared(c)) return;
824N/A if (c->lastNameIndex < globLastNameIndex)
824N/A DPSUpdateNameMap(ctxt);
824N/A /* disconnect temporarily so that high level procs can
824N/A be called safely */
824N/A if (children != NIL) ctxt->chainChild = NIL;
824N/A DURING
824N/A textInnerWritePostScript(ctxt, buf, nch);
824N/A HANDLER
824N/A if (children != NIL) ctxt->chainChild = children;
824N/A RERAISE;
824N/A END_HANDLER
824N/A if (children != NIL) {
824N/A ctxt->chainChild = children;
824N/A DPSBinObjSeqWrite(ctxt->chainChild, buf, nch);
824N/A }
824N/A}
824N/A
824N/Astatic void textWriteNumstring(
824N/A DPSContext ctxt,
824N/A DPSDefinedType type,
824N/A char *data,
824N/A unsigned int size,
824N/A int scale)
824N/A{
824N/A DPSPrivContext cc = (DPSPrivContext) ctxt;
824N/A#define BUFFER_GROW 10
824N/A
824N/A if (cc->contextFlags & DPS_FLAG_CONVERT_NUMSTRINGS) {
824N/A if (cc->numstringOffsets == NULL) {
824N/A cc->numstringOffsets = (int *) DPScalloc(sizeof(int),
824N/A BUFFER_GROW + 2);
824N/A cc->numstringOffsets[0] = BUFFER_GROW + 2; /* Current size */
824N/A cc->numstringOffsets[1] = 2; /* Next slot */
824N/A } else if (cc->numstringOffsets[1] >= cc->numstringOffsets[0]) {
824N/A cc->numstringOffsets[0] += BUFFER_GROW;
824N/A cc->numstringOffsets =
824N/A (int *) realloc(cc->numstringOffsets,
824N/A sizeof(int)* cc->numstringOffsets[0]);
824N/A }
824N/A
824N/A /* Subtract 4 because of binary object sequence header */
824N/A cc->numstringOffsets[cc->numstringOffsets[1]] = cc->nOutBufChars - 4;
824N/A cc->numstringOffsets[1] += 1;
824N/A }
824N/A
824N/A innerProcWriteNumstring(ctxt, type, data, size, scale, textInnerWritePostScript);
824N/A#undef BUFFER_GROW
824N/A} /* textWriteNumstring */
824N/A
824N/A/*********************/
824N/A/* Public procedures */
824N/A/*********************/
824N/A
824N/A/********************************************/
824N/A/* Public procs for dealing with user names */
824N/A
824N/Achar *DPSNameFromIndex(long int index)
824N/A{
824N/A if (DPSglobals == NIL || index < 0 || index > globLastNameIndex
824N/A || userNameDict == NIL)
824N/A return NIL;
824N/A return (char *) userNames[index];
824N/A}
824N/A
824N/Avoid DPSMapNames(
824N/A DPSContext ctxt,
824N/A unsigned int nNames,
824N/A char **names,
824N/A int **indices)
824N/A{
824N/A unsigned i;
824N/A char *last = names[0];
824N/A
824N/A DPSCheckInitClientGlobals();
824N/A
824N/A#define USERNAMEDICTLENGTH 100
824N/A
824N/A if (userNameDict == NIL) {
824N/A userNameDict = DPSCreatePSWDict(USERNAMEDICTLENGTH);
824N/A userNames = (char **)DPScalloc(sizeof(char *), USERNAMEDICTLENGTH);
824N/A userNamesLength = USERNAMEDICTLENGTH;
824N/A }
824N/A
824N/A for (i = 0; i < nNames; i++) {
824N/A integer j;
824N/A char *n = names[i];
824N/A DPSContext c;
824N/A
824N/A if (n == NIL)
824N/A n = last;
824N/A else
824N/A last = n;
824N/A DPSAssert(n != NIL);
824N/A if (strlen(n) > 128) {
824N/A DPSSafeSetLastNameIndex(ctxt);
824N/A (*ctxt->errorProc)(ctxt, dps_err_nameTooLong, (unsigned long) n, strlen(n));
824N/A return;
824N/A }
824N/A j = DPSWDictLookup(userNameDict, n);
824N/A if (j >= 0) {
824N/A *(indices[i]) = j;
824N/A /* handle the case where another context in another space has
824N/A defined this name */
824N/A if (((DPSPrivContext)ctxt)->lastNameIndex < j)
824N/A DPSUpdateNameMap(ctxt);
824N/A }
824N/A else {
824N/A /* handle other cases where another context in another
824N/A space has defined names */
824N/A if (((DPSPrivContext)ctxt)->lastNameIndex < globLastNameIndex)
824N/A DPSUpdateNameMap(ctxt);
824N/A globLastNameIndex++;
824N/A if (((globLastNameIndex + 1) > userNamesLength)) {
824N/A char **t = (char **)DPScalloc(sizeof(char *),
824N/A userNamesLength + USERNAMEDICTLENGTH);
824N/A for (j = 0; j < userNamesLength; j++) {
824N/A t[j] = userNames[j];
824N/A }
824N/A free(userNames);
824N/A userNames = t;
824N/A userNamesLength += USERNAMEDICTLENGTH;
824N/A }
824N/A userNames[globLastNameIndex] = n;
824N/A DPSWDictEnter(userNameDict, n, globLastNameIndex);
824N/A *(indices[i]) = globLastNameIndex;
824N/A DPSPrintf(ctxt, "%d /%s defineusername\n", globLastNameIndex, n);
824N/A for (c = ctxt; c != NIL; c = c->chainChild)
824N/A ((DPSPrivContext)c)->lastNameIndex = globLastNameIndex;
824N/A }
824N/A } /* for */
824N/A}
824N/A
824N/A/**********************/
824N/A/* Other public procs */
824N/A
824N/Avoid DPSDefaultErrorProc(
824N/A DPSContext ctxt,
824N/A DPSErrorCode errorCode,
824N/A long unsigned int arg1, long unsigned int arg2)
824N/A{
824N/A
824N/A DPSTextProc textProc = DPSGetCurrentTextBackstop();
824N/A
824N/A char *prefix = "%%[ Error: ";
824N/A char *suffix = " ]%%\n";
824N/A
824N/A char *infix = "; OffendingCommand: ";
824N/A char *nameinfix = "User name too long; Name: ";
824N/A char *contextinfix = "Invalid context: ";
824N/A char *taginfix = "Unexpected wrap result tag: ";
824N/A char *typeinfix = "Unexpected wrap result type; tag: ";
824N/A
824N/A switch (errorCode) {
824N/A case dps_err_ps: {
824N/A char *buf = (char *)arg1;
824N/A DPSBinObj ary = (DPSBinObj) (buf+DPS_HEADER_SIZE);
824N/A DPSBinObj elements;
824N/A char *error, *errorName;
824N/A integer errorCount, errorNameCount;
824N/A boolean resyncFlg;
824N/A
824N/A if ((ary->attributedType & 0x7f) != DPS_ARRAY
824N/A || ary->length != 4) {
824N/A DPSHandleBogusError(ctxt, prefix, suffix);
824N/A }
824N/A
824N/A elements = (DPSBinObj)(((char *) ary) + ary->val.arrayVal);
824N/A
824N/A errorName = (char *)(((char *) ary) + elements[1].val.nameVal);
824N/A errorNameCount = elements[1].length;
824N/A
824N/A error = (char *)(((char *) ary) + elements[2].val.nameVal);
824N/A errorCount = elements[2].length;
824N/A
824N/A resyncFlg = elements[3].val.booleanVal;
824N/A
824N/A if (textProc != NIL) {
824N/A (*textProc)(ctxt, prefix, strlen(prefix));
824N/A (*textProc)(ctxt, errorName, errorNameCount);
824N/A (*textProc)(ctxt, infix, strlen(infix));
824N/A (*textProc)(ctxt, error, errorCount);
824N/A (*textProc)(ctxt, suffix, strlen(suffix));
824N/A }
824N/A if (resyncFlg && (ctxt != dummyCtx) && (ctxt != NULL)) {
824N/A#if 0 /* Postpone the raise 'til later to avoid RAISEing through Xlib */
824N/A RAISE(dps_err_ps, (char *) ctxt);
824N/A DPSCantHappen();
824N/A#else
824N/A DPSPrivContext cc = (DPSPrivContext) ctxt;
824N/A cc->resyncing = true;
824N/A#endif
824N/A }
824N/A break;
824N/A }
824N/A case dps_err_nameTooLong:
824N/A if (textProc != NIL) {
824N/A char *buf = (char *)arg1;
824N/A (*textProc)(ctxt, prefix, strlen(prefix));
824N/A (*textProc)(ctxt, nameinfix, strlen(nameinfix));
824N/A (*textProc)(ctxt, buf, arg2);
824N/A (*textProc)(ctxt, suffix, strlen(suffix));
824N/A }
824N/A break;
824N/A case dps_err_invalidContext:
824N/A if (textProc != NIL) {
824N/A char m[100];
824N/A (void) sprintf(m, "%s%s%ld%s", prefix, contextinfix, arg1, suffix);
824N/A (*textProc)(ctxt, m, strlen(m));
824N/A }
824N/A break;
824N/A case dps_err_resultTagCheck:
824N/A if (textProc != NIL) {
824N/A char m[100];
824N/A unsigned char tag = *((unsigned char *) arg1+1);
824N/A (void) sprintf(m, "%s%s%d%s", prefix, taginfix, tag, suffix);
824N/A (*textProc)(ctxt, m, strlen(m));
824N/A }
824N/A break;
824N/A case dps_err_resultTypeCheck:
824N/A if (textProc != NIL) {
824N/A char m[100];
824N/A unsigned char tag = *((unsigned char *) arg1+1);
824N/A (void) sprintf(m, "%s%s%d%s", prefix, typeinfix, tag, suffix);
824N/A (*textProc)(ctxt, m, strlen(m));
824N/A }
824N/A break;
824N/A default:
824N/A DPSDefaultPrivateHandler(ctxt, errorCode, arg1, arg2, prefix, suffix);
824N/A break;
824N/A }
824N/A} /* DPSDefaultErrorProc */
824N/A
824N/Avoid DPSCheckRaiseError(DPSContext c)
824N/A{
824N/A DPSPrivContext cc = (DPSPrivContext) c;
824N/A if (cc != NULL && cc->resyncing) {
824N/A cc->resyncing = false;
824N/A RAISE(dps_err_ps, (char *) c);
824N/A DPSCantHappen();
824N/A }
824N/A}
824N/A
824N/A/**************************************/
824N/A/* Public procs for creating contexts */
824N/A
824N/A/* dps_err_invalidAccess is now defined for all clients. */
824N/A
824N/Astatic void textAwaitReturnValues(DPSContext ctxt)
824N/A{
824N/A (*ctxt->errorProc)(ctxt, dps_err_invalidAccess, 0, 0);
824N/A}
824N/A
824N/Astatic void Noop(void)
824N/A{
824N/A}
824N/A
824N/ADPSContext DPSCreateTextContext(
824N/A DPSTextProc textProc, DPSErrorProc errorProc)
824N/A{
824N/A DPSPrivContext c;
824N/A
824N/A if (DPSInitialize () != 0) return((DPSContext) NIL);
824N/A if (!textCtxProcs) {
824N/A textCtxProcs = (DPSProcs)DPScalloc(sizeof(DPSProcsRec), 1);
824N/A DPSInitCommonTextContextProcs(textCtxProcs);
824N/A DPSInitSysNames();
824N/A }
824N/A
824N/A c = (DPSPrivContext)DPScalloc(sizeof(DPSPrivContextRec), 1);
824N/A c->textProc = textProc;
824N/A c->procs = textCtxProcs;
824N/A c->textProc = textProc;
824N/A c->errorProc = errorProc;
824N/A c->programEncoding = dps_ascii;
824N/A c->nameEncoding = dps_strings; /* don't write user name indices on a file */
824N/A c->contextFlags = DPS_FLAG_CONVERT_NUMSTRINGS; /* Convert by default */
824N/A c->numFormat = DPSDefaultNumFormat;
824N/A c->numstringOffsets = NULL;
824N/A c->lastNameIndex = -1;
824N/A
824N/A /* Setup a dummy space */
824N/A if (textSpace == NIL)
824N/A {
824N/A textSpace = (DPSPrivSpace) DPScalloc(sizeof (DPSPrivSpaceRec), 1);
824N/A textSpace->procs = (DPSSpaceProcs) DPScalloc(sizeof (DPSSpaceProcsRec), 1);
824N/A textSpace->procs->DestroySpace = (DPSSpaceProc) Noop;
824N/A textSpace->lastNameIndex = -1;
824N/A DPSInitPrivateSpaceFields(textSpace);
824N/A }
824N/A c->space = (DPSSpace) textSpace;
824N/A
824N/A DPSInitPrivateTextContextFields(c, textSpace);
824N/A return (DPSContext)c;
824N/A} /* DPSCreateTextContext */
824N/A
824N/A
824N/Astatic DPSContext CreateDummyContext(void)
824N/A{
824N/A DPSPrivContext c;
824N/A
824N/A DPSCheckInitClientGlobals();
824N/A if (!dummyCtxProcs) {
824N/A dummyCtxProcs = (DPSProcs)DPScalloc(sizeof(DPSProcsRec), 1);
824N/A dummyCtxProcs->BinObjSeqWrite = (DPSContextBufProc) Noop;
824N/A dummyCtxProcs->WriteTypedObjectArray = (DPSContextTypedArrayProc) Noop;
824N/A dummyCtxProcs->WriteStringChars = (DPSContextBufProc) Noop;
824N/A dummyCtxProcs->WritePostScript = (DPSContextBufProc) Noop;
824N/A dummyCtxProcs->WriteData = (DPSContextBufProc) Noop;
824N/A dummyCtxProcs->FlushContext = (DPSContextProc) Noop;
824N/A dummyCtxProcs->ResetContext = (DPSContextProc) Noop;
824N/A dummyCtxProcs->WaitContext = (DPSContextProc) Noop;
824N/A dummyCtxProcs->UpdateNameMap = (DPSContextProc) Noop;
824N/A dummyCtxProcs->AwaitReturnValues = (DPSContextProc) Noop;
824N/A dummyCtxProcs->Interrupt = (DPSContextProc) Noop;
824N/A dummyCtxProcs->DestroyContext = (DPSContextProc) Noop;
824N/A dummyCtxProcs->WriteNumString = (DPSWriteNumStringProc) Noop;
824N/A }
824N/A
824N/A c = (DPSPrivContext)DPScalloc(sizeof(DPSPrivContextRec), 1);
824N/A c->procs = dummyCtxProcs;
824N/A c->programEncoding = DPSDefaultProgramEncoding;
824N/A c->nameEncoding = DPSDefaultNameEncoding; /* don't care */
824N/A c->numFormat = DPSDefaultNumFormat;
824N/A c->lastNameIndex = -1;
824N/A c->numstringOffsets = NULL;
824N/A
824N/A return (DPSContext)c;
824N/A} /* CreateDummyContext */
824N/A
824N/Avoid DPSSetTextBackstop(DPSTextProc textProc)
824N/A{
824N/A DPSCheckInitClientGlobals();
824N/A if (!dummyCtx) dummyCtx = CreateDummyContext();
824N/A dummyCtx->textProc = textProc;
824N/A}
824N/A
824N/ADPSTextProc DPSGetCurrentTextBackstop(void)
824N/A{
824N/A DPSCheckInitClientGlobals();
824N/A if (dummyCtx == NIL) return NIL;
824N/A else return dummyCtx->textProc;
824N/A}
824N/A
824N/Avoid DPSSetErrorBackstop(DPSErrorProc errorProc)
824N/A{
824N/A DPSCheckInitClientGlobals();
824N/A if (!dummyCtx) dummyCtx = CreateDummyContext();
824N/A dummyCtx->errorProc = errorProc;
824N/A}
824N/A
824N/ADPSErrorProc DPSGetCurrentErrorBackstop(void)
824N/A{
824N/A DPSCheckInitClientGlobals();
824N/A if (dummyCtx == NIL) return NIL;
824N/A else return dummyCtx->errorProc;
824N/A}
824N/A
824N/Astatic void NoteInitFailure(DPSContext ctxt, char *buf, long unsigned length)
824N/A{
824N/A initFailed = -1;
824N/A}
824N/A
824N/Aint DPSInitialize(void)
824N/A{
824N/A DPSCheckInitClientGlobals();
824N/A if (!clientStarted) {
824N/A clientStarted = true;
824N/A initFailed = 0;
824N/A DPSInitClient(NoteInitFailure, ReleaseInput); /* may call DPSCreateContext */
824N/A /* textProc will not be used unless DPS initialization fails */
824N/A }
824N/A return initFailed;
824N/A}
824N/A
824N/ADPSContext DPSCreateContext(
824N/A char *wh,
824N/A DPSTextProc textProc,
824N/A DPSErrorProc errorProc,
824N/A DPSSpace space)
824N/A{
824N/A
824N/A DPSPrivSpace ss;
824N/A DPSPrivContext c;
824N/A
824N/A if (DPSInitialize() != 0) return NIL;
824N/A
824N/A if (!ctxProcs) {
824N/A ctxProcs = (DPSProcs)DPScalloc(sizeof(DPSProcsRec), 1);
824N/A ctxProcs->BinObjSeqWrite = procBinObjSeqWrite;
824N/A ctxProcs->WriteTypedObjectArray = writeTypedObjectArray;
824N/A ctxProcs->WriteStringChars = procWriteStringChars;
824N/A ctxProcs->WritePostScript = procWritePostScript;
824N/A ctxProcs->WriteData = procWriteData;
824N/A ctxProcs->UpdateNameMap = procUpdateNameMap;
824N/A ctxProcs->Interrupt = procInterrupt;
824N/A ctxProcs->WriteNumString = (DPSWriteNumStringProc) procWriteNumstring;
824N/A }
824N/A if (!spaceProcs) {
824N/A spaceProcs = (DPSSpaceProcs)DPScalloc(sizeof(DPSSpaceProcsRec), 1);
824N/A DPSInitCommonSpaceProcs(spaceProcs);
824N/A }
824N/A
824N/A ss = (DPSPrivSpace)space;
824N/A
824N/A if (ss == NIL) {
824N/A ss = (DPSPrivSpace)DPScalloc(sizeof(DPSPrivSpaceRec), 1);
824N/A ss->procs = spaceProcs;
824N/A ss->lastNameIndex = -1;
824N/A ss->next = spaces;
824N/A DPSAssert(ss->next != ss);
824N/A spaces = ss;
824N/A DPSInitPrivateSpaceFields(ss);
824N/A }
824N/A
824N/A if (ss->wh == NIL) ss->wh = wh; /* KLUDGE to support DPSSendDestroySpace */
824N/A
824N/A c = (DPSPrivContext)DPScalloc(sizeof(DPSPrivContextRec), 1);
824N/A c->procs = ctxProcs;
824N/A c->wh = wh;
824N/A c->textProc = textProc;
824N/A c->errorProc = errorProc;
824N/A c->programEncoding = DPSDefaultProgramEncoding;
824N/A c->nameEncoding = DPSDefaultNameEncoding;
824N/A c->lastNameIndex = -1;
824N/A c->space = (DPSSpace)ss;
824N/A c->numstringOffsets = NULL;
824N/A
824N/A c->next = ss->firstContext;
824N/A DPSAssert(c->next != c);
824N/A ss->firstContext = c;
824N/A
824N/A DPSInitPrivateContextFields(c, ss);
824N/A
824N/A c->numFormat = DPSCreatePrivContext(
824N/A (XDPSPrivContext)wh,
824N/A (DPSContext)c,
824N/A (ContextPSID *)&c->cid,
824N/A (SpaceXID *)&ss->sid,
824N/A (space == NIL), DPSclientPrintProc);
824N/A if (c->numFormat == (DPSNumFormat) -1)
824N/A { /* can't create the context */
824N/A if (space == NIL) {
824N/A spaces = ss->next;
824N/A free(ss);
824N/A }
824N/A else ss->firstContext = c->next;
824N/A free(c);
824N/A return NIL;
824N/A }
824N/A else return (DPSContext)c;
824N/A} /* DPSCreateContext */
824N/A
824N/Achar *DPSSetWh(
824N/A DPSContext ctxt,
824N/A char *newWh)
824N/A{
824N/A DPSPrivContext cc = (DPSPrivContext) ctxt;
824N/A char *tmp = cc->wh;
824N/A cc->wh = newWh;
824N/A return(tmp);
824N/A}
824N/A
824N/A/*
824N/A The chainParent field is non-NIL if this context automatically receives
824N/A a copy of the PostScript code sent to the referenced (parent) context.
824N/A
824N/A The chainChild field is non-NIL if this context automatically sends along
824N/A to the referenced (child) context a copy of any PostScript code received.
824N/A*/
824N/Aint DPSChainContext(DPSContext parent, DPSContext child)
824N/A{
824N/A DPSContext cc = child->chainChild;
824N/A
824N/A if (child->chainParent != NIL)
824N/A return -1; /* report an error */
824N/A
824N/A /* insert new child between parent and existing children */
824N/A child->chainChild = parent->chainChild;
824N/A if (parent->chainChild != NIL) {
824N/A DPSAssertWarn(parent->chainChild->chainParent == parent, (DPSPrivContext)parent, "attempting to chain context on invalid chain");
824N/A child->chainChild->chainParent = child;
824N/A }
824N/A child->chainParent = parent;
824N/A parent->chainChild = child;
824N/A /* if child has children, recursively chain them */
824N/A if (cc != NIL) {
824N/A cc->chainParent = NIL;
824N/A (void) DPSChainContext(child, cc);
824N/A }
824N/A return 0;
824N/A}
824N/A
824N/Avoid DPSUnchainContext(DPSContext ctxt)
824N/A{
824N/A DPSContext p = ctxt->chainParent;
824N/A DPSContext c = ctxt->chainChild;
824N/A
824N/A if (p != NIL) { /* remove ctxt from parent's chain */
824N/A DPSAssertWarn(p->chainChild == ctxt, (DPSPrivContext)p, "attempting to unchain context from wrong chain (parent)");
824N/A p->chainChild = c;
824N/A ctxt->chainParent = NIL;
824N/A }
824N/A if (c != NIL) { /* remove ctxt's child (if any) from ctxt's chain */
824N/A DPSAssertWarn(c->chainParent == ctxt, (DPSPrivContext)c, "attempting to unchain context from wrong chain (child)");
824N/A c->chainParent = p;
824N/A ctxt->chainChild = NIL;
824N/A }
824N/A}
824N/A
824N/A/****************/
824N/A/* Veneer procs */
824N/A
824N/Avoid DPSAwaitReturnValues(DPSContext ctxt)
824N/A{
824N/A (*(ctxt)->procs->AwaitReturnValues)((ctxt));
824N/A}
824N/A
824N/Avoid DPSDestroyContext(DPSContext ctxt)
824N/A{
824N/A (*(ctxt)->procs->DestroyContext)((ctxt));
824N/A}
824N/A
824N/Avoid DPSDestroySpace(DPSSpace spc)
824N/A{
824N/A (*(spc)->procs->DestroySpace)((spc));
824N/A}
824N/A
824N/Avoid DPSFlushContext(DPSContext ctxt)
824N/A{
824N/A (*(ctxt)->procs->FlushContext)((ctxt));
824N/A}
824N/A
824N/ADPSContext DPSGetCurrentContext(void) { return DPSGlobalContext; }
824N/A
824N/Avoid DPSInterruptContext(DPSContext ctxt)
824N/A{
824N/A (*(ctxt)->procs->Interrupt)((ctxt));
824N/A}
824N/A
824N/ADPSContext DPSPrivCurrentContext(void) { return DPSGlobalContext; }
824N/A
824N/Avoid DPSResetContext(DPSContext ctxt)
824N/A{
824N/A (*(ctxt)->procs->ResetContext)((ctxt));
824N/A}
824N/A
824N/Avoid DPSSetResultTable(
824N/A register DPSContext ctxt,
824N/A DPSResults tbl,
824N/A unsigned int len)
824N/A{
824N/A (ctxt)->resultTable = (tbl);
824N/A (ctxt)->resultTableLength = (len);
824N/A}
824N/A
824N/Avoid DPSSetContext(
824N/A DPSContext ctxt)
824N/A{
824N/A DPSGlobalContext = ctxt;
824N/A}
824N/A
824N/Avoid DPSUpdateNameMap(
824N/A DPSContext ctxt)
824N/A{
824N/A (*(ctxt)->procs->UpdateNameMap)((ctxt));
824N/A}
824N/A
824N/Avoid DPSWaitContext(
824N/A DPSContext ctxt)
824N/A{
824N/A (*(ctxt)->procs->WaitContext)(ctxt);
824N/A}
824N/A
824N/Avoid DPSBinObjSeqWrite(
824N/A DPSContext ctxt,
824N/A char *buf,
824N/A unsigned int count)
824N/A{
824N/A (*(ctxt)->procs->BinObjSeqWrite)((ctxt), (buf), (count));
824N/A}
824N/A
824N/Avoid DPSWriteData(
824N/A DPSContext ctxt,
824N/A char *buf,
824N/A unsigned int count)
824N/A{
824N/A (*(ctxt)->procs->WriteData)((ctxt), (buf), (count));
824N/A}
824N/A
824N/Avoid DPSWritePostScript(
824N/A DPSContext ctxt,
824N/A char *buf,
824N/A unsigned int count)
824N/A{
824N/A (*(ctxt)->procs->WritePostScript)((ctxt), (buf), (count));
824N/A}
824N/A
824N/Avoid DPSWriteStringChars(
824N/A DPSContext ctxt,
824N/A char *buf,
824N/A unsigned int count)
824N/A{
824N/A (*(ctxt)->procs->WriteStringChars)((ctxt), (buf), (count));
824N/A}
824N/A
824N/Avoid DPSWriteNumString(ctxt, type, data, size, scale)
824N/A DPSContext ctxt;
824N/A DPSDefinedType type;
824N/A char *data;
824N/A unsigned int size;
824N/A int scale;
824N/A{
824N/A (*(ctxt)->procs->WriteNumString)((ctxt), (type), (data), (size), (scale));
824N/A}
824N/A
824N/Avoid DPSWriteTypedObjectArray(ctxt, type, array, length)
824N/A DPSContext ctxt;
824N/A DPSDefinedType type;
824N/A char *array;
824N/A unsigned int length; {
824N/A (*(ctxt)->procs->WriteTypedObjectArray)((ctxt), (type), (array), (length));
824N/A }
824N/A
824N/Avoid DPSInitCommonTextContextProcs(DPSProcs p)
824N/A{
824N/A p->BinObjSeqWrite = textBinObjSeqWrite;
824N/A p->WriteTypedObjectArray = writeTypedObjectArray;
824N/A p->WriteStringChars = textWriteStringChars;
824N/A p->WritePostScript = textWritePostScript;
824N/A p->WriteData = textWriteData;
824N/A p->FlushContext = textFlushContext;
824N/A p->ResetContext = (DPSContextProc) Noop;
824N/A p->WaitContext = (DPSContextProc) Noop;
824N/A p->UpdateNameMap = procUpdateNameMap;
824N/A p->AwaitReturnValues = textAwaitReturnValues;
824N/A p->Interrupt = textInterruptContext;
824N/A p->DestroyContext = textDestroyContext;
824N/A p->WriteNumString = (DPSWriteNumStringProc) textWriteNumstring;
824N/A}
824N/A
824N/Avoid DPSInitCommonContextProcs(DPSProcs p)
824N/A{
824N/A p->BinObjSeqWrite = procBinObjSeqWrite;
824N/A p->WriteTypedObjectArray = writeTypedObjectArray;
824N/A p->WriteStringChars = procWriteStringChars;
824N/A p->WritePostScript = procWritePostScript;
824N/A p->WaitContext = procWaitContext;
824N/A p->DestroyContext = procDestroyContext;
824N/A p->WriteData = procWriteData;
824N/A p->UpdateNameMap = procUpdateNameMap;
824N/A p->Interrupt = procInterrupt;
824N/A p->WriteNumString = (DPSWriteNumStringProc) procWriteNumstring;
824N/A}
824N/A
824N/Avoid DPSInitCommonSpaceProcs(DPSSpaceProcs p)
824N/A{
824N/A p->DestroySpace = procDestroySpace;
824N/A}
824N/A
824N/Avoid DPSSetNumStringConversion(ctxt, flag)
824N/A DPSContext ctxt;
824N/A int flag;
824N/A{
824N/A if (flag) ctxt->contextFlags |= DPS_FLAG_CONVERT_NUMSTRINGS;
824N/A else ctxt->contextFlags &= ~DPS_FLAG_CONVERT_NUMSTRINGS;
824N/A}
824N/A
824N/Avoid DPSSetWrapSynchronization(ctxt, flag)
824N/A DPSContext ctxt;
824N/A int flag;
824N/A{
824N/A if (flag) ctxt->contextFlags |= DPS_FLAG_SYNC;
824N/A else ctxt->contextFlags &= ~DPS_FLAG_SYNC;
824N/A}
824N/A
824N/Avoid DPSSuppressBinaryConversion(ctxt, flag)
824N/A DPSContext ctxt;
824N/A int flag;
824N/A{
824N/A if (flag) ctxt->contextFlags |= DPS_FLAG_NO_BINARY_CONVERSION;
824N/A else ctxt->contextFlags &= ~DPS_FLAG_NO_BINARY_CONVERSION;
824N/A}
824N/A
824N/Avoid DPSSetAbbrevMode(ctxt, flag)
824N/A DPSContext ctxt;
824N/A int flag;
824N/A{
824N/A if (flag) ctxt->contextFlags |= DPS_FLAG_USE_ABBREVS;
824N/A else ctxt->contextFlags &= ~DPS_FLAG_USE_ABBREVS;
824N/A}
824N/A
824N/ADPSContextExtensionRec *DPSGetContextExtensionRec(ctxt, extensionId)
824N/A DPSContext ctxt;
824N/A int extensionId;
824N/A{
824N/A DPSContextExtensionRec *r = ctxt->extension;
824N/A
824N/A while (r != NULL && r->extensionId != extensionId) r = r->next;
824N/A return r;
824N/A}
824N/A
824N/Avoid DPSAddContextExtensionRec(ctxt, rec)
824N/A DPSContext ctxt;
824N/A DPSContextExtensionRec *rec;
824N/A{
824N/A rec->next = ctxt->extension;
824N/A ctxt->extension = rec;
824N/A}
824N/A
824N/ADPSContextExtensionRec *DPSRemoveContextExtensionRec(ctxt, extensionId)
824N/A DPSContext ctxt;
824N/A int extensionId;
824N/A{
824N/A DPSContextExtensionRec *rret, **r = &ctxt->extension;
824N/A
824N/A
824N/A while (*r != NULL && (*r)->extensionId != extensionId) {
824N/A r = &(*r)->next;
824N/A }
824N/A rret = *r;
824N/A if (*r != NULL) *r = (*r)->next;
824N/A return rret;
824N/A}
824N/A
824N/Aint DPSGenerateExtensionRecID(void)
824N/A{
824N/A static int id = 1;
824N/A
824N/A return id++;
824N/A}
824N/A
824N/ADPSContextType DPSGetContextType(ctxt)
824N/A DPSContext ctxt;
824N/A{
824N/A DPSPrivContext c = (DPSPrivContext) ctxt;
824N/A
824N/A if (c->procs == textCtxProcs) return dps_context_text;
824N/A else return dps_context_execution;
824N/A}