#include #include "encoding.h" #include "pstoctable.h" #include "psio.h" /* Make it recognize raster files, and skip over them? */ #define RAS_MAGIC 0x59a66a95 char *system_tokens[] = { "arc", "ashow", "awidthshow", "closepath", "def", "dup", "exch", "fill", "findfont", "grestore", "gsave", "lineto", "moveto", "pop", "rlineto", "rmoveto", "scalefont", "setcolor", "setfont", "setgray", "show", "stroke", "translate", "widthshow", "abs", "add", "aload", "anchorsearch", "and", "arccos", "arcn", "arcsin", "arctan", "arcto", "array", "astore", "atan", "awaitevent", "begin", "bitshift", "buildimage", "clipcanvaspath", "cleartomark", "canvastobottom", "canvastotop", "ceiling", "charpath", "clear", "clip", "clipcanvas", "clippath", "closefile", "createmonitor", "concat", "concatmatrix", "contrastswithcurrent", "controlpoint", "copy", "copyarea", "cos", "countinputqueue", "counttomark", "newcanvas", "createevent", "createoverlay", "currentcanvas", "currentcolor", "currentdash", "currentdict", "currentfile", "currentflat", "currentfont", "currentgray", "currenthsbcolor", "currentlinecap", "currentlinejoin", "currentlinewidth", "currentmatrix", "currentmiterlimit", "currentcursorlocation", "currentpath", "currentpoint", "currentprintermatch", "currentprocess", "currentrgbcolor", "currenttime", "curveto", "cvi", "cvlit", "cvn", "cvr", "cvs", "cvx", "damagepath", "dict", "dictstack", "redistributeevent", "div", "dtransform", "emptypath", "end", "eoclip", "eoclipcanvas", "eocopyarea", "eocurrentpath", "eofill", "eoreshapecanvas", "eq", "erasepage", "exec", "executeonly", "exit", "exp", "revokeinterest", "expressinterest", "false", "file", "flattenpath", "floor", "for", "forall", "fork", "forkunix", "cvrs", "ge", "get", "getcanvaslocation", "getcanvasshape", "currentrasteropcode", "currentstate", "getcanvascursor", "getenv", "unblockinputqueue", "getinterval", "grestoreall", "gt", "hsbcolor", "idiv", "idtransform", "if", "ifelse", "image", "imagecanvas", "imagemaskcanvas", "index", "initclip", "initgraphics", "initmatrix", "insertcanvasabove", "insertcanvasbelow", "invertmatrix", "itransform", "min", "known", "kshow", "le", "length", "ln", "load", "log", "loop", "lt", "makefont", "max", "random", "mark", "matrix", "maxlength", "mod", "pathforallvec", "movecanvas", "mul", "ne", "neg", "newpath", "not", "null", "or", "pause", "pathbbox", "pathforall", "print", "put", "putinterval", "rcheck", "rcurveto", "read", "readcanvas", "readhexstring", "readline", "readstring", "repeat", "rcontrolpoint", "setcursorlocation", "reversepath", "rgbcolor", "roll", "rotate", "round", "scale", "search", "sendevent", "setcanvas", "reshapecanvas", "setdash", "setrasteropcode", "setstate", "setcanvascursor", "putenv", "setlinequality", "currentlinequality", "setfileinputtoken", "setflat", "sethsbcolor", "setlinecap", "setlinejoin", "setlinewidth", "setmatrix", "setmiterlimit", "setprintermatch", "setrgbcolor", "showpage", "sin", "sqrt", "status", "stop", "stopped", "store", "string", "stringwidth", "strokepath", "sub", "systemdict", "tagprint", "token", "pointinpath", "setpath", "transform", "true", "truncate", "type", "typedprint", "undef", "userdict", "usertime", "waitprocess", "where", "write", "writehexstring", "writestring", }; #define case4(tag) case tag: case tag+1: case tag+2: case tag+3 #define case16(tag) case4(tag):case4(tag+4):case4(tag+8):case4(tag+12) #define case32(tag) case16(tag):case16(tag+16) main (argc, argv) int argc; char **argv; { register int c, temp; while ((c = getchar ()) != EOF) { switch (c) { case16(enc_int): { register n; temp = c; c = getchar(); n = (char) c; while (temp & 3) { --temp; n = (n << 8) | getchar(); } if ((temp >> 2) & 3) { printf(" %g ", ((double) n) / (1 << (((temp >> 2) & 3) * 8))); } else { printf(" %d ", n); } } break; case16(enc_short_string): temp = c & 017; goto read_encoded_string; case enc_IEEEfloat: { union { float f; long n; } u; u.n = getchar(); u.n = (u.n << 8) | getchar(f); u.n = (u.n << 8) | getchar(f); u.n = (u.n << 8) | getchar(f); #if defined(vax) /* This call is dangerous, the first instance of * u is treated as a long and the second instance as * float. The conversion is returned in the second u. * If the following routine is modified, on must be * careful to isolate the values. */ ieee_vax_float(&u.n, &u.f); #endif printf(" %f ", u.f); } break; case4(enc_string): temp = 0; { register i = c & 3; do { temp = (temp << 8) | getchar(f); } while (--i >= 0); } read_encoded_string: putchar('('); while (--temp >= 0) { c = getchar(); switch (c) { case 8: printf ("\\b"); break; case 12: printf ("\\f"); break; case 10: printf ("\\n"); break; case 13: printf ("\\r"); break; case 9: printf ("\\t"); break; case '(': printf ("\\("); break; case ')': printf ("\\)"); break; case '\\': printf ("\\\\"); break; default: if (c < 32) printf ("\\%3o", c); else putchar (c); break; } } putchar (')'); break; case32(enc_syscommon): printf(" %s\n", system_tokens[c - enc_syscommon]); break; case enc_syscommon2: if (((temp = getchar() + 32) < 32) || (temp >= (sizeof(system_tokens) / sizeof(char *)))) { printf("\n%% BOGUS enc_syscommon2 token 0x%x 0x%x\n", c, temp); } else { printf(" %s\n", system_tokens[temp]); } break; default: if (c > 128) { printf ("\n%% BOGUS token 0x%x:\n%c\n", c, c); } else { putchar (c); } break; } } } #if defined(vax) /* What IEEE single precision floating point looks like on a Vax */ struct ieee_single { unsigned int mant: 23; unsigned int exp : 8; unsigned int sign : 1; }; /* Vax single precision floating point */ struct vax_single { unsigned int mant1 : 7; unsigned int exp : 8; unsigned int sign : 1; unsigned int mant2 : 16; }; #define VAX_SNG_BIAS 0x81 #define IEEE_SNG_BIAS 0x7f static struct sgl_limits { struct vax_single s; struct ieee_single ieee; } sgl_limits[2] = { {{ 0x7f, 0xff, 0x0, 0xffff }, /* Max Vax */ { 0x0, 0xff, 0x0 }}, /* Max IEEE */ {{ 0x0, 0x0, 0x0, 0x0 }, /* Min Vax */ { 0x0, 0x0, 0x0 }} /* Min IEEE */ }; /* Thsi routine is typically called with lp, and rfp pointing to * the same location (as a union). You can not modify part of rfp * and expect lp not to be changed. */ ieee_vax_float(lp, rfp) register long *lp; register float *rfp; { struct ieee_single is; struct vax_single *vsp; struct sgl_limits *lim; int i; is = *((struct ieee_single *)lp); vsp = (struct vax_single *)rfp; for (i = 0, lim = sgl_limits; i < sizeof(sgl_limits)/sizeof(struct sgl_limits); i++, lim++) { if ((is.exp == lim->ieee.exp) && (is.mant == lim->ieee.mant)) { *vsp = lim->s; goto returnit; } } vsp->exp = is.exp - IEEE_SNG_BIAS + VAX_SNG_BIAS; vsp->mant2 = is.mant; vsp->mant1 = (is.mant >> 16); returnit: vsp->sign = is.sign; } #endif