[comp.sources.misc] v06i005: HPGL to PostScript converter

allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) (01/22/89)

Posting-number: Volume 6, Issue 5
Submitted-by: federico@actisb.UUCP (Federico Heinz)
Archive-name: yahp2ps/part03

#! /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 <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 3 (of 6)."
# Contents:  basic.c dispatch.h penctrl.h shade.c
# Wrapped by federico@actisb on Wed Jan  4 13:34:47 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'basic.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'basic.c'\"
else
echo shar: Extracting \"'basic.c'\" \(4204 characters\)
sed "s/^X//" >'basic.c' <<'END_OF_FILE'
X/*
X        HPGL to PostScript converter
X   Copyright (C) 1988 (and following) Federico Heinz
X
Xyahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the Free Software Foundation's General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute yahp2ps,
Xbut only under the conditions described in the GNU General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with yahp2ps so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
XIn other words, go ahead and share yahp2ps, but don't try to stop
Xanyone else from sharing it farther.  Help stamp out software hoarding!
X
Xyahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
Xit is only released under the same conditions.
X
X    For bug reports, wishes, etc. send e-mail to
X
X    ...!mcvax!unido!tub!actisb!federico  (from Europe)
X    ...!uunet!pyramid!actisb!federico    (from anywhere else)
X
X    For Physical mail:
X
X    Federico Heinz
X    Beusselstr. 21
X    1000 Berlin 21
X
X    Tel. (+49 30) 396 77 92
X
X*/
X/***********************************************************************
X
X  Basical pen movement.
X
X***********************************************************************/
X
X#include <ctype.h>
X#include "defs.h"
X#include "penctrl.h"
X#include "io.h"
X#include "dispatch.h"
X#include "basic.h"
X
X
Xstatic Boolean     RelativePlot;         /* Are we plotting relative points? */
Xstatic char        SymbolChar;           /* Plot chars at end of vectors?    */
X
X
X/*
X
X  Reset this module's private status.
X
X*/
X
Xvoid basicInit()
X
X{ RelativePlot = False;
X  setDash(FullLine, P1P2Diagonal / 25);
X  SymbolChar = '\0';
X}
X
X
X
X/*
X
X  Follow a Polyline given as CoordinatePairs.
X
X*/
X
Xstatic void followPolyLine()
X
X{ CoordinatePair target;
X
X  while (isNumeric(LookAhead))
X  { if (!getCoordinatePair(target))
X    { endCommand();
X      return;
X    }
X    if (RelativePlot)
X    { target[X] = PenPosition[X] + target[X];
X      target[Y] = PenPosition[Y] + target[Y];
X    }
X    doLine(target[X], target[Y]);
X    if (SymbolChar)
X      /* symbol mode stuff here */ ;
X  }
X  if (isTerminator(LookAhead))
X    endCommand();
X}
X
X
X/***********************************************************************
X
X  User-controlled pen lifting, lowering and selecting.
X  
X***********************************************************************/
X
X
X/*
X
X  Select a new pen.
X
X*/
X
XCommandImplementation selectPen()
X
X{ Number pen;
X
X  if (isNumeric(LookAhead) && getNumber(&pen))
X    changePen(pen);
X  else
X    changePen(Zero);
X  endCommand();
X}
X
X
X
X/*
X
X  Lift the pen and follow the CoordinatePair list.
X
X*/
X
XCommandImplementation penUp()
X
X{ liftPen();
X  followPolyLine();
X}
X
X
X
X/*
X
X  Lower the pen and follow the CoordinatePair list.
X
X*/
X
XCommandImplementation penDown()
X
X{ lowerPen();
X  followPolyLine();
X}
X
X
X
X/************************************************************************
X
X     Mode switching (absolute/relative, symbol/no symbol)
X  
X************************************************************************/
X
X
X
X/*
X
X  Handle symbol mode switching.
X
X*/
X
XCommandImplementation setSymbolMode()
X
X{ SymbolChar = isTerminator(LookAhead) ? '\0' : getChar();
X  endCommand();
X}
X  
X
X
X/*
X
X  Start plotting with absolute coordinates.
X
X*/
X
XCommandImplementation setAbsolutePlot()
X
X{ RelativePlot = False;
X  followPolyLine();
X}
X
X
X
X/*
X
X  Start plotting with relative coordinate 
X
X*/
X
XCommandImplementation setRelativePlot()
X
X{ RelativePlot = True;
X  followPolyLine();
X}
X
X
X
X
X/*
X
X  Change the line type.
X
X*/
X
XCommandImplementation setLineType()
X
X{ Number pattern, patternLength;
X
X  if (isTerminator(LookAhead))
X    setDash(FullLine, DefaultPatternLength);
X  else if (getInteger(&pattern))
X    if (isTerminator(LookAhead))
X      setDash(pattern, DefaultPatternLength);
X    else if (getInteger(&patternLength))
X      setDash(pattern, patternLength);
X  endCommand();
X}
X
END_OF_FILE
if test 4204 -ne `wc -c <'basic.c'`; then
    echo shar: \"'basic.c'\" unpacked with wrong size!
