xref: /illumos-gate/usr/src/cmd/lp/filter/postscript/dpost/pictures.c (revision 7c478bd95313f5f23a4c958a745db2134aa0324)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.1	*/
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate /*
34*7c478bd9Sstevel@tonic-gate  *
35*7c478bd9Sstevel@tonic-gate  * PostScript picture inclusion routines. Support for managing in-line pictures
36*7c478bd9Sstevel@tonic-gate  * has been added, and works in combination with the simple picpack pre-processor
37*7c478bd9Sstevel@tonic-gate  * that's supplied with this package. An in-line picture begins with a special
38*7c478bd9Sstevel@tonic-gate  * device control command that looks like,
39*7c478bd9Sstevel@tonic-gate  *
40*7c478bd9Sstevel@tonic-gate  *		x X InlinPicture name size
41*7c478bd9Sstevel@tonic-gate  *
42*7c478bd9Sstevel@tonic-gate  * where name is the pathname of the original picture file and size is the number
43*7c478bd9Sstevel@tonic-gate  * of bytes in the picture, which begins immediately on the next line. When dpost
44*7c478bd9Sstevel@tonic-gate  * encounters the InlinePicture device control command inlinepic() is called and
45*7c478bd9Sstevel@tonic-gate  * that routine appends the string name and the integer size to a temporary file
46*7c478bd9Sstevel@tonic-gate  * (fp_pic) and then adds the next size bytes read from the current input file to
47*7c478bd9Sstevel@tonic-gate  * file fp_pic. All in-line pictures are saved in fp_pic and located later using
48*7c478bd9Sstevel@tonic-gate  * the name string and picture file size that separate pictures saved in fp_pic.
49*7c478bd9Sstevel@tonic-gate  *
50*7c478bd9Sstevel@tonic-gate  * When a picture request (ie. an "x X PI" command) is encountered picopen() is
51*7c478bd9Sstevel@tonic-gate  * called and it first looks for the picture file in fp_pic. If it's found there
52*7c478bd9Sstevel@tonic-gate  * the entire picture (ie. size bytes) is copied from fp_pic to a new temp file
53*7c478bd9Sstevel@tonic-gate  * and that temp file is used as the picture file. If there's nothing in fp_pic
54*7c478bd9Sstevel@tonic-gate  * or if the lookup failed the original route is taken.
55*7c478bd9Sstevel@tonic-gate  *
56*7c478bd9Sstevel@tonic-gate  * Support for in-line pictures is an attempt to address requirements, expressed
57*7c478bd9Sstevel@tonic-gate  * by several orginazations, of being able to store a document as a single file
58*7c478bd9Sstevel@tonic-gate  * (usually troff input) that can then be sent through dpost and ultimately to
59*7c478bd9Sstevel@tonic-gate  * a PostScript printer. The mechanism may help some users, but the are obvious
60*7c478bd9Sstevel@tonic-gate  * disadvantages to this approach, and the original mechanism is the recommended
61*7c478bd9Sstevel@tonic-gate  * approach! Perhaps the most important problem is that troff output, with in-line
62*7c478bd9Sstevel@tonic-gate  * pictures included, doesn't fit the device independent language accepted by
63*7c478bd9Sstevel@tonic-gate  * important post-processors (like proff) and that means you won't be able to
64*7c478bd9Sstevel@tonic-gate  * reliably preview a packed file on your 5620 (or whatever).
65*7c478bd9Sstevel@tonic-gate  *
66*7c478bd9Sstevel@tonic-gate  */
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate #include <stdio.h>
70*7c478bd9Sstevel@tonic-gate 
71*7c478bd9Sstevel@tonic-gate #include "comments.h"			/* PostScript file structuring comments */
72*7c478bd9Sstevel@tonic-gate #include "gen.h"			/* general purpose definitions */
73*7c478bd9Sstevel@tonic-gate #include "path.h"			/* just for TEMPDIR definition */
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate FILE	*fp_pic = NULL;			/* in-line pictures go here */
77*7c478bd9Sstevel@tonic-gate FILE	*picopen();
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate extern int	res, hpos, vpos;
80*7c478bd9Sstevel@tonic-gate extern int	picflag;
81*7c478bd9Sstevel@tonic-gate extern FILE	*tf;
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate /*****************************************************************************/
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate 
87*7c478bd9Sstevel@tonic-gate picture(buf)
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate     char	*buf;		/* stuff following 'x X PI' command */
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate 
93*7c478bd9Sstevel@tonic-gate {
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate     int		poffset;	/* page offset */
97*7c478bd9Sstevel@tonic-gate     int		indent;		/* indent */
98*7c478bd9Sstevel@tonic-gate     int		length;		/* line length  */
99*7c478bd9Sstevel@tonic-gate     int		totrap;		/* distance to next trap */
100*7c478bd9Sstevel@tonic-gate     char	name[100];	/* picture file and page string */
101*7c478bd9Sstevel@tonic-gate     char	hwo[40], *p;	/* height, width and offset strings */
102*7c478bd9Sstevel@tonic-gate     char	flags[20];	/* miscellaneous stuff */
103*7c478bd9Sstevel@tonic-gate     int		page = 1;	/* page number pulled from name[] */
104*7c478bd9Sstevel@tonic-gate     double	frame[4];	/* height, width, y, and x offsets from hwo[] */
105*7c478bd9Sstevel@tonic-gate     char	units;		/* scale indicator for frame dimensions */
106*7c478bd9Sstevel@tonic-gate     int		whiteout = 0;	/* white out the box? */
107*7c478bd9Sstevel@tonic-gate     int		outline = 0;	/* draw a box around the picture? */
108*7c478bd9Sstevel@tonic-gate     int		scaleboth = 0;	/* scale both dimensions? */
109*7c478bd9Sstevel@tonic-gate     double	adjx = 0.5;	/* left-right adjustment */
110*7c478bd9Sstevel@tonic-gate     double	adjy = 0.5;	/* top-bottom adjustment */
111*7c478bd9Sstevel@tonic-gate     double	rot = 0;	/* rotation in clockwise degrees */
112*7c478bd9Sstevel@tonic-gate     FILE	*fp_in;		/* for *name */
113*7c478bd9Sstevel@tonic-gate     int		i;		/* loop index */
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate     char	*strchr();
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate /*
119*7c478bd9Sstevel@tonic-gate  *
120*7c478bd9Sstevel@tonic-gate  * Called from devcntrl() after an 'x X PI' command is found. The syntax of that
121*7c478bd9Sstevel@tonic-gate  * command is:
122*7c478bd9Sstevel@tonic-gate  *
123*7c478bd9Sstevel@tonic-gate  *	x X PI:args
124*7c478bd9Sstevel@tonic-gate  *
125*7c478bd9Sstevel@tonic-gate  * with args separated by colons and given by:
126*7c478bd9Sstevel@tonic-gate  *
127*7c478bd9Sstevel@tonic-gate  *	poffset
128*7c478bd9Sstevel@tonic-gate  *	indent
129*7c478bd9Sstevel@tonic-gate  *	length
130*7c478bd9Sstevel@tonic-gate  *	totrap
131*7c478bd9Sstevel@tonic-gate  *	file[(page)]
132*7c478bd9Sstevel@tonic-gate  *	height[,width[,yoffset[,xoffset]]]
133*7c478bd9Sstevel@tonic-gate  *	[flags]
134*7c478bd9Sstevel@tonic-gate  *
135*7c478bd9Sstevel@tonic-gate  * poffset, indent, length, and totrap are given in machine units. height, width,
136*7c478bd9Sstevel@tonic-gate  * and offset refer to the picture frame in inches, unless they're followed by
137*7c478bd9Sstevel@tonic-gate  * the u scale indicator. flags is a string that provides a little bit of control
138*7c478bd9Sstevel@tonic-gate  * over the placement of the picture in the frame. Rotation of the picture, in
139*7c478bd9Sstevel@tonic-gate  * clockwise degrees, is set by the a flag. If it's not followed by an angle
140*7c478bd9Sstevel@tonic-gate  * the current rotation angle is incremented by 90 degrees, otherwise the angle
141*7c478bd9Sstevel@tonic-gate  * is set by the number that immediately follows the a.
142*7c478bd9Sstevel@tonic-gate  *
143*7c478bd9Sstevel@tonic-gate  */
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate     if ( picflag == OFF )		/* skip it */
147*7c478bd9Sstevel@tonic-gate 	return;
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate     endtext();
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate     flags[0] = '\0';			/* just to be safe */
152*7c478bd9Sstevel@tonic-gate     if ( sscanf(buf, "%d:%d:%d:%d:%[^:]:%[^:]:%[^:]", &poffset, &indent,
153*7c478bd9Sstevel@tonic-gate 		&length, &totrap, name, hwo, flags) < 6 )  {
154*7c478bd9Sstevel@tonic-gate 	    error(NON_FATAL, "too few arguments to specify picture");
155*7c478bd9Sstevel@tonic-gate 	    return;
156*7c478bd9Sstevel@tonic-gate     }	/* End if */
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate     if ( sscanf(name, "%*[^(](%d", &page) == 1 )	/* grab the page number */
159*7c478bd9Sstevel@tonic-gate 	strtok(name, "(");			/* and separate it from the name */
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate     if ( (fp_in = picopen(name)) == NULL ) {
162*7c478bd9Sstevel@tonic-gate 	error(NON_FATAL, "can't open picture file %s", name);
163*7c478bd9Sstevel@tonic-gate 	return;
164*7c478bd9Sstevel@tonic-gate     }	/* End if */
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate     frame[0] = frame[1] = -1;		/* default frame height, width */
167*7c478bd9Sstevel@tonic-gate     frame[2] = frame[3] = 0;		/* and y and x offsets */
168*7c478bd9Sstevel@tonic-gate 
169*7c478bd9Sstevel@tonic-gate     for ( i = 0, p = hwo-1; i < 4 && p != NULL; i++, p = strchr(p, ',') )
170*7c478bd9Sstevel@tonic-gate 	if ( sscanf(++p, "%lf%c", &frame[i], &units) == 2 )
171*7c478bd9Sstevel@tonic-gate 	    if ( units == 'i' || units == ',' || units == '\0' )
172*7c478bd9Sstevel@tonic-gate 		frame[i] *= res;
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate     if ( frame[0] <= 0 )		/* check what we got for height */
175*7c478bd9Sstevel@tonic-gate 	frame[0] = totrap;
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate     if ( frame[1] <= 0 )		/* and width - check too big?? */
178*7c478bd9Sstevel@tonic-gate 	frame[1] = length - indent;
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate     frame[3] += poffset + indent;	/* real x offset */
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate     for ( i = 0; flags[i]; i++ )
183*7c478bd9Sstevel@tonic-gate 	switch ( flags[i] )  {
184*7c478bd9Sstevel@tonic-gate 	    case 'c': adjx = adjy = 0.5; break;	/* move to the center */
185*7c478bd9Sstevel@tonic-gate 	    case 'l': adjx = 0; break;		/* left */
186*7c478bd9Sstevel@tonic-gate 	    case 'r': adjx = 1; break;		/* right */
187*7c478bd9Sstevel@tonic-gate 	    case 't': adjy = 1; break;		/* top */
188*7c478bd9Sstevel@tonic-gate 	    case 'b': adjy = 0; break;		/* or bottom justify */
189*7c478bd9Sstevel@tonic-gate 	    case 'o': outline = 1; break;	/* outline the picture */
190*7c478bd9Sstevel@tonic-gate 	    case 'w': whiteout = 1; break;	/* white out the box */
191*7c478bd9Sstevel@tonic-gate 	    case 's': scaleboth = 1; break;	/* scale both dimensions */
192*7c478bd9Sstevel@tonic-gate 	    case 'a': if ( sscanf(&flags[i+1], "%lf", &rot) != 1 )
193*7c478bd9Sstevel@tonic-gate 			  rot += 90;
194*7c478bd9Sstevel@tonic-gate 	}   /* End switch */
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate     fprintf(tf, "cleartomark restore\n");
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate     ps_include(fp_in, tf, page, whiteout, outline, scaleboth,
199*7c478bd9Sstevel@tonic-gate 		frame[3]+frame[1]/2, -vpos-frame[2]-frame[0]/2, frame[1], frame[0], adjx, adjy, -rot);
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate     fprintf(tf, "save mark\n");
202*7c478bd9Sstevel@tonic-gate     xymove(hpos, vpos);
203*7c478bd9Sstevel@tonic-gate     t_sf();
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate     fclose(fp_in);
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate }   /* End of picture */
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate /*****************************************************************************/
211*7c478bd9Sstevel@tonic-gate 
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate FILE *picopen(path)
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate     char	*path;			/* picture file pathname */
217*7c478bd9Sstevel@tonic-gate 
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate {
220*7c478bd9Sstevel@tonic-gate 
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate     char	name[100];		/* pathnames */
223*7c478bd9Sstevel@tonic-gate     long	total;			/* and sizes - from *fp_pic */
224*7c478bd9Sstevel@tonic-gate     char	*tname;			/* pathname */
225*7c478bd9Sstevel@tonic-gate     FILE	*fp;			/* and pointer for the new temp file */
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate 
228*7c478bd9Sstevel@tonic-gate /*
229*7c478bd9Sstevel@tonic-gate  *
230*7c478bd9Sstevel@tonic-gate  * Responsible for finding and opening the next picture file. If we've accumulated
231*7c478bd9Sstevel@tonic-gate  * any in-line pictures fp_pic won't be NULL and we'll look there first. If *path
232*7c478bd9Sstevel@tonic-gate  * is found in *fp_pic we create another temp file, open it for update, unlink it,
233*7c478bd9Sstevel@tonic-gate  * copy in the picture, seek back to the start of the new temp file, and return
234*7c478bd9Sstevel@tonic-gate  * the file pointer to the caller. If fp_pic is NULL or the lookup fails we just
235*7c478bd9Sstevel@tonic-gate  * open file *path and return the resulting file pointer to the caller.
236*7c478bd9Sstevel@tonic-gate  *
237*7c478bd9Sstevel@tonic-gate  */
238*7c478bd9Sstevel@tonic-gate 
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate     if ( fp_pic != NULL )  {
241*7c478bd9Sstevel@tonic-gate 	fseek(fp_pic, 0L, 0);
242*7c478bd9Sstevel@tonic-gate 	while ( fscanf(fp_pic, "%s %ld\n", name, &total) != EOF )  {
243*7c478bd9Sstevel@tonic-gate 	    if ( strcmp(path, name) == 0 )  {
244*7c478bd9Sstevel@tonic-gate 		if ( (tname = tempnam(TEMPDIR, "dpost")) == NULL )
245*7c478bd9Sstevel@tonic-gate 		    error(FATAL, "can't generate temp file name");
246*7c478bd9Sstevel@tonic-gate 		if ( (fp = fopen(tname, "w+")) == NULL )
247*7c478bd9Sstevel@tonic-gate 		    error(FATAL, "can't open %s", tname);
248*7c478bd9Sstevel@tonic-gate 		unlink(tname);
249*7c478bd9Sstevel@tonic-gate 		free(tname);
250*7c478bd9Sstevel@tonic-gate 		piccopy(fp_pic, fp, total);
251*7c478bd9Sstevel@tonic-gate 		fseek(fp, 0L, 0);
252*7c478bd9Sstevel@tonic-gate 		return(fp);
253*7c478bd9Sstevel@tonic-gate 	    }   /* End if */
254*7c478bd9Sstevel@tonic-gate 	    fseek(fp_pic, total, 1);
255*7c478bd9Sstevel@tonic-gate 	}   /* End while */
256*7c478bd9Sstevel@tonic-gate     }	/* End if */
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate     return(fopen(path, "r"));
259*7c478bd9Sstevel@tonic-gate 
260*7c478bd9Sstevel@tonic-gate }   /* End of picopen */
261*7c478bd9Sstevel@tonic-gate 
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate /*****************************************************************************/
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate 
266*7c478bd9Sstevel@tonic-gate inlinepic(fp, buf)
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate 
269*7c478bd9Sstevel@tonic-gate     FILE	*fp;			/* current input file */
270*7c478bd9Sstevel@tonic-gate     char	*buf;			/* whatever followed "x X InlinePicture" */
271*7c478bd9Sstevel@tonic-gate 
272*7c478bd9Sstevel@tonic-gate 
273*7c478bd9Sstevel@tonic-gate {
274*7c478bd9Sstevel@tonic-gate 
275*7c478bd9Sstevel@tonic-gate 
276*7c478bd9Sstevel@tonic-gate     char	*tname;			/* temp file pathname - for *fp_pic */
277*7c478bd9Sstevel@tonic-gate     char	name[100];		/* picture file pathname */
278*7c478bd9Sstevel@tonic-gate     long	total;			/* and size - both from *buf */
279*7c478bd9Sstevel@tonic-gate 
280*7c478bd9Sstevel@tonic-gate 
281*7c478bd9Sstevel@tonic-gate /*
282*7c478bd9Sstevel@tonic-gate  *
283*7c478bd9Sstevel@tonic-gate  * Adds an in-line picture file to the end of temporary file *fp_pic. All pictures
284*7c478bd9Sstevel@tonic-gate  * grabbed from the input file are saved in the same temp file. Each is preceeded
285*7c478bd9Sstevel@tonic-gate  * by a one line header that includes the original picture file pathname and the
286*7c478bd9Sstevel@tonic-gate  * size of the picture in bytes. The in-line picture file is opened for update,
287*7c478bd9Sstevel@tonic-gate  * left open, and unlinked so it disappears when we do.
288*7c478bd9Sstevel@tonic-gate  *
289*7c478bd9Sstevel@tonic-gate  */
290*7c478bd9Sstevel@tonic-gate 
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate     if ( fp_pic == NULL )  {
293*7c478bd9Sstevel@tonic-gate 	if ( (tname = tempnam(TEMPDIR, "dpost")) == NULL )
294*7c478bd9Sstevel@tonic-gate 	    error(FATAL, "can't generate in-line picture file name");
295*7c478bd9Sstevel@tonic-gate 	if ( (fp_pic = fopen(tname, "w+")) == NULL )
296*7c478bd9Sstevel@tonic-gate 	    error(FATAL, "can't open in-line picture file %s", tname);
297*7c478bd9Sstevel@tonic-gate 	unlink(tname);
298*7c478bd9Sstevel@tonic-gate     }	/* End if */
299*7c478bd9Sstevel@tonic-gate 
300*7c478bd9Sstevel@tonic-gate     if ( sscanf(buf, "%s %ld", name, &total) != 2 )
301*7c478bd9Sstevel@tonic-gate 	error(FATAL, "in-line picture error");
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate     fseek(fp_pic, 0L, 2);
304*7c478bd9Sstevel@tonic-gate     fprintf(fp_pic, "%s %ld\n", name, total);
305*7c478bd9Sstevel@tonic-gate     getc(fp);
306*7c478bd9Sstevel@tonic-gate     fflush(fp_pic);
307*7c478bd9Sstevel@tonic-gate     piccopy(fp, fp_pic, total);
308*7c478bd9Sstevel@tonic-gate     ungetc('\n', fp);
309*7c478bd9Sstevel@tonic-gate 
310*7c478bd9Sstevel@tonic-gate }   /* End of inlinepic */
311*7c478bd9Sstevel@tonic-gate 
312*7c478bd9Sstevel@tonic-gate 
313*7c478bd9Sstevel@tonic-gate /*****************************************************************************/
314*7c478bd9Sstevel@tonic-gate 
315*7c478bd9Sstevel@tonic-gate 
316*7c478bd9Sstevel@tonic-gate piccopy(fp_in, fp_out, total)
317*7c478bd9Sstevel@tonic-gate 
318*7c478bd9Sstevel@tonic-gate 
319*7c478bd9Sstevel@tonic-gate     FILE	*fp_in;			/* input */
320*7c478bd9Sstevel@tonic-gate     FILE	*fp_out;		/* and output file pointers */
321*7c478bd9Sstevel@tonic-gate     long	total;			/* number of bytes to be copied */
322*7c478bd9Sstevel@tonic-gate 
323*7c478bd9Sstevel@tonic-gate 
324*7c478bd9Sstevel@tonic-gate {
325*7c478bd9Sstevel@tonic-gate 
326*7c478bd9Sstevel@tonic-gate 
327*7c478bd9Sstevel@tonic-gate     long	i;			/* loop index */
328*7c478bd9Sstevel@tonic-gate 
329*7c478bd9Sstevel@tonic-gate 
330*7c478bd9Sstevel@tonic-gate /*
331*7c478bd9Sstevel@tonic-gate  *
332*7c478bd9Sstevel@tonic-gate  * Copies total bytes from file fp_in to fp_out. Used to append picture files to
333*7c478bd9Sstevel@tonic-gate  * *fp_pic and then copy them to yet another temporary file immediately before
334*7c478bd9Sstevel@tonic-gate  * they're used (in picture()).
335*7c478bd9Sstevel@tonic-gate  *
336*7c478bd9Sstevel@tonic-gate  */
337*7c478bd9Sstevel@tonic-gate 
338*7c478bd9Sstevel@tonic-gate 
339*7c478bd9Sstevel@tonic-gate     for ( i = 0; i < total; i++ )
340*7c478bd9Sstevel@tonic-gate 	if ( putc(getc(fp_in), fp_out) == EOF )
341*7c478bd9Sstevel@tonic-gate 	    error(FATAL, "error copying in-line picture file");
342*7c478bd9Sstevel@tonic-gate     fflush(fp_out);
343*7c478bd9Sstevel@tonic-gate 
344*7c478bd9Sstevel@tonic-gate }   /* End of piccopy */
345*7c478bd9Sstevel@tonic-gate 
346*7c478bd9Sstevel@tonic-gate 
347*7c478bd9Sstevel@tonic-gate /*****************************************************************************/
348*7c478bd9Sstevel@tonic-gate 
349