posttek.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* 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 (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
/*
*
* posttek - PostScript translator for tektronix 4014 files
*
* A program that can be used to translate tektronix 4014 files into PostScript.
* Most of the code was borrowed from the tektronix 4014 emulator that was written
* for DMDs. Things have been cleaned up some, but there's still plently that
* could be done.
*
* The PostScript prologue is copied from *prologue before any of the input files
* are translated. The program expects that the following PostScript procedures
* are defined in that file:
*
* setup
*
* mark ... setup -
*
* Handles special initialization stuff that depends on how the 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. Expects
* to find the current page number on the stack.
*
* v
*
* mark dx1 dy1 ... dxn dyn x y v mark
*
* Draws the vector described by the numbers on the stack. The top two
* numbers are the starting point. The rest are relative displacements
* from the preceeding point. Must make sure we don't put too much on
* the stack!
*
* t
*
* x y string t -
*
* Prints the string that's on the top of the stack starting at point
* (x, y).
*
* p
*
* x y p -
*
* Marks the point (x, y) with a circle whose radius varies with the
* current intensity setting.
*
* i
*
* percent focus i -
*
* Changes the size of the circle used to mark individual points to
* percent of maximum for focused mode (focus=1) or defocused mode
* (focus=0). The implementation leaves much to be desired!
*
* l
*
* mark array l mark
*
* Set the line drawing mode according to the description given in array.
* The arrays that describe the different line styles are declared in
* STYLES (file posttek.h). The array really belongs in the prologue!
*
* w
*
* n w -
*
* Adjusts the line width for vector drawing. Used to select normal (n=0)
* or defocused (n=1) mode.
*
* f
*
* size f -
*
* Changes the size of the font that's used to print characters in alpha
* mode. size is the tektronix character width and is used to choose an
* appropriate point size in the current font.
*
* 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.
*
* Many default values, like the magnification and orientation, are defined in
* the prologue, which is where they belong. If they're changed (by options), an
* appropriate definition is made after the prologue is added to the output file.
* The -P option passes arbitrary PostScript through to the output file. Among
* other things it can be used to set (or change) values that can't be accessed by
* other options.
*
*/
#include <stdio.h>
#include <signal.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 definitions */
#include "posttek.h" /* control codes and other definitions */
char *optnames = "a:c:f:m:n:o:p:w:x:y:A:C:J:L:P:R:DI";
int linestyle = 0; /* index into styles[] */
int linetype = 0; /* 0 for normal, 1 for defocused */
int points = 0; /* points making up the current vector */
int characters = 0; /* characters waiting to be printed */
int margin = 0; /* left edge - ALPHA state */
int page = 0; /* page we're working on */
int printed = 0; /* printed this many pages */
/*****************************************************************************/
int agc;
char *agv[];
{
/*
*
* A simple program that can be used to translate tektronix 4014 files into
* PostScript. Most of the code was taken from the DMD tektronix 4014 emulator,
* although things have been cleaned up some.
*
*/
init_signals(); /* sets up interrupt handling */
header(); /* PostScript header comments */
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 */
} /* End of main */
/*****************************************************************************/
{
void interrupt(); /* signal handler */
/*
*
* Make sure we handle interrupts.
*
*/
} else {
} /* End else */
} /* End of init_signals */
/*****************************************************************************/
header()
{
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 */
/*****************************************************************************/
options()
{
int ch; /* value returned by 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 'w': /* line width */
break;
case 'x': /* shift 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 know the option */
break;
default: /* don't know what to do for ch */
break;
} /* End switch */
} /* End while */
} /* End of options */
/*****************************************************************************/
char *name; /* 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 */
/*****************************************************************************/
setup()
{
/*
*
* 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 */
/*****************************************************************************/
{
/*
*
* 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 process stdin.
*
*/
if ( argc < 1 )
else { /* at least one argument is left */
while ( argc > 0 ) {
argc--;
argv++;
} /* End while */
} /* End else */
} /* End of arguments */
/*****************************************************************************/
done()
{
/*
*
* 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 */
/*****************************************************************************/
account()
{
/*
*
* Writes an accounting record to *fp_acct provided it's not NULL. Accounting
* is requested using the -A or -J options.
*
*/
} /* End of account */
/*****************************************************************************/
{
/*
*
* Controls the translation of the next input file. Tektronix states (dispmode)
* are typically changed in control() and esc().
*
*/
formfeed();
while ( 1 )
switch ( dispmode ) {
case RESET:
reset();
break;
case ALPHA:
alpha();
break;
case GIN:
gin();
break;
case GRAPH:
graph();
break;
case POINT:
case SPECIALPOINT:
point();
break;
case INCREMENTAL:
incremental();
break;
case EXIT:
formfeed();
return;
} /* End switch */
} /* End of statemachine */
/*****************************************************************************/
reset()
{
/*
*
* Called to reset things, typically only at the beginning of each input file.
*
*/
tekfont = -1;
home();
} /* End of reset */
/*****************************************************************************/
alpha()
{
int c; /* next character */
int x, y; /* cursor will be here when we're done */
/*
*
* Takes care of printing characters in the current font.
*
*/
return;
if ( (c < 040) && ((c = control(c)) <= 0) )
return;
x = cursor.x; /* where the cursor is right now */
y = cursor.y;
switch ( c ) {
case DEL:
return;
case BS:
break;
case NL:
y -= charheight[tekfont];
break;
case CR:
x = margin;
break;
case VT:
y = 0;
break;
case HT:
case ' ':
default:
if ( characters++ == 0 )
switch ( c ) {
case '(':
case ')':
case '\\':
default:
} /* End switch */
move(x, y);
break;
} /* End switch */
if (x >= TEKXMAX) {
x = margin;
y -= charheight[tekfont];
} /* End if */
if (y < 0) {
x -= margin;
x -= margin;
} /* End if */
text();
move(x, y);
} /* End of alpha */
/*****************************************************************************/
graph()
{
int c; /* next character */
int b; /* for figuring out loy */
int x, y; /* next point in the vector */
static int extra; /* for extended addressing */
/*
*
* Handles things when we're in GRAPH, POINT, or SPECIALPOINT mode.
*
*/
if ((c = nextchar()) < 040) {
control(c);
return;
} /* End if */
if ((c & 0140) == 040) { /* new hiy */
hiy = c & 037;
do
return;
while (c == 0);
} /* End if */
if ((c & 0140) == 0140) { /* new loy */
b = c & 037;
do
return;
while (c == 0);
if ((c & 0140) == 0140) { /* no, it was extra */
extra = b;
loy = c & 037;
do
return;
while (c == 0);
} else loy = b;
} /* End if */
if ((c & 0140) == 040) { /* new hix */
hix = c & 037;
do
return;
while (c == 0);
} /* End if */
if (extra & 020)
draw();
points = 1;
} /* End if */
if ( points++ )
move(x, y); /* adjust the cursor */
} /* End of graph */
/*****************************************************************************/
point()
{
int c; /* next input character */
/*
*
* Special point mode permits gray scaling by varying the size of the stored
* point, which is controlled by an intensity character that preceeds each point
* address.
*
*/
if ( dispmode == SPECIALPOINT ) {
return(control(c));
} /* End if */
graph();
draw();
} /* End of point */
/*****************************************************************************/
{
int c; /* for the next few characters */
int x, y; /* cursor position when we're done */
/*
*
* Handles incremental plot mode. It's entered after the RS control code and is
* used to mark points relative to our current position. It's typically followed
* by one or two bytes that set the pen state and are used to increment the
* current position.
*
*/
return;
if ( (c < 040) && ((c = control(c)) <= 0) )
return;
x = cursor.x; /* where we are right now */
y = cursor.y;
if ( c & 060 )
if ( c & 04 ) y++;
if ( c & 010 ) y--;
if ( c & 01 ) x++;
if ( c & 02 ) x--;
move(x, y);
points = 1;
draw();
} /* End if */
} /* End of incremental */
/*****************************************************************************/
gin()
{
/*
*
* All we really have to do for GIN mode is make sure it's properly ended.
*
*/
} /* End of gin */
/*****************************************************************************/
control(c)
int c; /* check this control character */
{
/*
*
* Checks character c and does special things, like mode changes, that depend
* not only on the character, but also on the current state. If the mode changed
* becuase of c, OUTMODED is returned to the caller. In all other cases the
* return value is c or 0, if c doesn't make sense in the current mode.
*
*/
switch ( c ) {
case BEL:
return(0);
case BS:
case HT:
case VT:
case CR:
return(OUTMODED);
} else return(c);
case FS:
return(OUTMODED);
} /* End if */
return(0);
case GS:
return(OUTMODED);
} /* End if */
return(0);
case NL:
case RS:
return(OUTMODED);
} /* End if */
return(0);
case US:
return(0);
return(OUTMODED);
case ESC:
return(esc());
case OUTMODED:
return(c);
default:
return(c < 040 ? 0 : c);
} /* End switch */
} /* End of control */
/*****************************************************************************/
esc()
{
int c; /* next input character */
int ignore; /* skip it if nonzero */
/*
*
* Handles tektronix escape code. Called from control() whenever an ESC character
* is found in the input file.
*
*/
do {
c = nextchar();
ignore = 0;
switch ( c ) {
case CAN:
return(0);
case CR:
ignore = 1;
break;
case ENQ:
return(OUTMODED);
case ETB:
return(0);
case FF:
formfeed();
return(OUTMODED);
case FS:
return(0);
return(OUTMODED);
case SI:
case SO:
return(0);
case SUB:
return(OUTMODED);
case OUTMODED:
return(OUTMODED);
case '8':
case '9':
case ':':
case ';':
setfont(c - '8');
return(0);
default:
return(DEL);
if ( (c<'`') || (c>'w') )
break;
c -= '`';
if ( (c & 010) != linetype )
if ( ((c + 1) & 7) >= 6 )
break;
if ( (c + 1) & 7 )
if ( (c & 7) != linestyle ) {
linestyle = c & 7;
} /* End if */
return(0);
} /* End switch */
} while (ignore);
return(0);
} /* End of esc */
/*****************************************************************************/
move(x, y)
int x, y; /* move the cursor here */
{
/*
*
* Moves the cursor to the point (x, y).
*
*/
cursor.x = x;
cursor.y = y;
} /* End of move */
/*****************************************************************************/
int mode; /* this should be the new mode */
{
/*
*
* Makes sure the current mode is properly ended and then sets dispmode to mode.
*
*/
switch ( dispmode ) {
case ALPHA:
text();
break;
case GRAPH:
draw();
break;
case INCREMENTAL:
break;
} /* End switch */
} /* End of setmode */
/*****************************************************************************/
home()
{
/*
*
* Makes sure the cursor is positioned at the upper left corner of the page.
*
*/
margin = 0;
} /* End of home */
/*****************************************************************************/
int newfont; /* use this font next */
{
/*
*
* Generates the call to the procedure that's responsible for changing the
* tektronix font (really just the size).
*
*/
} /* End if */
} /* End of setfont */
/*****************************************************************************/
text()
{
/*
*
* Makes sure any text we've put on the stack is printed.
*
*/
characters = 0;
} /* End of text */
/*****************************************************************************/
draw()
{
/*
*
* Called whenever we need to draw a vector or plot a point. Nothing will be
* done if points is 0 or if it's 1 and we're in GRAPH mode.
*
*/
points = 0;
} /* End of draw */
/*****************************************************************************/
formfeed()
{
/*
*
* Usually called when we've finished 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 exactly what's done.
*
*/
printed++;
redirect(-1);
home();
} /* End of formfeed */
/*****************************************************************************/
nextchar()
{
int ch; /* next input character */
/*
*
* Reads the next character from the current input file and returns it to the
* caller. When we're finished with the file dispmode is set to EXIT and OUTMODED
* is returned to the caller.
*
*/
} /* End if */
return(ch);
} /* End of nextchar */
/*****************************************************************************/
int pg; /* next page we're printing */
{
/*
*
* otherwise output goes to stdout.
*
*/
} /* End of redirect */
/*****************************************************************************/