fi
# end of 'basic.c'
fi
if test -f 'dispatch.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dispatch.h'\"
else
echo shar: Extracting \"'dispatch.h'\" \(5800 characters\)
sed "s/^X//" >'dispatch.h' <<'END_OF_FILE'
X/*
X        HPGL to PostScript converter
X   Copyright (C) 1988 (and following) Federico Heinz
X
Xyahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the Free Software Foundation's General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute yahp2ps,
Xbut only under the conditions described in the GNU General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with yahp2ps so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
XIn other words, go ahead and share yahp2ps, but don't try to stop
Xanyone else from sharing it farther.  Help stamp out software hoarding!
X
Xyahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
Xit is only released under the same conditions.
X
X    For bug reports, wishes, etc. send e-mail to
X
X    ...!mcvax!unido!tub!actisb!federico  (from Europe)
X    ...!uunet!pyramid!actisb!federico    (from anywhere else)
X
X    For Physical mail:
X
X    Federico Heinz
X    Beusselstr. 21
X    1000 Berlin 21
X
X    Tel. (+49 30) 396 77 92
X
X*/
X/**************************************************************************
X
X  Define the HPGL Command data type
X
X***************************************************************************/
X
X
X#define Command int
X
Xextern Command getCommand();    /* Get the next Command from the in stream */
X
X
X/* These are the valid Commands */
X
X#define NotImplemented          0       /* Useless functions in PostScript */
X#define Interactive             1       /* Fuctions requiring Plotter-
X                                           -Computer interaction */
X#define ArcAbsolute             2
X#define ArcRelative             3
X#define SetAlternateChar        4
X#define Circle                  5
X#define CharacterPlot           6
X#define SetStandardChar         7
X#define SetDefaults             8
X#define SetAbsoluteDirection    9
X#define SetRelativeDirection    10
X#define SetLabelTerminator      11
X#define RectangleAbsolute       12
X#define RectangleRelative       13
X#define Wedge                   14
X#define SetFillType             15
X#define Initialize              16
X#define InputP1P2               17
X#define InputWindow             18
X#define PutASCIILabel           19
X#define SetLineType             20
X#define SetAbsolutePlot         21
X#define PenDown                 22
X#define SetRelativePlot         23
X#define SetPaperSize            24
X#define PenUp                   25
X#define ShadeRectAbsolute       26
X#define RotateCoordSys          27
X#define ShadeRectRelative       28
X#define SelectAlternate         29
X#define SetScale                30
X#define SetAbsoluteCharSize     31
X#define SetAbsoluteCharSlant    32
X#define SetSymbolMode           33
X#define SelectPen               34
X#define SetRelativeCharSize     35
X#define SelectStandard          36
X#define SetTickLength           37
X#define UserChar                38
X#define ShadeWedge              39
X#define XTick                   40
X#define YTick                   41
X#define PenThickness		42
X
X#define NumberOfCommands        43
X
X
X
X/***************************************************************************
X
X   Define the CommandImplementation type.
X
X***************************************************************************/
X
Xtypedef void CommandImplementation;
X
X
X
X/****************************************************************************
X
X    These functions implement each command
X
X****************************************************************************/
X
Xextern CommandImplementation notImplemented();
Xextern CommandImplementation interactive();
Xextern CommandImplementation arcAbsolute();
Xextern CommandImplementation arcRelative();
Xextern CommandImplementation setAlternateChar();
Xextern CommandImplementation circle();
Xextern CommandImplementation characterPlot();
Xextern CommandImplementation setStandardChar();
Xextern CommandImplementation setDefaults();
Xextern CommandImplementation setAbsoluteDirection();
Xextern CommandImplementation setRelativeDirection();
Xextern CommandImplementation setLabelTerminator();
Xextern CommandImplementation rectangleAbsolute();
Xextern CommandImplementation rectangleRelative();
Xextern CommandImplementation wedge();
Xextern CommandImplementation setFillType();
Xextern CommandImplementation initialize();
Xextern CommandImplementation inputP1P2();
Xextern CommandImplementation inputWindow();
Xextern CommandImplementation putASCIILabel();
Xextern CommandImplementation setLineType();
Xextern CommandImplementation setAbsolutePlot();
Xextern CommandImplementation penDown();
Xextern CommandImplementation setRelativePlot();
Xextern CommandImplementation setPaperSize();
Xextern CommandImplementation penUp();
Xextern CommandImplementation shadeRectAbsolute();
Xextern CommandImplementation rotateCoordSys();
Xextern CommandImplementation shadeRectRelative();
Xextern CommandImplementation selectAlternate();
Xextern CommandImplementation setScale();
Xextern CommandImplementation setAbsoluteCharSize();
Xextern CommandImplementation setAbsoluteCharSlant();
Xextern CommandImplementation setSymbolMode();
Xextern CommandImplementation selectPen();
Xextern CommandImplementation setRelativeCharSize();
Xextern CommandImplementation selectStandard();
Xextern CommandImplementation setTickLength();
Xextern CommandImplementation userChar();
Xextern CommandImplementation shadeWedge();
Xextern CommandImplementation xTick();
Xextern CommandImplementation yTick();
Xextern CommandImplementation penThickness();
END_OF_FILE
if test 5800 -ne `wc -c <'dispatch.h'`; then
    echo shar: \"'dispatch.h'\" unpacked with wrong size!
