postplot.c revision f928ce67ef743c33ea27c573c9c7e2d4a4833cbd
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*
* postplot - PostScript translator for Unix (System V) plot files.
*
* Only support (currently) is for the System V version of plot. Ninth Edition
* plot is completely different and probably will need a separate translator.
* If character placement appears to be off a bit try changing the definitions
* of xtextshift and ytextshift in the prologue. Didn't spend much time trying
* to speed things up - there's undoubtedly much that could still be done.
*
* The program expects that the following PostScript procedures are defined in
* the prologue:
*
* setup
*
* mark ... setup -
*
* Handles special initialization stuff that depends on how this program
* stack. The def operator is applied to each pair up to the mark, then
* the default state is set up.
*
* pagesetup
*
* page pagesetup -
*
* Does whatever is needed to set things up for the next page. Expect
* to find the current page number on the stack.
*
* space
*
* height width space -
*
* Defines the height and width of the image space. Called outside page
* once at the beginning of each job.
*
* setupspace
*
* setupspace
*
* Finishes setting up the page coordinate system using the height and
* width definitions made by space (above). Usually called at the start
* of each page.
*
* l
*
* x0 y0 x1 y1 l -
*
* Draws a line from (x0, y0) to (x1, y1).
*
* n
*
* x y n -
*
* Adds the line segment from (hpos, vpos) to (x, y) to the current
* path.
*
* p
*
* x y p -
*
* Marks point (x, y) with a filled circle whose radius varies with
* the linewidth.
*
* c
*
* x y r c -
*
* Draws a circle of radius r centered at (x, y).
*
* a
*
* x y dx1 dy1 dx2 dy2 a -
*
* Draws a counterclockwise arc centered at (x, y) through (x+dx1, y+dy1)
* to (x+dx2, y+dy2).
*
* t
*
* s x y t -
*
* Prints string s starting at (x, y). xtextshift and ytextshift provide
* additional control over the placement of text strings.
*
* f
*
* array f -
*
* Selects the line style (e.g. dotted) according to the pattern in array.
*
* m
*
* x y m
*
* Starts a new path that begins at (x, y) - only used with connected
* lines.
*
* s
*
* s
*
* Strokes the current path - again only used with connected lines.
*
* done
*
* done
*
* Makes sure the last page is printed. Only needed when we're printing
* more than one page on each sheet of paper.
*
* The default line width is zero, which forces lines to be one pixel wide. That
* works well on 'write to black' engines but won't be right for 'write to white'
* engines. The line width can be changed using the -w option, or you can change
* the initialization of linewidth in the prologue.
*
*/
#include <stdio.h>
#include <signal.h>
#include <ctype.h>
#include <fcntl.h>
#include "comments.h" /* PostScript file structuring comments */
#include "gen.h" /* general purpose definitions */
#include "path.h" /* for the prologue */
#include "ext.h" /* external variable declarations */
#include "postplot.h" /* a few special definitions */
char *optnames = "a:c:f:m:n:o:p:s:w:x:y:A:C:J:L:P:R:DI";
int hpos; /* current horizontal */
int vpos; /* and vertical position */
int linestyle = 0; /* index into styles[] */
int page = 0; /* page we're working on */
int printed = 0; /* printed this many pages */
static void account(void);
static void arguments(void);
static void connect(void);
static void done(void);
static void formfeed(void);
static char *get_font(char *);
static int getint(void);
static void getstring(char *);
static void header(void);
static void init_signals(void);
static void options(void);
static void plot(void);
static void redirect(int);
static void setstyle(char *);
static void setup(void);
/*****************************************************************************/
int
{
/*
*
* Plot to PostScript translator for System V only.
*
*/
init_signals(); /* sets up interrupt handling */
header(); /* PostScript header and prologue */
options(); /* handle the command line options */
setup(); /* for PostScript */
arguments(); /* followed by each input file */
done(); /* print the last page etc. */
account(); /* job accounting data */
return (x_stat); /* not much could be wrong */
} /* End of main */
/*****************************************************************************/
static void
init_signals(void)
{
void interrupt(); /* signal handler */
/*
*
* Makes sure we handle interrupts.
*
*/
} else {
} /* End else */
} /* End of init_signals */
/*****************************************************************************/
static void
header(void)
{
int ch; /* return value from getopt() */
/*
*
* Scans the option list looking for things, like the prologue file, that we need
* right away but could be changed from the default. Doing things this way is an
* attempt to conform to Adobe's latest file structuring conventions. In particular
* they now say there should be nothing executed in the prologue, and they have
* added two new comments that delimit global initialization calls. Once we know
* where things really are we write out the job header, follow it by the prologue,
* and then add the ENDPROLOG and BEGINSETUP comments.
*
*/
if ( ch == 'L' )
else if ( ch == '?' )
} /* End of header */
/*****************************************************************************/
static void
options(void)
{
int ch; /* return value from getopt() */
/*
*
* Reads and processes the command line options. Added the -P option so arbitrary
* PostScript code can be passed through. Expect it could be useful for changing
* definitions in the prologue for which options have not been defined.
*
*/
switch ( ch ) {
case 'a': /* aspect ratio */
break;
case 'c': /* copies */
break;
case 'f': /* use this PostScript font */
break;
case 'm': /* magnification */
break;
case 'n': /* forms per page */
break;
case 'o': /* output page list */
break;
case 'p': /* landscape or portrait mode */
if ( *optarg == 'l' )
break;
case 's': /* point size */
break;
case 'w': /* line width */
break;
case 'x': /* shift things horizontally */
break;
case 'y': /* and vertically on the page */
break;
case 'A': /* force job accounting */
case 'J':
break;
case 'C': /* copy file straight to output */
break;
case 'L': /* PostScript prologue file */
break;
case 'P': /* PostScript pass through */
break;
case 'R': /* special global or page level request */
break;
case 'D': /* debug flag */
break;
case 'I': /* ignore FATAL errors */
break;
case '?': /* don't understand the option */
break;
default: /* don't know what to do for ch */
break;
} /* End switch */
} /* End while */
} /* End of options */
/*****************************************************************************/
static char *
/* name the user asked for */
{
int i; /* for looking through fontmap[] */
/*
*
* Called from options() to map a user's font name into a legal PostScript name.
* If the lookup fails *name is returned to the caller. That should let you choose
* any PostScript font.
*
*/
return(name);
} /* End of get_font */
/*****************************************************************************/
static void
setup(void)
{
/*
*
* Handles things that must be done after the options are read but before the
* input files are processed.
*
*/
if ( formsperpage > 1 ) {
} /* End if */
} /* End of setup */
/*****************************************************************************/
static void
arguments(void)
{
/*
*
* Makes sure all the non-option command line arguments are processed. If we get
* here and there aren't any arguments left, or if '-' is one of the input files
* we'll translate stdin.
*
*/
if ( argc < 1 )
plot();
else { /* at least one argument is left */
while ( argc > 0 ) {
plot();
argc--;
argv++;
} /* End while */
} /* End else */
} /* End of arguments */
/*****************************************************************************/
static void
plot(void)
{
int c;
char s[256];
int n, i, pat[256];
/*
*
* Parser - borrowed directly from tplot source.
*
*/
redirect(-1);
formfeed();
switch(c) {
case 'm':
break;
case 'l':
break;
case 't':
getstring(s);
if ( *s != '\0' )
break;
case 'e':
formfeed();
break;
case 'p':
break;
case 'n':
connect();
break;
case 's':
break;
case 'a':
break;
case 'c':
r = getint();
break;
case 'f':
getstring(s);
setstyle(s);
break;
case 'd': /* undocumented and unimplemented */
n = getint();
/*dot(x0,y0,dx0,n,pat);*/
break;
default:
} /* End switch */
} /* End while */
formfeed();
} /* End of plot */
/*****************************************************************************/
static void
connect(void)
{
int c;
int x, y;
int count = 0; /* so the path doesn't get to big */
/*
*
* Reads consecutive connect commands from the input file. Can't let the path
* get too big, so it's occasionally stroked.
*
*/
if ( count++ > 100 ) {
count = 1;
} /* End if */
x = getint();
y = getint();
hpos = x;
vpos = y;
} /* End while */
} /* End of connect */
/*****************************************************************************/
static void
{
int i;
/*
*
* Selects the line style that matches *str. No match resets the style to solid
* (unless you've changed STYLES in postplot.h).
*
*/
break;
linestyle = i;
} /* End if */
} /* End of setstyle */
/*****************************************************************************/
static int
getint(void)
{
short a, b;
/*
*
* Returns the integer stored in the next two bytes.
*
*/
return(EOF);
return(EOF);
a = a<<8;
return(a|b);
} /* End of getint */
/*****************************************************************************/
static void
getstring(char *s)
{
int c;
/*
*
* Reads characters, up to a newline, and stores the quoted string in s.
*
*/
if ( c == '(' || c == ')' || c == '\\' )
*s++ = '\\';
if( (*s = c) == '\n' )
break;
} /* End for */
*s = '\0';
} /* End of getstring */
/*****************************************************************************/
static void
done(void)
{
/*
*
* Finished with all the input files, so mark the end of the pages with a TRAILER
* comment, make sure the last page prints, and add things like the PAGES comment
* that can only be determined after all the input files have been read.
*
*/
} /* End of done */
/*****************************************************************************/
static void
account(void)
{
/*
*
* Writes an accounting record to *fp_acct provided it's not NULL. Accounting is
* requested using the -A or -J options.
*
*/
} /* End of account */
/*****************************************************************************/
static void
formfeed(void)
{
/*
*
* Called whenever we've finished with the last page and want to get ready for the
* next one. Also used at the beginning and end of each input file, so we have to
* be careful about what's done. The first time through (up to the redirect() call)
*
* Adobe now recommends that the showpage operator occur after the page level
* restore so it can be easily redefined to have side-effects in the printer's VM.
* Although it seems reasonable I haven't implemented it, because it makes other
* things, like selectively setting manual feed or choosing an alternate paper
* tray, clumsy - at least on a per page basis.
*
*/
printed++;
redirect(-1);
} /* End of formfeed */
/*****************************************************************************/
static void
/* next page we're printing */
{
/*
*
* otherwise output goes to stdout.
*
*/
} /* End of redirect */