/* VPLOT: version 4.2 updated %G%
* Reads standard graphics input and produces a plot on the
#define LPR "/usr/ucb/lpr"
#define mapx(x) ((DevRange*((x)-botx)/del)+centx)
#define mapy(y) ((DevRange*(del-(y)+boty)/del)-centy)
int radius
, startx
, starty
, endx
, endy
;
int warned
= 0; /* Indicates whether the warning message about
* unimplemented routines has been printed */
FILE *pfp
; /* output file */
char picture
[] = "/usr/tmp/rastAXXXXXX";
int run
= 13; /* index of 'a' in picture[] */
int DevRange
= 1536; /* output array size (square) in pixels */
int DevRange8
= 1536/8; /* output array size in bytes */
int BytesPerLine
= 264; /* Bytes per raster line (physical) */
int lparg
= 7; /* index into lpargs */
char *lpargs
[50] = { "lpr", "-Pvarian", "-v", "-s", "-r", "-J", "vplot" };
/* variables for used to print from font file */
int fontSet
= 0; /* Has the font file been read */
struct dispatch dispatch
[256];
char *fontFile
= "/usr/lib/vfont/R.6";
register char *cp1
, *arg
;
while (argc
> 1 && argv
[1][0] == '-') {
lpargs
[1] = "-Pversatec";
lpargs
[lparg
-1] = *++argv
;
fprintf(stderr
, "vplot: %s option unknown\n", *argv
);
if ((infile
= fopen(*++argv
, "r")) == NULL
) {
/* init constants for scaling */
delx
= dely
= del
= DevRange
;
centx
= (DevRange
- mapx(topx
))/2;
signal(SIGTERM
, cleanup
);
if (signal(SIGINT
, SIG_IGN
) != SIG_IGN
)
if ((obuf
= (char *) malloc(bufsize
= DevRange
* DevRange8
)) == NULL
) {
fprintf(stderr
, "vplot: ran out of memory\n");
if ((pfp
= fopen(picture
, "w")) == NULL
) {
fprintf(stderr
, "vplot: can't create %s\n", picture
);
if ((arg
= (char *) malloc(i
)) == NULL
) {
fprintf(stderr
, "ran out of memory\n");
for (cp1
= obuf
; cp1
< arg
; )
for (cp1
= obuf
; cp1
< arg
; cp1
+= DevRange8
) {
fwrite(cp1
, sizeof(char), DevRange8
, pfp
);
fseek(pfp
, (long) BytesPerLine
- DevRange8
, 1);
fprintf(stderr
, "can't exec %s\n", LPR
);
for (;;) switch (x1
= getc(infile
)) {
botx
= getinteger(infile
);
boty
= getinteger(infile
);
topx
= getinteger(infile
);
topy
= getinteger(infile
);
if (dely
/delx
> 1536./2048.)
centx
= (DevRange
- mapx(topx
))/2;
x1
= mapx(getinteger(infile
));
y1
= mapy(getinteger(infile
));
lastx
= mapx(getinteger(infile
));
lasty
= mapy(getinteger(infile
));
line(x1
, y1
, lastx
, lasty
);
x1
= mapx(getinteger(infile
));
y1
= mapy(getinteger(infile
));
radius
= mapx(getinteger(infile
));
fprintf(stderr
,"Circles are Implemented\n");
x1
= mapx(getinteger(infile
));
y1
= mapy(getinteger(infile
));
startx
= mapx(getinteger(infile
));
starty
= mapy(getinteger(infile
));
endx
= mapx(getinteger(infile
));
endy
= mapy(getinteger(infile
));
fprintf(stderr
,"Circles and Arcs are unimplemented\n");
lastx
= mapx(getinteger(infile
));
lasty
= mapy(getinteger(infile
));
while ((x1
= getc(infile
)) != '\n')
lastx
= mapx(getinteger(infile
));
lasty
= mapy(getinteger(infile
));
x1
= mapx(getinteger(infile
));
y1
= mapy(getinteger(infile
));
line(lastx
, lasty
, x1
, y1
);
while ((x1
= getc(infile
)) != '\n')
case 0: /* ignore null characters */
fprintf(stderr
, "Input format error %c(%o)\n",x1
,x1
);
InitFont(); /* Read font if not already read */
ptr
= bits
+ dispatch
[ch
].addr
;
for (i
= dispatch
[ch
].up
; i
> -dispatch
[ch
].down
; --i
) {
nbytes
= (dispatch
[ch
].right
+ dispatch
[ch
].left
+ 7)/8;
for (j
= 0; j
< nbytes
; j
++) {
point(lastx
+7-k
+j
*8-dispatch
[ch
].left
, lasty
-i
);
lastx
+= dispatch
[ch
].width
;
lastx
+= dispatch
['a'].width
;
if ((fonts
= open(s
, 0)) == -1) {
fprintf(stderr
, "Can't get font file");
/* Get the header and check magic number */
if (read(fonts
, &header
, sizeof(header
)) != sizeof(header
)) {
fprintf(stderr
, "Bad read in font file");
if (header
.magic
!= 0436) {
fprintf(stderr
,"Bad magic numer in font file");
if (read(fonts
, dispatch
, sizeof(dispatch
)) != sizeof(dispatch
)) {
fprintf(stderr
, "Bad read in font file");
/* Allocate space for bit map and read in bits */
bits
= (char *) malloc(header
.size
);
if (read(fonts
, bits
, header
.size
) != header
.size
) {
fprintf(stderr
,"Can't read bit map in font file");
fprintf(stderr
,"Can't close font file");
if (dx
>= dy
) while (x0
!= x1
) {
if ((x0
+slope
*y0
) & linmod
)
} else while (y0
!= y1
) {
if ((x0
+slope
*y0
) & linmod
)
if ((x1
+slope
*y1
) & linmod
)
#define labs(a) (a >= 0 ? a : -a)
for (dy
=c
; dy
>=dx
; dy
--) {
if (labs(ep
) >= labs(ep
+de
)) {
* Points should be in the range 0 <= x (or y) <= DevRange.
* The origin is the top left-hand corner with increasing x towards the
* right and increasing y going down.
byte
= y
* DevRange8
+ (x
>> 3);
obuf
[byte
] |= 1 << (7 - (x
& 07));
while (picture
[run
] != 'a') {
register int low
, high
, result
;
result
= ((high
<< 8) | low
);