fi
# end of 'dispatch.h'
fi
if test -f 'penctrl.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'penctrl.h'\"
else
echo shar: Extracting \"'penctrl.h'\" \(5545 characters\)
sed "s/^X//" >'penctrl.h' <<'END_OF_FILE'
X/*
X        HPGL to PostScript converter
X   Copyright (C) 1988 (and following) Federico Heinz
X
Xyahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the Free Software Foundation's General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute yahp2ps,
Xbut only under the conditions described in the GNU General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with yahp2ps so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
XIn other words, go ahead and share yahp2ps, but don't try to stop
Xanyone else from sharing it farther.  Help stamp out software hoarding!
X
Xyahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
Xit is only released under the same conditions.
X
X    For bug reports, wishes, etc. send e-mail to
X
X    ...!mcvax!unido!tub!actisb!federico  (from Europe)
X    ...!uunet!pyramid!actisb!federico    (from anywhere else)
X
X    For Physical mail:
X
X    Federico Heinz
X    Beusselstr. 21
X    1000 Berlin 21
X
X    Tel. (+49 30) 396 77 92
X
X*/
X/**************************************************************************
X
X   Ideal interface to the graphics hardware.
X
X**************************************************************************/
X
X/* Paper sizes */
X
X#define A	0
X#define A4	1
X#define B	2
X#define A3	3
X
X/* Constants for A paper */
X
X#define MaxXA		103650000L
X#define MaxYA		 79620000L
X
X#define InitialP1XA        2500000L
X#define InitialP1YA        5960000L
X#define InitialP2XA      102500000L
X#define InitialP2YA       77960000L
X
X#define InitialP1XAR       1540000L
X#define InitialP1YAR       2440000L
X#define InitialP2XAR      73540000L
X#define InitialP2YAR     102440000L
X
X
X/* Constants for DIN A4 paper (Default) */
X
X#define MaxXA4          110400000L
X#define MaxYA4           77210000L
X
X#define InitialP1XA4        6030000L
X#define InitialP1YA4        5210000L
X#define InitialP2XA4      106030000L
X#define InitialP2YA4       77210000L
X
X#define InitialP1XA4R         00000L
X#define InitialP1YA4R       6100000L
X#define InitialP2XA4R      72000000L
X#define InitialP2YA4R     106100000L
X
X
X/* Constants for B paper */
X
X#define MaxXB		166400000L
X#define MaxYB		103650000L
X
X#define InitialP1XB         5220000L
X#define InitialP1YB         2590000L
X#define InitialP2XB       157220000L
X#define InitialP2YB       102590000L
X
X#define InitialP1XBR        2830000L
X#define InitialP1YBR        9340000L
X#define InitialP2XBR      102830000L
X#define InitialP2YBR      161340000L
X
X
X/* Constants for A3 paper */
X
X#define MaxXA3		161580000L
X#define MaxYA3		110400000L
X
X#define InitialP1XA3        1700000L
X#define InitialP1YA3        6020000L
X#define InitialP2XA3      153700000L
X#define InitialP2YA3      106020000L
X
X#define InitialP1XA3R       6070000L
X#define InitialP1YA3R       7970000L
X#define InitialP2XA3R     106070000L
X#define InitialP2YA3R     159970000L
X
X
X#define MaxPen	60000L
X
X#define FullLine 70000L
X#define DefaultPatternLength 40000L
X
X
Xextern CoordinatePair PenPosition;          /* Current pen coordinates      */
Xextern CoordinatePair PlotterP1, PlotterP2; /* Pn's coords in Plotter Space */
Xextern Number P1P2Diagonal;		    /* Distance between P1 and P2   */
X
Xextern Boolean PenIsUp;         /* Is the plotting pen up?                  */
Xextern Boolean UserMode;	/* Are we plotting in user coordinates?     */
X
X
X/*
X
X  Convert from user to plotter coordinates
X
X*/
X
X#define PlotterUnitsFactor 40
X
X#define plotterXUnits(x) (UserMode ? \
X                           trunc(mulNum(XScaleFactor, (x))) : \
X                           trunc(x))
X#define plotterYUnits(x) (UserMode ? \
X                           trunc(mulNum(YScaleFactor, (x))) : \
X                           trunc(x))
X
X#define plotterXCoord(x) (UserMode ? \
X                           (trunc(mulNum(XScaleFactor, (x))) + XOrigin) : \
X                           trunc(x))
X#define plotterYCoord(x) (UserMode ? \
X                           (trunc(mulNum(YScaleFactor, (x))) + YOrigin) : \
X                           trunc(x))
X
X
Xextern Number XScaleFactor, YScaleFactor;
Xextern Number XOrigin, YOrigin;
X
X
X/* Change the location of the scaling points */
X
Xextern void changeP1P2();
X
X
X
X/* Reset P1 and P2 to default values */
X
Xextern void resetP1P2();
X
X
X/* Set the window to the whole plotting area */
X
Xextern void resetWindow();
X
X
X/* Set the window to a new value */
X
Xextern void setWindow();
X
X
X/* Reset the the pen control status to default values */
X
Xextern void penctrlInit();
X
X
X/* Set the scaling parameters to reflex the current status */
X
Xextern void updateScaling();
X
X
X/* Quit scaling coordinates */
X
Xextern void turnScalingOff();
X
X
X
X/* From now on, everything will be scaled */
X
Xextern void turnScalingOn();
X
X
X
X/* Rotate the coordinate system */
X
Xextern void rotate();
X
X
X
X/* Return coordinate system to default orientation */
X
Xextern void unRotate();
X
X
X
X/* Moves the pen in it's current state to the absolute coordinates
X   indicated in User Space */
X
Xextern void doLine();
X
X
X
X/* Raises the plotting pen */
X
Xextern void liftPen();
X
X
X
X/* Puts plotting pen in contact with the paper */
X
Xextern void lowerPen();
X
X
X
X/* Get a new pen */
X
Xextern void changePen();
X
X
X
X/* Change the line pattern */
X
Xextern void setDash();
END_OF_FILE
if test 5545 -ne `wc -c <'penctrl.h'`; then
    echo shar: \"'penctrl.h'\" unpacked with wrong size!
