home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8712 / hpgl2ps < prev    next >
Encoding:
Text File  |  1990-07-13  |  50.7 KB  |  2,404 lines

  1. Path: uunet!munnari!basser!john
  2. From: damc@natmlab.dms.oz.AU (Don McCormick)
  3. Newsgroups: comp.sources.misc
  4. Subject: HPGL to PostScript filter
  5. Message-ID: <1159@basser.oz>
  6. Date: 20 Dec 87 09:22:12 GMT
  7. Sender: john@basser.oz
  8. Lines: 2393
  9. Approved: john@basser.cs.su.oz.AU
  10.  
  11.  
  12.  
  13. The following shar contains the source for two filters.
  14. 1. HPGL to PostScript
  15. 2. DXY to PostScript
  16. --------------------------- Cut ------------------------------------------
  17. # This is a shell archive.  Remove anything before this line, then
  18. # unpack it by saving it in a file and typing "sh file".  (Files
  19. # unpacked will be owned by you and have default permissions.)
  20. #
  21. # This archive contains:
  22. # README Makefile dxy2ps.man hpgl2ps.man defn.h changesizes.c circle.c dxy2ps.c dxycom.c end_draw.c getval.c hpgl2ps.c hpglcom.c linesize.c linetype.c manualfeed.c plotcoords.c plotdot.c plotinit.c plotps.c ps_macros.c rectangle.c textps.c viewport.c test1.dxy test1.hpgl
  23.  
  24. echo x - README
  25. cat > "README" << '//E*O*F README//'
  26. There are two filters in this package which are based on the Roland
  27. plotter command set.
  28.  
  29. 1. DXY: A simple command set which is used with all DXY plotters
  30.  
  31. 2. RD-GL: This command set is a superset of the HP (Hewlet Packard)
  32.    graphics language.
  33.  
  34. Not all the commands of DXY or RD-GL (HPGL) are implemented (approx 95%
  35. are) and those commands that are not are skipped and a warning given.
  36. It is very easy to add to this filter if a particular unimplemented
  37. command is desired.
  38.  
  39. If you wish to implement a command go to the relevant portion in the
  40. command switch "dxycom.c" or "hpglcom.c" and call an appropriate user
  41. written procedure.  (You will need a good knowledge of writing
  42. PostScript programs)
  43.  
  44. The filters use the the procedure "getopt" which is used to interpret
  45. command line options and arguments and is normally available on 4.3 bsd
  46. and Sys V Unix. For those sites running 4.1 or 4.2 it may be available
  47. as a local library and must be written into the Makefile.
  48.  
  49. IF YOU DONT HAVE GETOPT YOU WILL HAVE REWRITE THE CODE THAT INTERPRETS
  50. COMMAND LINE OPTIONS AND ARGUMENTS.
  51.  
  52. NOTE 1: The method of writing text is not fully compatible with HPGL
  53. and will be changed at a later date.
  54.  
  55. NOTE 2: The PostScript macros are written into a C procedure to allow
  56. each filter to be a single stand alone program. These macros can easily
  57. be incorporated into other filter programs.
  58.  
  59. I have written some test procedures for the testing of each filter they
  60. are "test1.hpgl" for hpgl2ps and "test1.dxy" for dxy2ps.
  61.  
  62. Don McCormick.
  63.  
  64. //E*O*F README//
  65.  
  66. echo x - Makefile
  67. cat > "Makefile" << '//E*O*F Makefile//'
  68. # 1.0 dxy2ps and hpgl2ps (Copyright) D McCormick
  69. # Commercial reproduction prohibited.
  70. #
  71. FILTER1=    dxy2ps
  72. FILTER2=    hpgl2ps
  73. INSDIR=        /usr/local/bin
  74. INCLUDE=    defn.h
  75. LOCALLIB=    libroland.a
  76. AR=        ar
  77. ARFLAGS=    ru
  78. LOADLIBES=    -lm 
  79. CFLAGS=     -g
  80.  
  81. OBJ1=    dxy2ps.o
  82.  
  83. OBJ2=    hpgl2ps.o
  84.  
  85. OBJC=    changesizes.o circle.o      dxycom.o      end_draw.o\
  86.     getval.o      hpglcom.o     linesize.o    linetype.o\
  87.     manualfeed.o  plotdot.o     plotinit.o    plotps.o\
  88.     ps_macros.o   rectangle.o   textps.o      viewport.o\
  89.     plotcoords.o
  90.  
  91. all:        $(FILTER1) $(FILTER2)
  92.  
  93. $(FILTER1):    $(LOCALLIB) $(OBJ1)
  94.         $(CC) $(CFLAGS) -o $@ $(OBJ1) $(LOCALLIB) $(LOADLIBES)
  95.  
  96. $(FILTER2):    $(LOCALLIB) $(OBJ2)
  97.         $(CC) $(CFLAGS) -o $@ $(OBJ2) $(LOCALLIB) $(LOADLIBES)
  98.  
  99. $(LOCALLIB):    $(OBJC)
  100.         $(AR) $(ARFLAGS) $@ $(OBJC)
  101.         ranlib $(LOCALLIB)
  102.  
  103. $(OBJC):    $(INCLUDE)
  104.  
  105. $(OBJ1):    $(INCLUDE)
  106.  
  107. $(OBJ2):    $(INCLUDE)
  108.  
  109. install:    $(FILTER1)
  110.         install -s $(FILTER1) $(INSDIR)
  111.  
  112. install2:    $(FILTER2)
  113.         install -s $(FILTER2) $(INSDIR)
  114.  
  115. clean:
  116.         -rm -f *.o a.out core libroland.a
  117. //E*O*F Makefile//
  118.  
  119. echo x - dxy2ps.man
  120. cat > "dxy2ps.man" << '//E*O*F dxy2ps.man//'
  121. .TH DXY2PS (1L) "25 September 1987"
  122. .SH NAME
  123. dxy2ps - A Roland DXY plot command filter to PostScript
  124. .SH SYNOPSIS
  125. \fBdxy2ps\fR
  126. [\fB-amr\fR]
  127. [\fB-l \fIline sizes\fR]
  128. [\fB-s \fIscale\fR]
  129. [\fB-x \fIoffset\fR]
  130. [\fB-y \fIoffset\fR]
  131. [\fIplotfile\fR]
  132. .SH DESCRIPTION
  133. This filter is used to convert the Roland DXY and the Roland 
  134. Graphics Language (RD-GL) (which is a superset of the Hewlet Packard
  135. Graphics Language (HP-GL)) commands to PostScript.
  136. .PP
  137. The RD-GL commands are only operated on if each command is prefixed with
  138. a "^", therfore if your plotfile only contains HP-GL or RD-GL commands
  139. use the filter \fBhpgl2ps\fR.
  140. .PP
  141. The default conditions for \fBdxy2ps\fR are:
  142. .TP
  143. .B 1.
  144. The plot translation is from ISO A3 (420mm x 297mm) to ISO A4
  145. (297mm x 210mm) on the LaserWriter.
  146. .TP
  147. .B 2.
  148. Line thicknesses are in millimeters and are for lines (pens) 1 to 9:
  149. ( 0.1, 0.2, 0.3, 0.4, 0.5, 0.7, 1.0, 1.25, 1.5 )
  150. .TP
  151. .B Note:
  152. If the plotfile is not specified then standard input is assumed.
  153. .SH ARGUMENTS
  154. .TP
  155. .B -a
  156. Draw on an A4 ISO (297mm x 210mm) sheet of paper. This will give an
  157. aproximate 1:1 translation to the LaserWriter.
  158. .TP
  159. \fB-l \fIline sizes\fR
  160. This option allows the default line sizes to be replaced with different
  161. sizes starting from line (pen) one through nine. The new sizes (real or
  162. integer) are entered in a comma seperated string (\fIline size\fR) and
  163. are in millimeters. Only the sizes entered in the string will be
  164. changed with respect to lines (pens) one to nine while nonentered line
  165. (pen) sizes will retain the default sizes.
  166. .sp
  167. In the following example only the first three sizes will be changed.
  168. .sp
  169. eg: dxy2ps -l 0.4,0.3,1 file | lpr -Plaser1
  170. .TP
  171. .B -m
  172. Enable the manual feed on the LaserWriter (cutoff time 3 minutes).
  173. .TP
  174. .B -r
  175. Rotate plot(s) through 90 degrees. (The plot is made smaller)
  176. .TP
  177. \fB-s\fI scale\fR Scale the plot from 0.1 to 3 times its original
  178. size.
  179. .TP
  180. \fB-x\fI offset\fR Place an X offset (in mm) in the plot.
  181. .TP
  182. \fB-y\fI offset\fR Place an Y offset (in mm) in the plot.
  183. .PP
  184. \fBNote:\fR Offsets are with respect to the 0, 0 (origin) of the HP-GL
  185. / RD-GL plotting commands, thus if the minimum plotting coordinates are
  186. below either the X and/or Y zero axis then a positive offset is
  187. applied.  Similarly if the minimum plot coordinates are above the X
  188. and/or Y zero axis then a negative offset is applied.
  189. .SH FILES
  190. /usr/local/bin/dxy2ps
  191. .br
  192. /usr/local/bin/hpgl2ps
  193. .SH AUTHOR
  194. Don McCormick
  195. .br
  196. CSIRO
  197. .br
  198. Division of Applied Physics
  199. .br
  200. PO 218, Lindfield, N.S.W., 2070
  201. .br
  202. Australia
  203. .SH BUGS
  204. Some of the graphics commands are unimplemented and a warning will be
  205. displayed. If this command is vital then it must be written into the code.
  206. .PP
  207. No interactive command is suported.
  208. .PP
  209. If any bugs are found notify damc@natmlab or damc@nifty or root.
  210. //E*O*F dxy2ps.man//
  211.  
  212. echo x - hpgl2ps.man
  213. cat > "hpgl2ps.man" << '//E*O*F hpgl2ps.man//'
  214. .TH HPGL2PS (1L) "25 September 1987"
  215. .SH NAME
  216. hpgl2ps - A HP (Hewlet Packard) plot command filter to PostScript
  217. .SH SYNOPSIS
  218. \fBhpgl2ps\fR
  219. [\fB-amr\fR]
  220. [\fB-l \fIline sizes\fR]
  221. [\fB-s \fIscale\fR]
  222. [\fB-x \fIoffset\fR]
  223. [\fB-y \fIoffset\fR]
  224. [\fIplotfile\fR]
  225. .SH DESCRIPTION
  226. This filter is used to convert the Hewlet Packard Graphic Language (HP-GL)
  227. 9873C plotter commands to PostScript. The HP-GL commands are a subset of the
  228. Roland plotter command set (RD-GL).
  229. .PP
  230. The default conditions for \fBhpgl2ps\fR are:
  231. .TP
  232. .B 1.
  233. The plot translation is from ISO A3 (420mm x 297mm) to ISO A4
  234. (297mm x 210mm) on the LaserWriter.
  235. .TP
  236. .B 2.
  237. Line thicknesses are in millimeters and are for lines (pens) 1 to 9:
  238. ( 0.1, 0.2, 0.3, 0.4, 0.5, 0.7, 1.0, 1.25, 1.5 )
  239. .TP
  240. .B Note:
  241. If the plotfile is not specified then standard input is assumed.
  242. .SH ARGUMENTS
  243. .TP
  244. .B -a
  245. Draw on an A4 ISO (297mm x 210mm) sheet of paper. This will give an
  246. aproximate 1:1 translation to the LaserWriter.
  247. .TP
  248. \fB-l \fIline sizes\fR
  249. This option allows the default line sizes to be replaced with different
  250. sizes starting from line (pen) one through nine. The new sizes (real or
  251. integer) are entered in a comma seperated string (\fIline size\fR) and
  252. are in millimeters. Only the sizes entered in the string will be
  253. changed with respect to lines (pens) one to nine while nonentered line
  254. (pen) sizes will retain the default sizes.
  255. .sp
  256. In the following example only the first three sizes will be changed.
  257. .sp
  258. eg: hpgl2ps -l 0.4,0.3,1 file | lpr -Plaser1
  259. .TP
  260. .B -m
  261. Enable the manual feed on the LaserWriter (cutoff time 3 minutes).
  262. .TP
  263. .B -r
  264. Rotate plot(s) through 90 degrees. (The plot is made smaller)
  265. .TP
  266. \fB-s\fI scale\fR Scale the plot from 0.1 to 3 times its original
  267. size.
  268. .TP
  269. \fB-x\fI offset\fR Place an X offset (in mm) in the plot.
  270. .TP
  271. \fB-y\fI offset\fR Place an Y offset (in mm) in the plot.
  272. .PP
  273. \fBNote:\fR Offsets are with respect to the 0, 0 (origin) of the HP-GL
  274. / RD-GL plotting commands, thus if the minimum plotting coordinates are
  275. below either the X and/or Y zero axis then a positive offset is
  276. applied.  Similarly if the minimum plot coordinates are above the X
  277. and/or Y zero axis then a negative offset is applied.
  278. .SH FILES
  279. /usr/local/bin/hpgl2ps
  280. .SH AUTHOR
  281. Don McCormick
  282. .br
  283. CSIRO
  284. .br
  285. Division of Applied Physics
  286. .br
  287. PO 218, Lindfield, N.S.W., 2070
  288. .br
  289. Australia
  290. .SH BUGS
  291. Some of the graphics commands are unimplemented and a warning will be
  292. displayed. If this command is vital then it must be written into the code.
  293. .PP
  294. No interactive command is suported.
  295. .PP
  296. If any bugs are found notify damc@natmlab or damc@nifty or root.
  297. //E*O*F hpgl2ps.man//
  298.  
  299. echo x - defn.h
  300. cat > "defn.h" << '//E*O*F defn.h//'
  301. /*
  302.  *
  303.  *    The following definations allow for the efficient 
  304.  *    translation of DXY and RD-GL codes to PostScript code
  305.  *
  306.  */
  307.  
  308. #include <stdio.h>
  309. #include <math.h>
  310. #include <ctype.h>
  311.  
  312. #define CR    '\015'
  313. #define LF    '\012'
  314. #define SPACE    '\040'
  315.  
  316. #define SIGNED_NUMERIC  (ungetc(( ch = getc(stream)),stream) != EOF ) &&\
  317.         (((ch>='0') && (ch<='9')) || (ch=='-') || (ch=='+')\
  318.         || (ch==' ') || (ch==',') || (ch == '.'))
  319.  
  320. #define CIRCLE    21        /* DXY Circle */
  321. #define RCIRCLE 22        /* DXY Relative Circle */
  322. #define CCIRCLE 23        /* DXY Centered Circle */
  323. #define ACIRCLE 24        /* DXY Arc plus Circle */
  324. #define SCIRCLE 25        /* DXY Segment Circle */
  325. #define RDGLCIRCLE 26        /* RD-GL Circle */
  326.  
  327. #define TEXT    31
  328. #define MARK    32
  329.  
  330. #define LINETYPE    41
  331. #define LINESCALE    42
  332. #define LINE_TYPE_SCALE    43
  333. /*
  334.  *    Files to open if any
  335.  */
  336. FILE    *stream;
  337. FILE    *fopen();
  338. /*
  339.  *    Plotting Parameters that will contain the necessary PostScript
  340.  *    commands to plot (see dxy2ps.c for the initialisation) and
  341.  *    ps_macros.c for the plotting macros).
  342.  */
  343. char    *MOVE;
  344. char    *RMOVE;
  345. char    *DRAW;
  346. char    *RDRAW;
  347. /*
  348.  *    Definition of "ch" used in SIGNED_NUMERIC
  349.  */
  350. char    ch;
  351. /*
  352.  *    Define the function getval() which returns a real number.
  353.  */
  354. float    getval();
  355. /*
  356.  *    Scaling parameters used for translation from DXY and RD-GL
  357.  *    coordinate sytem to the PostScript coordinate system which
  358.  *    has been defined in millimeters. (See above)
  359.  */
  360. float    SCALE;
  361. float    XSCALE;
  362. float    YSCALE;
  363. float    xmax, xmin;
  364. float    ymax, ymin;
  365. /*
  366.  *    End of line terminator (RD-GL / HP-GL)
  367.  */
  368. char    EOL;
  369. /*
  370.  *    PostScript Coordinate parameters
  371.  */
  372. float    lastXmove;
  373. float    lastYmove;
  374. float    absX;
  375. float    absY;
  376. float    xval;
  377. float    yval;
  378. float    xoffset, yoffset;
  379. /*
  380.  *    Extra parameters
  381.  */
  382. float    char_angle;
  383. float    char_height;
  384. float    char_width;
  385. float    char_space;
  386. float    char_slant;
  387.  
  388. char    font[];
  389.  
  390. char    symbol;
  391.  
  392. int    dcount;
  393. /*
  394.  *    Degree radian conversion parameter ie: deg_rad = asin(1) / 90.0;
  395.  *    ( Defined in dxy2ps.c or rdgl2ps.c )
  396.  */
  397. float    deg_rad;
  398. /*
  399.  *    Line / pen size parameter (max 9 sizes)
  400.  */
  401. float    pen_size[9];
  402. /*
  403.  *    Paper size (ie A3 or A4) and Mode (HPGL or DXY)
  404.  */
  405. char    *PaperSize;
  406. char    *Mode;
  407. /*
  408.  *    Flags
  409.  */
  410. int    LANDSCAPE;
  411. int    DRAW_FLAG;
  412. int    PLOTABS;
  413. int    PENDOWN;
  414. int    SETDOT;     /* HP-GL commands only */
  415. int    SYMBOL;        /* HP-GL commands only */
  416. //E*O*F defn.h//
  417.  
  418. echo x - changesizes.c
  419. cat > "changesizes.c" << '//E*O*F changesizes.c//'
  420. /*
  421.  * This utility will take a string of real numbers seperated by commas and
  422.  * put them in an array. 
  423.  *
  424.  * Don McCormick 
  425.  */
  426. #include "defn.h"
  427.  
  428. #define ERROR1 "Only 9 line sizes allowed"
  429. #define ERROR2 "Too many decimal points in number"
  430. #define ERROR3 "line size specification incorrect"
  431. #define ERROR4 "Max no of characters for each line size is 5"
  432.  
  433. changesizes(sizebuf)
  434. char    sizebuf[50];
  435. {
  436.     int     i;
  437.     int     j = 0;
  438.     int     k = 0;
  439.     int     DECIMAL = 0;
  440.     float   number;
  441.     char    numbuf[5];
  442.  
  443.     for (i = 0; i < 50; i++)
  444.     {
  445.     if (sizebuf[i] == ',' || sizebuf[i] == NULL)
  446.     {
  447.         if ((number = atof(numbuf)) >= 0.01 && number <= 10)
  448.         pen_size[j] = number;    /* Put number in array */
  449.         else
  450.         fprintf(stderr, "Warning: line size too large ignored \n");
  451.  
  452.         if (sizebuf[i] == NULL) return;
  453.  
  454.         if (j++ > 8)
  455.         {
  456.         fprintf(stderr, "Error: %s\n", ERROR1);
  457.         exit(1);
  458.         }
  459.         for (k = 0; k < 5; k++)
  460.         numbuf[k] = NULL;    /* Clear number buffer */
  461.  
  462.         k = 0;
  463.         DECIMAL = 0;    /* One decimal per number */
  464.  
  465.         while (sizebuf[i + 1] == ',' && sizebuf[i + 1] != NULL)
  466.         i++;        /* Get rid of extra commas */
  467.     } else
  468.     {
  469.         if ((sizebuf[i] >= '0' && sizebuf[i] <= '9')
  470.         || sizebuf[i] == '.')
  471.         {
  472.         if (sizebuf[i] == '.')
  473.         {
  474.             if (DECIMAL == 1)
  475.             {
  476.                 fprintf(stderr, "Error: %s\n", ERROR2);
  477.                 exit(1);
  478.             }
  479.             DECIMAL = 1;
  480.         }
  481.         numbuf[k] = sizebuf[i];
  482.         } else
  483.         {
  484.         fprintf(stderr, "Error: %s\n", ERROR3);
  485.         exit(1);
  486.         }
  487.         if (k++ > 5)
  488.         {
  489.         fprintf(stderr, "Error: %s\n", ERROR4);
  490.         exit(1);
  491.         }
  492.     }
  493.     }
  494. }
  495. //E*O*F changesizes.c//
  496.  
  497. echo x - circle.c
  498. cat > "circle.c" << '//E*O*F circle.c//'
  499. #include "defn.h"
  500.  
  501. circle(type)
  502. int    type;
  503. {
  504.     float    radius;
  505.     float    start_angle = 0;
  506.     float    end_angle = 360;
  507.     float    chord_angle = 0;
  508.     float    Xc, Yc;
  509.     float    percent;
  510.     float    distance;
  511.     float    length;
  512.     float    angle;
  513.  
  514.     end_draw();
  515.  
  516.     switch (type)
  517.     {
  518.     case RDGLCIRCLE:
  519.     if (SIGNED_NUMERIC)
  520.         radius = getval() * XSCALE;
  521.     if (SIGNED_NUMERIC)
  522.         chord_angle = getval();
  523.     Xc = absX;
  524.     Yc = absY;
  525.     break;
  526.  
  527.     case CIRCLE:
  528.     if (SIGNED_NUMERIC)
  529.         absX = Xc = getval() * XSCALE;
  530.     if (SIGNED_NUMERIC)
  531.         absY = Yc = getval() * YSCALE;
  532.     if (SIGNED_NUMERIC)
  533.         radius = getval() * XSCALE;
  534.     if (SIGNED_NUMERIC)
  535.         start_angle = getval();
  536.     if (SIGNED_NUMERIC)
  537.         end_angle = getval();
  538.     if (SIGNED_NUMERIC)
  539.         chord_angle = getval();
  540.     break;
  541.  
  542.     case RCIRCLE:
  543.     if (SIGNED_NUMERIC)
  544.         radius = getval() * XSCALE;
  545.     if (SIGNED_NUMERIC)
  546.         start_angle = getval();
  547.     if (SIGNED_NUMERIC)
  548.         end_angle = getval();
  549.     if (SIGNED_NUMERIC)
  550.         chord_angle = getval();
  551.     angle = deg_rad * (90.0 - start_angle);
  552.     Xc = absX - radius * cos(angle);
  553.     angle = deg_rad * (90.0 - start_angle);
  554.     Yc = absY + radius * sin(angle);
  555.     break;
  556.  
  557.     case CCIRCLE:
  558.     if (SIGNED_NUMERIC)
  559.        absX = getval() * XSCALE;
  560.     if (SIGNED_NUMERIC)
  561.        absY = getval() * YSCALE;
  562.     break;
  563.  
  564.     case ACIRCLE:
  565.     Xc = absX;
  566.     Yc = absY;
  567.     if (SIGNED_NUMERIC)
  568.         radius = getval() * XSCALE;
  569.     if (SIGNED_NUMERIC)
  570.         start_angle = getval();
  571.     if (SIGNED_NUMERIC)
  572.         end_angle = getval();
  573.     if (SIGNED_NUMERIC)
  574.         chord_angle = getval();
  575.     break;
  576.  
  577.     case SCIRCLE:
  578.     if (SIGNED_NUMERIC)
  579.         percent = getval();
  580.     if (SIGNED_NUMERIC)
  581.         distance = getval();
  582.     if (SIGNED_NUMERIC)
  583.         length = getval();
  584.     fprintf("Warning: segment and indication lines not available yet\n");
  585.     break;
  586.     }
  587.  
  588.     printf("%g %g %g %g %g %g Ellipse\n",
  589.         Xc, Yc, radius, radius, start_angle, end_angle);
  590. }
  591. //E*O*F circle.c//
  592.  
  593. echo x - dxy2ps.c
  594. cat > "dxy2ps.c" << '//E*O*F dxy2ps.c//'
  595. #include    "defn.h"
  596.  
  597. #define USAGE "Usage: dxy2ps [-amr] [-l line sizes] [-s scale] [-x offset] [-y offset] [file]\n"
  598.  
  599. main(argc, argv)
  600. int     argc;
  601. char   *argv[];
  602. {
  603.     extern int optind;
  604.     extern char *optarg;
  605.  
  606.     char    op;
  607.     int        MANUAL_FEED = 0;            /* DEFAULT: No manual feed */
  608.  
  609.     PaperSize = "A3";
  610.     Mode = "DXY";
  611.     plotcoords();            /* Set up plotter coordinates */
  612.  
  613.     plotinit();            /* Get other initialisations */
  614.  
  615.     while ((ch = getopt(argc, argv, "al:ms:x:y:r")) != EOF)
  616.     {
  617.     switch (ch)
  618.     {
  619.     case 'a':        /* DXY ISO A4 297mm * 210mm */
  620.         PaperSize = "A4";
  621.             plotcoords();
  622.         break;
  623.  
  624.     case 'l':
  625.         changesizes(optarg);
  626.         break;
  627.  
  628.     case 'm':
  629.         MANUAL_FEED = 1;
  630.         break;
  631.  
  632.     case 'r':
  633.         LANDSCAPE = 0;
  634.         break;
  635.  
  636.     case 's':
  637.         SCALE = atof(optarg);
  638.         if (SCALE < 0.1)
  639.         SCALE = 0.1;
  640.         else
  641.         if (SCALE > 3)
  642.         SCALE = 3;
  643.         break;
  644.  
  645.     case 'x':
  646.         xoffset = atof(optarg);
  647.         break;
  648.  
  649.     case 'y':
  650.         yoffset = atof(optarg);
  651.         break;
  652.  
  653.     default:
  654.         fprintf(stderr, "%s\n", USAGE);
  655.         exit(1);
  656.     }
  657.     }
  658.     if (optind == argc)
  659.     stream = stdin;
  660.     else if ((stream = fopen(argv[optind], "r")) == NULL)
  661.     {
  662.     fprintf(stderr, "ERROR: cannot open \"%s\"\n", argv[optind]);
  663.     exit(1);
  664.     }
  665.     ps_macros();            /* Output PostScript Macros */
  666.  
  667.     viewport();        /* Scale the viewport for the plot */
  668.  
  669.     printf("/%s %g Font\n", font, char_height);
  670.  
  671.     if (MANUAL_FEED)
  672.     manualfeed(1);
  673.  
  674.     while ((op = getc(stream)) != EOF)
  675.     if ((isalpha(op) > 0) || op == '^')
  676.         dxycom(op);
  677.  
  678.     end_draw();
  679.  
  680.     printf("showpage\n");
  681.  
  682.     if (MANUAL_FEED)
  683.     manualfeed(0);
  684. }
  685. //E*O*F dxy2ps.c//
  686.  
  687. echo x - dxycom.c
  688. cat > "dxycom.c" << '//E*O*F dxycom.c//'
  689. #include "defn.h"
  690.  
  691. dxycom(op)
  692. char    op;
  693. {
  694.     int intval;
  695.  
  696.     switch (op)
  697.     {
  698.     case 'H':            /* HOME */
  699.     case 'h':
  700.     break;
  701.  
  702.     case 'D':            /* DRAW */
  703.     case 'd':
  704.     plotps(DRAW);
  705.     break;
  706.  
  707.     case 'M':            /* MOVE */
  708.     case 'm':
  709.     plotps(MOVE);
  710.     break;
  711.  
  712.     case 'I':            /* RELATIVE DRAW */
  713.     case 'i':
  714.     plotps(RDRAW);
  715.     break;
  716.  
  717.     case 'R':            /* RELATIVE MOVE */
  718.     case 'r':
  719.     plotps(RMOVE);
  720.     break;
  721.  
  722.     case 'L':            /* LINE TYPE */
  723.     case 'l':
  724.     linetype(LINETYPE);
  725.     break;
  726.  
  727.     case 'B':            /* LINE SCALE */
  728.     case 'b':
  729.     linetype(LINESCALE);
  730.     break;
  731.  
  732.     case 'X':            /* AXIS */
  733.     case 'x':
  734.     {
  735.         int     p, q, r;
  736.  
  737.         p = rint(getval());
  738.         q = rint(getval());
  739.         r = rint(getval());
  740.         fprintf(stderr, "Warning %c not implemented yet\n", op);
  741.     }
  742.     break;
  743.  
  744.     case 'P':            /* PRINT */
  745.     case 'p':
  746.     textps(TEXT);
  747.     break;
  748.  
  749.     case 'S':            /* ALPHA SCALE */
  750.     case 's':
  751.     {
  752.         int n;
  753.  
  754.         if (SIGNED_NUMERIC)
  755.             n = rint(getval());
  756.         else
  757.         n = 3;
  758.         char_height = (n + 1) * 0.8 * SCALE;
  759.         char_width = (n + 1) * 0.4 * SCALE;
  760.         char_space = (n + 1) * 0.2 * SCALE;
  761.     }
  762.     printf("/%s %g %g %g DefFont\n",
  763.         font, char_width, char_height, char_slant);
  764.     break;
  765.  
  766.     case 'Q':            /* ALPHA ROTATE */
  767.     case 'q':
  768.     intval = rint(getval());
  769.     switch (intval)
  770.     {
  771.     case 0:
  772.         char_angle = 0.0;
  773.         break;
  774.  
  775.     case 1:
  776.         char_angle = 90.0;
  777.         break;
  778.  
  779.     case 2:
  780.         char_angle = 180.0;
  781.         break;
  782.  
  783.     case 3:
  784.         char_angle = 270.0;
  785.         break;
  786.     }
  787.     break;
  788.  
  789.     case 'N':            /* MARK */
  790.     case 'n':
  791.     textps(MARK);
  792.     break;
  793.  
  794.     case 'J':            /* PEN CHANGE */
  795.     case 'j':
  796.     linesize();
  797.     break;
  798.  
  799.     case 'C':            /* CIRCLE */
  800.     case 'c':
  801.     circle(CIRCLE);
  802.     break;
  803.  
  804.     case 'E':            /* RELATIVE CIRCLE */
  805.     case 'e':
  806.     circle(RCIRCLE);
  807.     break;
  808.  
  809.     case 'A':            /* CIRCLE CENTER */
  810.     case 'a':
  811.     circle(CCIRCLE);
  812.     break;
  813.  
  814.     case 'G':            /* ARC + CIRCLE */
  815.     case 'g':
  816.     circle(ACIRCLE);
  817.     break;
  818.  
  819.     case 'K':            /* SEGMENT AND INDICATION LINES FOR CIRCLES */
  820.     case 'k':
  821.     circle(SCIRCLE);
  822.     break;
  823.  
  824.     case 'T':            /* HATCHING */
  825.     case 't':
  826.     rectangle();
  827.     break;
  828.  
  829.     case '^':            /* CALL HP-GL / RD-GL COMMANDS */
  830.     end_draw();
  831.     if ((ch = getc(stream)) != EOF)
  832.         hpglcom(ch);
  833.     break;
  834.  
  835.     default:
  836.     fprintf(stderr, "Warning: %c Unknown DXY command\n", op);
  837.     break;
  838.     }
  839. }
  840. //E*O*F dxycom.c//
  841.  
  842. echo x - end_draw.c
  843. cat > "end_draw.c" << '//E*O*F end_draw.c//'
  844. #include "defn.h"
  845.  
  846. end_draw()
  847. {
  848.     if (DRAW_FLAG)
  849.     {
  850.     if (lastXmove == absX && lastYmove == absY)
  851.         printf("closepath\n");
  852.  
  853.     printf("stroke\n");
  854.     DRAW_FLAG = 0;
  855.     }
  856.     dcount = 0;
  857. }
  858. //E*O*F end_draw.c//
  859.  
  860. echo x - getval.c
  861. cat > "getval.c" << '//E*O*F getval.c//'
  862. /*
  863.  * Returns a real number 
  864.  */
  865.  
  866. #include "defn.h"
  867.  
  868. #define ERROR "Two or more decimal places in a number"
  869.  
  870. float
  871. getval()
  872. {
  873.     char    valbuf[10];
  874.     float   value;
  875.     int     DECIMAL = 0;
  876.     int     i;
  877.  
  878.     /* Null the value buffer "valbuf" */
  879.     for (i = 0; i < 10; i++)
  880.     valbuf[i] = NULL;
  881.  
  882.     i = 0;
  883.  
  884.     ch = getc(stream);
  885.  
  886.     while ((ch == ' ') || (ch == ','))
  887.     ch = getc(stream);
  888.  
  889.     while ((ch >= '0' && ch <= '9') || ch == '.' || ch == '-' || ch == '+')
  890.     {
  891.     if (ch == '.')
  892.     {
  893.         if (DECIMAL)
  894.         {
  895.         fprintf(stderr,"Error: %s\n", ERROR);
  896.         exit(1);
  897.         }
  898.         DECIMAL = 1;
  899.     }
  900.     valbuf[i++] = ch;
  901.     ch = getc(stream);
  902.     }
  903.     ungetc(ch, stream);        /* Put non numeric char back */
  904.     value = atof (valbuf);
  905.     return (value);
  906. }
  907. //E*O*F getval.c//
  908.  
  909. echo x - hpgl2ps.c
  910. cat > "hpgl2ps.c" << '//E*O*F hpgl2ps.c//'
  911. #include    "defn.h"
  912.  
  913. #define USAGE "Usage: hpgl2ps [-amr] [-l line sizes] [-s scale] [-x offset] [-y offset] [file]\n"
  914.  
  915. main(argc, argv)
  916. int     argc;
  917. char   *argv[];
  918. {
  919.     extern int optind;
  920.     extern char *optarg;
  921.  
  922.     char    op;
  923.     int        MANUAL_FEED = 0;            /* DEFAULT: No manual feed */
  924.  
  925.     PaperSize = "A3";
  926.     Mode = "HPGL";
  927.     plotcoords();
  928.  
  929.     plotinit();            /* Get other initialiasations */
  930.  
  931.     while ((ch = getopt(argc, argv, "al:ms:x:y:r")) != EOF)
  932.     {
  933.     switch (ch)
  934.     {
  935.     case 'a':        /* HP-GL ISO A4 297mm * 210mm */
  936.         PaperSize = "A4";
  937.         plotcoords();
  938.         break;
  939.  
  940.     case 'l':
  941.         changesizes(optarg);
  942.         break;
  943.  
  944.     case 'm':
  945.         MANUAL_FEED = 1;
  946.         break;
  947.  
  948.     case 'r':
  949.         LANDSCAPE = 0;
  950.         break;
  951.  
  952.     case 's':
  953.         SCALE = atof(optarg);
  954.         if (SCALE < 0.1)
  955.         SCALE = 0.1;
  956.         else
  957.         if (SCALE > 3)
  958.         SCALE = 3;
  959.         break;
  960.  
  961.     case 'x':
  962.         xoffset = atof(optarg);
  963.         break;
  964.  
  965.     case 'y':
  966.         yoffset = atof(optarg);
  967.         break;
  968.  
  969.     default:
  970.         fprintf(stderr, "%s\n", USAGE);
  971.         exit(1);
  972.     }
  973.     }
  974.     if (optind == argc)
  975.     stream = stdin;
  976.     else if ((stream = fopen(argv[optind], "r")) == NULL)
  977.     {
  978.     fprintf(stderr, "ERROR: cannot open \"%s\"\n", argv[optind]);
  979.     exit(1);
  980.     }
  981.     ps_macros();            /* Output PostScript Macros */
  982.  
  983.     viewport();                /* Scale the viewport for the plot */
  984.  
  985.     printf("/%s %g Font\n", font, char_height);
  986.  
  987.     if (MANUAL_FEED)
  988.     manualfeed(1);
  989.  
  990.     while ((op = getc(stream)) != EOF)
  991.     if (isalpha(op) > 0)
  992.         hpglcom(op);
  993.  
  994.     end_draw();
  995.  
  996.     printf("showpage\n");
  997.  
  998.     if (MANUAL_FEED)
  999.     manualfeed(0);
  1000. }
  1001. //E*O*F hpgl2ps.c//
  1002.  
  1003. echo x - hpglcom.c
  1004. cat > "hpglcom.c" << '//E*O*F hpglcom.c//'
  1005. /*
  1006.  * This procedure translates RD-GL (Roland DG Graphic Language) into the
  1007.  * equivalent PostScript language. 
  1008.  *
  1009.  * The RD-GL is a superset equivalent to HP-GL 
  1010.  *
  1011.  * Don McCormick 
  1012.  */
  1013.  
  1014. #include "defn.h"
  1015.  
  1016. /* The folowing defaults should be 0.5% and 1.0% for the respective  character
  1017.  * width and height, however this is too small when scaled to Postcript
  1018.  * charcter sizes.
  1019.  */
  1020. float DEFWIDTH = 0.0075;    /* 0.75 % of P2x - P1x for default char width */
  1021. float DEFHEIGHT = 0.015;    /* 1.5 % of P2y - P1y for default char height */
  1022.  
  1023. hpglcom(op1)
  1024. char    op1;
  1025. {
  1026.     char    op2;
  1027.     int     no_op;        /* No operation value */
  1028.  
  1029.     switch (op1)
  1030.     {
  1031.     case 'A':
  1032.     case 'a':
  1033.     op2 = getc(stream);
  1034.     switch (op2)
  1035.     {
  1036.     case 'A':        /* Arc Absolute (not HP-GL) */
  1037.     case 'a':
  1038.         break;
  1039.  
  1040.     case 'P':        /* Automatic Pen Lift (HP-GL only) */
  1041.     case 'p':
  1042.         while (((ch = getc(stream)) != EOF) && ch != ';');
  1043.         break;
  1044.  
  1045.     case 'R':        /* Arc Relative (not HP-GL) */
  1046.     case 'r':
  1047.         break;
  1048.  
  1049.     default:
  1050.         fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n\n", op1, op2);
  1051.     }
  1052.     break;
  1053.  
  1054.     case 'C':
  1055.     case 'c':
  1056.     op2 = getc(stream);
  1057.     switch (op2)
  1058.     {
  1059.     case 'A':        /* Alternate Character Set (Not Used) */
  1060.     case 'a':
  1061.         while (((ch = getc(stream)) != EOF) && ch != ';');
  1062.         fprintf(stderr, "Warning: Alt character set not implemented yet\n");
  1063.         break;
  1064.  
  1065.     case 'I':        /* Circle */
  1066.     case 'i':
  1067.         circle(RDGLCIRCLE);
  1068.         break;
  1069.  
  1070.     case 'P':        /* Character Plot */
  1071.     case 'p':
  1072.         {
  1073.         float   xspace, yspace;
  1074.  
  1075.         xspace = getval() * XSCALE * SCALE * (char_width + char_space);
  1076.         yspace = getval() * YSCALE * SCALE * (char_width + char_space);
  1077.         end_draw();
  1078.         printf("    %g mm %g mm %s\n", xspace, yspace, RMOVE);
  1079.         }
  1080.         break;
  1081.  
  1082.     case 'S':        /* Standard Character Set */
  1083.     case 's':
  1084.         while (((ch = getc(stream)) != EOF) && ch != ';');
  1085.         break;
  1086.  
  1087.     default:
  1088.         fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
  1089.     }
  1090.     break;
  1091.  
  1092.     case 'D':
  1093.     case 'd':
  1094.     op2 = getc(stream);
  1095.     switch (op2)
  1096.     {
  1097.     case 'C':        /* Digitize Clear (Not Used) */
  1098.     case 'c':
  1099.         break;
  1100.  
  1101.     case 'F':        /* Default */
  1102.     case 'f':
  1103.         SETDOT = 0;
  1104.         SYMBOL = 0;
  1105.         PENDOWN = 0;
  1106.         EOL = '\003';
  1107.         char_angle = 0;
  1108.         char_slant = 0;
  1109.         char_width = DEFWIDTH * (xmax - xmin) * XSCALE * SCALE;
  1110.         char_height = DEFHEIGHT * (ymax - ymin) * YSCALE * SCALE;
  1111.         char_space = char_width * (1/.67 - 1);
  1112.         printf("/%s %g %g %g DefFont\n",
  1113.         font, char_width, char_height, char_slant);
  1114.         break;
  1115.  
  1116.     case 'I':        /* Absolute Direction */
  1117.     case 'i':
  1118.         {
  1119.         float   run, rise;
  1120.  
  1121.         if (SIGNED_NUMERIC)
  1122.         {
  1123.             run = getval() * XSCALE;
  1124.             rise = getval() * YSCALE;
  1125.             char_angle = atan2(rise, run) / deg_rad;
  1126.         }
  1127.         else
  1128.             char_angle = 0;
  1129.         }
  1130.         break;
  1131.  
  1132.     case 'P':        /* Digitize Point (Not Used) */
  1133.     case 'p':
  1134.         break;
  1135.  
  1136.     case 'R':        /* Relative Direction */
  1137.     case 'r':
  1138.         {
  1139.         float   run, rise;
  1140.  
  1141.         if (SIGNED_NUMERIC)
  1142.         {
  1143.             run = getval() * XSCALE;
  1144.             rise = getval() * YSCALE;
  1145.             char_angle += atan2(rise, run) / deg_rad;
  1146.         }
  1147.         else
  1148.             char_angle = 0;
  1149.         }
  1150.         break;
  1151.  
  1152.     case 'T':        /* Define Terminator */
  1153.     case 't':
  1154.         if ((ch = getc(stream)) != EOF)
  1155.         EOL = ch;    /* End of label terminator */
  1156.         break;
  1157.  
  1158.     default:
  1159.         fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
  1160.     }
  1161.     break;
  1162.  
  1163.     case 'E':            /* NOT HP-GL */
  1164.     case 'e':
  1165.     op2 = getc(stream);
  1166.     switch (op2)
  1167.     {
  1168.     case 'A':        /* Edge Rectangle Absolute */
  1169.     case 'a':
  1170.         break;
  1171.  
  1172.     case 'R':        /* Edge Rectangle Relative */
  1173.     case 'r':
  1174.         break;
  1175.  
  1176.     case 'W':        /* Edge Wedge */
  1177.     case 'w':
  1178.         break;
  1179.  
  1180.     default:
  1181.         fprintf(stderr, "Warning: %c%c Unknown RD-GL Command\n", op1, op2);
  1182.     }
  1183.     break;
  1184.  
  1185.     case 'F':            /* NOT HP-GL */
  1186.     case 'f':
  1187.     op2 = getc(stream);
  1188.     switch (op2)
  1189.     {
  1190.     case 'T':        /* Fill Type */
  1191.     case 't':
  1192.         break;
  1193.  
  1194.     default:
  1195.         fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
  1196.     }
  1197.     break;
  1198.  
  1199.     case 'I':
  1200.     case 'i':
  1201.     op2 = getc(stream);
  1202.     switch (op2)
  1203.     {
  1204.     case 'M':        /* Input Mask (Not Used) */
  1205.     case 'm':
  1206.         break;
  1207.  
  1208.     case 'N':        /* Initialize */
  1209.     case 'n':
  1210.         plotcoords();
  1211.         SETDOT = 0;
  1212.         SYMBOL = 0;
  1213.         PENDOWN = 0;
  1214.         EOL = '\003';
  1215.         char_angle = 0;
  1216.         char_slant = 0;
  1217.         char_width = DEFWIDTH * (xmax - xmin) * XSCALE * SCALE;
  1218.         char_height = DEFHEIGHT * (ymax - ymin) * YSCALE * SCALE;
  1219.         char_space = char_width * (1/0.67 - 1);
  1220.         printf("/%s %g %g %g DefFont\n",
  1221.         font, char_width, char_height, char_slant);
  1222.         break;
  1223.  
  1224.     case 'P':        /* Input P1 and P2 (Not Used) */
  1225.     case 'p':
  1226.         while (((ch = getc(stream)) != EOF) && ch != ';');
  1227.         fprintf(stderr,"Warning: IP command not implemented\n");
  1228.         break;
  1229.  
  1230.     case 'W':        /* Input Window */
  1231.     case 'w':
  1232.         while (((ch = getc(stream)) != EOF) && ch != ';');
  1233.         fprintf(stderr,"Warning: IW command not implemented\n");
  1234.         break;
  1235.  
  1236.     default:
  1237.         fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
  1238.     }
  1239.     break;
  1240.  
  1241.     case 'L':
  1242.     case 'l':
  1243.     op2 = getc(stream);
  1244.     switch (op2)
  1245.     {
  1246.     case 'B':        /* Label */
  1247.     case 'b':
  1248.         textps(TEXT);
  1249.         break;
  1250.  
  1251.     case 'T':        /* Line Type */
  1252.     case 't':
  1253.         linetype(LINE_TYPE_SCALE);
  1254.         break;
  1255.  
  1256.     default:
  1257.         fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
  1258.     }
  1259.     break;
  1260.  
  1261.     case 'O':            /* NOT USED */
  1262.     case 'o':
  1263.     op2 = getc(stream);
  1264.     switch (op2)
  1265.     {
  1266.     case 'A':        /* Output Actual Position (Not HP-GL) */
  1267.     case 'a':
  1268.         break;
  1269.  
  1270.     case 'C':        /* Output Commanded Position */
  1271.     case 'c':
  1272.         break;
  1273.  
  1274.     case 'D':        /* Output Digitise */
  1275.     case 'd':
  1276.         break;
  1277.  
  1278.     case 'E':        /* Output Error */
  1279.     case 'e':
  1280.         break;
  1281.  
  1282.     case 'P':        /* Output P1 and P2 */
  1283.     case 'p':
  1284.         break;
  1285.  
  1286.     case 'S':        /* Output Status */
  1287.     case 's':
  1288.         break;
  1289.  
  1290.     case 'W':        /* Output Window (Not HP-GL) */
  1291.     case 'w':
  1292.         break;
  1293.  
  1294.     default:
  1295.         fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
  1296.     }
  1297.     break;
  1298.  
  1299.     case 'P':
  1300.     case 'p':
  1301.     op2 = getc(stream);
  1302.     switch (op2)
  1303.     {
  1304.     case 'A':        /* Plot Absolute */
  1305.     case 'a':
  1306.         PLOTABS = 1;
  1307.         if (SIGNED_NUMERIC)
  1308.         if (SETDOT || SYMBOL)
  1309.             plotdot(MOVE);
  1310.         else if (PENDOWN)
  1311.             plotps(DRAW);
  1312.         else
  1313.             plotps(MOVE);
  1314.         break;
  1315.  
  1316.     case 'D':        /* Pen Down */
  1317.     case 'd':
  1318.         PENDOWN = 1;
  1319.         if (SIGNED_NUMERIC)
  1320.         if (SETDOT)
  1321.             plotdot(MOVE);
  1322.         else if (PLOTABS)
  1323.             plotps(DRAW);
  1324.         else 
  1325.             plotps(RDRAW);
  1326.         break;
  1327.  
  1328.     case 'R':        /* Plot Relative */
  1329.     case 'r':
  1330.         PLOTABS = 0;
  1331.         if (SIGNED_NUMERIC)
  1332.         if (SETDOT || SYMBOL)
  1333.             plotdot(RMOVE);
  1334.         else if (PENDOWN)
  1335.             plotps(RDRAW);
  1336.         else
  1337.             plotps(RMOVE);
  1338.         break;
  1339.  
  1340.     case 'T':        /* Pen Thickness (Not HP-GL) */
  1341.     case 't':
  1342.         {
  1343.         float   linewidth;
  1344.  
  1345.         linewidth = getval() * SCALE;        /* In mm */
  1346.         printf("%g mm setlinewidth\n", linewidth);
  1347.         }
  1348.         break;
  1349.  
  1350.     case 'U':        /* Pen Up */
  1351.     case 'u':
  1352.         PENDOWN = 0;
  1353.         if (SIGNED_NUMERIC)
  1354.         if (SETDOT)
  1355.             plotdot(MOVE);
  1356.         else if (PLOTABS)
  1357.             plotps(MOVE);
  1358.         else
  1359.             plotps(RMOVE);
  1360.         break;
  1361.  
  1362.     default:
  1363.         fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
  1364.     }
  1365.     break;
  1366.  
  1367.     case 'R':            /* Not HP-GL */
  1368.     case 'r':
  1369.     op2 = getc(stream);
  1370.     switch (op2)
  1371.     {
  1372.     case 'A':        /* Shade Rectange Absolute */
  1373.     case 'a':
  1374.         break;
  1375.  
  1376.     case 'R':        /* Shade Rectangle Relative */
  1377.     case 'r':
  1378.         break;
  1379.  
  1380.     default:
  1381.         fprintf(stderr, "Warning: %c%c Unknown RD-GL Command\n", op1, op2);
  1382.     }
  1383.     break;
  1384.  
  1385.     case 'S':
  1386.     case 's':
  1387.     op2 = getc(stream);
  1388.     switch (op2)
  1389.     {
  1390.     case 'A':        /* Select Alternate Set (Not Used) */
  1391.     case 'a':
  1392.         break;
  1393.  
  1394.     case 'C':        /* Scale */
  1395.     case 'c':
  1396.         if (SIGNED_NUMERIC)
  1397.         xmin = getval();
  1398.         else
  1399.         break;
  1400.  
  1401.         if (SIGNED_NUMERIC)
  1402.         xmax = getval();
  1403.         if (SIGNED_NUMERIC)
  1404.         ymin = getval();
  1405.         if (SIGNED_NUMERIC)
  1406.         ymax = getval();
  1407.         fprintf(stderr, "Warning: Scaling not implemented yet\n");
  1408.         break;
  1409.  
  1410.     case 'I':        /* Absolute Character Size */
  1411.     case 'i':
  1412.         if (SIGNED_NUMERIC)
  1413.         {
  1414.         char_width = getval() * 10 * SCALE;    /* In mm */
  1415.         char_height = getval() * 10 * SCALE;    /* In mm */
  1416.         } else
  1417.         {
  1418.         if ((ch = getc(stream)) == ';')
  1419.         {
  1420.             char_width = 2.7 * SCALE;
  1421.             char_height = 1.9 * SCALE;
  1422.         }
  1423.         }
  1424.         char_space = char_width * (1/.67 - 1);
  1425.         printf("/%s %g %g %g DefFont\n",
  1426.         font, char_width, char_height, char_slant);
  1427.         break;
  1428.  
  1429.     case 'L':        /* Character Slant */
  1430.     case 'l':
  1431.         if (SIGNED_NUMERIC)
  1432.         char_slant = char_height * getval();
  1433.         else
  1434.         char_slant = 0;
  1435.  
  1436.         char_space = char_width * (1/.67 - 1);
  1437.         printf("/%s %g %g %g DefFont\n",
  1438.         font, char_width, char_height, char_slant);
  1439.         break;
  1440.  
  1441.     case 'M':        /* Symbol Mode */
  1442.     case 'm':
  1443.         if ((ch = getc(stream)) != EOF && ch != ';' && isgraph(ch) > 0)
  1444.         {
  1445.          symbol = ch;
  1446.          SYMBOL = 1;
  1447.         }
  1448.         else
  1449.         SYMBOL = 0;
  1450.         break;
  1451.  
  1452.     case 'P':        /* Pen Select */
  1453.     case 'p':
  1454.         linesize();
  1455.         break;
  1456.  
  1457.     case 'R':        /* Relative Character Size */
  1458.     case 'r':
  1459.         {
  1460.         float   pwidth, pheight;
  1461.  
  1462.         if (SIGNED_NUMERIC)
  1463.         {
  1464.             pwidth = getval() * SCALE;        /* Percent */
  1465.             pheight = getval() * SCALE;        /* Percent */
  1466.         } else
  1467.         {
  1468.             pwidth = DEFWIDTH * 100 * SCALE;
  1469.             pheight = DEFHEIGHT * 100 * SCALE;
  1470.         }
  1471.         char_width = (xmax - xmin) * XSCALE * pwidth / 100.0;
  1472.         char_height = (ymax - ymin) * YSCALE * pheight / 100.0;
  1473.             char_space = char_width * (1/.67 - 1);
  1474.         }
  1475.         printf("/%s %g %g %g DefFont\n",
  1476.         font, char_width, char_height, char_slant);
  1477.         break;
  1478.  
  1479.     default:
  1480.         fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
  1481.     }
  1482.     break;
  1483.  
  1484.     case 'T':
  1485.     case 't':
  1486.     op2 = getc(stream);
  1487.     switch (op2)
  1488.     {
  1489.     case 'L':        /* Tick Length */
  1490.     case 'l':
  1491.         while (((ch = getc(stream)) != EOF) && ch != ';');
  1492.         fprintf(stderr, "Warning: Tick length not implemented yet\n");
  1493.         break;
  1494.  
  1495.     default:
  1496.         fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
  1497.     }
  1498.     break;
  1499.  
  1500.     case 'U':
  1501.     case 'u':
  1502.     op2 = getc(stream);
  1503.     switch (op2)
  1504.     {
  1505.     case 'C':        /* User Defined Character */
  1506.     case 'c':
  1507.         while (((ch = getc(stream)) != EOF) && ch != ';');
  1508.         fprintf(stderr, "Warning: User defined character not implemented yet\n");
  1509.         break;
  1510.  
  1511.     default:
  1512.         fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
  1513.     }
  1514.     break;
  1515.  
  1516.     case 'V':
  1517.     case 'v':
  1518.     op2 = getc(stream);
  1519.     switch (op2)
  1520.     {
  1521.     case 'S':        /* Velocity Select */
  1522.     case 's':
  1523.         while (((ch = getc(stream)) != EOF) && ch != ';');
  1524.         break;
  1525.  
  1526.     default:
  1527.         fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
  1528.     }
  1529.     break;
  1530.  
  1531.     case 'W':            /* Not HP-GL */
  1532.     case 'w':
  1533.     op2 = getc(stream);
  1534.     switch (op2)
  1535.     {
  1536.     case 'G':        /* Shade Wedge */
  1537.     case 'g':
  1538.         break;
  1539.  
  1540.     default:
  1541.         fprintf(stderr, "Warning: %c%c Unknown RD-GL Command\n", op1, op2);
  1542.     }
  1543.     break;
  1544.  
  1545.     case 'X':
  1546.     case 'x':
  1547.     op2 = getc(stream);
  1548.     switch (op2)
  1549.     {
  1550.     case 'T':        /* X Tick */
  1551.     case 't':
  1552.         while (((ch = getc(stream)) != EOF) && ch != ';');
  1553.         fprintf(stderr, "Warning: X tick not implemented yet\n");
  1554.         break;
  1555.  
  1556.     default:
  1557.         fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
  1558.     }
  1559.     break;
  1560.  
  1561.     case 'Y':
  1562.     case 'y':
  1563.     op2 = getc(stream);
  1564.     switch (op2)
  1565.     {
  1566.     case 'T':        /* Y Tick */
  1567.     case 't':
  1568.         while (((ch = getc(stream)) != EOF) && ch != ';');
  1569.         fprintf(stderr, "Warning: Y tick not implemented yet\n");
  1570.         break;
  1571.  
  1572.     default:
  1573.         fprintf(stderr, "Warning: %c%c Unknown HP-GL Command\n", op1, op2);
  1574.     }
  1575.     break;
  1576.  
  1577.     default:
  1578.     fprintf(stderr, "Warning: %c Unknown HP-GL First Op Command\n", op1);
  1579.     break;
  1580.     }
  1581. }
  1582. //E*O*F hpglcom.c//
  1583.  
  1584. echo x - linesize.c
  1585. cat > "linesize.c" << '//E*O*F linesize.c//'
  1586. #include "defn.h"
  1587.  
  1588. linesize()
  1589. {
  1590.     int        ipen = 0;
  1591.     float    linewidth;
  1592.  
  1593.    if (SIGNED_NUMERIC)
  1594.     ipen = getval() - 1;
  1595.  
  1596.    if (ipen < 0 || ipen > 8)
  1597.     ipen = 0;
  1598.  
  1599.     linewidth = pen_size[ipen] * SCALE;        /* In mm */
  1600.     printf("%g mm setlinewidth\n", linewidth);
  1601. }
  1602. //E*O*F linesize.c//
  1603.  
  1604. echo x - linetype.c
  1605. cat > "linetype.c" << '//E*O*F linetype.c//'
  1606. /*
  1607.  * Sets the line type and the scaling of the line pattern 
  1608.  *
  1609.  * Don McCormick CSIRO Division of Applied Physics National Measurements
  1610.  * Laboritory Bradfield Road Lindfield 2018 N.S.W. 
  1611.  *
  1612.  * NOTE: default length for a line pattern is approx 6.5 mm on A4 size paper. 
  1613.  */
  1614. #include "defn.h"
  1615.  
  1616. float   linescale;
  1617. int     linestyle;
  1618.  
  1619. linetype(line)
  1620. int     line;
  1621. {
  1622.     float   down1, down2;
  1623.     float   up1, up2;
  1624.     float   diagonal;
  1625.  
  1626.     end_draw();
  1627.  
  1628.     if (line == LINE_TYPE_SCALE)            /* HP-GL only */
  1629.     {
  1630.     if (SIGNED_NUMERIC)
  1631.     {
  1632.         if ((linestyle = rint(getval())) > 6)
  1633.         linestyle = 6;
  1634.         else if (linestyle < -6)
  1635.         linestyle = -6;
  1636.     }
  1637.     else
  1638.     {
  1639.         SETDOT = 0;
  1640.         printf("[] 0 setdash\n");
  1641.         return;
  1642.     }
  1643.  
  1644.     diagonal = pow((xmax - xmin),2.0) + pow((ymax - ymin),2.0);
  1645.     diagonal = pow(diagonal,0.5);
  1646.     if (SIGNED_NUMERIC)
  1647.         linescale = getval() * 0.01 * diagonal * XSCALE * SCALE * 0.2;
  1648.     else
  1649.         linescale = 0.015 * diagonal * XSCALE * SCALE * 0.2;
  1650.     } else
  1651.     if (line == LINESCALE)    /* DXY commands only */
  1652.     {
  1653.     if (SIGNED_NUMERIC)
  1654.         linescale = getval() / 80 * SCALE;
  1655.     else
  1656.         return;
  1657.     } else
  1658.     if (line == LINETYPE)    /* DXY commands only */
  1659.     {
  1660.     if (SIGNED_NUMERIC)
  1661.     {
  1662.         if ((linestyle = rint(getval())) > 5)
  1663.         linestyle = 5;
  1664.         else if (linestyle < -5)
  1665.         linestyle = -5;
  1666.     }
  1667.     else
  1668.         return;
  1669.     } else
  1670.     {
  1671.     fprintf(stderr, "Error: Unknown line flag in linetype.c\n");
  1672.     exit(1);
  1673.     }
  1674.     /*
  1675.      * select a line style/type and scale/pitch 
  1676.      */
  1677.     switch (linestyle)
  1678.     {
  1679.     case 6:
  1680.     down1 = 2.0;
  1681.     up1 = up2 = 1.5;
  1682.     down2 = 1.5;
  1683.     break;
  1684.  
  1685.     case 5:
  1686.     down1 = 3.0;
  1687.     up1 = up2 = 1.0;
  1688.     down2 = 1.5;
  1689.     break;
  1690.  
  1691.     case 4:
  1692.     down1 = 4.0;
  1693.     up1 = up2 = 0.75;
  1694.     down2 = 1.0;
  1695.     break;
  1696.  
  1697.     case 3:
  1698.     down1 = 5.0;
  1699.     up1 = up2 = 1.0;
  1700.     down2 = 0.5;
  1701.     break;
  1702.  
  1703.     case 2:
  1704.     down1 = 5.5;
  1705.     up1 = 1.0;
  1706.     up2 = down2 = 0.0;
  1707.     break;
  1708.  
  1709.     case 1:
  1710.     down1 = 5.0;
  1711.     up1 = 1.5;
  1712.     up2 = down2 = 0.0;
  1713.     break;
  1714.  
  1715.     case -1:
  1716.     down1 = 1.5;
  1717.     up1 = 3.5;
  1718.     down2 = 1.5;
  1719.     up2 = 0.0;
  1720.     break;
  1721.  
  1722.     case -2:
  1723.     down1 = 2.0;
  1724.     up1 = 2.5;
  1725.     down2 = 2.0;
  1726.     up2 = 0.0;
  1727.     break;
  1728.  
  1729.     case -3:
  1730.     down1 = 2.5;
  1731.     up1 = up2 = 1.75;
  1732.     down2 = 0.5;
  1733.     break;
  1734.  
  1735.     case -4:
  1736.     down1 = 2.5;
  1737.     up1 = up2 = 1.5;
  1738.     down2 = 1.5;
  1739.     break;
  1740.  
  1741.     case -5:
  1742.     down1 = down2 = 2.0;
  1743.     up1 = up2 = 1.25;
  1744.     break;
  1745.  
  1746.     case -6:
  1747.     down1 = down2 = 1.75;
  1748.     up1 = up2 = 1.5;
  1749.     break;
  1750.     }
  1751.     if (linestyle == 0)
  1752.     {
  1753.     SETDOT = 1;        /* For HP-GL only */
  1754.     printf("[] 0 setdash\n");    /* For DXY commands */
  1755.     } else
  1756.     {
  1757.     SETDOT = 0;        /* For HP-GL only */
  1758.     if (linescale <= 0) linescale = SCALE;
  1759.     down1 *= linescale;
  1760.     up2 *= linescale;
  1761.     up1 *= linescale;
  1762.     down2 *= linescale;
  1763.     printf("[%g mm %g mm %g mm %g mm] 0 setdash\n",
  1764.            down1, up1, down2, up2);
  1765.     }
  1766. }
  1767. //E*O*F linetype.c//
  1768.  
  1769. echo x - manualfeed.c
  1770. cat > "manualfeed.c" << '//E*O*F manualfeed.c//'
  1771. /*
  1772.  *    A procedure to allow the user to use the manual feed on
  1773.  *    the LaserWriter.
  1774.  *    The default wait before timeout is 3 minutes however this
  1775.  *    is easily changed.
  1776.  *
  1777.  *    argument: 1.   Enable manual feed.
  1778.  *          0.   Disable manual feed.
  1779.  *
  1780.  *    Don McCormick
  1781.  */
  1782. manualfeed(arg)
  1783. int     arg;
  1784. {
  1785.     if (arg == 1)
  1786.     {
  1787.     printf("statusdict /manualfeed true put\n");
  1788.     printf("statusdict /manualfeedtimeout 180 put\n");    /* 3 minute wait */
  1789.     } else
  1790.     printf("statusdict /manualfeed false put\n");
  1791.  
  1792.     printf("usertime 5000 add\n");
  1793.     printf("{dup usertime lt {pop exit} if} loop\n");
  1794. }
  1795. //E*O*F manualfeed.c//
  1796.  
  1797. echo x - plotcoords.c
  1798. cat > "plotcoords.c" << '//E*O*F plotcoords.c//'
  1799. /*
  1800.  *    Define default maximum and minimum plotting coordinates.
  1801.  *        P1 (xmin, ymin),  P2 (xmax, ymax)
  1802.  *
  1803.  *    PaperSize can be:
  1804.  *            "A3" ISO (420mm by 297mm)
  1805.  *            "A4" ISO (297mm by 210mm)
  1806.  *            "A"  ANSI (11" by 8.5")
  1807.  *            "B"  ANSI (17" by 11")
  1808.  *
  1809.  *    Mode can be:    "HPGL" or "DXY"
  1810.  *
  1811.  * Don McCormick
  1812.  */
  1813.  
  1814. #include "defn.h"
  1815.  
  1816. plotcoords()
  1817. {
  1818.     if (strcmp(Mode, "HPGL") == 0)
  1819.     {
  1820.     if (strcmp(PaperSize, "A3") == 0)    /* HP-GL ISO A3 420mm * 297mm */
  1821.     {
  1822.         xmax = 15200;
  1823.         ymax = 10800;
  1824.     }
  1825.     else                    /* HP-GL ISO A4 297mm * 210mm */
  1826.     {
  1827.         xmax = 10800;
  1828.         ymax = 7680;
  1829.     }
  1830.     }
  1831.     else
  1832.     {
  1833.     if (strcmp(PaperSize, "A3") == 0)    /* DXY ISO A3 420mm * 297mm */
  1834.     {
  1835.         xmax = 3800;
  1836.         ymax = 2700;
  1837.     }
  1838.     else                /* DXY ISO A4 297mm * 210mm */
  1839.     {
  1840.         xmax = 2700;
  1841.         ymax = 1920;
  1842.     }
  1843.     }
  1844.     xmin = ymin = 0.0;
  1845. }
  1846. //E*O*F plotcoords.c//
  1847.  
  1848. echo x - plotdot.c
  1849. cat > "plotdot.c" << '//E*O*F plotdot.c//'
  1850. /*
  1851.  * Plot a dot or symbol on the paper 
  1852.  */
  1853. #include "defn.h"
  1854.  
  1855. plotdot(type)
  1856. char   *type;
  1857. {
  1858.     end_draw();
  1859.  
  1860.     while (SIGNED_NUMERIC)
  1861.     {
  1862.     xval = getval() * XSCALE;
  1863.     yval = getval() * YSCALE;
  1864.     if (type == RMOVE)
  1865.     {
  1866.         absX += xval;
  1867.         absY += yval;
  1868.     } else
  1869.     if (type == MOVE)
  1870.     {
  1871.         absX = xval;
  1872.         absY = yval;
  1873.     } else
  1874.     {
  1875.         fprintf(stderr, "Error: expecting move command not %s\n", type);
  1876.         exit(1);
  1877.     }
  1878.  
  1879.     if (SYMBOL)
  1880.         printf("%g %g 5 %g (%c) Text\n", absX, absY, char_angle, symbol);
  1881.         else if (SETDOT)
  1882.     {
  1883.             printf("newpath\n");
  1884.             printf("  %g %g %s %g %g %s\n", absX, absY, MOVE, absX, absY, DRAW);
  1885.         printf("stroke\n");
  1886.     }
  1887.     }
  1888. }
  1889. //E*O*F plotdot.c//
  1890.  
  1891. echo x - plotinit.c
  1892. cat > "plotinit.c" << '//E*O*F plotinit.c//'
  1893. #include "defn.h"
  1894.  
  1895. plotinit()
  1896. {
  1897.     /*
  1898.      * Initialisation of PostScript plot macros 
  1899.      */
  1900.     MOVE = "M";
  1901.     RMOVE = "R";
  1902.     DRAW = "D";
  1903.     RDRAW = "I";
  1904.  
  1905.     LANDSCAPE = 1;        /* Display plot in Landscape mode */
  1906.  
  1907.     SCALE = 1;            /* Default Scale */
  1908.  
  1909.     PLOTABS = 1;        /* Absolute plot coordinates */
  1910.  
  1911.     PENDOWN = 0;        /* Penup */
  1912.  
  1913.     SETDOT = 0;            /* HP-GL only for linetype = 0 */
  1914.  
  1915.     SYMBOL = 0;            /* HP-GL only */
  1916.     /*
  1917.      *       Default line/pen sizes (in mm)
  1918.      */
  1919.     pen_size[0] = 0.1;
  1920.     pen_size[1] = 0.2;
  1921.     pen_size[2] = 0.3;
  1922.     pen_size[3] = 0.4;
  1923.     pen_size[4] = 0.5;
  1924.     pen_size[5] = 0.7;
  1925.     pen_size[6] = 1.0;
  1926.     pen_size[7] = 1.25;
  1927.     pen_size[8] = 1.5;
  1928.  
  1929.     font = "Helvetica";        /* Default font */
  1930.  
  1931.     EOL = '\003';        /* End of line terminator default */
  1932.  
  1933.     /*
  1934.      * Default character specifications
  1935.      */
  1936.     char_angle = 0;        /* Degrees */
  1937.     char_slant = 0;        /* tan(angle) */
  1938.     char_height = 2.7;        /* mm */
  1939.     char_space = 0.8;        /* mm */
  1940.     char_width = 1.9;        /* mm */
  1941.     /*
  1942.      * Page offsets set to zero
  1943.      */
  1944.     xoffset = yoffset = 0;
  1945.     /*
  1946.      * Define degree to radian parameter
  1947.      */
  1948.     deg_rad = asin(1.0) / 90.0;
  1949. }
  1950. //E*O*F plotinit.c//
  1951.  
  1952. echo x - plotps.c
  1953. cat > "plotps.c" << '//E*O*F plotps.c//'
  1954. #include "defn.h"
  1955.  
  1956. #define MAXDRAWPOINTS    100
  1957.  
  1958. plotps(type)
  1959. char   *type;
  1960. {
  1961.     if (type == MOVE || type == RMOVE)
  1962.     {
  1963.     while (SIGNED_NUMERIC)
  1964.     {
  1965.         if (type == MOVE)
  1966.         {
  1967.         end_draw();
  1968.         absX = lastXmove = getval() * XSCALE;
  1969.         absY = lastYmove = getval() * YSCALE;
  1970.         } else
  1971.         if (type == RMOVE)
  1972.         {
  1973.         end_draw();
  1974.         lastXmove = absX += getval() * XSCALE;
  1975.         lastYmove = absY += getval() * YSCALE;
  1976.         }
  1977.     }
  1978.     }
  1979.     else            /* Must be a DRAW or RDRAW */
  1980.     {
  1981.     while (SIGNED_NUMERIC)
  1982.     {
  1983.         if (dcount++ >= MAXDRAWPOINTS)
  1984.         {
  1985.         end_draw();
  1986.         printf("newpath\n");
  1987.         printf("  %g %g %s\n", absX, absY, MOVE);
  1988.         DRAW_FLAG = 1;
  1989.         fprintf(stderr, "Warning exceeded 100 draw points\n");
  1990.         }
  1991.         xval = getval() * XSCALE;
  1992.         yval = getval() * YSCALE;
  1993.         if (!DRAW_FLAG)
  1994.         {
  1995.         printf("newpath\n");
  1996.         printf("  %g %g %s\n", absX, absY, MOVE);
  1997.         DRAW_FLAG = 1;
  1998.         }
  1999.         if (type == RDRAW)
  2000.         {
  2001.         absX += xval;
  2002.         absY += yval;
  2003.         printf("  %g %g %s\n", xval, yval, RDRAW);
  2004.         } else
  2005.         if (type == DRAW)
  2006.         {
  2007.         absX = xval;
  2008.         absY = yval;
  2009.         printf("  %g %g %s\n", absX, absY, DRAW);
  2010.         } else
  2011.         {
  2012.         fprintf(stderr, "Error: expecting draw command not %s\n", type);
  2013.         exit(1);
  2014.         }
  2015.     }
  2016.     }
  2017. }
  2018. //E*O*F plotps.c//
  2019.  
  2020. echo x - ps_macros.c
  2021. cat > "ps_macros.c" << '//E*O*F ps_macros.c//'
  2022. ps_macros()
  2023. {
  2024.     printf("%%! PS-Adobe-1.0: For Apple LaserWriter\n");
  2025.     printf("%% default font is 10 pt. Helvetica\n");
  2026.     printf("/basefont {/Helvetica findfont 10 scalefont setfont} def\n");
  2027.  
  2028.     printf("/mm {72.27 mul 25.4 div} def\n");    /* Specify millimeters */
  2029.  
  2030.     printf("/M\n");                /* Move macro */
  2031.     printf("{\n");
  2032.     printf("    /Ymove exch def\n");
  2033.     printf("    /Xmove exch def\n");
  2034.     printf("    Xmove mm Ymove mm moveto\n");
  2035.     printf("} def\n");
  2036.  
  2037.     printf("/R\n");                /* Relative move macro */
  2038.     printf("{\n");
  2039.     printf("    /Yrmove exch def\n");
  2040.     printf("    /Xrmove exch def\n");
  2041.     printf("    Xrmove mm Yrmove mm rmoveto\n");
  2042.     printf("} def\n");
  2043.  
  2044.     printf("/D\n");                /* Draw macro */
  2045.     printf("{\n");
  2046.     printf("    /Ydraw exch def\n");
  2047.     printf("    /Xdraw exch def\n");
  2048.     printf("    Xdraw mm Ydraw mm lineto\n");
  2049.     printf("} def\n");
  2050.  
  2051.     printf("/I\n");                /* Relative draw  macro */
  2052.     printf("{\n");
  2053.     printf("    /Yrdraw exch def\n");
  2054.     printf("    /Xrdraw exch def\n");
  2055.     printf("    Xrdraw mm Yrdraw mm rlineto\n");
  2056.     printf("} def\n");
  2057.     /*
  2058.      *        Procedure to change font and size of font
  2059.      *        ---->   font size Font    <----
  2060.      */
  2061.     printf("/Font\n");
  2062.     printf("{\n");
  2063.     printf("    /Height exch def\n");
  2064.     printf("    /FontName exch def\n");
  2065.     printf("    FontName findfont Height mm scalefont setfont\n");
  2066.     printf("} def\n");
  2067.     /*
  2068.      *        Procedure to change font, width, slant and height
  2069.      *        ---->   font width height slant DefFont    <----
  2070.      *
  2071.      *    Note: slant = height * tan( slant_angle )
  2072.      */
  2073.     printf("/DefFont\n");
  2074.     printf("{\n");
  2075.     printf("    /Slant exch def\n");
  2076.     printf("    /Height exch def\n");
  2077.     printf("    /Width exch def\n");
  2078.     printf("    /FontName exch def\n");
  2079.     printf("    FontName findfont [ Width mm 0 Slant mm Height mm 0 0] makefont setfont\n");
  2080.     printf("} def\n");
  2081.     /*
  2082.      *        General Text Layout Procedure
  2083.      *        ---->   x y pos_num angle (text) Text    <----
  2084.      */
  2085.     printf("/Text\n");
  2086.     printf("{\n");
  2087.     printf("    /String exch def\n");
  2088.     printf("    /Angle exch def\n");
  2089.     printf("    /Position exch def\n");
  2090.     printf("    /Ymove exch def\n");
  2091.     printf("    /Xmove exch def\n");
  2092.     printf("    Position 1 lt {/hpf 0 def /lpf 0 def} if\n");
  2093.     printf("    Position 1 eq {/hpf 0 def /lpf 0 def} if\n");
  2094.     printf("    Position 2 eq {/hpf 0 def /lpf 0.5 def} if\n");
  2095.     printf("    Position 3 eq {/hpf 0 def /lpf 1 def} if\n");
  2096.     printf("    Position 4 eq {/hpf 0.5 def /lpf 0 def} if\n");
  2097.     printf("    Position 5 eq {/hpf 0.5 def /lpf 0.5 def} if\n");
  2098.     printf("    Position 6 eq {/hpf 0.5 def /lpf 1 def} if\n");
  2099.     printf("    Position 7 eq {/hpf 1 def /lpf 0 def} if\n");
  2100.     printf("    Position 8 eq {/hpf 1 def /lpf 0.5 def} if\n");
  2101.     printf("    Position 9 eq {/hpf 1 def /lpf 1 def} if\n");
  2102.     printf("    Position 9 gt {/hpf 1 def /lpf 1 def} if\n");
  2103.     printf("    /StrLen String stringwidth pop lpf mul def\n");
  2104.     printf("    /StrHt Height mm hpf mul def\n");
  2105.     printf("    /Xdiff StrHt Angle sin mul StrLen Angle cos mul sub def\n");
  2106.     printf("    /Ydiff StrHt Angle cos mul StrLen Angle sin mul add def\n");
  2107.     printf("    Xmove mm Xdiff add Ymove mm Ydiff sub moveto\n");
  2108.     printf("    gsave\n");
  2109.     printf("        Angle rotate\n");
  2110.     printf("        String show\n");
  2111.     printf("    grestore\n");
  2112.     printf("    /PosterOnly 0 def\n");
  2113.     printf("} def\n");
  2114.     /*
  2115.      *        Ellipse and Circle procedure.
  2116.      *  ---->   xcen ycen xrad yrad start_angle end_angle Ellipse   <----
  2117.      */
  2118.     printf("/EllipseDict 8 dict def\n");
  2119.     printf("EllipseDict /mtrx matrix put\n");
  2120.     printf("/Ellipse \n");
  2121.     printf("{   EllipseDict begin\n");
  2122.     printf("    /endangle exch def\n");
  2123.     printf("    /startangle exch def\n");
  2124.     printf("    /yradius exch def\n");
  2125.     printf("    /xradius exch def\n");
  2126.     printf("    /ycenter exch def\n");
  2127.     printf("    /xcenter exch def\n");
  2128.     printf("    /savematrix mtrx currentmatrix def\n");
  2129.     printf("    xcenter mm ycenter mm translate\n");
  2130.     printf("    xradius mm yradius mm div 1 scale\n");
  2131.     printf("    newpath\n");
  2132.     printf("        0 0 xradius mm startangle endangle arc\n");
  2133.     printf("    stroke\n");
  2134.     printf("    savematrix setmatrix\n");
  2135.     printf("    end\n");
  2136.     printf("} def\n");
  2137.  
  2138.     printf("basefont\n");        /* Set the default font */
  2139.     printf("1 setlinecap\n");        /* Use round caps */
  2140.     printf("1 setlinejoin\n");        /* Use round joins */
  2141.     printf("3 setmiterlimit\n");    /* Bevel small angle miters */
  2142. }
  2143. //E*O*F ps_macros.c//
  2144.  
  2145. echo x - rectangle.c
  2146. cat > "rectangle.c" << '//E*O*F rectangle.c//'
  2147. #include "defn.h"
  2148.  
  2149. rectangle()
  2150. {
  2151.     int        hatch;
  2152.     float    width, height;
  2153.     float    hatch_spacing;
  2154.     float    hatch_angle;
  2155.     
  2156.     if (SIGNED_NUMERIC)
  2157.     hatch = getval();
  2158.     if (SIGNED_NUMERIC)
  2159.     width = getval() * XSCALE;
  2160.     if (SIGNED_NUMERIC)
  2161.     height = getval() * YSCALE;
  2162.     if (SIGNED_NUMERIC)
  2163.     hatch_spacing = getval() * XSCALE;
  2164.     if (SIGNED_NUMERIC)
  2165.     hatch_angle = getval();
  2166.  
  2167.     end_draw();
  2168.     printf("%g %g M\n", xval, yval);
  2169.     printf("%g 0 I\n", width);
  2170.     printf("0 %g I\n", height);
  2171.     printf("-%g 0 I\n", width);
  2172.     printf("closepath stroke\n");
  2173.     if (hatch != 2)
  2174.         fprintf(stderr, "Warning: Cross hatching not implemented yet\n");
  2175. }
  2176. //E*O*F rectangle.c//
  2177.  
  2178. echo x - textps.c
  2179. cat > "textps.c" << '//E*O*F textps.c//'
  2180. #include "defn.h"
  2181.  
  2182. #define MAXBUFSIZE 100
  2183.  
  2184. textps(type)
  2185. int     type;
  2186. {
  2187.     char    string[4];
  2188.     char    buffer[MAXBUFSIZE];
  2189.     float   Xch, Ych;
  2190.     int        intval;
  2191.     int     i;
  2192.  
  2193.     end_draw();
  2194.  
  2195.     if (type == TEXT)
  2196.     {
  2197.     for (i = 0 ; i < MAXBUFSIZE; i++)    /* Clear buffer */
  2198.         buffer[i] = NULL;
  2199.  
  2200.     i = 0;                    /* Reset buffer counter */
  2201.  
  2202.     while (((ch = getc(stream)) != EOF)
  2203.             && ch != CR && ch != LF && ch != EOL)
  2204.     {
  2205.         buffer[i++] = ch;
  2206. /*        printf("%g %g 1 %g (%c) Text\n", absX, absY, char_angle, ch);
  2207.  *        absX += (char_width + char_space) * cos(char_angle * deg_rad);
  2208.  *        absY += (char_width + char_space) * sin(char_angle * deg_rad);
  2209.  */
  2210.     }
  2211.     printf("%g %g 1 %g (%s) Text\n", absX, absY, char_angle, buffer);
  2212.     } else            /* Must be a MARK */
  2213.     {
  2214.     int     symb_num;
  2215.  
  2216.     if (SIGNED_NUMERIC)
  2217.         symb_num = getval();
  2218.     else
  2219.     {
  2220.         fprintf(stderr,
  2221.             "Error: expecting a symbol number not %c (%d)",
  2222.             symb_num, symb_num);
  2223.         exit(1);
  2224.     }
  2225.     intval = (int)(getval() + 0.5);
  2226.     switch (intval)
  2227.     {
  2228.     case 0:
  2229.         strcpy(string, "*");
  2230.         break;
  2231.  
  2232.     case 1:
  2233.         strcpy(string, "+");
  2234.         break;
  2235.  
  2236.     case 2:
  2237.         strcpy(string, "#");
  2238.         break;
  2239.  
  2240.     case 3:
  2241.         strcpy(string, "@");
  2242.         break;
  2243.  
  2244.     case 4:
  2245.         strcpy(string, "%");
  2246.         break;
  2247.  
  2248.     case 5:
  2249.         strcpy(string, "|");
  2250.         break;
  2251.  
  2252.     case 6:
  2253.         strcpy(string, "=");
  2254.         break;
  2255.  
  2256.     case 7:
  2257.         strcpy(string, "&");
  2258.         break;
  2259.  
  2260.     case 9:
  2261.         strcpy(string, "O");
  2262.         break;
  2263.  
  2264.     case 10:
  2265.         strcpy(string, "0");
  2266.         break;
  2267.  
  2268.     case 11:
  2269.         strcpy(string, "Y");
  2270.         break;
  2271.  
  2272.     case 12:
  2273.         strcpy(string, "X");
  2274.         break;
  2275.  
  2276.     case 13:
  2277.         strcpy(string, "Z");
  2278.         break;
  2279.  
  2280.     case 14:
  2281.         strcpy(string, "S");
  2282.         break;
  2283.  
  2284.     case 15:
  2285.         strcpy(string, "Q");
  2286.         break;
  2287.  
  2288.     default:
  2289.         fprintf(stderr, "Warning symbol number is %d\n", symb_num);
  2290.         strcpy(string, "*");
  2291.         break;
  2292.     }
  2293.     printf("%g %g 5 %g (%s) Text\n", absX, absY, char_angle, string);
  2294.     }
  2295. }
  2296. //E*O*F textps.c//
  2297.  
  2298. echo x - viewport.c
  2299. cat > "viewport.c" << '//E*O*F viewport.c//'
  2300. /*
  2301.  * This procedure sets up the variables for the translation of plotter
  2302.  * coordinates to PostScript coordinates.
  2303.  *
  2304.  * Note: the procedure "defaults" may be incorporated here, however
  2305.  *    I have not had the time to work it out properly.
  2306.  *
  2307.  * Don McCormick
  2308.  */
  2309. #include "defn.h"
  2310.  
  2311. viewport()
  2312. {
  2313.     float pagewidth = 197.0;        /* Page width for Laser Printer */
  2314.     float pageheight = 280.0;        /* Page height for Laser Printer */
  2315.     float pwoffset = 12;
  2316.     float phoffset = 12;
  2317.  
  2318.     float psxmax, psymax;        /* Sizes scaled to the viewport */
  2319.  
  2320.     if (LANDSCAPE)        /* Default mode */
  2321.     {
  2322.     psymax = pagewidth * 0.938095;
  2323.     psxmax = psymax * (xmax - xmin)/ (ymax - ymin);
  2324.     xoffset += (pageheight + phoffset - psxmax) / 2.0;
  2325.     yoffset -= (pagewidth + pwoffset + psymax) / 2.0;
  2326.     printf("90 rotate\n");
  2327.     } else
  2328.     {
  2329.     psxmax = pagewidth * 0.938095;
  2330.     psymax = psxmax * (ymax - ymin) / (xmax - xmin);
  2331.     xoffset += (pagewidth + pwoffset - psxmax) / 2.0;
  2332.     yoffset += (pageheight + phoffset - psymax) / 2.0;
  2333.     }
  2334.     printf("%g mm %g mm translate\n", xoffset, yoffset);
  2335.     XSCALE = psxmax / xmax * SCALE;
  2336.     YSCALE = psymax / ymax * SCALE;
  2337. }
  2338. //E*O*F viewport.c//
  2339.  
  2340. echo x - test1.dxy
  2341. cat > "test1.dxy" << '//E*O*F test1.dxy//'
  2342. J1
  2343. M 1000, 1000
  2344. I 100, 0, -200,0, 100, 0, 0,100,0, -200
  2345. P Hi There
  2346. C 1000, 1000, 500, 0, 250
  2347. M 2000,1000
  2348. I 100, 0, -200,0, 100, 0, 0,100,0, -200
  2349. L 2
  2350. J5
  2351. C 2000, 1000, 500, 250, 0
  2352. J3
  2353. M 0 0
  2354. I 3800,0,0,2700,-3800,0,0,-2700
  2355. M 500,2000
  2356. ^SL1;S50PDXY-880
  2357. ^SL;S3
  2358.  
  2359. //E*O*F test1.dxy//
  2360.  
  2361. echo x - test1.hpgl
  2362. cat > "test1.hpgl" << '//E*O*F test1.hpgl//'
  2363. DF;IN;LT;PU1000,1000;PD2000,1000,2000,2000,1000,2000,1000,1000;
  2364. PR-100,0,0,-100,100,0,0,100;
  2365. PU;PA0,0;PD10800,0,10800,7680,0,7680,0,0;PU;
  2366. LT6,2;PA;PU4000,1400;PD;PR4000,0;
  2367. LT5,2;PA;PU4000,1300;PD;PR4000,0;
  2368. LT4,2;PA;PU4000,1200;PD;PR4000,0;
  2369. LT3,2;PA;PU4000,1100;PD;PR4000,0;
  2370. LT2,2;PA;PU4000,1000;PD;PR4000,0;
  2371. LT1,2;PA;PU4000,900;PD;PR4000,0;
  2372. LT0;PA;PU4000,800;PD;PR4000,0;
  2373. LT-1,2;PA;PU4000,700;PD;PR4000,0;
  2374. LT-2,2;PA;PU4000,600;PD;PR4000,0;
  2375. LT-3,2;PA;PU4000,500;PD;PR4000,0;
  2376. LT-4,2;PA;PU4000,400;PD;PR4000,0;
  2377. LT-5,2;PA;PU4000,300;PD;PR4000,0;
  2378. LT-6,2;PA;PU4000,200;PD;PR4000,0;
  2379. PU;PA2000,4000;
  2380. DI;LB  --   0deg --
  2381. DI1,1;LB  --  45deg --
  2382. DI0,1;LB  --  90deg --
  2383. DI-1,1;LB  -- 135deg --
  2384. DI-1,0;LB  -- 180deg --
  2385. DI-1,-1;LB  -- 225deg --
  2386. DI0,-1;LB  -- 270deg --
  2387. DI1,-1;LB  -- 315deg --
  2388. PA4000,4000;
  2389. DI;SL1;LB SLANT of 45deg
  2390. PA4000,3600;
  2391. SL-1;LB SLANT of -45deg
  2392. PA2000,6000;
  2393. SL;SR;LB Size is relative
  2394. PA2000,5500;
  2395. SI;LB DEFAULT sizes
  2396. PA2000,5000;
  2397. SI.8,1;LBLARGE size (w=8mm, h=10mm)
  2398. LT;        PA 9000,1000;CI500,20;CI400;CI300;CI200,1;CI100;CI50;
  2399. IN;SM+;PA9000,1000,10000,1000;SM%;PR0,500,0,-1000;
  2400. SM;
  2401. //E*O*F test1.hpgl//
  2402.  
  2403. exit 0
  2404.