Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!rsalz From: rsalz@uunet.UU.NET (Rich Salz) Newsgroups: comp.sources.unix Subject: v12i056: A PostScript interpreter, Part07/18 Message-ID: <2854@uunet.UU.NET> Date: Fri, 6-Nov-87 14:01:09 EST Article-I.D.: uunet.2854 Posted: Fri Nov 6 14:01:09 1987 Date-Received: Sun, 8-Nov-87 15:39:20 EST Organization: UUNET Communications Services, Arlington, VA Lines: 4989 Approved: rs@uunet.UU.NET Submitted-by: Crispin Goswell Posting-number: Volume 12, Issue 56 Archive-name: postscript/part07 #! /bin/sh # This is a shell archive. Remove anything before this line, then unpack # it by saving it into a file and typing "sh file". To overwrite existing # files, type "sh file -c". You can also feed this as standard input via # unshar, or by typing "sh 'doc/hard-interface.c' <<'END_OF_FILE' X#include "main.h" X#include "graphics.h" X Xstruct hardware X { X /* X * Each driver is expected to provide its own definition of this structure. X * It is only ever used as a pointer and is never dereferenced outside the driver. X */ X int pad; X }; X X/* X * This file describes the interface that PostScript requires to the graphics system at Version 1.4. X * X * ''Hardware'' in this context refers to a pointer to windows and/or bitmaps and is the lowest level X * of access that PostScript is interested in. Any Hardware parameter may be expected to be NULL. X */ X X/*********************************** CREATION OF WINDOWS AND BITMAPS *******************/ X Xstruct hardware *InitHardware () {} X/* X * InitHardware () returns a default device which PostScript may use immediately (or NULL if not appropriate). X * Its size and shape are not defined. Most typically the user will want to start up another device X * before it is used anyway. No attempt will be made by PostScript to Destroy the resulting X * device. X */ X Xstruct hardware *NewBitmapHardware (width, height) int width, height; {} X Xstruct hardware *NewWindowHardware (width, height) int width, height; {} X/* X * NewBitmapHardware () is expected to create a new bitmap. Only one plane will be needed. X * X * NewWindowHardware () is expected to create a window on the screen. On a colour system this will X * be expected to support full colour. X */ X Xint IsWindowHardware (h) struct hardware *h; {} X/* X * IsWindowHardware () should return TRUE if the hardware is a window, FALSE otherwise. X * NULL is a window. X */ X Xvoid DestroyHardware (h) struct hardware *h; {} X/* X * DestroyHardware () should release the resources required by the hardware, bitmap or window. X * This should cause a window device to vanish. NULL is not an error (does nothing). X */ X X XMatrix DeviceMatrix (width, height) int width, height; {} X X/* X * X * DeviceMatrix () should return a matrix appropriate to a device of the given height and width. X * For a typical display with a graphics origin at the top left of a window, X * an appropriate definition would be: X * X * Matrix DeviceMatrix (width, height) int width, height; X * { X * return NewMatrix (PIXELS_PER_INCH / 72.0, 0.0, 0.0, -PIXELS_PER_INCH / 72.0, 0.0, (float) height); X * } X */ X XDevicePoint HardwareExtent (h) struct hardware *h; {} X/* HardwareExtent () returns a DevicePoint describing the width and height of the argument. X * NULL has extent NewDevicePoint (0, 0). X */ X X/******************************************* OUTPUT PRIMITIVES ******************************/ X Xvoid BitBlt (from, to, fromPoint, toPoint, extent, rop) X struct hardware *from, *to; X DevicePoint toPoint, fromPoint, extent; X int rop; X {} X Xvoid Paint (from, to, fromPoint, toPoint, extent, colour) X struct hardware *from, *to; X DevicePoint toPoint, fromPoint, extent; X Colour colour; X {} X X/* X * BitBlt () is a full function RasterOp. The 'rop' argument X * will have values as described in the header file hard.h. If the from argument is NULL it is taken to be X * a bitmap full of ones the shape of the fromPoint and extent. If the to argument is NULL, this is a no-op. X * X * Paint () is an addition to BitBlt. Bits that are set in the source are Painted into the destination X * in the given colour with a copying rasterop so that they replace pixels previously there. If the X * machine does not support colour windows, half-toning should be performed. X * Colour values have hue, saturation and brightness components. on a black and white or greyscale X * system the brightness value will be a FP value between 0.0 (black) and 1.1 (white), which can be X * used as a grey level. X * X * Paint is expected to mask with the clip mask. BitBlt is not, X */ X Xvoid BitBltTrapezoid (to, lefttop, leftbottom, righttop, rightbottom, top, bottom, rop) X struct hardware *to; X DevicePoint lefttop, leftbottom, righttop, rightbottom; X int top, bottom, rop; X {} X Xvoid PaintTrapezoid (to, lefttop, leftbottom, righttop, rightbottom, top, bottom, colour) X struct hardware *to; X DevicePoint lefttop, leftbottom, righttop, rightbottom; X int top, bottom; X Colour colour; X {} X X/* X * BitBltTrapezoid () and PaintTrapezoid () render a complete trapezoidal shape. X * The corners of the trapezoid may lie far outside the range of interesting scan-lines, but the slope X * of the line should be clipped by the top and bottom. The coordinates are half-open. X */ X Xvoid BitBltLine (h, fromPoint, toPoint, rop) X struct hardware *h; X DevicePoint fromPoint, toPoint; X int rop; X {} X Xvoid PaintLine (h, fromPoint, toPoint, colour) X struct hardware *h; X DevicePoint fromPoint, toPoint; X Colour colour; X {} X X/* X * BitBltLine () is expected to draw a line between the given points X * with the given RasterOp and colour masking. X * The line should be one pixel wide and half-open. X * [Thicker lines are done with BitBlt.] X * X * PaintLine () is expected to Paint a line by analogy with Paint and BitBlt. X */ X Xvoid BitBltBlob (to, top, height, left, right, rop) X struct hardware *to; X int top, height, *left, *right, rop; X {} X X /* X * BitBltBlob () takes a set of pixel coordinates and fills the trapezon figure X * half open. X */ X Xvoid RasterTile (from, to, toPoint, extent, rop) X struct hardware *from, *to; X DevicePoint toPoint, extent; X int rop; X {} X X/* X * RasterTile () replicates the whole of ``from'' over ``to'', but clipped by the X * rectangle bounded by ``toPoint'' and ``extent''. X */ X X/*********************************** BRIGHTNESS TRANSFER FUNCTION ************************/ X Xint TransferSize () {} X Xvoid SetTransfer (vec) float *vec; {} X/* X * TransferSize () and SetTransfer () control the mapping function between user brightnesses X * and device brightnesses. The interface is expected to perform this mapping of brightnesses X * to a sufficient resolution. SetTransfer takes a table of floating point numbers between X * 0 and 1. User brightnesses are scaled to the size of this table and mapped through it. X * The argument table given to SetTransfer () will be deleted after use. TransferSize () simply X * enquires the required size of the table. X * X * It may be appropriate to half-tone on a grayscale or colour device to improve rendering if it is not too X * expensive. TransferSize () returns the size of the pattern table. X */ X X/********************************** BITMAP CONVERSION ********************************/ X Xchar *StringFromHardware (h) struct hardware *h; {} X Xstruct hardware *HardwareFromString (s, width, height) char *s; int width, height; {} X/* X * StringFromHardware () produces a string from its argument which describes the bitmap. X * The bitmap is returned in row-major order with the leftmost bit of each byte in the most significant X * position. Rows are padded to byte boundaries. Only single plane bitmaps are used. X * X * HardwareFromString () performs the inverse mapping, generating a bitmap from a set of bits, given X * a width and height. Only single plane bitmaps are used. X */ X X/************************************* HALF-TONE SCREEN ***********************************/ X Xint ScreenSize (freq, rotation) float freq, rotation; {} X Xvoid BuildScreen (freq, rotation, x, y) float freq, rotation, *x, *y; {} X Xvoid SetScreen (freq, rotation, thresh) float freq, rotation, *thresh; {} X/* X * ScreenSize () allows PostScript to determine how large an array of sample points to expect. X * It should return the length of the side of the sample square. X * X * BuildScreen () returns a set of sampling coordinates to PostScript to hand to the users spot-function X * X * SetScreen () allows PostScript to set the thresholds for each sample point so that half-tone bitmaps X * can be made. X */ X X/************************************* CLIPPING **********************************************/ X Xvoid SetClipHardware (h, clip) struct hardware *h, *clip; {} X/* X * SetClipHardware sets hardware which is a clip mask for BitBlt. This mask should be ANDed with any output X * operation. If clip is NULL, masking will not be needed. X */ X X/**************************************** UPDATE CONTROLS ******************************************/ X Xvoid HardUpdate () {} X/* X * HardUpdate is a hook to allow devices which do output buffering to flush that buffering when appropriate. X * This allows an interactive user to see completed graphics between prompts (it is called as a side-effect X * of the PostScript flush operator). Typically is is a no-op. X */ X Xvoid UpdateControl (h, on) struct hardware *h; int on; {} X/* X * This call can be used to enable batching of output operations. UpdateControl (h, FALSE) means ``start of X * batching'' UpdateControl (h, TRUE) means ``end of batching''. It is used to improve performance on machines X * where screen updates have a high locking overhead. It may be a no-op. X * The operation should nest if batching is already in progress: FALSE increments a counter, X * TRUE decrements a counter. Display changes are allowed when the counter is non-zero. X */ X X/********************************** CANONICAL IMPLEMENTATION LIBRARY ******************************/ X X/* X * Some parts of the above interface can be supported by a canonical library. X * This library contains: X XSetClipHardware XHardUpdate XIsWindowHardware XHardwareExtent X XPaintTrapezoid XBitBltTrapezoid X XPaint XPaintLine X XDeviceMatrix XInitTransfer XTransferSize XSetTransfer XScreenSize XBuildScreen XSetScreen X X * X * As the driver matures, the user may provide his own versions of the canonical routines. X * This leaves the following for implementation by the user. X * X XInitHardware XNewBitmapHardware XNewWindowHardware XDestroyHardware XHardwareFromString XStringFromHardware XUpdateControl XRasterTile XBitBlt XBitBltLine XBitBltBlob X X * There is a pedagogical implementation in null.c X * X * There are a number of interface issues concerning the canonical driver. X * Firstly, a canonical struct hardware is defined, which contains a union of X * a char * and an int handle. The remainder are expected to use this to store X * device specific information. X * X * InitTransfer() should be called during InitHardware with the number of pixels X * per inch on the display as an argument. X */ END_OF_FILE if test 10105 -ne `wc -c <'doc/hard-interface.c'`; then echo shar: \"'doc/hard-interface.c'\" unpacked with wrong size! fi # end of 'doc/hard-interface.c' fi if test -f 'postscript/fonts/Sans/italic.r' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'postscript/fonts/Sans/italic.r'\" else echo shar: Extracting \"'postscript/fonts/Sans/italic.r'\" \(9970 characters\) sed "s/^X//" >'postscript/fonts/Sans/italic.r' <<'END_OF_FILE' XCharStrings X/651 X Xput XMetrics X/651 X[0 X16] Xput XCharStrings X/652 X Xput XMetrics X/652 X[7 X14] Xput XCharStrings X/653 X Xput XMetrics X/653 X[0 X11] Xput XCharStrings X/654 X Xput XMetrics X/654 X[6 X16] Xput XCharStrings X/655 X Xput XMetrics X/655 X[0 X10] Xput XCharStrings X/656 X Xput XMetrics X/656 X[9 X8] Xput XCharStrings X/657 X Xput XMetrics X/657 X[0 X15] Xput XCharStrings X/658 X Xput XMetrics X/658 X[7 X15] Xput XCharStrings X/659 X Xput XMetrics X/659 X[3 X7] Xput XCharStrings X/660 X Xput XMetrics X/660 X[8 X7] Xput XCharStrings X/661 X Xput XMetrics X/661 X[7 X14] Xput XCharStrings X/662 X Xput XMetrics X/662 X[9 X8] Xput XCharStrings X/663 X Xput XMetrics X/663 X[0 X25] Xput XCharStrings X/664 X Xput XMetrics X/664 X[0 X18] Xput XCharStrings X/665 X Xput XMetrics X/665 X[0 X14] Xput XCharStrings X/666 X Xput XMetrics X/666 X[4 X15] Xput XCharStrings X/667 X Xput XMetrics X/667 X[0 X15] Xput XCharStrings X/668 X Xput XMetrics X/668 X[0 X13] Xput XCharStrings X/669 X Xput XMetrics X/669 X[0 X11] Xput XCharStrings X/670 X Xput XMetrics X/670 X[9 X9] Xput XCharStrings X/671 X Xput XMetrics X/671 X[0 X15] Xput XCharStrings X/672 X Xput XMetrics X/672 X[0 X15] Xput XCharStrings X/673 X Xput XMetrics X/673 X[0 X21] Xput XCharStrings X/674 X Xput XMetrics X/674 X[0 X16] Xput XCharStrings X/675 X Xput XMetrics X/675 X[0 X15] Xput XCharStrings X/676 X Xput XMetrics X/676 X[0 X14] Xput XCharStrings X/677 X Xput XMetrics X/677 X[4 X18] Xput XCharStrings X/683 X Xput XMetrics X/683 X[3 X18] Xput XCharStrings X/684 X Xput XMetrics X/684 X[-3 X16] Xput XCharStrings X/685 X Xput XMetrics X/685 X[4 X17] Xput XCharStrings X/686 X Xput XMetrics X/686 X[2 X20] Xput XCharStrings X/687 X Xput XMetrics X/687 X[-3 X18] Xput XCharStrings X/697 X<8000 X27A3C X4400 X002FB X3848 X> Xput XMetrics X/697 X[64 X0] Xput XCharStrings X/551 X Xput XMetrics X/551 X[1 X20] Xput XCharStrings X/552 X Xput XMetrics X/552 X[0 X23] Xput XCharStrings X/553 X Xput XMetrics X/553 X[2 X20] Xput XCharStrings X/554 X Xput XMetrics X/554 X[1 X23] Xput XCharStrings X/555 X Xput XMetrics X/555 X[2 X20] Xput XCharStrings X/556 X Xput XMetrics X/556 X[2 X20] Xput XCharStrings X/557 X Xput XMetrics X/557 X[1 X23] Xput XCharStrings X/558 X Xput XMetrics X/558 X[0 X24] Xput XCharStrings X/559 X Xput XMetrics X/559 X[3 X17] Xput XCharStrings X/560 X Xput XMetrics X/560 X[4 X15] Xput XCharStrings X/561 X Xput XMetrics X/561 X[0 X24] Xput XCharStrings X/562 X Xput XMetrics X/562 X[3 X19] Xput XCharStrings X/563 X Xput XMetrics X/563 X[-2 X33] Xput XCharStrings X/564 X Xput XMetrics X/564 X[-1 X24] Xput XCharStrings X/565 X Xput XMetrics X/565 X[2 X21] Xput XCharStrings X/566 X Xput XMetrics X/566 X[0 X25] Xput XCharStrings X/567 X Xput XMetrics X/567 X[2 X22] Xput XCharStrings X/568 X Xput XMetrics X/568 X[0 X25] Xput XCharStrings X/569 X Xput XMetrics X/569 X[2 X20] Xput XCharStrings X/570 X Xput XMetrics X/570 X[2 X19] Xput XCharStrings X/571 X Xput XMetrics X/571 X[-1 X24] Xput XCharStrings X/572 X Xput XMetrics X/572 X[0 X23] Xput XCharStrings X/573 X Xput XMetrics X/573 X[-2 X28] Xput XCharStrings X/574 X Xput XMetrics X/574 X[0 X24] Xput XCharStrings X/575 X Xput XMetrics X/575 X[0 X23] Xput XCharStrings X/576 X Xput XMetrics X/576 X[2 X21] Xput END_OF_FILE if test 9970 -ne `wc -c <'postscript/fonts/Sans/italic.r'`; then echo shar: \"'postscript/fonts/Sans/italic.r'\" unpacked with wrong size! fi # end of 'postscript/fonts/Sans/italic.r' fi if test -f 'postscript/fonts/times/italic.r' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'postscript/fonts/times/italic.r'\" else echo shar: Extracting \"'postscript/fonts/times/italic.r'\" \(9432 characters\) sed "s/^X//" >'postscript/fonts/times/italic.r' <<'END_OF_FILE' XCharStrings X/a Xput XMetrics X/a[-2 X15] Xput XCharStrings X/b Xput XMetrics X/b[-1 X14] Xput XCharStrings X/c Xput XMetrics X/c[-2 X13] Xput XCharStrings X/d Xput XMetrics X/d[0 X15] Xput XCharStrings X/e Xput XMetrics X/e[-2 X12] Xput XCharStrings X/f Xput XMetrics X/f[2 X11] Xput XCharStrings X/g Xput XMetrics X/g[-1 X14] Xput XCharStrings X/h Xput XMetrics X/h[0 X15] Xput XCharStrings X/i Xput XMetrics X/i[2 X10] Xput XCharStrings X/j Xput XMetrics X/j[2 X10] Xput XCharStrings X/k Xput XMetrics X/k[0 X13] Xput XCharStrings X/l Xput XMetrics X/l[3 X8] Xput XCharStrings X/m Xput XMetrics X/m[-1 X24] Xput XCharStrings X/n Xput XMetrics X/n[-1 X17] Xput XCharStrings X/o Xput XMetrics X/o[-2 X13] Xput XCharStrings X/p Xput XMetrics X/p[0 X15] Xput XCharStrings X/q Xput XMetrics X/q[-2 X14] Xput XCharStrings X/r Xput XMetrics X/r[-1 X12] Xput XCharStrings X/s Xput XMetrics X/s[-2 X13] Xput XCharStrings X/t Xput XMetrics X/t[3 X9] Xput XCharStrings X/u Xput XMetrics X/u[-1 X17] Xput XCharStrings X/v Xput XMetrics X/v[-1 X14] Xput XCharStrings X/w Xput XMetrics X/w[-1 X20] Xput XCharStrings X/x Xput XMetrics X/x[-2 X16] Xput XCharStrings X/y Xput XMetrics X/y[-1 X16] Xput XCharStrings X/z Xput XMetrics X/z[-2 X14] Xput XCharStrings X/A Xput XMetrics X/A[2 X14] Xput XCharStrings X/B Xput XMetrics X/B[0 X15] Xput XCharStrings X/C Xput XMetrics X/C[0 X13] Xput XCharStrings X/D Xput XMetrics X/D[0 X15] Xput XCharStrings X/E Xput XMetrics X/E[0 X15] Xput XCharStrings X/F Xput XMetrics X/F[0 X14] Xput XCharStrings X/G Xput XMetrics X/G[0 X14] Xput XCharStrings X/H Xput XMetrics X/H[0 X17] Xput XCharStrings X/I Xput XMetrics X/I[3 X9] Xput XCharStrings X/J Xput XMetrics X/J[1 X12] Xput XCharStrings X/K Xput XMetrics X/K[0 X16] Xput XCharStrings X/L Xput XMetrics X/L[0 X13] Xput XCharStrings X/M Xput XMetrics X/M[0 X19] Xput XCharStrings X/N Xput XMetrics X/N[0 X16] Xput XCharStrings X/O Xput XMetrics X/O[0 X14] Xput XCharStrings X/P Xput XMetrics X/P[0 X15] Xput XCharStrings X/Q Xput XMetrics X/Q[0 X14] Xput XCharStrings X/R Xput XMetrics X/R[0 X16] Xput XCharStrings X/S Xput XMetrics X/S[0 X15] Xput XCharStrings X/T Xput XMetrics X/T[0 X15] Xput XCharStrings X/U Xput XMetrics X/U[-1 X17] Xput XCharStrings X/V Xput XMetrics X/V[0 X14] Xput XCharStrings X/W Xput XMetrics X/W[-2 X18] Xput XCharStrings X/X Xput XMetrics X/X[1 X15] Xput XCharStrings X/Y Xput XMetrics X/Y[1 X13] Xput XCharStrings X/Z Xput XMetrics X/Z[1 X13] Xput XCharStrings X/ff X Xput XMetrics X/ff X[1 X18] Xput XCharStrings X/fi X Xput XMetrics X/fi X[1 X17] Xput XCharStrings X/fl X Xput XMetrics X/fl X[1 X17] Xput XCharStrings X/ffi X Xput XMetrics X/ffi X[1 X24] Xput XCharStrings X/ffl X Xput XMetrics X/ffl X[1 X24] Xput XCharStrings X/dotlessi X Xput XMetrics X/dotlessi X[-1 X10] Xput XCharStrings X/space X<8000 X46E3D X4300 X004EF X3A46 X> Xput XMetrics X/space X[64 X0] Xput END_OF_FILE if test 9432 -ne `wc -c <'postscript/fonts/times/italic.r'`; then echo shar: \"'postscript/fonts/times/italic.r'\" unpacked with wrong size! fi # end of 'postscript/fonts/times/italic.r' fi if test -f 'source/array.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'source/array.c'\" else echo shar: Extracting \"'source/array.c'\" \(9489 characters\) sed "s/^X//" >'source/array.c' <<'END_OF_FILE' X/* X * Copyright (C) Rutherford Appleton Laboratory 1987 X * X * This source may be copied, distributed, altered or used, but not sold for profit X * or incorporated into a product except under licence from the author. X * It is not in the public domain. X * This notice should remain in the source unaltered, and any changes to the source X * made by persons other than the author should be marked as such. X * X * Crispin Goswell @ Rutherford Appleton Laboratory caag@uk.ac.rl.vd X */ X#include "main.h" X Xstatic Object OpForAll; X Xstatic int PLength (), PArray (), PRBracket (), PAload (), PAstore (); X Xstatic int forAll (), ForAll (), PReadOnly (), PExecOnly (), PrCheck (), PwCheck (); Xstatic int PutInterval (), GetInterval (), Put (), Get (), Length (), Copy (), Eq (); X Xint ExecArray (); XObject Marker; X Xstatic int autobind = 0; X Xstatic int PSetAutoBind (), PGetAutoBind (); X XInitArray () X { X TypeInstallOp (Mark, "eq", EqTrue, 2, 1, 0, 0, Mark, Mark); X X Marker = MakeObject (Mark); X X OpForAll = MakeOp ("(forallarray)", forAll, 0, 0, 3, 5); X X Install ("[", Marker); X Install ("null", Nil); X X InstallOp ("array", PArray, 1, 1, 0, 0, Integer); X InstallOp ("]", PRBracket, 0, 1, 0, 0); X InstallOp ("aload", PAload, 1, 0, 0, 0, Array); X InstallOp ("astore", PAstore, 1, 1, 0, 0, Array); X X InstallOp ("setautobind", PSetAutoBind, 1, 0, 0, 0, Boolean); X InstallOp ("getautobind", PGetAutoBind, 0, 1, 0, 0); X X TypeInstallOp (Array, "exec", ExecArray, 1, 1, 0, 2, Array); X TypeInstallOp (Array, "eq", Eq, 2, 1, 0, 0, Array, Array); X TypeInstallOp (Array, "put", Put, 3, 0, 0, 0, Array, Integer, Poly); X TypeInstallOp (Array, "get", Get, 2, 1, 0, 0, Array, Integer); X TypeInstallOp (Array, "putinterval", PutInterval, 3, 0, 0, 0, Array, Integer, Array); X TypeInstallOp (Array, "getinterval", GetInterval, 3, 1, 0, 0, Array, Integer, Integer); X TypeInstallOp (Array, "length", PLength, 1, 1, 0, 0, Array); X TypeInstallOp (Array, "copy", Copy, 2, 0, 0, 0, Array, Array); X TypeInstallOp (Array, "forall", ForAll, 2, 0, 0, 4, Array, Array); X TypeInstallOp (Array, "executeonly", PExecOnly, 1, 1, 0, 0, Array); X TypeInstallOp (Array, "readonly", PReadOnly, 1, 1, 0, 0, Array); X TypeInstallOp (Array, "rcheck", PrCheck, 1, 1, 0, 0, Array); X TypeInstallOp (Array, "wcheck", PwCheck, 1, 1, 0, 0, Array); X } X X XObject MakeArray (p, length) Object *p; int length; X { X Object res; X X res = MakeObject (Array); X res.u.Array = p; X res.Length = length; X X return res; X } X X Xstatic Object Make (p, length) Object *p; int length; X { X Object res; X X res = MakeObject (Array); X res.u.Array = p; X res.Length = length; X X return res; X } X Xstatic Object *Body (item) Object item; X { X return item.u.Array; X } X X#define Body(a) ((a).u.Array) X XObject *BodyArray (item) Object item; X { X return item.u.Array; X } X Xstatic Object ArrayStore (n) int n; X { X Object *body = (Object *) Malloc ((unsigned) sizeof (Object) * n); X int i, h = Height (OpStack); X X for (i = h - n; i < h; i++) X body[i-h+n] = OpStack->stack_body[i]; X OpStack->stack_fill -= n; X return Make (body, n); X } X X/*VARARGS XObject ArrayFrom (length, args) int length; Object args; X { X Object *argv = &args, *array = (Object *) Malloc ((unsigned) (sizeof (Object) * length)); X int i; X X for (i = 0; i < length; i++) X array[i] = argv[i]; X return Cvx (Make (array, length)); X } X*/ X XlengthArray (item) Object item; X { X return item.Length; X } X Xstatic int Length (object) Object object; X { X return object.Length; X } X X#define lengthArray(a) ((a).Length) X Xstatic int PLength (object) Object object; X { X return Push (OpStack, MakeInteger (Length (object))); X } X Xint ExecArray (item) Object item; X { X int l = lengthArray (item); X X if (l == 0) X return TRUE; X Push (ExecStack, SameFlags (item, Make (Body (item) + 1, l - 1))); X if (TypeOf (Body (item) [0]) == Name || TypeOf (Body (item) [0]) == Operator) X Push (ExecStack, Body (item) [0]); X else X Push (OpStack, Body (item) [0]); X X return TRUE; X } X Xstatic int Get (object, key) Object object, key; X { X int index; X X if (TypeOf (key) == Integer) X index = BodyInteger (key); X else if (TypeOf (key) == Real) X index = (int) BodyReal (key); X else X return Error (PTypeCheck); X if (index >= 0 && index < Length (object)) X { X Object t; X X t = Body (object) [index]; /* VAX Compiler Broken */ X return Push (OpStack, t); X } X else X return Error (PRangeCheck); X } X XObject getArray (o, index) Object o; int index; X { X return Body (o)[index]; X } X Xstatic int GetInterval (object, begin, length) Object object, begin, length; X { X int b = BodyInteger (begin), l = BodyInteger (length); X X if (l < 0 || b < 0 || b + l > Length (object)) X return Error (PRangeCheck); X return Push (OpStack, Make (Body (object) + b, l)); X } X XObject getIArray (object, begin, length) Object object; int begin, length; X { X return Make (Body (object) + begin, length); X } X Xstatic int Put (object, key, value) Object object, key, value; X { X int index = BodyInteger (key); X X if (index < 0 || index >= Length (object)) X return Error (PRangeCheck); X Body (object) [index] = value; X return TRUE; X } X Xint putArray (object, index, value) Object object, value; int index; X { X if (index < 0 || index >= Length (object)) X return Error (PRangeCheck); X Body (object) [index] = value; X return TRUE; X X } X Xstatic int PutInterval (object1, begin, object2) Object object1, begin, object2; X { X int i, l1 = Length (object1), l2 = Length (object2), b = BodyInteger (begin); X X if (b < 0 || l2 + b > l1) X return Error (PRangeCheck); X for (i = b; i < b + l2; i++) X Body (object1) [i] = Body (object2) [i - b]; X return TRUE; X } X Xstatic int Copy (object1, object2) Object object1, object2; X { X if (Length (object1) <= Length (object2)) X return PutInterval (object2, MakeInteger (0), object1) X && Push (OpStack, Make (Body (object2), Length (object1))); X else X return Error (PRangeCheck); X } X Xstatic Eq (a, b) Object a, b; X { X return Push (OpStack, MakeBoolean (Length (a) == Length (b) && (Length (a) == 0 || Body (a) == Body (b)))); X } X Xstatic int ForAll (array, proc) Object array, proc; X { X return Push (ExecStack, array) X && Push (ExecStack, MakeInteger (0)) X && Push (ExecStack, proc) X && Push (ExecStack, OpForAll); X } X Xstatic forAll () X { X Object array, index, proc; X X proc = Pop (ExecStack); X index = Pop (ExecStack); X array = Pop (ExecStack); X X if (BodyInteger (index) >= lengthArray (array)) X return TRUE; X return Push (ExecStack, array) X && Push (ExecStack, MakeInteger (BodyInteger (index) + 1)) X && Push (ExecStack, proc) X && Push (ExecStack, OpForAll) X && Push (ExecStack, proc) X && Push (OpStack, Body (array) [BodyInteger (index)]); X } X Xstatic int PSetAutoBind (bool) Object bool; X { X autobind = BodyBoolean (bool); X X return TRUE; X } X Xstatic int PGetAutoBind () X { X return Push (OpStack, MakeBoolean (autobind)); X } X XObject ParseArray (o) Object o; X { X Object res, *array; X int i, length = 0; X struct acc X { X Object item; X struct acc *prev; X } *p = NULL; X X for (;;) X { X struct acc *item = (struct acc *) Malloc (sizeof (struct acc)); X res = Parse (o); X X if (TypeOf (res) == Condition) X return Absent; X if (TypeOf (res) == Boolean) X if (BodyBoolean (res)) X break; X else X return Absent; X else if (TypeOf (res) == Null) X return res; X X if (autobind && TypeOf (res) == Name && xCheck (res)) X { X Object binding; X X binding = Load (res); X X if (TypeOf (binding) == Operator) X res = binding; X } X item->item = res; X item->prev = p; X p = item; X ++length; X } X array = (Object *) Malloc ((unsigned) sizeof (Object) * length); X X for (i = length - 1; i >= 0; i--) X { X struct acc *prev = p->prev; X X array[i] = p->item; X Free ((char *)p); X p = prev; X } X PanicIf (p != NULL, "Something badly wrong in Array literal parser\n"); X return Make (array, length); X } X Xstatic int PArray (size) Object size; X { X if (BodyInteger (size) < 0) X return Error (PRangeCheck); X else X { X int i, s = BodyInteger (size); X Object *body = (Object *) Malloc ((unsigned) sizeof (Object) * s); X X for (i = 0; i < s; i++) X body[i] = Nil; X return Push (OpStack, Make (body, s)); X } X } X Xstatic int PRBracket () /* [ a1 ... an --- array */ X { X int n = CountTo (Mark, OpStack); X X if (n < 0) X return Error (PUnMatched); X else X { X Object res; X X res = ArrayStore (n); X VOID Pop (OpStack); X return Push (OpStack, res); X } X } X Xstatic int PAload (array) Object array; X { X Object *body = Body (array); X int i, l = lengthArray (array); X X if (MaxStack (OpStack) - Height (OpStack) < l + 1) X return Error (POpOverflow); X else X { X for (i = 0; i < l; i++) X if (!Push (OpStack, body[i])) X break; X return Push (OpStack, array); X } X } X Xstatic int PAstore (array) Object array; X { X if (lengthArray (array) > Height (OpStack)) X return Error (POpUnderflow); X else X { X Object *body = Body (array); X int i, l = lengthArray (array); X X for (i = l-1; i >= 0; i--) X body[i] = Pop (OpStack); X return Push (OpStack, array); X } X } X Xstatic int PExecOnly (item) Object item; X { X return Push (OpStack, ExecOnly (item)); X } X Xstatic int PReadOnly (item) Object item; X { X return Push (OpStack, ReadOnly (item)); X } X Xstatic int PrCheck (v) Object v; X { X return Push (OpStack, MakeBoolean (rCheck (v))); X } X Xstatic int PwCheck (v) Object v; X { X return Push (OpStack, MakeBoolean (wCheck (v))); X } END_OF_FILE if test 9489 -ne `wc -c <'source/array.c'`; then echo shar: \"'source/array.c'\" unpacked with wrong size! fi # end of 'source/array.c' fi if test -f 'source/viewer.c' -a "${1}" != "-c" ; then echo shar: Will not clobber existing file \"'source/viewer.c'\" else echo shar: Extracting \"'source/viewer.c'\" \(10083 characters\) sed "s/^X//" >'source/viewer.c' <<'END_OF_FILE' X/* X * Copyright (C) Rutherford Appleton Laboratory 1987 X * X * This source may be copied, distributed, altered or used, but not sold for profit X * or incorporated into a product except under licence from the author. X * It is not in the public domain. X * This notice should remain in the source unaltered, and any changes to the source X * made by persons other than the author should be marked as such. X * X * Crispin Goswell @ Rutherford Appleton Laboratory caag@uk.ac.rl.vd X */ X#include X#include X X#include "main.h" X#include "graphics.h" X#include "protocol.h" X X#define CHUNK 500 X Xstruct hardware **hards, *get_hard (); Xchar *malloc (), *realloc (); Xvoid set_hard (); X Xint nhard = 0; X XColour Black, White; X Xint monitor; X Xmain (argc, argv) int argc; char **argv; X { X int c; X struct hardware *res; X DevicePoint ex; X X signal (SIGINT, SIG_IGN); X X monitor = !strcmp (argv[0], "monitor"); X X if (monitor) X fprintf (stderr, "Monitoring\n"); X slave_protocol (); X Black = NewColour (0.0, 0.0, 0.0); X White = NewColour (0.0, 0.0, 1.0); X X hards = (struct hardware **) malloc (sizeof (struct hardware *) * CHUNK); X nhard = CHUNK; X X (void) set_hard (1, res = InitHardware ()); X ex = HardwareExtent (res); X send_short (ex.dx); X send_short (ex.dy); X flush_protocol (); X X while ((c = recv_byte ()) != 255) X { X if (monitor) X fprintf (stderr, "command = %d\n", c); X switch (c) X { X case NEW_WINDOW: DoNewWindow (); break; X case NEW_BITMAP: DoNewBitmap (); break; X case BITBLT: DoBitBlt (); break; X case PAINT: DoPaint (); break; X case SEND_BITMAP: DoSendBitmap (); break; X case GET_BITMAP: DoGetBitmap (); break; X case DESTROY_HARDWARE: DoDestroyHardware (); break; X case GET_MATRIX: DoGetMatrix (); break; X case LINE: DoLine (); break; X case PAINT_LINE: DoPaintLine (); break; X case GET_TRANSFERSIZE: DoGetTransferSize (); break; X case SET_TRANSFER: DoSetTransfer (); break; X case HARD_FLUSH: HardUpdate (); break; X case SCREEN_SIZE: DoScreenSize (); break; X case BUILD_SCREEN: DoBuildScreen (); break; X case SET_SCREEN: DoSetScreen (); break; X case SET_CLIP_HARDWARE: DoSetClipHardware (); break; X case BITBLT_TRAPEZOID: DoBitBltTrapezoid (); break; X case PAINT_TRAPEZOID: DoPaintTrapezoid (); break; X case SET_UPDATE_CONTROL:DoSetUpdateControl (); break; X X default: X fprintf (stderr, "Unknown request type %d\n", c); X exit (1); X } X } X } X XDoNewWindow () X { X int h = recv_hardware (); X int width = recv_short (); X int height = recv_short (); X X if (monitor) X fprintf (stderr, "%d = NewWindowHardware (%d, %d)\n", h, width, height); X set_hard (h, NewWindowHardware (width, height)); X } X XDoNewBitmap () X { X int h = recv_hardware (); X int width = recv_short (); X int height = recv_short (); X X if (monitor) X fprintf (stderr, "%d = NewBitmapHardware (%d, %d)\n", h, width, height); X set_hard (h, NewBitmapHardware (width, height)); X } X XDoBitBlt () X { X int rop, f, t; X DevicePoint fromPoint, toPoint, extent; X struct hardware *from = get_hard (f = recv_hardware ()); X struct hardware *to = get_hard (t = recv_hardware ()); X X fromPoint = recv_point (); X toPoint = recv_point (); X extent = recv_point (); X rop = recv_byte (); X X if (monitor) X fprintf (stderr, "BitBlt (%d, %d, (%d, %d), (%d, %d), (%d, %d), %d)\n", X f, t, X fromPoint.dx, fromPoint.dy, toPoint.dx, toPoint.dy, X extent.dx, extent.dy, X rop); X BitBlt (from, to, fromPoint, toPoint, extent, rop); X } X XDoPaint () X { X int f, t; X Colour colour; X DevicePoint fromPoint, toPoint, extent; X struct hardware *from = get_hard (f = recv_hardware ()); X struct hardware *to = get_hard (t = recv_hardware ()); X X fromPoint = recv_point (); X toPoint = recv_point (); X extent = recv_point (); X colour = recv_colour (); X X if (monitor) X fprintf (stderr, "Paint (%d, %d, (%d, %d), (%d, %d), (%d, %d), [%g, %g, %g])\n", X f, t, X fromPoint.dx, fromPoint.dy, toPoint.dx, toPoint.dy, X extent.dx, extent.dy, X colour.hue, colour.saturation, colour.brightness); X Paint (from, to, fromPoint, toPoint, extent, colour); X } X Xint size (width, height) int width, height; X { X return (width + 7) / 8 * height; X } X XDoSendBitmap () /* actually receives this end */ X { X int h = recv_hardware (); X int width = recv_short (); X int height = recv_short (); X int len = size (width, height); X char *s; X X recv_string ((s = malloc (len)), len); X if (monitor) X fprintf (stderr, "%d = HardwareFromString (, %d, %d)\n", h, width, height); X set_hard (h, HardwareFromString (s, width, height)); X free (s); X } X XDoGetBitmap () X { X struct hardware *h = get_hard (recv_hardware ()); X char *s = StringFromHardware (h); X DevicePoint ex; X X ex = HardwareExtent (h); X X if (monitor) X fprintf (stderr, "StringFromHardware (%d)\n", h); X send_string (s, size (ex.dx, ex.dy)); X flush_protocol (); X free (s); X } X XDoDestroyHardware () X { X int n = recv_hardware (); X X if (monitor) X fprintf (stderr, "DestroyHardware (%d)\n", n); X DestroyHardware (get_hard (n)); X set_hard (n, NULL); X } X XDoGetMatrix () X { X int width = recv_short (); X int height = recv_short (); X Matrix m; X X if (monitor) X fprintf (stderr, "DeviceMatrix (%d, %d)\n", width, height); X m = DeviceMatrix (width, height); X send_float (m.A); X send_float (m.B); X send_float (m.C); X send_float (m.D); X send_float (m.tx); X send_float (m.ty); X flush_protocol (); X } X XDoLine () X { X DevicePoint fromPoint, toPoint; X int rop; X struct hardware *h = get_hard (recv_hardware ()); X X fromPoint = recv_point (); X toPoint = recv_point (); X rop = recv_byte (); X X if (monitor) X fprintf (stderr, "BitBltLine ((%d, %d), (%d, %d), %d)\n", X fromPoint.dx, fromPoint.dy, toPoint.dx, toPoint.dy, X rop); X BitBltLine (h, fromPoint, toPoint, rop); X } X XDoPaintLine () X { X DevicePoint fromPoint, toPoint; X Colour colour; X struct hardware *h = get_hard (recv_hardware ()); X X fromPoint = recv_point (); X toPoint = recv_point (); X colour = recv_colour (); X X if (monitor) X fprintf (stderr, "PaintLine ((%d, %d), (%d, %d), [%g, %g, %g])\n", X fromPoint.dx, fromPoint.dy, toPoint.dx, toPoint.dy, X colour.hue, colour.saturation, colour.brightness); X PaintLine (h, fromPoint, toPoint, colour); X } X Xint recv_hardware () X { X return recv_short (); X } X Xstruct hardware *get_hard (h) int h; X { X if (nhard <= h) X { X fprintf (stderr, "%d is not a valid device\n", h); X return NULL; X } X return hards [h]; X } X Xvoid set_hard (n, h) int n; struct hardware *h; X { X if (nhard <= n) X hards = (struct hardware **) realloc ((char *) hards, sizeof (struct hardware *) * (nhard += CHUNK)); X hards [n] = h; X } X Xint Max (a, b) int a, b; X { X return a > b ? a : b; X } X Xint Min (a, b) int a, b; X { X return a < b ? a : b; X } X XMatrix NewMatrix (a, b, c, d, e, f) float a, b, c, d, e, f; X { X Matrix res; X X res.A = a; res.B = b; res.C = c; res.D = d; res.tx = e; res.ty = f; X X return res; X } X Xchar *Malloc (i) unsigned i; X { X return malloc (i); X } X XFree (s) char *s; X { X free (s); X } X Xunsigned char *Bcopy (to, from, count) unsigned char *from, *to; int count; X { X unsigned char *res = to; X X while (count --) X *to++ = *from++; X X return res; X } X XPanicIf (flag, s) int flag; char *s; X { X if (flag) X fprintf (stderr, "Viewer panic: %s\n", s), X exit (1); X } X XDevicePoint NewDevicePoint (x, y) int x, y; X { X DevicePoint res; X X res.dx = x; res.dy = y; X X return res; X } X XColour NewColour (h, s, b) float h, s, b; X { X Colour res; X X res.hue = h; X res.saturation = s; X res.brightness = b; X X return res; X } X XDoGetTransferSize () X { X send_short (TransferSize ()); X flush_protocol (); X } X XDoSetTransfer () X { X int i, size = TransferSize (); X float *val = (float *) malloc (sizeof (float) * size); X X for (i = 0; i < size; i++) X val [i] = recv_small (); X X SetTransfer (val); X Free ((char *) val); X } X XDoScreenSize () X { X float freq = recv_float (), rotation = recv_float (); X X send_short (ScreenSize (freq, rotation)); X flush_protocol (); X } X XDoBuildScreen () X { X float freq = recv_float (), rotation = recv_float (); X int i, size = ScreenSize (freq, rotation); X float *x, *y; X X send_short (size); X x = (float *) malloc (sizeof (float) * size); X y = (float *) malloc (sizeof (float) * size); X X BuildScreen (freq, rotation, x, y); X for (i = 0; i < size; i++) X send_small (x[i]), X send_small (y[i]); X flush_protocol (); X free ((char *) x); X free ((char *) y); X } X XDoSetScreen () X { X float freq = recv_float (), rotation = recv_float (); X int i, size = ScreenSize (freq, rotation); X float *th = (float *) malloc (sizeof (float) * size); X X for (i = 0; i < size; i++) X th[i] = recv_small (); X SetScreen (freq, rotation, th); X free ((char *) th); X } X XDoSetClipHardware () X { X struct hardware *h = get_hard (recv_hardware ()); X X if (monitor) X fprintf (stderr, "SetClipHardware ()\n"); X SetClipHardware (h, get_hard (recv_hardware ())); X } X XDoBitBltTrapezoid () X { X DevicePoint lefttop, leftbottom, righttop, rightbottom; X int top, bottom, rop; X struct hardware *h = get_hard (recv_hardware ()); X X lefttop = recv_point (); X leftbottom = recv_point (); X righttop = recv_point (); X rightbottom = recv_point (); X top = recv_short (); X bottom = recv_short (); X rop = recv_byte (); X X if (monitor) X fprintf (stderr, "BitBltTrapezoid ()\n"); X BitBltTrapezoid (h, lefttop, leftbottom, righttop, rightbottom, rop); X } X XDoPaintTrapezoid () X { X DevicePoint lefttop, leftbottom, righttop, rightbottom; X int top, bottom; X Colour colour; X struct hardware *h = get_hard (recv_hardware ()); X X lefttop = recv_point (); X leftbottom = recv_point (); X righttop = recv_point (); X rightbottom = recv_point (); X top = recv_short (); X bottom = recv_short (); X colour = recv_colour (); X X if (monitor) X fprintf (stderr, "PaintTrapezoid ()\n"); X PaintTrapezoid (h, lefttop, leftbottom, righttop, rightbottom, top, bottom, colour); X } X XDoSetUpdateControl () X { X struct hardware *h = get_hard (recv_hardware ()); X UpdateControl (h, recv_byte ()); X } END_OF_FILE if test 10083 -ne `wc -c <'source/viewer.c'`; then echo shar: \"'source/viewer.c'\" unpacked with wrong size! fi # end of 'source/viewer.c' fi echo shar: End of archive 7 \(of 18\). cp /dev/null ark7isdone MISSING="" for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 18 archives. rm -f ark[1-9]isdone ark[1-9][0-9]isdone else echo You still need to unpack the following archives: echo " " ${MISSING} fi ## End of shell archive. exitof