fi
# end of 'penctrl.h'
fi
if test -f 'shade.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'shade.c'\"
else
echo shar: Extracting \"'shade.c'\" \(4134 characters\)
sed "s/^X//" >'shade.c' <<'END_OF_FILE'
X/*
X        HPGL to PostScript converter
X   Copyright (C) 1988 (and following) Federico Heinz
X
Xyahp2ps is distributed in the hope that it will be useful, but WITHOUT ANY
XWARRANTY.  No author or distributor accepts responsibility to anyone
Xfor the consequences of using it or for whether it serves any
Xparticular purpose or works at all, unless he says so in writing.
XRefer to the Free Software Foundation's General Public License for full details.
X
XEveryone is granted permission to copy, modify and redistribute yahp2ps,
Xbut only under the conditions described in the GNU General Public
XLicense.  A copy of this license is supposed to have been given to you
Xalong with yahp2ps so you can know your rights and responsibilities.  It
Xshould be in a file named COPYING.  Among other things, the copyright
Xnotice and this notice must be preserved on all copies.
X
XIn other words, go ahead and share yahp2ps, but don't try to stop
Xanyone else from sharing it farther.  Help stamp out software hoarding!
X
Xyahp2ps is TOTALLY unrelated to GNU or the Free Software Foundation,
Xit is only released under the same conditions.
X
X    For bug reports, wishes, etc. send e-mail to
X
X    ...!mcvax!unido!tub!actisb!federico  (from Europe)
X    ...!uunet!pyramid!actisb!federico    (from anywhere else)
X
X    For Physical mail:
X
X    Federico Heinz
X    Beusselstr. 21
X    1000 Berlin 21
X
X    Tel. (+49 30) 396 77 92
X
X*/
X/************************************************************************
X
X  Shaded figures.
X
X************************************************************************/
X
X
X#include "defs.h"
X#include "dispatch.h"
X#include "mchinery.h"
X#include "io.h"
X#include "penctrl.h"
X#include "circle.h"
X#include "shade.h"
X
Xstatic Number FillType;            /* Kind of area filling pattern   */
Xstatic Number FillSpacing;         /* Spacing betwen lines */
Xstatic Number FillAngle;           /* Angle at which to draw pattern */
Xstatic Number PenWidth;            /* User-set pen width */
X
X
X/*
X
X  Set the default parameter values for this module.
X
X*/
X
Xvoid shadeInit()
X
X{ FillType = DefaultFillType;
X  FillSpacing = P1P2Diagonal / 100;
X  FillAngle = Zero;
X  PenWidth = DefaultPenWidth;
X}
X
X/*
X
X  Set the pen's width.
X
X*/
X
XCommandImplementation penThickness()
X
X{ Number temp;
X
X  if (isTerminator(LookAhead) || !getNumber(&temp))
X    PenWidth = DefaultPenWidth;
X  else if ((temp < MinPenWidth) || (temp > MaxPenWidth))
X    warning("Illegal pen thickness.");
X  else
X    PenWidth = temp;
X  endCommand();
X}
X
X
X/*
X
X  Set the area fill parameters.
X
X*/
X
XCommandImplementation setFillType()
X
X{ Number temp;
X
X  if (isTerminator(LookAhead))
X    FillType = DefaultFillType;
X  else if (getInteger(&FillType))
X    if (!isTerminator(LookAhead) && getNumber(&temp))
X    { if (!temp) FillSpacing = PenWidth * PlotterUnitsFactor;
X      else if (UserMode) FillSpacing = plotterXCoord(temp);
X      if (!isTerminator(LookAhead) && getInteger(&temp))
X        if (!(temp % (OneSquare / 2))) FillAngle = temp;
X    }
X  endCommand();
X}
X
X
X
X/*
X
X  Shade a rectangle defined in absolute coordinates.
X
X*/
X
XCommandImplementation shadeRectAbsolute()
X
X{ CoordinatePair corner;
X
X  if (getCoordinatePair(corner))
X    doShadeRectangle(corner, FillType, FillSpacing, FillAngle);
X  endCommand();
X}
X
X
X
X/*
X
X  Shade a rectangle defined in relative coordinates.
X
X*/
X
XCommandImplementation shadeRectRelative()
X
X{ CoordinatePair corner;
X
X  if (getCoordinatePair(corner))
X  { corner[X] = PenPosition[X] + corner[X];
X    corner[Y] = PenPosition[Y] + corner[Y];
X    doShadeRectangle(corner);
X  }
X  endCommand();
X}
X
X
X
X/*
X
X  Shade a circle wedge.
X
X*/
X
XCommandImplementation shadeWedge()
X
X{ Number radius, startAngle, sweepAngle, chordAngle;
X
X  if (getNumber(&radius) &&
X      getInteger(&startAngle) &&
X      getInteger(&sweepAngle))
X  { fixUpStartAndSweep(&startAngle, &sweepAngle);
X    getChordAngle(&chordAngle, sweepAngle, MinimumChordForWedge);
X    if (chordAngle > MaximumChordAngle)
X      warning("Chord angle out of range.");
X    else
X      doShadeWedge(PenPosition, radius, startAngle, sweepAngle, chordAngle,
X                   FillType, FillSpacing, FillAngle);
X    endCommand();
X  }
X}
X
X
X
X
X
X
X
END_OF_FILE
if test 4134 -ne `wc -c <'shade.c'`; then
    echo shar: \"'shade.c'\" unpacked with wrong size!
fi
# end of 'shade.c'
fi
echo shar: End of archive 3 \(of 6\).
cp /dev/null ark3isdone
MISSING=""
for I in 1 2 3 4 5 6 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 6 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0