summaryrefslogtreecommitdiffstats
path: root/src/preproc/pic
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 19:44:05 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 19:44:05 +0000
commitd318611dd6f23fcfedd50e9b9e24620b102ba96a (patch)
tree8b9eef82ca40fdd5a8deeabf07572074c236095d /src/preproc/pic
parentInitial commit. (diff)
downloadgroff-upstream.tar.xz
groff-upstream.zip
Adding upstream version 1.23.0.upstream/1.23.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/preproc/pic')
-rw-r--r--src/preproc/pic/TODO35
-rw-r--r--src/preproc/pic/common.cpp647
-rw-r--r--src/preproc/pic/common.h79
-rw-r--r--src/preproc/pic/lex.cpp2039
-rw-r--r--src/preproc/pic/main.cpp664
-rw-r--r--src/preproc/pic/object.cpp2079
-rw-r--r--src/preproc/pic/object.h227
-rw-r--r--src/preproc/pic/output.h82
-rw-r--r--src/preproc/pic/pic.1.man1569
-rw-r--r--src/preproc/pic/pic.am56
-rw-r--r--src/preproc/pic/pic.cpp5080
-rw-r--r--src/preproc/pic/pic.h122
-rw-r--r--src/preproc/pic/pic.hpp348
-rw-r--r--src/preproc/pic/pic.ypp1957
-rw-r--r--src/preproc/pic/position.h46
-rw-r--r--src/preproc/pic/tex.cpp458
-rw-r--r--src/preproc/pic/text.h46
-rw-r--r--src/preproc/pic/troff.cpp579
18 files changed, 16113 insertions, 0 deletions
diff --git a/src/preproc/pic/TODO b/src/preproc/pic/TODO
new file mode 100644
index 0000000..53ca282
--- /dev/null
+++ b/src/preproc/pic/TODO
@@ -0,0 +1,35 @@
+In troff mode, dotted and dashed splines.
+
+Make DELIMITED have type lstr; this would allow us to give better
+error messages for problems within the body of for and if constructs.
+
+In troff mode without -x, fake \D't' with .ps commands.
+
+Perhaps an option to set command char.
+
+Add an output class for dumb line printers. It wouldn't be pretty but
+it would be better than nothing. Integrate it with texinfo. Useful
+for groff -Tascii as well.
+
+Option to allow better positioning of arrowheads on arcs.
+
+Perhaps add PostScript output mode.
+
+Change the interface to the output class so that output devices have
+the opportunity to handle arrowheads themselves.
+
+Consider whether the line thickness should scale.
+
+Consider whether the test in a for loop should be fuzzy (as it
+apparently is in grap).
+
+Possibly change fillval so that zero is black.
+
+Provide a way of getting text blocks (positioned with '.in' rather
+than \h), into pic. Should be possible to use block of diverted text
+in pic. Possibly something similar to T{ and T} in tbl.
+
+Option to provide macro backtraces.
+
+Have a path that is searched by 'copy' statement. Set by environment
+variable or command-line option.
diff --git a/src/preproc/pic/common.cpp b/src/preproc/pic/common.cpp
new file mode 100644
index 0000000..6a4a93e
--- /dev/null
+++ b/src/preproc/pic/common.cpp
@@ -0,0 +1,647 @@
+// -*- C++ -*-
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+ Written by James Clark (jjc@jclark.com)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+groff is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "pic.h"
+#include "common.h"
+
+// output a dashed circle as a series of arcs
+
+void common_output::dashed_circle(const position &cent, double rad,
+ const line_type &lt)
+{
+ assert(lt.type == line_type::dashed);
+ line_type slt = lt;
+ slt.type = line_type::solid;
+ double dash_angle = lt.dash_width/rad;
+ int ndashes;
+ double gap_angle;
+ if (dash_angle >= M_PI/4.0) {
+ if (dash_angle < M_PI/2.0) {
+ gap_angle = M_PI/2.0 - dash_angle;
+ ndashes = 4;
+ }
+ else if (dash_angle < M_PI) {
+ gap_angle = M_PI - dash_angle;
+ ndashes = 2;
+ }
+ else {
+ circle(cent, rad, slt, -1.0);
+ return;
+ }
+ }
+ else {
+ ndashes = 4*int(ceil(M_PI/(4.0*dash_angle)));
+ gap_angle = (M_PI*2.0)/ndashes - dash_angle;
+ }
+ for (int i = 0; i < ndashes; i++) {
+ double start_angle = i*(dash_angle+gap_angle) - dash_angle/2.0;
+ solid_arc(cent, rad, start_angle, start_angle + dash_angle, lt);
+ }
+}
+
+// output a dotted circle as a series of dots
+
+void common_output::dotted_circle(const position &cent, double rad,
+ const line_type &lt)
+{
+ assert(lt.type == line_type::dotted);
+ double gap_angle = lt.dash_width/rad;
+ int ndots;
+ if (gap_angle >= M_PI/2.0) {
+ // always have at least 2 dots
+ gap_angle = M_PI;
+ ndots = 2;
+ }
+ else {
+ ndots = 4*int(M_PI/(2.0*gap_angle));
+ gap_angle = (M_PI*2.0)/ndots;
+ }
+ double ang = 0.0;
+ for (int i = 0; i < ndots; i++, ang += gap_angle)
+ dot(cent + position(cos(ang), sin(ang))*rad, lt);
+}
+
+// recursive function for dash drawing, used by dashed_ellipse
+
+void common_output::ellipse_arc(const position &cent,
+ const position &z0, const position &z1,
+ const distance &dim, const line_type &lt)
+{
+ assert(lt.type == line_type::solid);
+ assert(dim.x != 0 && dim.y != 0);
+ double eps = 0.0001;
+ position zml = (z0 + z1) / 2;
+ // apply affine transformation (from ellipse to circle) to compute angle
+ // of new position, then invert transformation to get exact position
+ double psi = atan2(zml.y / dim.y, zml.x / dim.x);
+ position zm = position(dim.x * cos(psi), dim.y * sin(psi));
+ // to approximate the ellipse arc with one or more circle arcs, we
+ // first compute the radius of curvature in zm
+ double a_2 = dim.x * dim.x;
+ double a_4 = a_2 * a_2;
+ double b_2 = dim.y * dim.y;
+ double b_4 = b_2 * b_2;
+ double e_2 = a_2 - b_2;
+ double temp = a_4 * zm.y * zm.y + b_4 * zm.x * zm.x;
+ double rho = sqrt(temp / a_4 / b_4 * temp / a_4 / b_4 * temp);
+ // compute center of curvature circle
+ position M = position(e_2 * zm.x / a_2 * zm.x / a_2 * zm.x,
+ -e_2 * zm.y / b_2 * zm.y / b_2 * zm.y);
+ // compute distance between circle and ellipse arc at start and end
+ double phi0 = atan2(z0.y - M.y, z0.x - M.x);
+ double phi1 = atan2(z1.y - M.y, z1.x - M.x);
+ position M0 = position(rho * cos(phi0), rho * sin(phi0)) + M;
+ position M1 = position(rho * cos(phi1), rho * sin(phi1)) + M;
+ double dist0 = hypot(z0 - M0) / sqrt(z0 * z0);
+ double dist1 = hypot(z1 - M1) / sqrt(z1 * z1);
+ if (dist0 < eps && dist1 < eps)
+ solid_arc(M + cent, rho, phi0, phi1, lt);
+ else {
+ ellipse_arc(cent, z0, zm, dim, lt);
+ ellipse_arc(cent, zm, z1, dim, lt);
+ }
+}
+
+// output a dashed ellipse as a series of arcs
+
+void common_output::dashed_ellipse(const position &cent, const distance &dim,
+ const line_type &lt)
+{
+ assert(lt.type == line_type::dashed);
+ double dim_x = dim.x / 2;
+ double dim_y = dim.y / 2;
+ line_type slt = lt;
+ slt.type = line_type::solid;
+ double dw = lt.dash_width;
+ // we use an approximation to compute the ellipse length (found in:
+ // Bronstein, Semendjajew, Taschenbuch der Mathematik)
+ double lambda = (dim.x - dim.y) / (dim.x + dim.y);
+ double le = M_PI / 2 * (dim.x + dim.y)
+ * ((64 - 3 * lambda * lambda * lambda * lambda )
+ / (64 - 16 * lambda * lambda));
+ // for symmetry we make nmax a multiple of 8
+ int nmax = 8 * int(le / dw / 8 + 0.5);
+ if (nmax < 8) {
+ nmax = 8;
+ dw = le / 8;
+ }
+ int ndash = nmax / 2;
+ double gapwidth = (le - dw * ndash) / ndash;
+ double l = 0;
+ position z = position(dim_x, 0);
+ position zdot = z;
+ int j = 0;
+ int jmax = int(10 / lt.dash_width);
+ for (int i = 0; i <= nmax; i++) {
+ position zold = z;
+ position zpre = zdot;
+ double ld = (int(i / 2) + 0.5) * dw + int((i + 1) / 2) * gapwidth;
+ double lold = 0;
+ double dl = 1;
+ // find next position for fixed arc length
+ while (l < ld) {
+ j++;
+ lold = l;
+ zold = z;
+ double phi = j * 2 * M_PI / jmax;
+ z = position(dim_x * cos(phi), dim_y * sin(phi));
+ dl = hypot(z - zold);
+ l += dl;
+ }
+ // interpolate linearly between the last two points,
+ // using the length difference as the scaling factor
+ double delta = (ld - lold) / dl;
+ zdot = zold + (z - zold) * delta;
+ // compute angle of new position on the affine circle
+ // and use it to get the exact value on the ellipse
+ double psi = atan2(zdot.y / dim_y, zdot.x / dim_x);
+ zdot = position(dim_x * cos(psi), dim_y * sin(psi));
+ if ((i % 2 == 0) && (i > 1))
+ ellipse_arc(cent, zpre, zdot, dim / 2, slt);
+ }
+}
+
+// output a dotted ellipse as a series of dots
+
+void common_output::dotted_ellipse(const position &cent, const distance &dim,
+ const line_type &lt)
+{
+ assert(lt.type == line_type::dotted);
+ double dim_x = dim.x / 2;
+ double dim_y = dim.y / 2;
+ line_type slt = lt;
+ slt.type = line_type::solid;
+ // we use an approximation to compute the ellipse length (found in:
+ // Bronstein, Semendjajew, Taschenbuch der Mathematik)
+ double lambda = (dim.x - dim.y) / (dim.x + dim.y);
+ double le = M_PI / 2 * (dim.x + dim.y)
+ * ((64 - 3 * lambda * lambda * lambda * lambda )
+ / (64 - 16 * lambda * lambda));
+ // for symmetry we make nmax a multiple of 4
+ int ndots = 4 * int(le / lt.dash_width / 4 + 0.5);
+ if (ndots < 4)
+ ndots = 4;
+ double l = 0;
+ position z = position(dim_x, 0);
+ int j = 0;
+ int jmax = int(10 / lt.dash_width);
+ for (int i = 1; i <= ndots; i++) {
+ position zold = z;
+ double lold = l;
+ double ld = i * le / ndots;
+ double dl = 1;
+ // find next position for fixed arc length
+ while (l < ld) {
+ j++;
+ lold = l;
+ zold = z;
+ double phi = j * 2 * M_PI / jmax;
+ z = position(dim_x * cos(phi), dim_y * sin(phi));
+ dl = hypot(z - zold);
+ l += dl;
+ }
+ // interpolate linearly between the last two points,
+ // using the length difference as the scaling factor
+ double delta = (ld - lold) / dl;
+ position zdot = zold + (z - zold) * delta;
+ // compute angle of new position on the affine circle
+ // and use it to get the exact value on the ellipse
+ double psi = atan2(zdot.y / dim_y, zdot.x / dim_x);
+ zdot = position(dim_x * cos(psi), dim_y * sin(psi));
+ dot(cent + zdot, slt);
+ }
+}
+
+// return non-zero iff we can compute a center
+
+int compute_arc_center(const position &start, const position &cent,
+ const position &end, position *result)
+{
+ // This finds the point along the vector from start to cent that
+ // is equidistant between start and end.
+ distance c = cent - start;
+ distance e = end - start;
+ double n = c*e;
+ if (n == 0.0)
+ return 0;
+ *result = start + c*((e*e)/(2.0*n));
+ return 1;
+}
+
+// output a dashed arc as a series of arcs
+
+void common_output::dashed_arc(const position &start, const position &cent,
+ const position &end, const line_type &lt)
+{
+ assert(lt.type == line_type::dashed);
+ position c;
+ if (!compute_arc_center(start, cent, end, &c)) {
+ line(start, &end, 1, lt);
+ return;
+ }
+ distance start_offset = start - c;
+ distance end_offset = end - c;
+ double start_angle = atan2(start_offset.y, start_offset.x);
+ double end_angle = atan2(end_offset.y, end_offset.x);
+ double rad = hypot(c - start);
+ double dash_angle = lt.dash_width/rad;
+ double total_angle = end_angle - start_angle;
+ while (total_angle < 0)
+ total_angle += M_PI + M_PI;
+ if (total_angle <= dash_angle*2.0) {
+ solid_arc(cent, rad, start_angle, end_angle, lt);
+ return;
+ }
+ int ndashes = int((total_angle - dash_angle)/(dash_angle*2.0) + .5);
+ double dash_and_gap_angle = (total_angle - dash_angle)/ndashes;
+ for (int i = 0; i <= ndashes; i++)
+ solid_arc(cent, rad, start_angle + i*dash_and_gap_angle,
+ start_angle + i*dash_and_gap_angle + dash_angle, lt);
+}
+
+// output a dotted arc as a series of dots
+
+void common_output::dotted_arc(const position &start, const position &cent,
+ const position &end, const line_type &lt)
+{
+ assert(lt.type == line_type::dotted);
+ position c;
+ if (!compute_arc_center(start, cent, end, &c)) {
+ line(start, &end, 1, lt);
+ return;
+ }
+ distance start_offset = start - c;
+ distance end_offset = end - c;
+ double start_angle = atan2(start_offset.y, start_offset.x);
+ double total_angle = atan2(end_offset.y, end_offset.x) - start_angle;
+ while (total_angle < 0)
+ total_angle += M_PI + M_PI;
+ double rad = hypot(c - start);
+ int ndots = int(total_angle/(lt.dash_width/rad) + .5);
+ if (ndots == 0)
+ dot(start, lt);
+ else {
+ for (int i = 0; i <= ndots; i++) {
+ double a = start_angle + (total_angle*i)/ndots;
+ dot(cent + position(cos(a), sin(a))*rad, lt);
+ }
+ }
+}
+
+void common_output::solid_arc(const position &cent, double rad,
+ double start_angle, double end_angle,
+ const line_type &lt)
+{
+ line_type slt = lt;
+ slt.type = line_type::solid;
+ arc(cent + position(cos(start_angle), sin(start_angle))*rad,
+ cent,
+ cent + position(cos(end_angle), sin(end_angle))*rad,
+ slt);
+}
+
+
+void common_output::rounded_box(const position &cent, const distance &dim,
+ double rad, const line_type &lt,
+ double fill, char *color_fill)
+{
+ if (fill >= 0.0 || color_fill)
+ filled_rounded_box(cent, dim, rad, fill);
+ switch (lt.type) {
+ case line_type::invisible:
+ break;
+ case line_type::dashed:
+ dashed_rounded_box(cent, dim, rad, lt);
+ break;
+ case line_type::dotted:
+ dotted_rounded_box(cent, dim, rad, lt);
+ break;
+ case line_type::solid:
+ solid_rounded_box(cent, dim, rad, lt);
+ break;
+ default:
+ assert(0);
+ }
+}
+
+
+void common_output::dashed_rounded_box(const position &cent,
+ const distance &dim, double rad,
+ const line_type &lt)
+{
+ line_type slt = lt;
+ slt.type = line_type::solid;
+
+ double hor_length = dim.x + (M_PI/2.0 - 2.0)*rad;
+ int n_hor_dashes = int(hor_length/(lt.dash_width*2.0) + .5);
+ double hor_gap_width = (n_hor_dashes != 0
+ ? hor_length/n_hor_dashes - lt.dash_width
+ : 0.0);
+
+ double vert_length = dim.y + (M_PI/2.0 - 2.0)*rad;
+ int n_vert_dashes = int(vert_length/(lt.dash_width*2.0) + .5);
+ double vert_gap_width = (n_vert_dashes != 0
+ ? vert_length/n_vert_dashes - lt.dash_width
+ : 0.0);
+ // Note that each corner arc has to be split into two for dashing,
+ // because one part is dashed using vert_gap_width, and the other
+ // using hor_gap_width.
+ double offset = lt.dash_width/2.0;
+ dash_arc(cent + position(dim.x/2.0 - rad, -dim.y/2.0 + rad), rad,
+ -M_PI/4.0, 0, slt, lt.dash_width, vert_gap_width, &offset);
+ dash_line(cent + position(dim.x/2.0, -dim.y/2.0 + rad),
+ cent + position(dim.x/2.0, dim.y/2.0 - rad),
+ slt, lt.dash_width, vert_gap_width, &offset);
+ dash_arc(cent + position(dim.x/2.0 - rad, dim.y/2.0 - rad), rad,
+ 0, M_PI/4.0, slt, lt.dash_width, vert_gap_width, &offset);
+
+ offset = lt.dash_width/2.0;
+ dash_arc(cent + position(dim.x/2.0 - rad, dim.y/2.0 - rad), rad,
+ M_PI/4.0, M_PI/2, slt, lt.dash_width, hor_gap_width, &offset);
+ dash_line(cent + position(dim.x/2.0 - rad, dim.y/2.0),
+ cent + position(-dim.x/2.0 + rad, dim.y/2.0),
+ slt, lt.dash_width, hor_gap_width, &offset);
+ dash_arc(cent + position(-dim.x/2.0 + rad, dim.y/2.0 - rad), rad,
+ M_PI/2, 3*M_PI/4.0, slt, lt.dash_width, hor_gap_width, &offset);
+
+ offset = lt.dash_width/2.0;
+ dash_arc(cent + position(-dim.x/2.0 + rad, dim.y/2.0 - rad), rad,
+ 3.0*M_PI/4.0, M_PI, slt, lt.dash_width, vert_gap_width, &offset);
+ dash_line(cent + position(-dim.x/2.0, dim.y/2.0 - rad),
+ cent + position(-dim.x/2.0, -dim.y/2.0 + rad),
+ slt, lt.dash_width, vert_gap_width, &offset);
+ dash_arc(cent + position(-dim.x/2.0 + rad, -dim.y/2.0 + rad), rad,
+ M_PI, 5.0*M_PI/4.0, slt, lt.dash_width, vert_gap_width, &offset);
+
+ offset = lt.dash_width/2.0;
+ dash_arc(cent + position(-dim.x/2.0 + rad, -dim.y/2.0 + rad), rad,
+ 5*M_PI/4.0, 3*M_PI/2.0, slt, lt.dash_width, hor_gap_width, &offset);
+ dash_line(cent + position(-dim.x/2.0 + rad, -dim.y/2.0),
+ cent + position(dim.x/2.0 - rad, -dim.y/2.0),
+ slt, lt.dash_width, hor_gap_width, &offset);
+ dash_arc(cent + position(dim.x/2.0 - rad, -dim.y/2.0 + rad), rad,
+ 3*M_PI/2, 7*M_PI/4, slt, lt.dash_width, hor_gap_width, &offset);
+}
+
+// Used by dashed_rounded_box.
+
+void common_output::dash_arc(const position &cent, double rad,
+ double start_angle, double end_angle,
+ const line_type &lt,
+ double dash_width, double gap_width,
+ double *offsetp)
+{
+ double length = (end_angle - start_angle)*rad;
+ double pos = 0.0;
+ for (;;) {
+ if (*offsetp >= dash_width) {
+ double rem = dash_width + gap_width - *offsetp;
+ if (pos + rem > length) {
+ *offsetp += length - pos;
+ break;
+ }
+ else {
+ pos += rem;
+ *offsetp = 0.0;
+ }
+ }
+ else {
+ double rem = dash_width - *offsetp;
+ if (pos + rem > length) {
+ solid_arc(cent, rad, start_angle + pos/rad, end_angle, lt);
+ *offsetp += length - pos;
+ break;
+ }
+ else {
+ solid_arc(cent, rad, start_angle + pos/rad,
+ start_angle + (pos + rem)/rad, lt);
+ pos += rem;
+ *offsetp = dash_width;
+ }
+ }
+ }
+}
+
+// Used by dashed_rounded_box.
+
+void common_output::dash_line(const position &start, const position &end,
+ const line_type &lt,
+ double dash_width, double gap_width,
+ double *offsetp)
+{
+ distance dist = end - start;
+ double length = hypot(dist);
+ if (length == 0.0)
+ return;
+ double pos = 0.0;
+ for (;;) {
+ if (*offsetp >= dash_width) {
+ double rem = dash_width + gap_width - *offsetp;
+ if (pos + rem > length) {
+ *offsetp += length - pos;
+ break;
+ }
+ else {
+ pos += rem;
+ *offsetp = 0.0;
+ }
+ }
+ else {
+ double rem = dash_width - *offsetp;
+ if (pos + rem > length) {
+ line(start + dist*(pos/length), &end, 1, lt);
+ *offsetp += length - pos;
+ break;
+ }
+ else {
+ position p(start + dist*((pos + rem)/length));
+ line(start + dist*(pos/length), &p, 1, lt);
+ pos += rem;
+ *offsetp = dash_width;
+ }
+ }
+ }
+}
+
+void common_output::dotted_rounded_box(const position &cent,
+ const distance &dim, double rad,
+ const line_type &lt)
+{
+ line_type slt = lt;
+ slt.type = line_type::solid;
+
+ double hor_length = dim.x + (M_PI/2.0 - 2.0)*rad;
+ int n_hor_dots = int(hor_length/lt.dash_width + .5);
+ double hor_gap_width = (n_hor_dots != 0
+ ? hor_length/n_hor_dots
+ : lt.dash_width);
+
+ double vert_length = dim.y + (M_PI/2.0 - 2.0)*rad;
+ int n_vert_dots = int(vert_length/lt.dash_width + .5);
+ double vert_gap_width = (n_vert_dots != 0
+ ? vert_length/n_vert_dots
+ : lt.dash_width);
+ double epsilon = lt.dash_width/(rad*100.0);
+
+ double offset = 0.0;
+ dot_arc(cent + position(dim.x/2.0 - rad, -dim.y/2.0 + rad), rad,
+ -M_PI/4.0, 0, slt, vert_gap_width, &offset);
+ dot_line(cent + position(dim.x/2.0, -dim.y/2.0 + rad),
+ cent + position(dim.x/2.0, dim.y/2.0 - rad),
+ slt, vert_gap_width, &offset);
+ dot_arc(cent + position(dim.x/2.0 - rad, dim.y/2.0 - rad), rad,
+ 0, M_PI/4.0 - epsilon, slt, vert_gap_width, &offset);
+
+ offset = 0.0;
+ dot_arc(cent + position(dim.x/2.0 - rad, dim.y/2.0 - rad), rad,
+ M_PI/4.0, M_PI/2, slt, hor_gap_width, &offset);
+ dot_line(cent + position(dim.x/2.0 - rad, dim.y/2.0),
+ cent + position(-dim.x/2.0 + rad, dim.y/2.0),
+ slt, hor_gap_width, &offset);
+ dot_arc(cent + position(-dim.x/2.0 + rad, dim.y/2.0 - rad), rad,
+ M_PI/2, 3*M_PI/4.0 - epsilon, slt, hor_gap_width, &offset);
+
+ offset = 0.0;
+ dot_arc(cent + position(-dim.x/2.0 + rad, dim.y/2.0 - rad), rad,
+ 3.0*M_PI/4.0, M_PI, slt, vert_gap_width, &offset);
+ dot_line(cent + position(-dim.x/2.0, dim.y/2.0 - rad),
+ cent + position(-dim.x/2.0, -dim.y/2.0 + rad),
+ slt, vert_gap_width, &offset);
+ dot_arc(cent + position(-dim.x/2.0 + rad, -dim.y/2.0 + rad), rad,
+ M_PI, 5.0*M_PI/4.0 - epsilon, slt, vert_gap_width, &offset);
+
+ offset = 0.0;
+ dot_arc(cent + position(-dim.x/2.0 + rad, -dim.y/2.0 + rad), rad,
+ 5*M_PI/4.0, 3*M_PI/2.0, slt, hor_gap_width, &offset);
+ dot_line(cent + position(-dim.x/2.0 + rad, -dim.y/2.0),
+ cent + position(dim.x/2.0 - rad, -dim.y/2.0),
+ slt, hor_gap_width, &offset);
+ dot_arc(cent + position(dim.x/2.0 - rad, -dim.y/2.0 + rad), rad,
+ 3*M_PI/2, 7*M_PI/4 - epsilon, slt, hor_gap_width, &offset);
+}
+
+// Used by dotted_rounded_box.
+
+void common_output::dot_arc(const position &cent, double rad,
+ double start_angle, double end_angle,
+ const line_type &lt, double gap_width,
+ double *offsetp)
+{
+ double length = (end_angle - start_angle)*rad;
+ double pos = 0.0;
+ for (;;) {
+ if (*offsetp == 0.0) {
+ double ang = start_angle + pos/rad;
+ dot(cent + position(cos(ang), sin(ang))*rad, lt);
+ }
+ double rem = gap_width - *offsetp;
+ if (pos + rem > length) {
+ *offsetp += length - pos;
+ break;
+ }
+ else {
+ pos += rem;
+ *offsetp = 0.0;
+ }
+ }
+}
+
+// Used by dotted_rounded_box.
+
+void common_output::dot_line(const position &start, const position &end,
+ const line_type &lt, double gap_width,
+ double *offsetp)
+{
+ distance dist = end - start;
+ double length = hypot(dist);
+ if (length == 0.0)
+ return;
+ double pos = 0.0;
+ for (;;) {
+ if (*offsetp == 0.0)
+ dot(start + dist*(pos/length), lt);
+ double rem = gap_width - *offsetp;
+ if (pos + rem > length) {
+ *offsetp += length - pos;
+ break;
+ }
+ else {
+ pos += rem;
+ *offsetp = 0.0;
+ }
+ }
+}
+
+void common_output::solid_rounded_box(const position &cent,
+ const distance &dim, double rad,
+ const line_type &lt)
+{
+ position tem = cent - dim/2.0;
+ arc(tem + position(0.0, rad),
+ tem + position(rad, rad),
+ tem + position(rad, 0.0),
+ lt);
+ tem = cent + position(-dim.x/2.0, dim.y/2.0);
+ arc(tem + position(rad, 0.0),
+ tem + position(rad, -rad),
+ tem + position(0.0, -rad),
+ lt);
+ tem = cent + dim/2.0;
+ arc(tem + position(0.0, -rad),
+ tem + position(-rad, -rad),
+ tem + position(-rad, 0.0),
+ lt);
+ tem = cent + position(dim.x/2.0, -dim.y/2.0);
+ arc(tem + position(-rad, 0.0),
+ tem + position(-rad, rad),
+ tem + position(0.0, rad),
+ lt);
+ position end;
+ end = cent + position(-dim.x/2.0, dim.y/2.0 - rad);
+ line(cent - dim/2.0 + position(0.0, rad), &end, 1, lt);
+ end = cent + position(dim.x/2.0 - rad, dim.y/2.0);
+ line(cent + position(-dim.x/2.0 + rad, dim.y/2.0), &end, 1, lt);
+ end = cent + position(dim.x/2.0, -dim.y/2.0 + rad);
+ line(cent + position(dim.x/2.0, dim.y/2.0 - rad), &end, 1, lt);
+ end = cent + position(-dim.x/2.0 + rad, -dim.y/2.0);
+ line(cent + position(dim.x/2.0 - rad, -dim.y/2.0), &end, 1, lt);
+}
+
+void common_output::filled_rounded_box(const position &cent,
+ const distance &dim, double rad,
+ double fill)
+{
+ line_type ilt;
+ ilt.type = line_type::invisible;
+ circle(cent + position(dim.x/2.0 - rad, dim.y/2.0 - rad), rad, ilt, fill);
+ circle(cent + position(-dim.x/2.0 + rad, dim.y/2.0 - rad), rad, ilt, fill);
+ circle(cent + position(-dim.x/2.0 + rad, -dim.y/2.0 + rad), rad, ilt, fill);
+ circle(cent + position(dim.x/2.0 - rad, -dim.y/2.0 + rad), rad, ilt, fill);
+ position vec[4];
+ vec[0] = cent + position(dim.x/2.0, dim.y/2.0 - rad);
+ vec[1] = cent + position(-dim.x/2.0, dim.y/2.0 - rad);
+ vec[2] = cent + position(-dim.x/2.0, -dim.y/2.0 + rad);
+ vec[3] = cent + position(dim.x/2.0, -dim.y/2.0 + rad);
+ polygon(vec, 4, ilt, fill);
+ vec[0] = cent + position(dim.x/2.0 - rad, dim.y/2.0);
+ vec[1] = cent + position(-dim.x/2.0 + rad, dim.y/2.0);
+ vec[2] = cent + position(-dim.x/2.0 + rad, -dim.y/2.0);
+ vec[3] = cent + position(dim.x/2.0 - rad, -dim.y/2.0);
+ polygon(vec, 4, ilt, fill);
+}
diff --git a/src/preproc/pic/common.h b/src/preproc/pic/common.h
new file mode 100644
index 0000000..a2d5f70
--- /dev/null
+++ b/src/preproc/pic/common.h
@@ -0,0 +1,79 @@
+// -*- C++ -*-
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+ Written by James Clark (jjc@jclark.com)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+groff is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+class common_output : public output {
+private:
+ void dash_line(const position &start, const position &end,
+ const line_type &lt, double dash_width, double gap_width,
+ double *offsetp);
+ void dash_arc(const position &cent, double rad,
+ double start_angle, double end_angle, const line_type &lt,
+ double dash_width, double gap_width, double *offsetp);
+ void dot_line(const position &start, const position &end,
+ const line_type &lt, double gap_width, double *offsetp);
+ void dot_arc(const position &cent, double rad,
+ double start_angle, double end_angle, const line_type &lt,
+ double gap_width, double *offsetp);
+protected:
+ virtual void dot(const position &, const line_type &) = 0;
+ void ellipse_arc(const position &, const position &,
+ const position &, const distance &,
+ const line_type &);
+ void dashed_circle(const position &, double rad, const line_type &);
+ void dotted_circle(const position &, double rad, const line_type &);
+ void dashed_ellipse(const position &, const distance &, const line_type &);
+ void dotted_ellipse(const position &, const distance &, const line_type &);
+ void dashed_arc(const position &, const position &, const position &,
+ const line_type &);
+ void dotted_arc(const position &, const position &, const position &,
+ const line_type &);
+ virtual void solid_arc(const position &cent, double rad, double start_angle,
+ double end_angle, const line_type &lt);
+ void dashed_rounded_box(const position &, const distance &, double,
+ const line_type &);
+ void dotted_rounded_box(const position &, const distance &, double,
+ const line_type &);
+ void solid_rounded_box(const position &, const distance &, double,
+ const line_type &);
+ void filled_rounded_box(const position &, const distance &, double,
+ double);
+public:
+ void start_picture(double sc, const position &ll, const position &ur) = 0;
+ void finish_picture() = 0;
+ void circle(const position &, double rad, const line_type &, double) = 0;
+ void text(const position &, text_piece *, int, double) = 0;
+ void line(const position &, const position *, int n, const line_type &) = 0;
+ void polygon(const position *, int n, const line_type &, double) = 0;
+ void spline(const position &, const position *, int n,
+ const line_type &) = 0;
+ void arc(const position &, const position &, const position &,
+ const line_type &) = 0;
+ void ellipse(const position &, const distance &,
+ const line_type &, double) = 0;
+ void rounded_box(const position &, const distance &, double,
+ const line_type &, double, char *);
+ void set_color(char *, char *) = 0;
+ void reset_color() = 0;
+ char *get_last_filled() = 0;
+ char *get_outline_color() = 0;
+};
+
+int compute_arc_center(const position &start, const position &cent,
+ const position &end, position *result);
+
diff --git a/src/preproc/pic/lex.cpp b/src/preproc/pic/lex.cpp
new file mode 100644
index 0000000..e59801b
--- /dev/null
+++ b/src/preproc/pic/lex.cpp
@@ -0,0 +1,2039 @@
+// -*- C++ -*-
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+ Written by James Clark (jjc@jclark.com)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+groff is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "pic.h"
+#include "ptable.h"
+#include "object.h"
+#include "pic.hpp"
+
+declare_ptable(char)
+implement_ptable(char)
+
+PTABLE(char) macro_table;
+
+// First character of the range representing $1-$<MAX_ARG>.
+// All of them must be invalid input characters.
+#ifndef IS_EBCDIC_HOST
+#define ARG1 0x80
+#define MAX_ARG 32
+#else
+#define ARG1 0x30
+#define MAX_ARG 16
+#endif
+
+class macro_input : public input {
+ char *s;
+ char *p;
+public:
+ macro_input(const char *);
+ ~macro_input();
+ int get();
+ int peek();
+};
+
+class argument_macro_input : public input {
+ char *s;
+ char *p;
+ char *ap;
+ int argc;
+ char *argv[MAX_ARG];
+public:
+ argument_macro_input(const char *, int, char **);
+ ~argument_macro_input();
+ int get();
+ int peek();
+};
+
+input::input() : next(0)
+{
+}
+
+input::~input()
+{
+}
+
+int input::get_location(const char **, int *)
+{
+ return 0;
+}
+
+file_input::file_input(FILE *f, const char *fn)
+: fp(f), filename(fn), lineno(0), ptr("")
+{
+}
+
+file_input::~file_input()
+{
+ fclose(fp);
+}
+
+int file_input::read_line()
+{
+ for (;;) {
+ line.clear();
+ lineno++;
+ for (;;) {
+ int c = getc(fp);
+ if (c == '\r') {
+ c = getc(fp);
+ if (c != '\n')
+ lex_error("invalid input character code %1", '\r');
+ }
+ if (c == EOF)
+ break;
+ else if (is_invalid_input_char(c))
+ lex_error("invalid input character code %1", c);
+ else {
+ line += char(c);
+ if (c == '\n')
+ break;
+ }
+ }
+ if (line.length() == 0)
+ return 0;
+ if (!(line.length() >= 3 && line[0] == '.' && line[1] == 'P'
+ && (line[2] == 'S' || line[2] == 'E' || line[2] == 'F')
+ && (line.length() == 3 || line[3] == ' ' || line[3] == '\n'
+ || compatible_flag))) {
+ line += '\0';
+ ptr = line.contents();
+ return 1;
+ }
+ }
+}
+
+int file_input::get()
+{
+ if (*ptr != '\0' || read_line())
+ return (unsigned char)*ptr++;
+ else
+ return EOF;
+}
+
+int file_input::peek()
+{
+ if (*ptr != '\0' || read_line())
+ return (unsigned char)*ptr;
+ else
+ return EOF;
+}
+
+int file_input::get_location(const char **fnp, int *lnp)
+{
+ *fnp = filename;
+ *lnp = lineno;
+ return 1;
+}
+
+macro_input::macro_input(const char *str)
+{
+ p = s = strsave(str);
+}
+
+macro_input::~macro_input()
+{
+ free(s);
+}
+
+int macro_input::get()
+{
+ if (p == 0 || *p == '\0')
+ return EOF;
+ else
+ return (unsigned char)*p++;
+}
+
+int macro_input::peek()
+{
+ if (p == 0 || *p == '\0')
+ return EOF;
+ else
+ return (unsigned char)*p;
+}
+
+char *process_body(const char *body)
+{
+ char *s = strsave(body);
+ int j = 0;
+ for (int i = 0; s[i] != '\0'; i++)
+ if (s[i] == '$' && csdigit(s[i + 1])) {
+ int n = 0;
+ int start = i;
+ i++;
+ while (csdigit(s[i]))
+ if (n > MAX_ARG)
+ i++;
+ else
+ n = 10 * n + s[i++] - '0';
+ if (n > MAX_ARG) {
+ string arg;
+ for (int k = start; k < i; k++)
+ arg += s[k];
+ lex_error("invalid macro argument number %1", arg.contents());
+ }
+ else if (n > 0)
+ s[j++] = ARG1 + n - 1;
+ i--;
+ }
+ else
+ s[j++] = s[i];
+ s[j] = '\0';
+ return s;
+}
+
+argument_macro_input::argument_macro_input(const char *body, int ac, char **av)
+: ap(0), argc(ac)
+{
+ for (int i = 0; i < argc; i++)
+ argv[i] = av[i];
+ p = s = process_body(body);
+}
+
+argument_macro_input::~argument_macro_input()
+{
+ for (int i = 0; i < argc; i++)
+ free(argv[i]);
+ free(s);
+}
+
+int argument_macro_input::get()
+{
+ if (ap) {
+ if (*ap != '\0')
+ return (unsigned char)*ap++;
+ ap = 0;
+ }
+ if (p == 0)
+ return EOF;
+ while ((unsigned char)*p >= ARG1
+ && (unsigned char)*p <= ARG1 + MAX_ARG - 1) {
+ int i = (unsigned char)*p++ - ARG1;
+ if (i < argc && argv[i] != 0 && argv[i][0] != '\0') {
+ ap = argv[i];
+ return (unsigned char)*ap++;
+ }
+ }
+ if (*p == '\0')
+ return EOF;
+ return (unsigned char)*p++;
+}
+
+int argument_macro_input::peek()
+{
+ if (ap) {
+ if (*ap != '\0')
+ return (unsigned char)*ap;
+ ap = 0;
+ }
+ if (p == 0)
+ return EOF;
+ while ((unsigned char)*p >= ARG1
+ && (unsigned char)*p <= ARG1 + MAX_ARG - 1) {
+ int i = (unsigned char)*p++ - ARG1;
+ if (i < argc && argv[i] != 0 && argv[i][0] != '\0') {
+ ap = argv[i];
+ return (unsigned char)*ap;
+ }
+ }
+ if (*p == '\0')
+ return EOF;
+ return (unsigned char)*p;
+}
+
+class input_stack {
+ static input *current_input;
+ static int bol_flag;
+public:
+ static void push(input *);
+ static void clear();
+ static int get_char();
+ static int peek_char();
+ static int get_location(const char **fnp, int *lnp);
+ static void push_back(unsigned char c, int was_bol = 0);
+ static int bol();
+};
+
+input *input_stack::current_input = 0;
+int input_stack::bol_flag = 0;
+
+inline int input_stack::bol()
+{
+ return bol_flag;
+}
+
+void input_stack::clear()
+{
+ while (current_input != 0) {
+ input *tem = current_input;
+ current_input = current_input->next;
+ delete tem;
+ }
+ bol_flag = 1;
+}
+
+void input_stack::push(input *in)
+{
+ in->next = current_input;
+ current_input = in;
+}
+
+void lex_init(input *top)
+{
+ input_stack::clear();
+ input_stack::push(top);
+}
+
+void lex_cleanup()
+{
+ while (input_stack::get_char() != EOF)
+ ;
+}
+
+int input_stack::get_char()
+{
+ while (current_input != 0) {
+ int c = current_input->get();
+ if (c != EOF) {
+ bol_flag = c == '\n';
+ return c;
+ }
+ // don't pop the top-level input off the stack
+ if (current_input->next == 0)
+ return EOF;
+ input *tem = current_input;
+ current_input = current_input->next;
+ delete tem;
+ }
+ return EOF;
+}
+
+int input_stack::peek_char()
+{
+ while (current_input != 0) {
+ int c = current_input->peek();
+ if (c != EOF)
+ return c;
+ if (current_input->next == 0)
+ return EOF;
+ input *tem = current_input;
+ current_input = current_input->next;
+ delete tem;
+ }
+ return EOF;
+}
+
+class char_input : public input {
+ int c;
+public:
+ char_input(int);
+ int get();
+ int peek();
+};
+
+char_input::char_input(int n) : c((unsigned char)n)
+{
+}
+
+int char_input::get()
+{
+ int n = c;
+ c = EOF;
+ return n;
+}
+
+int char_input::peek()
+{
+ return c;
+}
+
+void input_stack::push_back(unsigned char c, int was_bol)
+{
+ push(new char_input(c));
+ bol_flag = was_bol;
+}
+
+int input_stack::get_location(const char **fnp, int *lnp)
+{
+ for (input *p = current_input; p; p = p->next)
+ if (p->get_location(fnp, lnp))
+ return 1;
+ return 0;
+}
+
+string context_buffer;
+
+string token_buffer;
+double token_double;
+int token_int;
+
+void interpolate_macro_with_args(const char *body)
+{
+ char *argv[MAX_ARG];
+ int argc = 0;
+ int ignore = 0;
+ int i;
+ for (i = 0; i < MAX_ARG; i++)
+ argv[i] = 0;
+ int level = 0;
+ int c;
+ enum { NORMAL, IN_STRING, IN_STRING_QUOTED } state = NORMAL;
+ do {
+ token_buffer.clear();
+ for (;;) {
+ c = input_stack::get_char();
+ if (c == EOF) {
+ lex_error("end of input while scanning macro arguments");
+ break;
+ }
+ if (state == NORMAL && level == 0 && (c == ',' || c == ')')) {
+ if (token_buffer.length() > 0) {
+ token_buffer += '\0';
+ if (!ignore) {
+ if (argc == MAX_ARG) {
+ lex_warning("only %1 macro arguments supported", MAX_ARG);
+ ignore = 1;
+ }
+ else
+ argv[argc] = strsave(token_buffer.contents());
+ }
+ }
+ // for 'foo()', argc = 0
+ if (argc > 0 || c != ')' || i > 0)
+ if (!ignore)
+ argc++;
+ break;
+ }
+ token_buffer += char(c);
+ switch (state) {
+ case NORMAL:
+ if (c == '"')
+ state = IN_STRING;
+ else if (c == '(')
+ level++;
+ else if (c == ')')
+ level--;
+ break;
+ case IN_STRING:
+ if (c == '"')
+ state = NORMAL;
+ else if (c == '\\')
+ state = IN_STRING_QUOTED;
+ break;
+ case IN_STRING_QUOTED:
+ state = IN_STRING;
+ break;
+ }
+ }
+ } while (c != ')' && c != EOF);
+ input_stack::push(new argument_macro_input(body, argc, argv));
+}
+
+static int docmp(const char *s1, int n1, const char *s2, int n2)
+{
+ if (n1 < n2) {
+ int r = memcmp(s1, s2, n1);
+ return r ? r : -1;
+ }
+ else if (n1 > n2) {
+ int r = memcmp(s1, s2, n2);
+ return r ? r : 1;
+ }
+ else
+ return memcmp(s1, s2, n1);
+}
+
+int lookup_keyword(const char *str, int len)
+{
+ static struct keyword {
+ const char *name;
+ int token;
+ } table[] = {
+ { "Here", HERE },
+ { "above", ABOVE },
+ { "aligned", ALIGNED },
+ { "and", AND },
+ { "arc", ARC },
+ { "arrow", ARROW },
+ { "at", AT },
+ { "atan2", ATAN2 },
+ { "below", BELOW },
+ { "between", BETWEEN },
+ { "bottom", BOTTOM },
+ { "box", BOX },
+ { "by", BY },
+ { "ccw", CCW },
+ { "center", CENTER },
+ { "chop", CHOP },
+ { "circle", CIRCLE },
+ { "color", COLORED },
+ { "colored", COLORED },
+ { "colour", COLORED },
+ { "coloured", COLORED },
+ { "command", COMMAND },
+ { "copy", COPY },
+ { "cos", COS },
+ { "cw", CW },
+ { "dashed", DASHED },
+ { "define", DEFINE },
+ { "diam", DIAMETER },
+ { "diameter", DIAMETER },
+ { "do", DO },
+ { "dotted", DOTTED },
+ { "down", DOWN },
+ { "east", EAST },
+ { "ellipse", ELLIPSE },
+ { "else", ELSE },
+ { "end", END },
+ { "exp", EXP },
+ { "figname", FIGNAME },
+ { "fill", FILL },
+ { "filled", FILL },
+ { "for", FOR },
+ { "from", FROM },
+ { "height", HEIGHT },
+ { "ht", HEIGHT },
+ { "if", IF },
+ { "int", INT },
+ { "invis", INVISIBLE },
+ { "invisible", INVISIBLE },
+ { "last", LAST },
+ { "left", LEFT },
+ { "line", LINE },
+ { "ljust", LJUST },
+ { "log", LOG },
+ { "lower", LOWER },
+ { "max", K_MAX },
+ { "min", K_MIN },
+ { "move", MOVE },
+ { "north", NORTH },
+ { "of", OF },
+ { "outline", OUTLINED },
+ { "outlined", OUTLINED },
+ { "plot", PLOT },
+ { "print", PRINT },
+ { "rad", RADIUS },
+ { "radius", RADIUS },
+ { "rand", RAND },
+ { "reset", RESET },
+ { "right", RIGHT },
+ { "rjust", RJUST },
+ { "same", SAME },
+ { "sh", SH },
+ { "shaded", SHADED },
+ { "sin", SIN },
+ { "solid", SOLID },
+ { "south", SOUTH },
+ { "spline", SPLINE },
+ { "sprintf", SPRINTF },
+ { "sqrt", SQRT },
+ { "srand", SRAND },
+ { "start", START },
+ { "the", THE },
+ { "then", THEN },
+ { "thick", THICKNESS },
+ { "thickness", THICKNESS },
+ { "thru", THRU },
+ { "to", TO },
+ { "top", TOP },
+ { "undef", UNDEF },
+ { "until", UNTIL },
+ { "up", UP },
+ { "upper", UPPER },
+ { "way", WAY },
+ { "west", WEST },
+ { "wid", WIDTH },
+ { "width", WIDTH },
+ { "with", WITH },
+ { "xslanted", XSLANTED },
+ { "yslanted", YSLANTED },
+ };
+
+ const keyword *start = table;
+ const keyword *end = table + sizeof(table)/sizeof(table[0]);
+ while (start < end) {
+ // start <= target < end
+ const keyword *mid = start + (end - start)/2;
+
+ int cmp = docmp(str, len, mid->name, strlen(mid->name));
+ if (cmp == 0)
+ return mid->token;
+ if (cmp < 0)
+ end = mid;
+ else
+ start = mid + 1;
+ }
+ return 0;
+}
+
+int get_token_after_dot(int c)
+{
+ // get_token deals with the case where c is a digit
+ switch (c) {
+ case 'h':
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 't') {
+ input_stack::get_char();
+ context_buffer = ".ht";
+ return DOT_HT;
+ }
+ else if (c == 'e') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'i') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'g') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'h') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 't') {
+ input_stack::get_char();
+ context_buffer = ".height";
+ return DOT_HT;
+ }
+ input_stack::push_back('h');
+ }
+ input_stack::push_back('g');
+ }
+ input_stack::push_back('i');
+ }
+ input_stack::push_back('e');
+ }
+ input_stack::push_back('h');
+ return '.';
+ case 'x':
+ input_stack::get_char();
+ context_buffer = ".x";
+ return DOT_X;
+ case 'y':
+ input_stack::get_char();
+ context_buffer = ".y";
+ return DOT_Y;
+ case 'c':
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'e') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'n') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 't') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'e') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'r') {
+ input_stack::get_char();
+ context_buffer = ".center";
+ return DOT_C;
+ }
+ input_stack::push_back('e');
+ }
+ input_stack::push_back('t');
+ }
+ input_stack::push_back('n');
+ }
+ input_stack::push_back('e');
+ }
+ context_buffer = ".c";
+ return DOT_C;
+ case 'n':
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'e') {
+ input_stack::get_char();
+ context_buffer = ".ne";
+ return DOT_NE;
+ }
+ else if (c == 'w') {
+ input_stack::get_char();
+ context_buffer = ".nw";
+ return DOT_NW;
+ }
+ else {
+ context_buffer = ".n";
+ return DOT_N;
+ }
+ break;
+ case 'e':
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'n') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'd') {
+ input_stack::get_char();
+ context_buffer = ".end";
+ return DOT_END;
+ }
+ input_stack::push_back('n');
+ context_buffer = ".e";
+ return DOT_E;
+ }
+ context_buffer = ".e";
+ return DOT_E;
+ case 'w':
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'i') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'd') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 't') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'h') {
+ input_stack::get_char();
+ context_buffer = ".width";
+ return DOT_WID;
+ }
+ input_stack::push_back('t');
+ }
+ context_buffer = ".wid";
+ return DOT_WID;
+ }
+ input_stack::push_back('i');
+ }
+ context_buffer = ".w";
+ return DOT_W;
+ case 's':
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'e') {
+ input_stack::get_char();
+ context_buffer = ".se";
+ return DOT_SE;
+ }
+ else if (c == 'w') {
+ input_stack::get_char();
+ context_buffer = ".sw";
+ return DOT_SW;
+ }
+ else {
+ if (c == 't') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'a') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'r') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 't') {
+ input_stack::get_char();
+ context_buffer = ".start";
+ return DOT_START;
+ }
+ input_stack::push_back('r');
+ }
+ input_stack::push_back('a');
+ }
+ input_stack::push_back('t');
+ }
+ context_buffer = ".s";
+ return DOT_S;
+ }
+ break;
+ case 't':
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'o') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'p') {
+ input_stack::get_char();
+ context_buffer = ".top";
+ return DOT_N;
+ }
+ input_stack::push_back('o');
+ }
+ context_buffer = ".t";
+ return DOT_N;
+ case 'l':
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'e') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'f') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 't') {
+ input_stack::get_char();
+ context_buffer = ".left";
+ return DOT_W;
+ }
+ input_stack::push_back('f');
+ }
+ input_stack::push_back('e');
+ }
+ context_buffer = ".l";
+ return DOT_W;
+ case 'r':
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'a') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'd') {
+ input_stack::get_char();
+ context_buffer = ".rad";
+ return DOT_RAD;
+ }
+ input_stack::push_back('a');
+ }
+ else if (c == 'i') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'g') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'h') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 't') {
+ input_stack::get_char();
+ context_buffer = ".right";
+ return DOT_E;
+ }
+ input_stack::push_back('h');
+ }
+ input_stack::push_back('g');
+ }
+ input_stack::push_back('i');
+ }
+ context_buffer = ".r";
+ return DOT_E;
+ case 'b':
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'o') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 't') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 't') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'o') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'm') {
+ input_stack::get_char();
+ context_buffer = ".bottom";
+ return DOT_S;
+ }
+ input_stack::push_back('o');
+ }
+ input_stack::push_back('t');
+ }
+ context_buffer = ".bot";
+ return DOT_S;
+ }
+ input_stack::push_back('o');
+ }
+ context_buffer = ".b";
+ return DOT_S;
+ default:
+ context_buffer = '.';
+ return '.';
+ }
+}
+
+int get_token(int lookup_flag)
+{
+ context_buffer.clear();
+ for (;;) {
+ int n = 0;
+ int bol = input_stack::bol();
+ int c = input_stack::get_char();
+ if (bol && c == command_char) {
+ token_buffer.clear();
+ token_buffer += c;
+ // the newline is not part of the token
+ for (;;) {
+ c = input_stack::peek_char();
+ if (c == EOF || c == '\n')
+ break;
+ input_stack::get_char();
+ token_buffer += char(c);
+ }
+ context_buffer = token_buffer;
+ return COMMAND_LINE;
+ }
+ switch (c) {
+ case EOF:
+ return EOF;
+ case ' ':
+ case '\t':
+ break;
+ case '\\':
+ {
+ int d = input_stack::peek_char();
+ if (d != '\n') {
+ context_buffer = '\\';
+ return '\\';
+ }
+ input_stack::get_char();
+ break;
+ }
+ case '#':
+ do {
+ c = input_stack::get_char();
+ } while (c != '\n' && c != EOF);
+ if (c == '\n')
+ context_buffer = '\n';
+ return c;
+ case '"':
+ context_buffer = '"';
+ token_buffer.clear();
+ for (;;) {
+ c = input_stack::get_char();
+ if (c == '\\') {
+ context_buffer += '\\';
+ c = input_stack::peek_char();
+ if (c == '"') {
+ input_stack::get_char();
+ token_buffer += '"';
+ context_buffer += '"';
+ }
+ else
+ token_buffer += '\\';
+ }
+ else if (c == '\n') {
+ error("newline in string");
+ break;
+ }
+ else if (c == EOF) {
+ error("missing '\"'");
+ break;
+ }
+ else if (c == '"') {
+ context_buffer += '"';
+ break;
+ }
+ else {
+ context_buffer += char(c);
+ token_buffer += char(c);
+ }
+ }
+ return TEXT;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ case '7':
+ case '8':
+ case '9':
+ {
+ int overflow = 0;
+ n = 0;
+ for (;;) {
+ if (n > (INT_MAX - 9)/10) {
+ overflow = 1;
+ break;
+ }
+ n *= 10;
+ n += c - '0';
+ context_buffer += char(c);
+ c = input_stack::peek_char();
+ if (c == EOF || !csdigit(c))
+ break;
+ c = input_stack::get_char();
+ }
+ token_double = n;
+ if (overflow) {
+ for (;;) {
+ token_double *= 10.0;
+ token_double += c - '0';
+ context_buffer += char(c);
+ c = input_stack::peek_char();
+ if (c == EOF || !csdigit(c))
+ break;
+ c = input_stack::get_char();
+ }
+ // if somebody asks for 1000000000000th, we will silently
+ // give them INT_MAXth
+ double temp = token_double; // work around gas 1.34/sparc bug
+ if (token_double > INT_MAX)
+ n = INT_MAX;
+ else
+ n = int(temp);
+ }
+ }
+ switch (c) {
+ case 'i':
+ case 'I':
+ context_buffer += char(c);
+ input_stack::get_char();
+ return NUMBER;
+ case '.':
+ {
+ context_buffer += '.';
+ input_stack::get_char();
+ got_dot:
+ double factor = 1.0;
+ for (;;) {
+ c = input_stack::peek_char();
+ if (c == EOF || !csdigit(c))
+ break;
+ input_stack::get_char();
+ context_buffer += char(c);
+ factor /= 10.0;
+ if (c != '0')
+ token_double += factor*(c - '0');
+ }
+ if (c != 'e' && c != 'E') {
+ if (c == 'i' || c == 'I') {
+ context_buffer += char(c);
+ input_stack::get_char();
+ }
+ return NUMBER;
+ }
+ }
+ // fall through
+ case 'e':
+ case 'E':
+ {
+ int echar = c;
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ int sign = '+';
+ if (c == '+' || c == '-') {
+ sign = c;
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == EOF || !csdigit(c)) {
+ input_stack::push_back(sign);
+ input_stack::push_back(echar);
+ return NUMBER;
+ }
+ context_buffer += char(echar);
+ context_buffer += char(sign);
+ }
+ else {
+ if (c == EOF || !csdigit(c)) {
+ input_stack::push_back(echar);
+ return NUMBER;
+ }
+ context_buffer += char(echar);
+ }
+ input_stack::get_char();
+ context_buffer += char(c);
+ n = c - '0';
+ for (;;) {
+ c = input_stack::peek_char();
+ if (c == EOF || !csdigit(c))
+ break;
+ input_stack::get_char();
+ context_buffer += char(c);
+ n = n*10 + (c - '0');
+ }
+ if (sign == '-')
+ n = -n;
+ if (c == 'i' || c == 'I') {
+ context_buffer += char(c);
+ input_stack::get_char();
+ }
+ token_double *= pow(10.0, n);
+ return NUMBER;
+ }
+ case 'n':
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'd') {
+ input_stack::get_char();
+ token_int = n;
+ context_buffer += "nd";
+ return ORDINAL;
+ }
+ input_stack::push_back('n');
+ return NUMBER;
+ case 'r':
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'd') {
+ input_stack::get_char();
+ token_int = n;
+ context_buffer += "rd";
+ return ORDINAL;
+ }
+ input_stack::push_back('r');
+ return NUMBER;
+ case 't':
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'h') {
+ input_stack::get_char();
+ token_int = n;
+ context_buffer += "th";
+ return ORDINAL;
+ }
+ input_stack::push_back('t');
+ return NUMBER;
+ case 's':
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 't') {
+ input_stack::get_char();
+ token_int = n;
+ context_buffer += "st";
+ return ORDINAL;
+ }
+ input_stack::push_back('s');
+ return NUMBER;
+ default:
+ return NUMBER;
+ }
+ break;
+ case '\'':
+ {
+ c = input_stack::peek_char();
+ if (c == 't') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == 'h') {
+ input_stack::get_char();
+ context_buffer = "'th";
+ return TH;
+ }
+ else
+ input_stack::push_back('t');
+ }
+ context_buffer = "'";
+ return '\'';
+ }
+ case '.':
+ {
+ c = input_stack::peek_char();
+ if (c != EOF && csdigit(c)) {
+ n = 0;
+ token_double = 0.0;
+ context_buffer = '.';
+ goto got_dot;
+ }
+ return get_token_after_dot(c);
+ }
+ case '<':
+ c = input_stack::peek_char();
+ if (c == '-') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ if (c == '>') {
+ input_stack::get_char();
+ context_buffer = "<->";
+ return DOUBLE_ARROW_HEAD;
+ }
+ context_buffer = "<-";
+ return LEFT_ARROW_HEAD;
+ }
+ else if (c == '=') {
+ input_stack::get_char();
+ context_buffer = "<=";
+ return LESSEQUAL;
+ }
+ context_buffer = "<";
+ return '<';
+ case '-':
+ c = input_stack::peek_char();
+ if (c == '>') {
+ input_stack::get_char();
+ context_buffer = "->";
+ return RIGHT_ARROW_HEAD;
+ }
+ context_buffer = "-";
+ return '-';
+ case '!':
+ c = input_stack::peek_char();
+ if (c == '=') {
+ input_stack::get_char();
+ context_buffer = "!=";
+ return NOTEQUAL;
+ }
+ context_buffer = "!";
+ return '!';
+ case '>':
+ c = input_stack::peek_char();
+ if (c == '=') {
+ input_stack::get_char();
+ context_buffer = ">=";
+ return GREATEREQUAL;
+ }
+ context_buffer = ">";
+ return '>';
+ case '=':
+ c = input_stack::peek_char();
+ if (c == '=') {
+ input_stack::get_char();
+ context_buffer = "==";
+ return EQUALEQUAL;
+ }
+ context_buffer = "=";
+ return '=';
+ case '&':
+ c = input_stack::peek_char();
+ if (c == '&') {
+ input_stack::get_char();
+ context_buffer = "&&";
+ return ANDAND;
+ }
+ context_buffer = "&";
+ return '&';
+ case '|':
+ c = input_stack::peek_char();
+ if (c == '|') {
+ input_stack::get_char();
+ context_buffer = "||";
+ return OROR;
+ }
+ context_buffer = "|";
+ return '|';
+ default:
+ if (c != EOF && csalpha(c)) {
+ token_buffer.clear();
+ token_buffer = c;
+ for (;;) {
+ c = input_stack::peek_char();
+ if (c == EOF || (!csalnum(c) && c != '_'))
+ break;
+ input_stack::get_char();
+ token_buffer += char(c);
+ }
+ int tok = lookup_keyword(token_buffer.contents(),
+ token_buffer.length());
+ if (tok != 0) {
+ context_buffer = token_buffer;
+ return tok;
+ }
+ char *def = 0;
+ if (lookup_flag) {
+ token_buffer += '\0';
+ def = macro_table.lookup(token_buffer.contents());
+ token_buffer.set_length(token_buffer.length() - 1);
+ if (def) {
+ if (c == '(') {
+ input_stack::get_char();
+ interpolate_macro_with_args(def);
+ }
+ else
+ input_stack::push(new macro_input(def));
+ }
+ }
+ if (!def) {
+ context_buffer = token_buffer;
+ if (csupper(token_buffer[0]))
+ return LABEL;
+ else
+ return VARIABLE;
+ }
+ }
+ else {
+ context_buffer = char(c);
+ return (unsigned char)c;
+ }
+ break;
+ }
+ }
+}
+
+int get_delimited()
+{
+ token_buffer.clear();
+ int c = input_stack::get_char();
+ while (c == ' ' || c == '\t' || c == '\n')
+ c = input_stack::get_char();
+ if (c == EOF) {
+ lex_error("missing delimiter");
+ return 0;
+ }
+ context_buffer = char(c);
+ int had_newline = 0;
+ int start = c;
+ int level = 0;
+ enum { NORMAL, IN_STRING, IN_STRING_QUOTED, DELIM_END } state = NORMAL;
+ for (;;) {
+ c = input_stack::get_char();
+ if (c == EOF) {
+ lex_error("missing closing delimiter");
+ return 0;
+ }
+ if (c == '\n')
+ had_newline = 1;
+ else if (!had_newline)
+ context_buffer += char(c);
+ switch (state) {
+ case NORMAL:
+ if (start == '{') {
+ if (c == '{') {
+ level++;
+ break;
+ }
+ if (c == '}') {
+ if (--level < 0)
+ state = DELIM_END;
+ break;
+ }
+ }
+ else {
+ if (c == start) {
+ state = DELIM_END;
+ break;
+ }
+ }
+ if (c == '"')
+ state = IN_STRING;
+ break;
+ case IN_STRING_QUOTED:
+ if (c == '\n')
+ state = NORMAL;
+ else
+ state = IN_STRING;
+ break;
+ case IN_STRING:
+ if (c == '"' || c == '\n')
+ state = NORMAL;
+ else if (c == '\\')
+ state = IN_STRING_QUOTED;
+ break;
+ case DELIM_END:
+ // This case it just to shut cfront 2.0 up.
+ default:
+ assert(0);
+ }
+ if (state == DELIM_END)
+ break;
+ token_buffer += c;
+ }
+ return 1;
+}
+
+void do_define()
+{
+ int t = get_token(0); // do not expand what we are defining
+ if (t != VARIABLE && t != LABEL) {
+ lex_error("can only define variable or placename");
+ return;
+ }
+ token_buffer += '\0';
+ string nm = token_buffer;
+ const char *name = nm.contents();
+ if (!get_delimited())
+ return;
+ token_buffer += '\0';
+ macro_table.define(name, strsave(token_buffer.contents()));
+}
+
+void do_undef()
+{
+ int t = get_token(0); // do not expand what we are undefining
+ if (t != VARIABLE && t != LABEL) {
+ lex_error("can only define variable or placename");
+ return;
+ }
+ token_buffer += '\0';
+ macro_table.define(token_buffer.contents(), 0);
+}
+
+
+class for_input : public input {
+ char *var;
+ char *body;
+ double from;
+ double to;
+ int by_is_multiplicative;
+ double by;
+ const char *p;
+ int done_newline;
+public:
+ for_input(char *, double, double, int, double, char *);
+ ~for_input();
+ int get();
+ int peek();
+};
+
+for_input::for_input(char *vr, double f, double t,
+ int bim, double b, char *bd)
+: var(vr), body(bd), from(f), to(t), by_is_multiplicative(bim), by(b),
+ p(body), done_newline(0)
+{
+}
+
+for_input::~for_input()
+{
+ free(var);
+ free(body);
+}
+
+int for_input::get()
+{
+ if (p == 0)
+ return EOF;
+ for (;;) {
+ if (*p != '\0')
+ return (unsigned char)*p++;
+ if (!done_newline) {
+ done_newline = 1;
+ return '\n';
+ }
+ double val;
+ if (!lookup_variable(var, &val)) {
+ lex_error("body of 'for' terminated enclosing block");
+ return EOF;
+ }
+ if (by_is_multiplicative)
+ val *= by;
+ else
+ val += by;
+ define_variable(var, val);
+ if ((from <= to && val > to)
+ || (from >= to && val < to)) {
+ p = 0;
+ return EOF;
+ }
+ p = body;
+ done_newline = 0;
+ }
+}
+
+int for_input::peek()
+{
+ if (p == 0)
+ return EOF;
+ if (*p != '\0')
+ return (unsigned char)*p;
+ if (!done_newline)
+ return '\n';
+ double val;
+ if (!lookup_variable(var, &val))
+ return EOF;
+ if (by_is_multiplicative) {
+ if (val * by > to)
+ return EOF;
+ }
+ else {
+ if ((from <= to && val + by > to)
+ || (from >= to && val + by < to))
+ return EOF;
+ }
+ if (*body == '\0')
+ return EOF;
+ return (unsigned char)*body;
+}
+
+void do_for(char *var, double from, double to, int by_is_multiplicative,
+ double by, char *body)
+{
+ define_variable(var, from);
+ if ((by_is_multiplicative && by <= 0)
+ || (by > 0 && from > to)
+ || (by < 0 && from < to))
+ return;
+ input_stack::push(new for_input(var, from, to,
+ by_is_multiplicative, by, body));
+}
+
+
+void do_copy(const char *filename)
+{
+ errno = 0;
+ FILE *fp = fopen(filename, "r");
+ if (fp == 0) {
+ lex_error("can't open '%1': %2", filename, strerror(errno));
+ return;
+ }
+ input_stack::push(new file_input(fp, filename));
+}
+
+class copy_thru_input : public input {
+ int done;
+ char *body;
+ char *until;
+ const char *p;
+ const char *ap;
+ int argv[MAX_ARG];
+ int argc;
+ string line;
+ int get_line();
+ virtual int inget() = 0;
+public:
+ copy_thru_input(const char *b, const char *u);
+ ~copy_thru_input();
+ int get();
+ int peek();
+};
+
+class copy_file_thru_input : public copy_thru_input {
+ input *in;
+public:
+ copy_file_thru_input(input *, const char *b, const char *u);
+ ~copy_file_thru_input();
+ int inget();
+};
+
+copy_file_thru_input::copy_file_thru_input(input *i, const char *b,
+ const char *u)
+: copy_thru_input(b, u), in(i)
+{
+}
+
+copy_file_thru_input::~copy_file_thru_input()
+{
+ delete in;
+}
+
+int copy_file_thru_input::inget()
+{
+ if (!in)
+ return EOF;
+ else
+ return in->get();
+}
+
+class copy_rest_thru_input : public copy_thru_input {
+public:
+ copy_rest_thru_input(const char *, const char *u);
+ int inget();
+};
+
+copy_rest_thru_input::copy_rest_thru_input(const char *b, const char *u)
+: copy_thru_input(b, u)
+{
+}
+
+int copy_rest_thru_input::inget()
+{
+ while (next != 0) {
+ int c = next->get();
+ if (c != EOF)
+ return c;
+ if (next->next == 0)
+ return EOF;
+ input *tem = next;
+ next = next->next;
+ delete tem;
+ }
+ return EOF;
+
+}
+
+copy_thru_input::copy_thru_input(const char *b, const char *u)
+: done(0)
+{
+ ap = 0;
+ body = process_body(b);
+ p = 0;
+ until = strsave(u);
+}
+
+
+copy_thru_input::~copy_thru_input()
+{
+ delete[] body;
+ delete[] until;
+}
+
+int copy_thru_input::get()
+{
+ if (ap) {
+ if (*ap != '\0')
+ return (unsigned char)*ap++;
+ ap = 0;
+ }
+ for (;;) {
+ if (p == 0) {
+ if (!get_line())
+ break;
+ p = body;
+ }
+ if (*p == '\0') {
+ p = 0;
+ return '\n';
+ }
+ while ((unsigned char)*p >= ARG1
+ && (unsigned char)*p <= ARG1 + MAX_ARG - 1) {
+ int i = (unsigned char)*p++ - ARG1;
+ if (i < argc && line[argv[i]] != '\0') {
+ ap = line.contents() + argv[i];
+ return (unsigned char)*ap++;
+ }
+ }
+ if (*p != '\0')
+ return (unsigned char)*p++;
+ }
+ return EOF;
+}
+
+int copy_thru_input::peek()
+{
+ if (ap) {
+ if (*ap != '\0')
+ return (unsigned char)*ap;
+ ap = 0;
+ }
+ for (;;) {
+ if (p == 0) {
+ if (!get_line())
+ break;
+ p = body;
+ }
+ if (*p == '\0')
+ return '\n';
+ while ((unsigned char)*p >= ARG1
+ && (unsigned char)*p <= ARG1 + MAX_ARG - 1) {
+ int i = (unsigned char)*p++ - ARG1;
+ if (i < argc && line[argv[i]] != '\0') {
+ ap = line.contents() + argv[i];
+ return (unsigned char)*ap;
+ }
+ }
+ if (*p != '\0')
+ return (unsigned char)*p;
+ }
+ return EOF;
+}
+
+int copy_thru_input::get_line()
+{
+ if (done)
+ return 0;
+ line.clear();
+ argc = 0;
+ int c = inget();
+ for (;;) {
+ while (c == ' ')
+ c = inget();
+ if (c == EOF || c == '\n')
+ break;
+ if (argc == MAX_ARG) {
+ do {
+ c = inget();
+ } while (c != '\n' && c != EOF);
+ break;
+ }
+ argv[argc++] = line.length();
+ do {
+ line += char(c);
+ c = inget();
+ } while (c != ' ' && c != '\n');
+ line += '\0';
+ }
+ if (until != 0 && argc > 0 && strcmp(&line[argv[0]], until) == 0) {
+ done = 1;
+ return 0;
+ }
+ return argc > 0 || c == '\n';
+}
+
+class simple_file_input : public input {
+ const char *filename;
+ int lineno;
+ FILE *fp;
+public:
+ simple_file_input(FILE *, const char *);
+ ~simple_file_input();
+ int get();
+ int peek();
+ int get_location(const char **, int *);
+};
+
+simple_file_input::simple_file_input(FILE *p, const char *s)
+: filename(s), lineno(1), fp(p)
+{
+}
+
+simple_file_input::~simple_file_input()
+{
+ // don't delete the filename
+ fclose(fp);
+}
+
+int simple_file_input::get()
+{
+ int c = getc(fp);
+ while (is_invalid_input_char(c)) {
+ error("invalid input character code %1", c);
+ c = getc(fp);
+ }
+ if (c == '\n')
+ lineno++;
+ return c;
+}
+
+int simple_file_input::peek()
+{
+ int c = getc(fp);
+ while (is_invalid_input_char(c)) {
+ error("invalid input character code %1", c);
+ c = getc(fp);
+ }
+ if (c != EOF)
+ ungetc(c, fp);
+ return c;
+}
+
+int simple_file_input::get_location(const char **fnp, int *lnp)
+{
+ *fnp = filename;
+ *lnp = lineno;
+ return 1;
+}
+
+
+void copy_file_thru(const char *filename, const char *body, const char *until)
+{
+ errno = 0;
+ FILE *fp = fopen(filename, "r");
+ if (fp == 0) {
+ lex_error("can't open '%1': %2", filename, strerror(errno));
+ return;
+ }
+ input *in = new copy_file_thru_input(new simple_file_input(fp, filename),
+ body, until);
+ input_stack::push(in);
+}
+
+void copy_rest_thru(const char *body, const char *until)
+{
+ input_stack::push(new copy_rest_thru_input(body, until));
+}
+
+void push_body(const char *s)
+{
+ input_stack::push(new char_input('\n'));
+ input_stack::push(new macro_input(s));
+}
+
+int delim_flag = 0;
+
+char *get_thru_arg()
+{
+ int c = input_stack::peek_char();
+ while (c == ' ') {
+ input_stack::get_char();
+ c = input_stack::peek_char();
+ }
+ if (c != EOF && csalpha(c)) {
+ // looks like a macro
+ input_stack::get_char();
+ token_buffer = c;
+ for (;;) {
+ c = input_stack::peek_char();
+ if (c == EOF || (!csalnum(c) && c != '_'))
+ break;
+ input_stack::get_char();
+ token_buffer += char(c);
+ }
+ context_buffer = token_buffer;
+ token_buffer += '\0';
+ char *def = macro_table.lookup(token_buffer.contents());
+ if (def)
+ return strsave(def);
+ // I guess it wasn't a macro after all; so push the macro name back.
+ // -2 because we added a '\0'
+ for (int i = token_buffer.length() - 2; i >= 0; i--)
+ input_stack::push_back(token_buffer[i]);
+ }
+ if (get_delimited()) {
+ token_buffer += '\0';
+ return strsave(token_buffer.contents());
+ }
+ else
+ return 0;
+}
+
+int lookahead_token = -1;
+string old_context_buffer;
+
+void do_lookahead()
+{
+ if (lookahead_token == -1) {
+ old_context_buffer = context_buffer;
+ lookahead_token = get_token(1);
+ }
+}
+
+int yylex()
+{
+ if (delim_flag) {
+ assert(lookahead_token == -1);
+ if (delim_flag == 2) {
+ if ((yylval.str = get_thru_arg()) != 0)
+ return DELIMITED;
+ else
+ return 0;
+ }
+ else {
+ if (get_delimited()) {
+ token_buffer += '\0';
+ yylval.str = strsave(token_buffer.contents());
+ return DELIMITED;
+ }
+ else
+ return 0;
+ }
+ }
+ for (;;) {
+ int t;
+ if (lookahead_token >= 0) {
+ t = lookahead_token;
+ lookahead_token = -1;
+ }
+ else
+ t = get_token(1);
+ switch (t) {
+ case '\n':
+ return ';';
+ case EOF:
+ return 0;
+ case DEFINE:
+ do_define();
+ break;
+ case UNDEF:
+ do_undef();
+ break;
+ case ORDINAL:
+ yylval.n = token_int;
+ return t;
+ case NUMBER:
+ yylval.x = token_double;
+ return t;
+ case COMMAND_LINE:
+ case TEXT:
+ token_buffer += '\0';
+ if (!input_stack::get_location(&yylval.lstr.filename,
+ &yylval.lstr.lineno)) {
+ yylval.lstr.filename = 0;
+ yylval.lstr.lineno = -1;
+ }
+ yylval.lstr.str = strsave(token_buffer.contents());
+ return t;
+ case LABEL:
+ case VARIABLE:
+ token_buffer += '\0';
+ yylval.str = strsave(token_buffer.contents());
+ return t;
+ case LEFT:
+ // change LEFT to LEFT_CORNER when followed by OF
+ old_context_buffer = context_buffer;
+ lookahead_token = get_token(1);
+ if (lookahead_token == OF)
+ return LEFT_CORNER;
+ else
+ return t;
+ case RIGHT:
+ // change RIGHT to RIGHT_CORNER when followed by OF
+ old_context_buffer = context_buffer;
+ lookahead_token = get_token(1);
+ if (lookahead_token == OF)
+ return RIGHT_CORNER;
+ else
+ return t;
+ case UPPER:
+ // recognise UPPER only before LEFT or RIGHT
+ old_context_buffer = context_buffer;
+ lookahead_token = get_token(1);
+ if (lookahead_token != LEFT && lookahead_token != RIGHT) {
+ yylval.str = strsave("upper");
+ return VARIABLE;
+ }
+ else
+ return t;
+ case LOWER:
+ // recognise LOWER only before LEFT or RIGHT
+ old_context_buffer = context_buffer;
+ lookahead_token = get_token(1);
+ if (lookahead_token != LEFT && lookahead_token != RIGHT) {
+ yylval.str = strsave("lower");
+ return VARIABLE;
+ }
+ else
+ return t;
+ case NORTH:
+ // recognise NORTH only before OF
+ old_context_buffer = context_buffer;
+ lookahead_token = get_token(1);
+ if (lookahead_token != OF) {
+ yylval.str = strsave("north");
+ return VARIABLE;
+ }
+ else
+ return t;
+ case SOUTH:
+ // recognise SOUTH only before OF
+ old_context_buffer = context_buffer;
+ lookahead_token = get_token(1);
+ if (lookahead_token != OF) {
+ yylval.str = strsave("south");
+ return VARIABLE;
+ }
+ else
+ return t;
+ case EAST:
+ // recognise EAST only before OF
+ old_context_buffer = context_buffer;
+ lookahead_token = get_token(1);
+ if (lookahead_token != OF) {
+ yylval.str = strsave("east");
+ return VARIABLE;
+ }
+ else
+ return t;
+ case WEST:
+ // recognise WEST only before OF
+ old_context_buffer = context_buffer;
+ lookahead_token = get_token(1);
+ if (lookahead_token != OF) {
+ yylval.str = strsave("west");
+ return VARIABLE;
+ }
+ else
+ return t;
+ case TOP:
+ // recognise TOP only before OF
+ old_context_buffer = context_buffer;
+ lookahead_token = get_token(1);
+ if (lookahead_token != OF) {
+ yylval.str = strsave("top");
+ return VARIABLE;
+ }
+ else
+ return t;
+ case BOTTOM:
+ // recognise BOTTOM only before OF
+ old_context_buffer = context_buffer;
+ lookahead_token = get_token(1);
+ if (lookahead_token != OF) {
+ yylval.str = strsave("bottom");
+ return VARIABLE;
+ }
+ else
+ return t;
+ case CENTER:
+ // recognise CENTER only before OF
+ old_context_buffer = context_buffer;
+ lookahead_token = get_token(1);
+ if (lookahead_token != OF) {
+ yylval.str = strsave("center");
+ return VARIABLE;
+ }
+ else
+ return t;
+ case START:
+ // recognise START only before OF
+ old_context_buffer = context_buffer;
+ lookahead_token = get_token(1);
+ if (lookahead_token != OF) {
+ yylval.str = strsave("start");
+ return VARIABLE;
+ }
+ else
+ return t;
+ case END:
+ // recognise END only before OF
+ old_context_buffer = context_buffer;
+ lookahead_token = get_token(1);
+ if (lookahead_token != OF) {
+ yylval.str = strsave("end");
+ return VARIABLE;
+ }
+ else
+ return t;
+ default:
+ return t;
+ }
+ }
+}
+
+void lex_error(const char *message,
+ const errarg &arg1,
+ const errarg &arg2,
+ const errarg &arg3)
+{
+ const char *filename;
+ int lineno;
+ if (!input_stack::get_location(&filename, &lineno))
+ error(message, arg1, arg2, arg3);
+ else
+ error_with_file_and_line(filename, lineno, message, arg1, arg2, arg3);
+}
+
+void lex_warning(const char *message,
+ const errarg &arg1,
+ const errarg &arg2,
+ const errarg &arg3)
+{
+ const char *filename;
+ int lineno;
+ if (!input_stack::get_location(&filename, &lineno))
+ warning(message, arg1, arg2, arg3);
+ else
+ warning_with_file_and_line(filename, lineno, message, arg1, arg2, arg3);
+}
+
+void yyerror(const char *s)
+{
+ const char *filename;
+ int lineno;
+ const char *context = 0;
+ if (lookahead_token == -1) {
+ if (context_buffer.length() > 0) {
+ context_buffer += '\0';
+ context = context_buffer.contents();
+ }
+ }
+ else {
+ if (old_context_buffer.length() > 0) {
+ old_context_buffer += '\0';
+ context = old_context_buffer.contents();
+ }
+ }
+ if (!input_stack::get_location(&filename, &lineno)) {
+ if (context) {
+ if (context[0] == '\n' && context[1] == '\0')
+ error("%1 before newline", s);
+ else
+ error("%1 before '%2'", s, context);
+ }
+ else
+ error("%1 at end of picture", s);
+ }
+ else {
+ if (context) {
+ if (context[0] == '\n' && context[1] == '\0')
+ error_with_file_and_line(filename, lineno, "%1 before newline", s);
+ else
+ error_with_file_and_line(filename, lineno, "%1 before '%2'",
+ s, context);
+ }
+ else
+ error_with_file_and_line(filename, lineno, "%1 at end of picture", s);
+ }
+}
+
diff --git a/src/preproc/pic/main.cpp b/src/preproc/pic/main.cpp
new file mode 100644
index 0000000..f7e194f
--- /dev/null
+++ b/src/preproc/pic/main.cpp
@@ -0,0 +1,664 @@
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+ Written by James Clark (jjc@jclark.com)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+groff is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "pic.h"
+
+extern int yyparse();
+extern "C" const char *Version_string;
+
+output *out;
+char *graphname; // the picture box name in TeX mode
+
+bool want_flyback = false;
+// groff pic supports '.PY' to work around mm package stepping on 'PF'.
+bool want_alternate_flyback = false;
+int zero_length_line_flag = 0;
+// Non-zero means we're using a groff driver.
+int driver_extension_flag = 1;
+int compatible_flag = 0;
+int safer_flag = 1;
+int command_char = '.'; // the character that introduces lines
+ // that should be passed through transparently
+static int lf_flag = 1; // non-zero if we should attempt to understand
+ // lines beginning with '.lf'
+
+// Non-zero means a parse error was encountered.
+static int had_parse_error = 0;
+
+void do_file(const char *filename);
+
+class top_input : public input {
+ FILE *fp;
+ int bol;
+ int eof;
+ int push_back[3];
+ int start_lineno;
+public:
+ top_input(FILE *);
+ int get();
+ int peek();
+ int get_location(const char **, int *);
+};
+
+top_input::top_input(FILE *p) : fp(p), bol(1), eof(0)
+{
+ push_back[0] = push_back[1] = push_back[2] = EOF;
+ start_lineno = current_lineno;
+}
+
+int top_input::get()
+{
+ if (eof)
+ return EOF;
+ if (push_back[2] != EOF) {
+ int c = push_back[2];
+ push_back[2] = EOF;
+ return c;
+ }
+ else if (push_back[1] != EOF) {
+ int c = push_back[1];
+ push_back[1] = EOF;
+ return c;
+ }
+ else if (push_back[0] != EOF) {
+ int c = push_back[0];
+ push_back[0] = EOF;
+ return c;
+ }
+ int c = getc(fp);
+ while (is_invalid_input_char(c)) {
+ error("invalid input character code %1", int(c));
+ c = getc(fp);
+ bol = 0;
+ }
+ if (bol && c == '.') {
+ c = getc(fp);
+ if (c == 'P') {
+ c = getc(fp);
+ if (c == 'E' || c == 'F' || c == 'Y') {
+ int d = getc(fp);
+ if (d != EOF)
+ ungetc(d, fp);
+ if (d == EOF || d == ' ' || d == '\n' || compatible_flag) {
+ eof = 1;
+ want_flyback = (c == 'F');
+ want_alternate_flyback = (c == 'Y');
+ return EOF;
+ }
+ push_back[0] = c;
+ push_back[1] = 'P';
+ return '.';
+ }
+ if (c == 'S') {
+ c = getc(fp);
+ if (c != EOF)
+ ungetc(c, fp);
+ if (c == EOF || c == ' ' || c == '\n' || compatible_flag) {
+ error("nested .PS");
+ eof = 1;
+ return EOF;
+ }
+ push_back[0] = 'S';
+ push_back[1] = 'P';
+ return '.';
+ }
+ if (c != EOF)
+ ungetc(c, fp);
+ push_back[0] = 'P';
+ return '.';
+ }
+ else {
+ if (c != EOF)
+ ungetc(c, fp);
+ return '.';
+ }
+ }
+ if (c == '\n') {
+ bol = 1;
+ current_lineno++;
+ return '\n';
+ }
+ bol = 0;
+ if (c == EOF) {
+ eof = 1;
+ error("end of file before .PE, .PF, or .PY");
+ error_with_file_and_line(current_filename, start_lineno - 1,
+ ".PS was here");
+ }
+ return c;
+}
+
+int top_input::peek()
+{
+ if (eof)
+ return EOF;
+ if (push_back[2] != EOF)
+ return push_back[2];
+ if (push_back[1] != EOF)
+ return push_back[1];
+ if (push_back[0] != EOF)
+ return push_back[0];
+ int c = getc(fp);
+ while (is_invalid_input_char(c)) {
+ error("invalid input character code %1", int(c));
+ c = getc(fp);
+ bol = 0;
+ }
+ if (bol && c == '.') {
+ c = getc(fp);
+ if (c == 'P') {
+ c = getc(fp);
+ if (c == 'E' || c == 'F' || c == 'Y') {
+ int d = getc(fp);
+ if (d != EOF)
+ ungetc(d, fp);
+ if (d == EOF || d == ' ' || d == '\n' || compatible_flag) {
+ eof = 1;
+ want_flyback = (c == 'F');
+ want_alternate_flyback = (c == 'Y');
+ return EOF;
+ }
+ push_back[0] = c;
+ push_back[1] = 'P';
+ push_back[2] = '.';
+ return '.';
+ }
+ if (c == 'S') {
+ c = getc(fp);
+ if (c != EOF)
+ ungetc(c, fp);
+ if (c == EOF || c == ' ' || c == '\n' || compatible_flag) {
+ error("nested .PS");
+ eof = 1;
+ return EOF;
+ }
+ push_back[0] = 'S';
+ push_back[1] = 'P';
+ push_back[2] = '.';
+ return '.';
+ }
+ if (c != EOF)
+ ungetc(c, fp);
+ push_back[0] = 'P';
+ push_back[1] = '.';
+ return '.';
+ }
+ else {
+ if (c != EOF)
+ ungetc(c, fp);
+ push_back[0] = '.';
+ return '.';
+ }
+ }
+ if (c != EOF)
+ ungetc(c, fp);
+ if (c == '\n')
+ return '\n';
+ return c;
+}
+
+int top_input::get_location(const char **filenamep, int *linenop)
+{
+ *filenamep = current_filename;
+ *linenop = current_lineno;
+ return 1;
+}
+
+void do_picture(FILE *fp)
+{
+ want_flyback = false;
+ int c;
+ if (!graphname)
+ free(graphname);
+ graphname = strsave("graph"); // default picture name in TeX mode
+ while ((c = getc(fp)) == ' ')
+ ;
+ if (c == '<') {
+ string filename;
+ while ((c = getc(fp)) == ' ')
+ ;
+ while (c != EOF && c != ' ' && c != '\n') {
+ filename += char(c);
+ c = getc(fp);
+ }
+ if (c == ' ') {
+ do {
+ c = getc(fp);
+ } while (c != EOF && c != '\n');
+ }
+ if (c == '\n')
+ current_lineno++;
+ if (filename.length() == 0)
+ error("missing filename after '<'");
+ else {
+ filename += '\0';
+ const char *old_filename = current_filename;
+ int old_lineno = current_lineno;
+ // filenames must be permanent
+ do_file(strsave(filename.contents()));
+ current_filename = old_filename;
+ current_lineno = old_lineno;
+ }
+ out->set_location(current_filename, current_lineno);
+ }
+ else {
+ out->set_location(current_filename, current_lineno);
+ string start_line;
+ while (c != EOF) {
+ if (c == '\n') {
+ current_lineno++;
+ break;
+ }
+ start_line += c;
+ c = getc(fp);
+ }
+ if (c == EOF)
+ return;
+ start_line += '\0';
+ double wid, ht;
+ switch (sscanf(&start_line[0], "%lf %lf", &wid, &ht)) {
+ case 1:
+ ht = 0.0;
+ break;
+ case 2:
+ break;
+ default:
+ ht = wid = 0.0;
+ break;
+ }
+ out->set_desired_width_height(wid, ht);
+ out->set_args(start_line.contents());
+ lex_init(new top_input(fp));
+ if (yyparse()) {
+ had_parse_error = 1;
+ lex_error("giving up on this picture");
+ }
+ parse_cleanup();
+ lex_cleanup();
+
+ // skip the rest of the .PE/.PF/.PY line
+ while ((c = getc(fp)) != EOF && c != '\n')
+ ;
+ if (c == '\n')
+ current_lineno++;
+ out->set_location(current_filename, current_lineno);
+ }
+}
+
+void do_file(const char *filename)
+{
+ FILE *fp;
+ if (strcmp(filename, "-") == 0)
+ fp = stdin;
+ else {
+ errno = 0;
+ fp = fopen(filename, "r");
+ if (fp == 0) {
+ delete out;
+ fatal("can't open '%1': %2", filename, strerror(errno));
+ }
+ }
+ string fn(filename);
+ fn += '\0';
+ normalize_for_lf(fn);
+ current_filename = fn.contents();
+ out->set_location(current_filename, 1);
+ current_lineno = 1;
+ enum { START, MIDDLE, HAD_DOT, HAD_P, HAD_PS, HAD_l, HAD_lf } state = START;
+ for (;;) {
+ int c = getc(fp);
+ while (is_invalid_input_char(c)) {
+ error("invalid input character code %1", int(c));
+ c = getc(fp);
+ }
+ if (c == EOF)
+ break;
+ switch (state) {
+ case START:
+ if (c == '.')
+ state = HAD_DOT;
+ else {
+ putchar(c);
+ if (c == '\n') {
+ current_lineno++;
+ state = START;
+ }
+ else
+ state = MIDDLE;
+ }
+ break;
+ case MIDDLE:
+ putchar(c);
+ if (c == '\n') {
+ current_lineno++;
+ state = START;
+ }
+ break;
+ case HAD_DOT:
+ if (c == 'P')
+ state = HAD_P;
+ else if (lf_flag && c == 'l')
+ state = HAD_l;
+ else {
+ putchar('.');
+ putchar(c);
+ if (c == '\n') {
+ current_lineno++;
+ state = START;
+ }
+ else
+ state = MIDDLE;
+ }
+ break;
+ case HAD_P:
+ if (c == 'S')
+ state = HAD_PS;
+ else {
+ putchar('.');
+ putchar('P');
+ putchar(c);
+ if (c == '\n') {
+ current_lineno++;
+ state = START;
+ }
+ else
+ state = MIDDLE;
+ }
+ break;
+ case HAD_PS:
+ if (c == ' ' || c == '\n' || compatible_flag) {
+ ungetc(c, fp);
+ do_picture(fp);
+ state = START;
+ }
+ else {
+ fputs(".PS", stdout);
+ putchar(c);
+ state = MIDDLE;
+ }
+ break;
+ case HAD_l:
+ if (c == 'f')
+ state = HAD_lf;
+ else {
+ putchar('.');
+ putchar('l');
+ putchar(c);
+ if (c == '\n') {
+ current_lineno++;
+ state = START;
+ }
+ else
+ state = MIDDLE;
+ }
+ break;
+ case HAD_lf:
+ if (c == ' ' || c == '\n' || compatible_flag) {
+ string line;
+ while (c != EOF) {
+ line += c;
+ if (c == '\n') {
+ current_lineno++;
+ break;
+ }
+ c = getc(fp);
+ }
+ line += '\0';
+ interpret_lf_args(line.contents());
+ printf(".lf%s", line.contents());
+ state = START;
+ }
+ else {
+ fputs(".lf", stdout);
+ putchar(c);
+ state = MIDDLE;
+ }
+ break;
+ default:
+ assert(0);
+ }
+ }
+ switch (state) {
+ case START:
+ break;
+ case MIDDLE:
+ putchar('\n');
+ break;
+ case HAD_DOT:
+ fputs(".\n", stdout);
+ break;
+ case HAD_P:
+ fputs(".P\n", stdout);
+ break;
+ case HAD_PS:
+ fputs(".PS\n", stdout);
+ break;
+ case HAD_l:
+ fputs(".l\n", stdout);
+ break;
+ case HAD_lf:
+ fputs(".lf\n", stdout);
+ break;
+ }
+ if (fp != stdin)
+ fclose(fp);
+}
+
+#ifdef FIG_SUPPORT
+void do_whole_file(const char *filename)
+{
+ // Do not set current_filename.
+ FILE *fp;
+ if (strcmp(filename, "-") == 0)
+ fp = stdin;
+ else {
+ errno = 0;
+ fp = fopen(filename, "r");
+ if (fp == 0)
+ fatal("can't open '%1': %2", filename, strerror(errno));
+ }
+ lex_init(new file_input(fp, filename));
+ if (yyparse())
+ had_parse_error = 1;
+ parse_cleanup();
+ lex_cleanup();
+}
+#endif
+
+void usage(FILE *stream)
+{
+ fprintf(stream, "usage: %s [-CnSU] [file ...]\n", program_name);
+#ifdef TEX_SUPPORT
+ fprintf(stream, "usage: %s -t [-cCSUz] [file ...]\n", program_name);
+#endif
+#ifdef FIG_SUPPORT
+ fprintf(stream, "usage: %s -f [-v] [file]\n", program_name);
+#endif
+ fprintf(stream, "usage: %s {-v | --version}\n", program_name);
+ fprintf(stream, "usage: %s --help\n", program_name);
+}
+
+#if defined(__MSDOS__) || defined(__EMX__)
+static char *fix_program_name(char *arg, char *dflt)
+{
+ if (!arg)
+ return dflt;
+ char *prog = strchr(arg, '\0');
+ for (;;) {
+ if (prog == arg)
+ break;
+ --prog;
+ if (strchr("\\/:", *prog)) {
+ prog++;
+ break;
+ }
+ }
+ char *ext = strchr(prog, '.');
+ if (ext)
+ *ext = '\0';
+ for (char *p = prog; *p; p++)
+ if ('A' <= *p && *p <= 'Z')
+ *p = 'a' + (*p - 'A');
+ return prog;
+}
+#endif /* __MSDOS__ || __EMX__ */
+
+int main(int argc, char **argv)
+{
+ setlocale(LC_NUMERIC, "C");
+#if defined(__MSDOS__) || defined(__EMX__)
+ argv[0] = fix_program_name(argv[0], "pic");
+#endif /* __MSDOS__ || __EMX__ */
+ program_name = argv[0];
+ static char stderr_buf[BUFSIZ];
+ setbuf(stderr, stderr_buf);
+ int opt;
+#ifdef TEX_SUPPORT
+ int tex_flag = 0;
+ int tpic_flag = 0;
+#endif
+#ifdef FIG_SUPPORT
+ int whole_file_flag = 0;
+ int fig_flag = 0;
+#endif
+ static const struct option long_options[] = {
+ { "help", no_argument, 0, CHAR_MAX + 1 },
+ { "version", no_argument, 0, 'v' },
+ { NULL, 0, 0, 0 }
+ };
+ while ((opt = getopt_long(argc, argv, "T:CDSUtcvnxzpf", long_options, NULL))
+ != EOF)
+ switch (opt) {
+ case 'C':
+ compatible_flag = 1;
+ break;
+ case 'D':
+ case 'T':
+ break;
+ case 'S':
+ safer_flag = 1;
+ break;
+ case 'U':
+ safer_flag = 0;
+ break;
+ case 'f':
+#ifdef FIG_SUPPORT
+ whole_file_flag++;
+ fig_flag++;
+#else
+ fatal("fig support not included");
+#endif
+ break;
+ case 'n':
+ driver_extension_flag = 0;
+ break;
+ case 'p':
+ case 'x':
+ warning("-%1 option is obsolete", char(opt));
+ break;
+ case 't':
+#ifdef TEX_SUPPORT
+ tex_flag++;
+#else
+ fatal("TeX support not included");
+#endif
+ break;
+ case 'c':
+#ifdef TEX_SUPPORT
+ tpic_flag++;
+#else
+ fatal("TeX support not included");
+#endif
+ break;
+ case 'v':
+ {
+ printf("GNU pic (groff) version %s\n", Version_string);
+ exit(0);
+ break;
+ }
+ case 'z':
+ // zero length lines will be printed as dots
+ zero_length_line_flag++;
+ break;
+ case CHAR_MAX + 1: // --help
+ usage(stdout);
+ exit(0);
+ break;
+ case '?':
+ usage(stderr);
+ exit(1);
+ break;
+ default:
+ assert(0);
+ }
+ parse_init();
+#ifdef TEX_SUPPORT
+ if (tpic_flag) {
+ out = make_tpic_output();
+ lf_flag = 0;
+ }
+ else if (tex_flag) {
+ out = make_tex_output();
+ command_char = '\\';
+ lf_flag = 0;
+ }
+ else
+#endif
+#ifdef FIG_SUPPORT
+ if (fig_flag)
+ out = make_fig_output();
+ else
+#endif
+ {
+ out = make_troff_output();
+ printf(".do if !dPS .ds PS\n"
+ ".do if !dPE .ds PE\n"
+ ".do if !dPF .ds PF\n"
+ ".do if !dPY .ds PY\n");
+ }
+#ifdef FIG_SUPPORT
+ if (whole_file_flag) {
+ if (optind >= argc)
+ do_whole_file("-");
+ else if (argc - optind > 1) {
+ usage(stderr);
+ exit(1);
+ } else
+ do_whole_file(argv[optind]);
+ }
+ else {
+#endif
+ if (optind >= argc)
+ do_file("-");
+ else
+ for (int i = optind; i < argc; i++)
+ do_file(argv[i]);
+#ifdef FIG_SUPPORT
+ }
+#endif
+ delete out;
+ if (ferror(stdout) || fflush(stdout) < 0)
+ fatal("output error");
+ return had_parse_error;
+}
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/preproc/pic/object.cpp b/src/preproc/pic/object.cpp
new file mode 100644
index 0000000..e207fb1
--- /dev/null
+++ b/src/preproc/pic/object.cpp
@@ -0,0 +1,2079 @@
+// -*- C++ -*-
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+ Written by James Clark (jjc@jclark.com)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+groff is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+
+#include "pic.h"
+#include "ptable.h"
+#include "object.h"
+
+void print_object_list(object *);
+
+line_type::line_type()
+: type(solid), thickness(1.0)
+{
+}
+
+output::output() : args(0), desired_height(0.0), desired_width(0.0)
+{
+}
+
+output::~output()
+{
+ delete[] args;
+}
+
+void output::set_desired_width_height(double wid, double ht)
+{
+ desired_width = wid;
+ desired_height = ht;
+}
+
+void output::set_args(const char *s)
+{
+ delete[] args;
+ if (s == 0 || *s == '\0')
+ args = 0;
+ else
+ args = strsave(s);
+}
+
+int output::supports_filled_polygons()
+{
+ return 0;
+}
+
+void output::begin_block(const position &, const position &)
+{
+}
+
+void output::end_block()
+{
+}
+
+double output::compute_scale(double sc, const position &ll, const position &ur)
+{
+ distance dim = ur - ll;
+ if (desired_width != 0.0 || desired_height != 0.0) {
+ sc = 0.0;
+ if (desired_width != 0.0) {
+ if (dim.x == 0.0)
+ error("width specified for picture with zero width");
+ else
+ sc = dim.x/desired_width;
+ }
+ if (desired_height != 0.0) {
+ if (dim.y == 0.0)
+ error("height specified for picture with zero height");
+ else {
+ double tem = dim.y/desired_height;
+ if (tem > sc)
+ sc = tem;
+ }
+ }
+ return sc == 0.0 ? 1.0 : sc;
+ }
+ else {
+ if (sc <= 0.0)
+ sc = 1.0;
+ distance sdim = dim/sc;
+ double max_width = 0.0;
+ lookup_variable("maxpswid", &max_width);
+ double max_height = 0.0;
+ lookup_variable("maxpsht", &max_height);
+ if ((max_width > 0.0 && sdim.x > max_width)
+ || (max_height > 0.0 && sdim.y > max_height)) {
+ double xscale = dim.x/max_width;
+ double yscale = dim.y/max_height;
+ return xscale > yscale ? xscale : yscale;
+ }
+ else
+ return sc;
+ }
+}
+
+position::position(const place &pl)
+{
+ if (pl.obj != 0) {
+ // Use two statements to work around bug in SGI C++.
+ object *tem = pl.obj;
+ *this = tem->origin();
+ }
+ else {
+ x = pl.x;
+ y = pl.y;
+ }
+}
+
+position::position() : x(0.0), y(0.0)
+{
+}
+
+position::position(double a, double b) : x(a), y(b)
+{
+}
+
+
+int operator==(const position &a, const position &b)
+{
+ return a.x == b.x && a.y == b.y;
+}
+
+int operator!=(const position &a, const position &b)
+{
+ return a.x != b.x || a.y != b.y;
+}
+
+position &position::operator+=(const position &a)
+{
+ x += a.x;
+ y += a.y;
+ return *this;
+}
+
+position &position::operator-=(const position &a)
+{
+ x -= a.x;
+ y -= a.y;
+ return *this;
+}
+
+position &position::operator*=(double a)
+{
+ x *= a;
+ y *= a;
+ return *this;
+}
+
+position &position::operator/=(double a)
+{
+ x /= a;
+ y /= a;
+ return *this;
+}
+
+position operator-(const position &a)
+{
+ return position(-a.x, -a.y);
+}
+
+position operator+(const position &a, const position &b)
+{
+ return position(a.x + b.x, a.y + b.y);
+}
+
+position operator-(const position &a, const position &b)
+{
+ return position(a.x - b.x, a.y - b.y);
+}
+
+position operator/(const position &a, double n)
+{
+ return position(a.x/n, a.y/n);
+}
+
+position operator*(const position &a, double n)
+{
+ return position(a.x*n, a.y*n);
+}
+
+// dot product
+
+double operator*(const position &a, const position &b)
+{
+ return a.x*b.x + a.y*b.y;
+}
+
+double hypot(const position &a)
+{
+ return groff_hypot(a.x, a.y);
+}
+
+struct arrow_head_type {
+ double height;
+ double width;
+ int solid;
+};
+
+void draw_arrow(const position &pos, const distance &dir,
+ const arrow_head_type &aht, const line_type &lt,
+ char *outline_color_for_fill)
+{
+ double hyp = hypot(dir);
+ if (hyp == 0.0) {
+ error("cannot draw arrow on object with zero length");
+ return;
+ }
+ position base = -dir;
+ base *= aht.height/hyp;
+ position n(dir.y, -dir.x);
+ n *= aht.width/(hyp*2.0);
+ line_type slt = lt;
+ slt.type = line_type::solid;
+ if (aht.solid && out->supports_filled_polygons()) {
+ position v[3];
+ v[0] = pos;
+ v[1] = pos + base + n;
+ v[2] = pos + base - n;
+ // fill with outline color
+ out->set_color(outline_color_for_fill, outline_color_for_fill);
+ // make stroke thin to avoid arrow sticking
+ slt.thickness = 0.1;
+ out->polygon(v, 3, slt, 1);
+ }
+ else {
+ // use two line segments to avoid arrow sticking
+ out->line(pos + base - n, &pos, 1, slt);
+ out->line(pos + base + n, &pos, 1, slt);
+ }
+}
+
+object::object() : prev(0), next(0)
+{
+}
+
+object::~object()
+{
+}
+
+void object::move_by(const position &)
+{
+}
+
+void object::print()
+{
+}
+
+void object::print_text()
+{
+}
+
+int object::blank()
+{
+ return 0;
+}
+
+struct bounding_box {
+ int blank;
+ position ll;
+ position ur;
+
+ bounding_box();
+ void encompass(const position &);
+};
+
+bounding_box::bounding_box()
+: blank(1)
+{
+}
+
+void bounding_box::encompass(const position &pos)
+{
+ if (blank) {
+ ll = pos;
+ ur = pos;
+ blank = 0;
+ }
+ else {
+ if (pos.x < ll.x)
+ ll.x = pos.x;
+ if (pos.y < ll.y)
+ ll.y = pos.y;
+ if (pos.x > ur.x)
+ ur.x = pos.x;
+ if (pos.y > ur.y)
+ ur.y = pos.y;
+ }
+}
+
+void object::update_bounding_box(bounding_box *)
+{
+}
+
+position object::origin()
+{
+ return position(0.0,0.0);
+}
+
+position object::north()
+{
+ return origin();
+}
+
+position object::south()
+{
+ return origin();
+}
+
+position object::east()
+{
+ return origin();
+}
+
+position object::west()
+{
+ return origin();
+}
+
+position object::north_east()
+{
+ return origin();
+}
+
+position object::north_west()
+{
+ return origin();
+}
+
+position object::south_east()
+{
+ return origin();
+}
+
+position object::south_west()
+{
+ return origin();
+}
+
+position object::start()
+{
+ return origin();
+}
+
+position object::end()
+{
+ return origin();
+}
+
+position object::center()
+{
+ return origin();
+}
+
+double object::width()
+{
+ return 0.0;
+}
+
+double object::radius()
+{
+ return 0.0;
+}
+
+double object::height()
+{
+ return 0.0;
+}
+
+place *object::find_label(const char *)
+{
+ return 0;
+}
+
+segment::segment(const position &a, int n, segment *p)
+: is_absolute(n), pos(a), next(p)
+{
+}
+
+text_item::text_item(char *t, const char *fn, int ln)
+: next(0), text(t), filename(fn), lineno(ln)
+{
+ adj.h = CENTER_ADJUST;
+ adj.v = NONE_ADJUST;
+}
+
+text_item::~text_item()
+{
+ delete[] text;
+}
+
+object_spec::object_spec(object_type t) : type(t)
+{
+ flags = 0;
+ tbl = 0;
+ segment_list = 0;
+ segment_width = segment_height = 0.0;
+ segment_is_absolute = 0;
+ text = 0;
+ shaded = 0;
+ xslanted = 0;
+ yslanted = 0;
+ outlined = 0;
+ with = 0;
+ dir = RIGHT_DIRECTION;
+}
+
+object_spec::~object_spec()
+{
+ delete tbl;
+ while (segment_list != 0) {
+ segment *tem = segment_list;
+ segment_list = segment_list->next;
+ delete tem;
+ }
+ object *p = oblist.head;
+ while (p != 0) {
+ object *tem = p;
+ p = p->next;
+ delete tem;
+ }
+ while (text != 0) {
+ text_item *tem = text;
+ text = text->next;
+ delete tem;
+ }
+ delete with;
+ delete[] shaded;
+ delete[] outlined;
+}
+
+class command_object : public object {
+ char *s;
+ const char *filename;
+ int lineno;
+public:
+ command_object(char *, const char *, int);
+ ~command_object();
+ object_type type() { return OTHER_OBJECT; }
+ void print();
+};
+
+command_object::command_object(char *p, const char *fn, int ln)
+: s(p), filename(fn), lineno(ln)
+{
+}
+
+command_object::~command_object()
+{
+ delete[] s;
+}
+
+void command_object::print()
+{
+ out->command(s, filename, lineno);
+}
+
+object *make_command_object(char *s, const char *fn, int ln)
+{
+ return new command_object(s, fn, ln);
+}
+
+class mark_object : public object {
+public:
+ mark_object();
+ object_type type();
+};
+
+object *make_mark_object()
+{
+ return new mark_object();
+}
+
+mark_object::mark_object()
+{
+}
+
+object_type mark_object::type()
+{
+ return MARK_OBJECT;
+}
+
+object_list::object_list() : head(0), tail(0)
+{
+}
+
+void object_list::append(object *obj)
+{
+ if (tail == 0) {
+ obj->next = obj->prev = 0;
+ head = tail = obj;
+ }
+ else {
+ obj->prev = tail;
+ obj->next = 0;
+ tail->next = obj;
+ tail = obj;
+ }
+}
+
+void object_list::wrap_up_block(object_list *ol)
+{
+ object *p;
+ for (p = tail; p && p->type() != MARK_OBJECT; p = p->prev)
+ ;
+ assert(p != 0);
+ ol->head = p->next;
+ if (ol->head) {
+ ol->tail = tail;
+ ol->head->prev = 0;
+ }
+ else
+ ol->tail = 0;
+ tail = p->prev;
+ if (tail)
+ tail->next = 0;
+ else
+ head = 0;
+ delete p;
+}
+
+text_piece::text_piece()
+: text(0), filename(0), lineno(-1)
+{
+ adj.h = CENTER_ADJUST;
+ adj.v = NONE_ADJUST;
+}
+
+text_piece::~text_piece()
+{
+ free(text);
+}
+
+class graphic_object : public object {
+ int ntext;
+ text_piece *text;
+ int aligned;
+protected:
+ line_type lt;
+ char *outline_color;
+ char *color_fill;
+public:
+ graphic_object();
+ ~graphic_object();
+ object_type type() = 0;
+ void print_text();
+ void add_text(text_item *, int);
+ void set_dotted(double);
+ void set_dashed(double);
+ void set_thickness(double);
+ void set_invisible();
+ void set_outline_color(char *);
+ char *get_outline_color();
+ virtual void set_fill(double);
+ virtual void set_xslanted(double);
+ virtual void set_yslanted(double);
+ virtual void set_fill_color(char *);
+};
+
+graphic_object::graphic_object()
+: ntext(0), text(0), aligned(0), outline_color(0), color_fill(0)
+{
+}
+
+void graphic_object::set_dotted(double wid)
+{
+ lt.type = line_type::dotted;
+ lt.dash_width = wid;
+}
+
+void graphic_object::set_dashed(double wid)
+{
+ lt.type = line_type::dashed;
+ lt.dash_width = wid;
+}
+
+void graphic_object::set_thickness(double th)
+{
+ lt.thickness = th;
+}
+
+void graphic_object::set_fill(double)
+{
+}
+
+void graphic_object::set_xslanted(double)
+{
+}
+
+void graphic_object::set_yslanted(double)
+{
+}
+
+void graphic_object::set_fill_color(char *c)
+{
+ color_fill = strsave(c);
+}
+
+void graphic_object::set_outline_color(char *c)
+{
+ outline_color = strsave(c);
+}
+
+char *graphic_object::get_outline_color()
+{
+ return outline_color;
+}
+
+void graphic_object::set_invisible()
+{
+ lt.type = line_type::invisible;
+}
+
+void graphic_object::add_text(text_item *t, int a)
+{
+ aligned = a;
+ int len = 0;
+ text_item *p;
+ for (p = t; p; p = p->next)
+ len++;
+ if (len == 0)
+ text = 0;
+ else {
+ text = new text_piece[len];
+ for (p = t, len = 0; p; p = p->next, len++) {
+ text[len].text = p->text;
+ p->text = 0;
+ text[len].adj = p->adj;
+ text[len].filename = p->filename;
+ text[len].lineno = p->lineno;
+ }
+ }
+ ntext = len;
+}
+
+void graphic_object::print_text()
+{
+ double angle = 0.0;
+ if (aligned) {
+ position d(end() - start());
+ if (d.x != 0.0 || d.y != 0.0)
+ angle = atan2(d.y, d.x);
+ }
+ if (text != 0) {
+ out->set_color(color_fill, get_outline_color());
+ out->text(center(), text, ntext, angle);
+ out->reset_color();
+ }
+}
+
+graphic_object::~graphic_object()
+{
+ if (text)
+ delete[] text;
+}
+
+class rectangle_object : public graphic_object {
+protected:
+ position cent;
+ position dim;
+public:
+ rectangle_object(const position &);
+ double width() { return dim.x; }
+ double height() { return dim.y; }
+ position origin() { return cent; }
+ position center() { return cent; }
+ position north() { return position(cent.x, cent.y + dim.y/2.0); }
+ position south() { return position(cent.x, cent.y - dim.y/2.0); }
+ position east() { return position(cent.x + dim.x/2.0, cent.y); }
+ position west() { return position(cent.x - dim.x/2.0, cent.y); }
+ position north_east() { return position(cent.x + dim.x/2.0, cent.y + dim.y/2.0); }
+ position north_west() { return position(cent.x - dim.x/2.0, cent.y + dim.y/2.0); }
+ position south_east() { return position(cent.x + dim.x/2.0, cent.y - dim.y/2.0); }
+ position south_west() { return position(cent.x - dim.x/2.0, cent.y - dim.y/2.0); }
+ object_type type() = 0;
+ void update_bounding_box(bounding_box *);
+ void move_by(const position &);
+};
+
+rectangle_object::rectangle_object(const position &d)
+: dim(d)
+{
+}
+
+void rectangle_object::update_bounding_box(bounding_box *p)
+{
+ p->encompass(cent - dim/2.0);
+ p->encompass(cent + dim/2.0);
+}
+
+void rectangle_object::move_by(const position &a)
+{
+ cent += a;
+}
+
+class closed_object : public rectangle_object {
+public:
+ closed_object(const position &);
+ object_type type() = 0;
+ void set_fill(double);
+ void set_xslanted(double);
+ void set_yslanted(double);
+ void set_fill_color(char *fill);
+protected:
+ double fill; // < 0 if not filled
+ double xslanted; // !=0 if x is slanted
+ double yslanted; // !=0 if y is slanted
+ char *color_fill; // = 0 if not colored
+};
+
+closed_object::closed_object(const position &pos)
+: rectangle_object(pos), fill(-1.0), xslanted(0), yslanted(0), color_fill(0)
+{
+}
+
+void closed_object::set_fill(double f)
+{
+ assert(f >= 0.0);
+ fill = f;
+}
+
+/* accept positive and negative values */
+void closed_object::set_xslanted(double s)
+{
+ //assert(s >= 0.0);
+ xslanted = s;
+}
+/* accept positive and negative values */
+void closed_object::set_yslanted(double s)
+{
+ //assert(s >= 0.0);
+ yslanted = s;
+}
+
+void closed_object::set_fill_color(char *f)
+{
+ color_fill = strsave(f);
+}
+
+class box_object : public closed_object {
+ double xrad;
+ double yrad;
+public:
+ box_object(const position &, double);
+ object_type type() { return BOX_OBJECT; }
+ void print();
+ position north_east();
+ position north_west();
+ position south_east();
+ position south_west();
+};
+
+box_object::box_object(const position &pos, double r)
+: closed_object(pos), xrad(dim.x > 0 ? r : -r), yrad(dim.y > 0 ? r : -r)
+{
+}
+
+const double CHOP_FACTOR = 1.0 - 1.0/M_SQRT2;
+
+position box_object::north_east()
+{
+ return position(cent.x + dim.x/2.0 - CHOP_FACTOR*xrad,
+ cent.y + dim.y/2.0 - CHOP_FACTOR*yrad);
+}
+
+position box_object::north_west()
+{
+ return position(cent.x - dim.x/2.0 + CHOP_FACTOR*xrad,
+ cent.y + dim.y/2.0 - CHOP_FACTOR*yrad);
+}
+
+position box_object::south_east()
+{
+ return position(cent.x + dim.x/2.0 - CHOP_FACTOR*xrad,
+ cent.y - dim.y/2.0 + CHOP_FACTOR*yrad);
+}
+
+position box_object::south_west()
+{
+ return position(cent.x - dim.x/2.0 + CHOP_FACTOR*xrad,
+ cent.y - dim.y/2.0 + CHOP_FACTOR*yrad);
+}
+
+void box_object::print()
+{
+ if (lt.type == line_type::invisible && fill < 0.0 && color_fill == 0)
+ return;
+ out->set_color(color_fill, graphic_object::get_outline_color());
+ if (xrad == 0.0) {
+ distance dim2 = dim/2.0;
+ position vec[4];
+ /* error("x slanted %1", xslanted); */
+ /* error("y slanted %1", yslanted); */
+ vec[0] = cent + position(dim2.x, -(dim2.y - yslanted)); /* lr */
+ vec[1] = cent + position(dim2.x + xslanted, dim2.y + yslanted); /* ur */
+ vec[2] = cent + position(-(dim2.x - xslanted), dim2.y); /* ul */
+ vec[3] = cent + position(-(dim2.x), -dim2.y); /* ll */
+ out->polygon(vec, 4, lt, fill);
+ }
+ else {
+ distance abs_dim(fabs(dim.x), fabs(dim.y));
+ out->rounded_box(cent, abs_dim, fabs(xrad), lt, fill, color_fill);
+ }
+ out->reset_color();
+}
+
+graphic_object *object_spec::make_box(position *curpos, direction *dirp)
+{
+ static double last_box_height;
+ static double last_box_width;
+ static double last_box_radius;
+ static int have_last_box = 0;
+ if (!(flags & HAS_HEIGHT)) {
+ if ((flags & IS_SAME) && have_last_box)
+ height = last_box_height;
+ else
+ lookup_variable("boxht", &height);
+ }
+ if (!(flags & HAS_WIDTH)) {
+ if ((flags & IS_SAME) && have_last_box)
+ width = last_box_width;
+ else
+ lookup_variable("boxwid", &width);
+ }
+ if (!(flags & HAS_RADIUS)) {
+ if ((flags & IS_SAME) && have_last_box)
+ radius = last_box_radius;
+ else
+ lookup_variable("boxrad", &radius);
+ }
+ last_box_width = width;
+ last_box_height = height;
+ last_box_radius = radius;
+ have_last_box = 1;
+ radius = fabs(radius);
+ if (radius*2.0 > fabs(width))
+ radius = fabs(width/2.0);
+ if (radius*2.0 > fabs(height))
+ radius = fabs(height/2.0);
+ box_object *p = new box_object(position(width, height), radius);
+ if (!position_rectangle(p, curpos, dirp)) {
+ delete p;
+ p = 0;
+ }
+ return p;
+}
+
+// return non-zero for success
+
+int object_spec::position_rectangle(rectangle_object *p,
+ position *curpos, direction *dirp)
+{
+ position pos;
+ dir = *dirp; // ignore any direction in attribute list
+ position motion;
+ switch (dir) {
+ case UP_DIRECTION:
+ motion.y = p->height()/2.0;
+ break;
+ case DOWN_DIRECTION:
+ motion.y = -p->height()/2.0;
+ break;
+ case LEFT_DIRECTION:
+ motion.x = -p->width()/2.0;
+ break;
+ case RIGHT_DIRECTION:
+ motion.x = p->width()/2.0;
+ break;
+ default:
+ assert(0);
+ }
+ if (flags & HAS_AT) {
+ pos = at;
+ if (flags & HAS_WITH) {
+ place offset;
+ place here;
+ here.obj = p;
+ if (!with->follow(here, &offset))
+ return 0;
+ pos -= offset;
+ }
+ }
+ else {
+ pos = *curpos;
+ pos += motion;
+ }
+ p->move_by(pos);
+ pos += motion;
+ *curpos = pos;
+ return 1;
+}
+
+class block_object : public rectangle_object {
+ object_list oblist;
+ PTABLE(place) *tbl;
+public:
+ block_object(const position &, const object_list &ol, PTABLE(place) *t);
+ ~block_object();
+ place *find_label(const char *);
+ object_type type();
+ void move_by(const position &);
+ void print();
+};
+
+block_object::block_object(const position &d, const object_list &ol,
+ PTABLE(place) *t)
+: rectangle_object(d), oblist(ol), tbl(t)
+{
+}
+
+block_object::~block_object()
+{
+ delete tbl;
+ object *p = oblist.head;
+ while (p != 0) {
+ object *tem = p;
+ p = p->next;
+ delete tem;
+ }
+}
+
+void block_object::print()
+{
+ out->begin_block(south_west(), north_east());
+ print_object_list(oblist.head);
+ out->end_block();
+}
+
+static void adjust_objectless_places(PTABLE(place) *tbl, const position &a)
+{
+ // Adjust all the labels that aren't attached to objects.
+ PTABLE_ITERATOR(place) iter(tbl);
+ const char *key;
+ place *pl;
+ while (iter.next(&key, &pl))
+ if (key && csupper(key[0]) && pl->obj == 0) {
+ pl->x += a.x;
+ pl->y += a.y;
+ }
+}
+
+void block_object::move_by(const position &a)
+{
+ cent += a;
+ for (object *p = oblist.head; p; p = p->next)
+ p->move_by(a);
+ adjust_objectless_places(tbl, a);
+}
+
+
+place *block_object::find_label(const char *name)
+{
+ return tbl->lookup(name);
+}
+
+object_type block_object::type()
+{
+ return BLOCK_OBJECT;
+}
+
+graphic_object *object_spec::make_block(position *curpos, direction *dirp)
+{
+ bounding_box bb;
+ for (object *p = oblist.head; p; p = p->next)
+ p->update_bounding_box(&bb);
+ position dim;
+ if (!bb.blank) {
+ position m = -(bb.ll + bb.ur)/2.0;
+ for (object *p = oblist.head; p; p = p->next)
+ p->move_by(m);
+ adjust_objectless_places(tbl, m);
+ dim = bb.ur - bb.ll;
+ }
+ if (flags & HAS_WIDTH)
+ dim.x = width;
+ if (flags & HAS_HEIGHT)
+ dim.y = height;
+ block_object *block = new block_object(dim, oblist, tbl);
+ if (!position_rectangle(block, curpos, dirp)) {
+ delete block;
+ block = 0;
+ }
+ tbl = 0;
+ oblist.head = oblist.tail = 0;
+ return block;
+}
+
+class text_object : public rectangle_object {
+public:
+ text_object(const position &);
+ object_type type() { return TEXT_OBJECT; }
+};
+
+text_object::text_object(const position &d)
+: rectangle_object(d)
+{
+}
+
+graphic_object *object_spec::make_text(position *curpos, direction *dirp)
+{
+ if (!(flags & HAS_HEIGHT)) {
+ lookup_variable("textht", &height);
+ int nitems = 0;
+ for (text_item *t = text; t; t = t->next)
+ nitems++;
+ height *= nitems;
+ }
+ if (!(flags & HAS_WIDTH))
+ lookup_variable("textwid", &width);
+ text_object *p = new text_object(position(width, height));
+ if (!position_rectangle(p, curpos, dirp)) {
+ delete p;
+ p = 0;
+ }
+ return p;
+}
+
+
+class ellipse_object : public closed_object {
+public:
+ ellipse_object(const position &);
+ position north_east() { return position(cent.x + dim.x/(M_SQRT2*2.0),
+ cent.y + dim.y/(M_SQRT2*2.0)); }
+ position north_west() { return position(cent.x - dim.x/(M_SQRT2*2.0),
+ cent.y + dim.y/(M_SQRT2*2.0)); }
+ position south_east() { return position(cent.x + dim.x/(M_SQRT2*2.0),
+ cent.y - dim.y/(M_SQRT2*2.0)); }
+ position south_west() { return position(cent.x - dim.x/(M_SQRT2*2.0),
+ cent.y - dim.y/(M_SQRT2*2.0)); }
+ double radius() { return dim.x/2.0; }
+ object_type type() { return ELLIPSE_OBJECT; }
+ void print();
+};
+
+ellipse_object::ellipse_object(const position &d)
+: closed_object(d)
+{
+}
+
+void ellipse_object::print()
+{
+ if (lt.type == line_type::invisible && fill < 0.0 && color_fill == 0)
+ return;
+ out->set_color(color_fill, graphic_object::get_outline_color());
+ out->ellipse(cent, dim, lt, fill);
+ out->reset_color();
+}
+
+graphic_object *object_spec::make_ellipse(position *curpos, direction *dirp)
+{
+ static double last_ellipse_height;
+ static double last_ellipse_width;
+ static int have_last_ellipse = 0;
+ if (!(flags & HAS_HEIGHT)) {
+ if ((flags & IS_SAME) && have_last_ellipse)
+ height = last_ellipse_height;
+ else
+ lookup_variable("ellipseht", &height);
+ }
+ if (!(flags & HAS_WIDTH)) {
+ if ((flags & IS_SAME) && have_last_ellipse)
+ width = last_ellipse_width;
+ else
+ lookup_variable("ellipsewid", &width);
+ }
+ last_ellipse_width = width;
+ last_ellipse_height = height;
+ have_last_ellipse = 1;
+ ellipse_object *p = new ellipse_object(position(width, height));
+ if (!position_rectangle(p, curpos, dirp)) {
+ delete p;
+ return 0;
+ }
+ return p;
+}
+
+class circle_object : public ellipse_object {
+public:
+ circle_object(double);
+ object_type type() { return CIRCLE_OBJECT; }
+ void print();
+};
+
+circle_object::circle_object(double diam)
+: ellipse_object(position(diam, diam))
+{
+}
+
+void circle_object::print()
+{
+ if (lt.type == line_type::invisible && fill < 0.0 && color_fill == 0)
+ return;
+ out->set_color(color_fill, graphic_object::get_outline_color());
+ out->circle(cent, dim.x/2.0, lt, fill);
+ out->reset_color();
+}
+
+graphic_object *object_spec::make_circle(position *curpos, direction *dirp)
+{
+ static double last_circle_radius;
+ static int have_last_circle = 0;
+ if (!(flags & HAS_RADIUS)) {
+ if ((flags & IS_SAME) && have_last_circle)
+ radius = last_circle_radius;
+ else
+ lookup_variable("circlerad", &radius);
+ }
+ last_circle_radius = radius;
+ have_last_circle = 1;
+ circle_object *p = new circle_object(radius*2.0);
+ if (!position_rectangle(p, curpos, dirp)) {
+ delete p;
+ return 0;
+ }
+ return p;
+}
+
+class move_object : public graphic_object {
+ position strt;
+ position en;
+public:
+ move_object(const position &s, const position &e);
+ position origin() { return en; }
+ object_type type() { return MOVE_OBJECT; }
+ void update_bounding_box(bounding_box *);
+ void move_by(const position &);
+};
+
+move_object::move_object(const position &s, const position &e)
+: strt(s), en(e)
+{
+}
+
+void move_object::update_bounding_box(bounding_box *p)
+{
+ p->encompass(strt);
+ p->encompass(en);
+}
+
+void move_object::move_by(const position &a)
+{
+ strt += a;
+ en += a;
+}
+
+graphic_object *object_spec::make_move(position *curpos, direction *dirp)
+{
+ static position last_move;
+ static int have_last_move = 0;
+ *dirp = dir;
+ // No need to look at at since 'at' attribute sets 'from' attribute.
+ position startpos = (flags & HAS_FROM) ? from : *curpos;
+ if (!(flags & HAS_SEGMENT)) {
+ if ((flags & IS_SAME) && have_last_move)
+ segment_pos = last_move;
+ else {
+ switch (dir) {
+ case UP_DIRECTION:
+ segment_pos.y = segment_height;
+ break;
+ case DOWN_DIRECTION:
+ segment_pos.y = -segment_height;
+ break;
+ case LEFT_DIRECTION:
+ segment_pos.x = -segment_width;
+ break;
+ case RIGHT_DIRECTION:
+ segment_pos.x = segment_width;
+ break;
+ default:
+ assert(0);
+ }
+ }
+ }
+ segment_list = new segment(segment_pos, segment_is_absolute, segment_list);
+ // Reverse the segment_list so that it's in forward order.
+ segment *old = segment_list;
+ segment_list = 0;
+ while (old != 0) {
+ segment *tem = old->next;
+ old->next = segment_list;
+ segment_list = old;
+ old = tem;
+ }
+ // Compute the end position.
+ position endpos = startpos;
+ for (segment *s = segment_list; s; s = s->next)
+ if (s->is_absolute)
+ endpos = s->pos;
+ else
+ endpos += s->pos;
+ have_last_move = 1;
+ last_move = endpos - startpos;
+ move_object *p = new move_object(startpos, endpos);
+ *curpos = endpos;
+ return p;
+}
+
+class linear_object : public graphic_object {
+protected:
+ char arrow_at_start;
+ char arrow_at_end;
+ arrow_head_type aht;
+ position strt;
+ position en;
+public:
+ linear_object(const position &s, const position &e);
+ position start() { return strt; }
+ position end() { return en; }
+ void move_by(const position &);
+ void update_bounding_box(bounding_box *) = 0;
+ object_type type() = 0;
+ void add_arrows(int at_start, int at_end, const arrow_head_type &);
+};
+
+class line_object : public linear_object {
+protected:
+ position *v;
+ int n;
+public:
+ line_object(const position &s, const position &e, position *, int);
+ ~line_object();
+ position origin() { return strt; }
+ position center() { return (strt + en)/2.0; }
+ position north() { return (en.y - strt.y) > 0 ? en : strt; }
+ position south() { return (en.y - strt.y) < 0 ? en : strt; }
+ position east() { return (en.x - strt.x) > 0 ? en : strt; }
+ position west() { return (en.x - strt.x) < 0 ? en : strt; }
+ object_type type() { return LINE_OBJECT; }
+ void update_bounding_box(bounding_box *);
+ void print();
+ void move_by(const position &);
+};
+
+class arrow_object : public line_object {
+public:
+ arrow_object(const position &, const position &, position *, int);
+ object_type type() { return ARROW_OBJECT; }
+};
+
+class spline_object : public line_object {
+public:
+ spline_object(const position &, const position &, position *, int);
+ object_type type() { return SPLINE_OBJECT; }
+ void print();
+ void update_bounding_box(bounding_box *);
+};
+
+linear_object::linear_object(const position &s, const position &e)
+: arrow_at_start(0), arrow_at_end(0), strt(s), en(e)
+{
+}
+
+void linear_object::move_by(const position &a)
+{
+ strt += a;
+ en += a;
+}
+
+void linear_object::add_arrows(int at_start, int at_end,
+ const arrow_head_type &a)
+{
+ arrow_at_start = at_start;
+ arrow_at_end = at_end;
+ aht = a;
+}
+
+line_object::line_object(const position &s, const position &e,
+ position *p, int i)
+: linear_object(s, e), v(p), n(i)
+{
+}
+
+void line_object::print()
+{
+ if (lt.type == line_type::invisible)
+ return;
+ out->set_color(0, graphic_object::get_outline_color());
+ // shorten line length to avoid arrow sticking.
+ position sp = strt;
+ if (arrow_at_start) {
+ position base = v[0] - strt;
+ double hyp = hypot(base);
+ if (hyp == 0.0) {
+ error("cannot draw arrow on object with zero length");
+ return;
+ }
+ if (aht.solid && out->supports_filled_polygons()) {
+ base *= aht.height / hyp;
+ draw_arrow(strt, strt - v[0], aht, lt,
+ graphic_object::get_outline_color());
+ sp = strt + base;
+ } else {
+ base *= fabs(lt.thickness) / hyp / 72 / 4;
+ sp = strt + base;
+ draw_arrow(sp, sp - v[0], aht, lt,
+ graphic_object::get_outline_color());
+ }
+ }
+ if (arrow_at_end) {
+ position base = v[n-1] - (n > 1 ? v[n-2] : strt);
+ double hyp = hypot(base);
+ if (hyp == 0.0) {
+ error("cannot draw arrow on object with zero length");
+ return;
+ }
+ if (aht.solid && out->supports_filled_polygons()) {
+ base *= aht.height / hyp;
+ draw_arrow(en, v[n-1] - (n > 1 ? v[n-2] : strt), aht, lt,
+ graphic_object::get_outline_color());
+ v[n-1] = en - base;
+ } else {
+ base *= fabs(lt.thickness) / hyp / 72 / 4;
+ v[n-1] = en - base;
+ draw_arrow(v[n-1], v[n-1] - (n > 1 ? v[n-2] : strt), aht, lt,
+ graphic_object::get_outline_color());
+ }
+ }
+ out->line(sp, v, n, lt);
+ out->reset_color();
+}
+
+void line_object::update_bounding_box(bounding_box *p)
+{
+ p->encompass(strt);
+ for (int i = 0; i < n; i++)
+ p->encompass(v[i]);
+}
+
+void line_object::move_by(const position &pos)
+{
+ linear_object::move_by(pos);
+ for (int i = 0; i < n; i++)
+ v[i] += pos;
+}
+
+void spline_object::update_bounding_box(bounding_box *p)
+{
+ p->encompass(strt);
+ p->encompass(en);
+ /*
+
+ If
+
+ p1 = q1/2 + q2/2
+ p2 = q1/6 + q2*5/6
+ p3 = q2*5/6 + q3/6
+ p4 = q2/2 + q3/2
+ [ the points for the Bezier cubic ]
+
+ and
+
+ t = .5
+
+ then
+
+ (1-t)^3*p1 + 3*t*(t - 1)^2*p2 + 3*t^2*(1-t)*p3 + t^3*p4
+ [ the equation for the Bezier cubic ]
+
+ = .125*q1 + .75*q2 + .125*q3
+
+ */
+ for (int i = 1; i < n; i++)
+ p->encompass((i == 1 ? strt : v[i-2])*.125 + v[i-1]*.75 + v[i]*.125);
+}
+
+arrow_object::arrow_object(const position &s, const position &e,
+ position *p, int i)
+: line_object(s, e, p, i)
+{
+}
+
+spline_object::spline_object(const position &s, const position &e,
+ position *p, int i)
+: line_object(s, e, p, i)
+{
+}
+
+void spline_object::print()
+{
+ if (lt.type == line_type::invisible)
+ return;
+ out->set_color(0, graphic_object::get_outline_color());
+ // shorten line length for spline to avoid arrow sticking
+ position sp = strt;
+ if (arrow_at_start) {
+ position base = v[0] - strt;
+ double hyp = hypot(base);
+ if (hyp == 0.0) {
+ error("cannot draw arrow on object with zero length");
+ return;
+ }
+ if (aht.solid && out->supports_filled_polygons()) {
+ base *= aht.height / hyp;
+ draw_arrow(strt, strt - v[0], aht, lt,
+ graphic_object::get_outline_color());
+ sp = strt + base*0.1; // to reserve spline shape
+ } else {
+ base *= fabs(lt.thickness) / hyp / 72 / 4;
+ sp = strt + base;
+ draw_arrow(sp, sp - v[0], aht, lt,
+ graphic_object::get_outline_color());
+ }
+ }
+ if (arrow_at_end) {
+ position base = v[n-1] - (n > 1 ? v[n-2] : strt);
+ double hyp = hypot(base);
+ if (hyp == 0.0) {
+ error("cannot draw arrow on object with zero length");
+ return;
+ }
+ if (aht.solid && out->supports_filled_polygons()) {
+ base *= aht.height / hyp;
+ draw_arrow(en, v[n-1] - (n > 1 ? v[n-2] : strt), aht, lt,
+ graphic_object::get_outline_color());
+ v[n-1] = en - base*0.1; // to reserve spline shape
+ } else {
+ base *= fabs(lt.thickness) / hyp / 72 / 4;
+ v[n-1] = en - base;
+ draw_arrow(v[n-1], v[n-1] - (n > 1 ? v[n-2] : strt), aht, lt,
+ graphic_object::get_outline_color());
+ }
+ }
+ out->spline(sp, v, n, lt);
+ out->reset_color();
+}
+
+line_object::~line_object()
+{
+ delete[] v;
+}
+
+linear_object *object_spec::make_line(position *curpos, direction *dirp)
+{
+ static position last_line;
+ static int have_last_line = 0;
+ *dirp = dir;
+ // We handle 'at' only in conjunction with 'with', otherwise it is
+ // the same as the 'from' attribute.
+ position startpos;
+ if ((flags & HAS_AT) && (flags & HAS_WITH))
+ // handled later -- we need the end position
+ startpos = *curpos;
+ else if (flags & HAS_FROM)
+ startpos = from;
+ else
+ startpos = *curpos;
+ if (!(flags & HAS_SEGMENT)) {
+ if ((flags & IS_SAME) && (type == LINE_OBJECT || type == ARROW_OBJECT)
+ && have_last_line)
+ segment_pos = last_line;
+ else
+ switch (dir) {
+ case UP_DIRECTION:
+ segment_pos.y = segment_height;
+ break;
+ case DOWN_DIRECTION:
+ segment_pos.y = -segment_height;
+ break;
+ case LEFT_DIRECTION:
+ segment_pos.x = -segment_width;
+ break;
+ case RIGHT_DIRECTION:
+ segment_pos.x = segment_width;
+ break;
+ default:
+ assert(0);
+ }
+ }
+ segment_list = new segment(segment_pos, segment_is_absolute, segment_list);
+ // reverse the segment_list so that it's in forward order
+ segment *old = segment_list;
+ segment_list = 0;
+ while (old != 0) {
+ segment *tem = old->next;
+ old->next = segment_list;
+ segment_list = old;
+ old = tem;
+ }
+ // Absolutise all movements
+ position endpos = startpos;
+ int nsegments = 0;
+ segment *s;
+ for (s = segment_list; s; s = s->next, nsegments++)
+ if (s->is_absolute)
+ endpos = s->pos;
+ else {
+ endpos += s->pos;
+ s->pos = endpos;
+ s->is_absolute = 1; // to avoid confusion
+ }
+ if ((flags & HAS_AT) && (flags & HAS_WITH)) {
+ // 'tmpobj' works for arrows and splines too -- we only need positions
+ line_object tmpobj(startpos, endpos, 0, 0);
+ position pos = at;
+ place offset;
+ place here;
+ here.obj = &tmpobj;
+ if (!with->follow(here, &offset))
+ return 0;
+ pos -= offset;
+ for (s = segment_list; s; s = s->next)
+ s->pos += pos;
+ startpos += pos;
+ endpos += pos;
+ }
+ // handle chop
+ line_object *p = 0;
+ position *v = new position[nsegments];
+ int i = 0;
+ for (s = segment_list; s; s = s->next, i++)
+ v[i] = s->pos;
+ if (flags & IS_DEFAULT_CHOPPED) {
+ lookup_variable("circlerad", &start_chop);
+ end_chop = start_chop;
+ flags |= IS_CHOPPED;
+ }
+ if (flags & IS_CHOPPED) {
+ position start_chop_vec, end_chop_vec;
+ if (start_chop != 0.0) {
+ start_chop_vec = v[0] - startpos;
+ start_chop_vec *= start_chop / hypot(start_chop_vec);
+ }
+ if (end_chop != 0.0) {
+ end_chop_vec = (v[nsegments - 1]
+ - (nsegments > 1 ? v[nsegments - 2] : startpos));
+ end_chop_vec *= end_chop / hypot(end_chop_vec);
+ }
+ startpos += start_chop_vec;
+ v[nsegments - 1] -= end_chop_vec;
+ endpos -= end_chop_vec;
+ }
+ switch (type) {
+ case SPLINE_OBJECT:
+ p = new spline_object(startpos, endpos, v, nsegments);
+ break;
+ case ARROW_OBJECT:
+ p = new arrow_object(startpos, endpos, v, nsegments);
+ break;
+ case LINE_OBJECT:
+ p = new line_object(startpos, endpos, v, nsegments);
+ break;
+ default:
+ assert(0);
+ }
+ have_last_line = 1;
+ last_line = endpos - startpos;
+ *curpos = endpos;
+ return p;
+}
+
+class arc_object : public linear_object {
+ int clockwise;
+ position cent;
+ double rad;
+public:
+ arc_object(int, const position &, const position &, const position &);
+ position origin() { return cent; }
+ position center() { return cent; }
+ double radius() { return rad; }
+ position north();
+ position south();
+ position east();
+ position west();
+ position north_east();
+ position north_west();
+ position south_east();
+ position south_west();
+ void update_bounding_box(bounding_box *);
+ object_type type() { return ARC_OBJECT; }
+ void print();
+ void move_by(const position &pos);
+};
+
+arc_object::arc_object(int cw, const position &s, const position &e,
+ const position &c)
+: linear_object(s, e), clockwise(cw), cent(c)
+{
+ rad = hypot(c - s);
+}
+
+void arc_object::move_by(const position &pos)
+{
+ linear_object::move_by(pos);
+ cent += pos;
+}
+
+// we get arc corners from the corresponding circle
+
+position arc_object::north()
+{
+ position result(cent);
+ result.y += rad;
+ return result;
+}
+
+position arc_object::south()
+{
+ position result(cent);
+ result.y -= rad;
+ return result;
+}
+
+position arc_object::east()
+{
+ position result(cent);
+ result.x += rad;
+ return result;
+}
+
+position arc_object::west()
+{
+ position result(cent);
+ result.x -= rad;
+ return result;
+}
+
+position arc_object::north_east()
+{
+ position result(cent);
+ result.x += rad/M_SQRT2;
+ result.y += rad/M_SQRT2;
+ return result;
+}
+
+position arc_object::north_west()
+{
+ position result(cent);
+ result.x -= rad/M_SQRT2;
+ result.y += rad/M_SQRT2;
+ return result;
+}
+
+position arc_object::south_east()
+{
+ position result(cent);
+ result.x += rad/M_SQRT2;
+ result.y -= rad/M_SQRT2;
+ return result;
+}
+
+position arc_object::south_west()
+{
+ position result(cent);
+ result.x -= rad/M_SQRT2;
+ result.y -= rad/M_SQRT2;
+ return result;
+}
+
+
+void arc_object::print()
+{
+ if (lt.type == line_type::invisible)
+ return;
+ out->set_color(0, graphic_object::get_outline_color());
+ // handle arrow direction; make shorter line for arc
+ position sp, ep, b;
+ if (clockwise) {
+ sp = en;
+ ep = strt;
+ } else {
+ sp = strt;
+ ep = en;
+ }
+ if (arrow_at_start) {
+ double theta = aht.height / rad;
+ if (clockwise)
+ theta = - theta;
+ b = strt - cent;
+ b = position(b.x*cos(theta) - b.y*sin(theta),
+ b.x*sin(theta) + b.y*cos(theta)) + cent;
+ if (clockwise)
+ ep = b;
+ else
+ sp = b;
+ if (aht.solid && out->supports_filled_polygons()) {
+ draw_arrow(strt, strt - b, aht, lt,
+ graphic_object::get_outline_color());
+ } else {
+ position v = b;
+ theta = fabs(lt.thickness) / 72 / 4 / rad;
+ if (clockwise)
+ theta = - theta;
+ b = strt - cent;
+ b = position(b.x*cos(theta) - b.y*sin(theta),
+ b.x*sin(theta) + b.y*cos(theta)) + cent;
+ draw_arrow(b, b - v, aht, lt,
+ graphic_object::get_outline_color());
+ out->line(b, &v, 1, lt);
+ }
+ }
+ if (arrow_at_end) {
+ double theta = aht.height / rad;
+ if (!clockwise)
+ theta = - theta;
+ b = en - cent;
+ b = position(b.x*cos(theta) - b.y*sin(theta),
+ b.x*sin(theta) + b.y*cos(theta)) + cent;
+ if (clockwise)
+ sp = b;
+ else
+ ep = b;
+ if (aht.solid && out->supports_filled_polygons()) {
+ draw_arrow(en, en - b, aht, lt,
+ graphic_object::get_outline_color());
+ } else {
+ position v = b;
+ theta = fabs(lt.thickness) / 72 / 4 / rad;
+ if (!clockwise)
+ theta = - theta;
+ b = en - cent;
+ b = position(b.x*cos(theta) - b.y*sin(theta),
+ b.x*sin(theta) + b.y*cos(theta)) + cent;
+ draw_arrow(b, b - v, aht, lt,
+ graphic_object::get_outline_color());
+ out->line(b, &v, 1, lt);
+ }
+ }
+ out->arc(sp, cent, ep, lt);
+ out->reset_color();
+}
+
+inline double max(double a, double b)
+{
+ return a > b ? a : b;
+}
+
+void arc_object::update_bounding_box(bounding_box *p)
+{
+ p->encompass(strt);
+ p->encompass(en);
+ position start_offset = strt - cent;
+ if (start_offset.x == 0.0 && start_offset.y == 0.0)
+ return;
+ position end_offset = en - cent;
+ if (end_offset.x == 0.0 && end_offset.y == 0.0)
+ return;
+ double start_quad = atan2(start_offset.y, start_offset.x)/(M_PI/2.0);
+ double end_quad = atan2(end_offset.y, end_offset.x)/(M_PI/2.0);
+ if (clockwise) {
+ double temp = start_quad;
+ start_quad = end_quad;
+ end_quad = temp;
+ }
+ if (start_quad < 0.0)
+ start_quad += 4.0;
+ while (end_quad <= start_quad)
+ end_quad += 4.0;
+ double r = max(hypot(start_offset), hypot(end_offset));
+ for (int q = int(start_quad) + 1; q < end_quad; q++) {
+ position offset;
+ switch (q % 4) {
+ case 0:
+ offset.x = r;
+ break;
+ case 1:
+ offset.y = r;
+ break;
+ case 2:
+ offset.x = -r;
+ break;
+ case 3:
+ offset.y = -r;
+ break;
+ }
+ p->encompass(cent + offset);
+ }
+}
+
+// We ignore the with attribute. The at attribute always refers to the center.
+
+linear_object *object_spec::make_arc(position *curpos, direction *dirp)
+{
+ *dirp = dir;
+ int cw = (flags & IS_CLOCKWISE) != 0;
+ // compute the start
+ position startpos;
+ if (flags & HAS_FROM)
+ startpos = from;
+ else
+ startpos = *curpos;
+ if (!(flags & HAS_RADIUS))
+ lookup_variable("arcrad", &radius);
+ // compute the end
+ position endpos;
+ if (flags & HAS_TO)
+ endpos = to;
+ else {
+ position m(radius, radius);
+ // Adjust the signs.
+ if (cw) {
+ if (dir == DOWN_DIRECTION || dir == LEFT_DIRECTION)
+ m.x = -m.x;
+ if (dir == DOWN_DIRECTION || dir == RIGHT_DIRECTION)
+ m.y = -m.y;
+ *dirp = direction((dir + 3) % 4);
+ }
+ else {
+ if (dir == UP_DIRECTION || dir == LEFT_DIRECTION)
+ m.x = -m.x;
+ if (dir == DOWN_DIRECTION || dir == LEFT_DIRECTION)
+ m.y = -m.y;
+ *dirp = direction((dir + 1) % 4);
+ }
+ endpos = startpos + m;
+ }
+ // compute the center
+ position centerpos;
+ if (flags & HAS_AT)
+ centerpos = at;
+ else if (startpos == endpos)
+ centerpos = startpos;
+ else {
+ position h = (endpos - startpos)/2.0;
+ double d = hypot(h);
+ if (radius <= 0)
+ radius = .25;
+ // make the radius big enough
+ if (radius < d)
+ radius = d;
+ double alpha = acos(d/radius);
+ double theta = atan2(h.y, h.x);
+ if (cw)
+ theta -= alpha;
+ else
+ theta += alpha;
+ centerpos = position(cos(theta), sin(theta))*radius + startpos;
+ }
+ arc_object *p = new arc_object(cw, startpos, endpos, centerpos);
+ *curpos = endpos;
+ return p;
+}
+
+graphic_object *object_spec::make_linear(position *curpos, direction *dirp)
+{
+ linear_object *obj;
+ if (type == ARC_OBJECT)
+ obj = make_arc(curpos, dirp);
+ else
+ obj = make_line(curpos, dirp);
+ if (type == ARROW_OBJECT
+ && (flags & (HAS_LEFT_ARROW_HEAD|HAS_RIGHT_ARROW_HEAD)) == 0)
+ flags |= HAS_RIGHT_ARROW_HEAD;
+ if (obj && (flags & (HAS_LEFT_ARROW_HEAD|HAS_RIGHT_ARROW_HEAD))) {
+ arrow_head_type a;
+ int at_start = (flags & HAS_LEFT_ARROW_HEAD) != 0;
+ int at_end = (flags & HAS_RIGHT_ARROW_HEAD) != 0;
+ if (flags & HAS_HEIGHT)
+ a.height = height;
+ else
+ lookup_variable("arrowht", &a.height);
+ if (flags & HAS_WIDTH)
+ a.width = width;
+ else
+ lookup_variable("arrowwid", &a.width);
+ double solid;
+ lookup_variable("arrowhead", &solid);
+ a.solid = solid != 0.0;
+ obj->add_arrows(at_start, at_end, a);
+ }
+ return obj;
+}
+
+object *object_spec::make_object(position *curpos, direction *dirp)
+{
+ graphic_object *obj = 0;
+ switch (type) {
+ case BLOCK_OBJECT:
+ obj = make_block(curpos, dirp);
+ break;
+ case BOX_OBJECT:
+ obj = make_box(curpos, dirp);
+ break;
+ case TEXT_OBJECT:
+ obj = make_text(curpos, dirp);
+ break;
+ case ELLIPSE_OBJECT:
+ obj = make_ellipse(curpos, dirp);
+ break;
+ case CIRCLE_OBJECT:
+ obj = make_circle(curpos, dirp);
+ break;
+ case MOVE_OBJECT:
+ obj = make_move(curpos, dirp);
+ break;
+ case ARC_OBJECT:
+ case LINE_OBJECT:
+ case SPLINE_OBJECT:
+ case ARROW_OBJECT:
+ obj = make_linear(curpos, dirp);
+ break;
+ case MARK_OBJECT:
+ case OTHER_OBJECT:
+ default:
+ assert(0);
+ break;
+ }
+ if (obj) {
+ if (flags & IS_INVISIBLE)
+ obj->set_invisible();
+ if (text != 0)
+ obj->add_text(text, (flags & IS_ALIGNED) != 0);
+ if (flags & IS_DOTTED)
+ obj->set_dotted(dash_width);
+ else if (flags & IS_DASHED)
+ obj->set_dashed(dash_width);
+ double th;
+ if (flags & HAS_THICKNESS)
+ th = thickness;
+ else
+ lookup_variable("linethick", &th);
+ obj->set_thickness(th);
+ if (flags & IS_OUTLINED)
+ obj->set_outline_color(outlined);
+ if (flags & IS_XSLANTED)
+ obj->set_xslanted(xslanted);
+ if (flags & IS_YSLANTED)
+ obj->set_yslanted(yslanted);
+ if (flags & (IS_DEFAULT_FILLED | IS_FILLED)) {
+ if (flags & IS_SHADED)
+ obj->set_fill_color(shaded);
+ else {
+ if (flags & IS_DEFAULT_FILLED)
+ lookup_variable("fillval", &fill);
+ if (fill < 0.0)
+ error("bad fill value %1", fill);
+ else
+ obj->set_fill(fill);
+ }
+ }
+ }
+ return obj;
+}
+
+struct string_list {
+ string_list *next;
+ char *str;
+ string_list(char *);
+ ~string_list();
+};
+
+string_list::string_list(char *s)
+: next(0), str(s)
+{
+}
+
+string_list::~string_list()
+{
+ free(str);
+}
+
+/* A path is used to hold the argument to the 'with' attribute. For
+ example, '.nw' or '.A.s' or '.A'. The major operation on a path is to
+ take a place and follow the path through the place to place within the
+ place. Note that '.A.B.C.sw' will work.
+
+ For compatibility with DWB pic, 'with' accepts positions also (this
+ is incorrectly documented in CSTR 116). */
+
+path::path(corner c)
+: crn(c), label_list(0), ypath(0), is_position(0)
+{
+}
+
+path::path(position p)
+: crn(0), label_list(0), ypath(0), is_position(1)
+{
+ pos.x = p.x;
+ pos.y = p.y;
+}
+
+path::path(char *l, corner c)
+: crn(c), ypath(0), is_position(0)
+{
+ label_list = new string_list(l);
+}
+
+path::~path()
+{
+ while (label_list) {
+ string_list *tem = label_list;
+ label_list = label_list->next;
+ delete tem;
+ }
+ delete ypath;
+}
+
+void path::append(corner c)
+{
+ assert(crn == 0);
+ crn = c;
+}
+
+void path::append(char *s)
+{
+ string_list **p;
+ for (p = &label_list; *p; p = &(*p)->next)
+ ;
+ *p = new string_list(s);
+}
+
+void path::set_ypath(path *p)
+{
+ ypath = p;
+}
+
+// return non-zero for success
+
+int path::follow(const place &pl, place *result) const
+{
+ if (is_position) {
+ result->x = pos.x;
+ result->y = pos.y;
+ result->obj = 0;
+ return 1;
+ }
+ const place *p = &pl;
+ for (string_list *lb = label_list; lb; lb = lb->next)
+ if (p->obj == 0 || (p = p->obj->find_label(lb->str)) == 0) {
+ lex_error("object does not contain a place '%1'", lb->str);
+ return 0;
+ }
+ if (crn == 0 || p->obj == 0)
+ *result = *p;
+ else {
+ position ps = ((p->obj)->*(crn))();
+ result->x = ps.x;
+ result->y = ps.y;
+ result->obj = 0;
+ }
+ if (ypath) {
+ place tem;
+ if (!ypath->follow(pl, &tem))
+ return 0;
+ result->y = tem.y;
+ if (result->obj != tem.obj)
+ result->obj = 0;
+ }
+ return 1;
+}
+
+void print_object_list(object *p)
+{
+ for (; p; p = p->next) {
+ p->print();
+ p->print_text();
+ }
+}
+
+void print_picture(object *obj)
+{
+ bounding_box bb;
+ for (object *p = obj; p; p = p->next)
+ p->update_bounding_box(&bb);
+ double scale;
+ lookup_variable("scale", &scale);
+ out->start_picture(scale, bb.ll, bb.ur);
+ print_object_list(obj);
+ out->finish_picture();
+}
+
diff --git a/src/preproc/pic/object.h b/src/preproc/pic/object.h
new file mode 100644
index 0000000..e39b6a6
--- /dev/null
+++ b/src/preproc/pic/object.h
@@ -0,0 +1,227 @@
+// -*- C++ -*-
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+ Written by James Clark (jjc@jclark.com)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+groff is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+struct place;
+
+enum object_type {
+ OTHER_OBJECT,
+ BOX_OBJECT,
+ CIRCLE_OBJECT,
+ ELLIPSE_OBJECT,
+ ARC_OBJECT,
+ SPLINE_OBJECT,
+ LINE_OBJECT,
+ ARROW_OBJECT,
+ MOVE_OBJECT,
+ TEXT_OBJECT,
+ BLOCK_OBJECT,
+ MARK_OBJECT
+ };
+
+struct bounding_box;
+
+struct object {
+ object *prev;
+ object *next;
+ object();
+ virtual ~object();
+ virtual position origin();
+ virtual double width();
+ virtual double radius();
+ virtual double height();
+ virtual position north();
+ virtual position south();
+ virtual position east();
+ virtual position west();
+ virtual position north_east();
+ virtual position north_west();
+ virtual position south_east();
+ virtual position south_west();
+ virtual position start();
+ virtual position end();
+ virtual position center();
+ virtual place *find_label(const char *);
+ virtual void move_by(const position &);
+ virtual int blank();
+ virtual void update_bounding_box(bounding_box *);
+ virtual object_type type() = 0;
+ virtual void print();
+ virtual void print_text();
+};
+
+typedef position (object::*corner)();
+
+struct place {
+ object *obj;
+ double x, y;
+};
+
+struct string_list;
+
+class path {
+ position pos;
+ corner crn;
+ string_list *label_list;
+ path *ypath;
+ int is_position;
+public:
+ path(corner = 0);
+ path(position);
+ path(char *, corner = 0);
+ ~path();
+ void append(corner);
+ void append(char *);
+ void set_ypath(path *);
+ int follow(const place &, place *) const;
+};
+
+struct object_list {
+ object *head;
+ object *tail;
+ object_list();
+ void append(object *);
+ void wrap_up_block(object_list *);
+};
+
+declare_ptable(place)
+
+// these go counterclockwise
+enum direction {
+ RIGHT_DIRECTION,
+ UP_DIRECTION,
+ LEFT_DIRECTION,
+ DOWN_DIRECTION
+ };
+
+struct graphics_state {
+ double x, y;
+ direction dir;
+};
+
+struct saved_state : public graphics_state {
+ saved_state *prev;
+ PTABLE(place) *tbl;
+};
+
+
+struct text_item {
+ text_item *next;
+ char *text;
+ adjustment adj;
+ const char *filename;
+ int lineno;
+
+ text_item(char *, const char *, int);
+ ~text_item();
+};
+
+const unsigned long IS_DOTTED = 01;
+const unsigned long IS_DASHED = 02;
+const unsigned long IS_CLOCKWISE = 04;
+const unsigned long IS_INVISIBLE = 020;
+const unsigned long HAS_LEFT_ARROW_HEAD = 040;
+const unsigned long HAS_RIGHT_ARROW_HEAD = 0100;
+const unsigned long HAS_SEGMENT = 0200;
+const unsigned long IS_SAME = 0400;
+const unsigned long HAS_FROM = 01000;
+const unsigned long HAS_AT = 02000;
+const unsigned long HAS_WITH = 04000;
+const unsigned long HAS_HEIGHT = 010000;
+const unsigned long HAS_WIDTH = 020000;
+const unsigned long HAS_RADIUS = 040000;
+const unsigned long HAS_TO = 0100000;
+const unsigned long IS_CHOPPED = 0200000;
+const unsigned long IS_DEFAULT_CHOPPED = 0400000;
+const unsigned long HAS_THICKNESS = 01000000;
+const unsigned long IS_FILLED = 02000000;
+const unsigned long IS_DEFAULT_FILLED = 04000000;
+const unsigned long IS_ALIGNED = 010000000;
+const unsigned long IS_SHADED = 020000000;
+const unsigned long IS_OUTLINED = 040000000;
+const unsigned long IS_XSLANTED = 0100000000;
+const unsigned long IS_YSLANTED = 0200000000;
+
+struct segment {
+ int is_absolute;
+ position pos;
+ segment *next;
+ segment(const position &, int, segment *);
+};
+
+class rectangle_object;
+class graphic_object;
+class linear_object;
+
+struct object_spec {
+ unsigned long flags;
+ object_type type;
+ object_list oblist;
+ PTABLE(place) *tbl;
+ double dash_width;
+ position from;
+ position to;
+ position at;
+ position by;
+ path *with;
+ text_item *text;
+ double height;
+ double radius;
+ double width;
+ double segment_width;
+ double segment_height;
+ double start_chop;
+ double end_chop;
+ double thickness;
+ double fill;
+ double xslanted;
+ double yslanted;
+ char *shaded;
+ char *outlined;
+ direction dir;
+ segment *segment_list;
+ position segment_pos;
+ int segment_is_absolute;
+
+ object_spec(object_type);
+ ~object_spec();
+ object *make_object(position *, direction *);
+ graphic_object *make_box(position *, direction *);
+ graphic_object *make_block(position *, direction *);
+ graphic_object *make_text(position *, direction *);
+ graphic_object *make_ellipse(position *, direction *);
+ graphic_object *make_circle(position *, direction *);
+ linear_object *make_line(position *, direction *);
+ linear_object *make_arc(position *, direction *);
+ graphic_object *make_linear(position *, direction *);
+ graphic_object *make_move(position *, direction *);
+ int position_rectangle(rectangle_object *p, position *curpos,
+ direction *dirp);
+};
+
+
+object *make_object(object_spec *, position *, direction *);
+
+object *make_mark_object();
+object *make_command_object(char *, const char *, int);
+
+int lookup_variable(const char *name, double *val);
+void define_variable(const char *name, double val);
+
+void print_picture(object *);
+
diff --git a/src/preproc/pic/output.h b/src/preproc/pic/output.h
new file mode 100644
index 0000000..f01e0a1
--- /dev/null
+++ b/src/preproc/pic/output.h
@@ -0,0 +1,82 @@
+// -*- C++ -*-
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+ Written by James Clark (jjc@jclark.com)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+groff is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+struct line_type {
+ enum { invisible, solid, dotted, dashed } type;
+ double dash_width;
+ double thickness; // the thickness is in points
+
+ line_type();
+};
+
+
+class output {
+protected:
+ char *args;
+ double desired_height; // zero if no height specified
+ double desired_width; // zero if no depth specified
+ double compute_scale(double, const position &, const position &);
+public:
+ output();
+ virtual ~output();
+ void set_desired_width_height(double wid, double ht);
+ void set_args(const char *);
+ virtual void start_picture(double sc, const position &ll, const position &ur) = 0;
+ virtual void finish_picture() = 0;
+ virtual void circle(const position &, double rad,
+ const line_type &, double) = 0;
+ virtual void text(const position &, text_piece *, int, double) = 0;
+ virtual void line(const position &, const position *, int n,
+ const line_type &) = 0;
+ virtual void polygon(const position *, int n,
+ const line_type &, double) = 0;
+ virtual void spline(const position &, const position *, int n,
+ const line_type &) = 0;
+ virtual void arc(const position &, const position &, const position &,
+ const line_type &) = 0;
+ virtual void ellipse(const position &, const distance &,
+ const line_type &, double) = 0;
+ virtual void rounded_box(const position &, const distance &, double,
+ const line_type &, double, char *) = 0;
+ virtual void command(const char *, const char *, int) = 0;
+ virtual void set_location(const char *, int) {}
+ virtual void set_color(char *, char *) = 0;
+ virtual void reset_color() = 0;
+ virtual char *get_last_filled() = 0;
+ virtual char *get_outline_color() = 0;
+ virtual int supports_filled_polygons();
+ virtual void begin_block(const position &ll, const position &ur);
+ virtual void end_block();
+};
+
+extern output *out;
+
+/* #define FIG_SUPPORT 1 */
+#define TEX_SUPPORT 1
+
+output *make_troff_output();
+
+#ifdef TEX_SUPPORT
+output *make_tex_output();
+output *make_tpic_output();
+#endif /* TEX_SUPPORT */
+
+#ifdef FIG_SUPPORT
+output *make_fig_output();
+#endif /* FIG_SUPPORT */
diff --git a/src/preproc/pic/pic.1.man b/src/preproc/pic/pic.1.man
new file mode 100644
index 0000000..727cbc3
--- /dev/null
+++ b/src/preproc/pic/pic.1.man
@@ -0,0 +1,1569 @@
+.TH @g@pic @MAN1EXT@ "@MDATE@" "groff @VERSION@"
+.SH Name
+@g@pic \- compile pictures for
+.I troff
+or TeX
+.
+.
+.\" ====================================================================
+.\" Legal Terms
+.\" ====================================================================
+.\"
+.\" Copyright (C) 1989-2020 Free Software Foundation, Inc.
+.\"
+.\" Permission is granted to make and distribute verbatim copies of this
+.\" manual provided the copyright notice and this permission notice are
+.\" preserved on all copies.
+.\"
+.\" Permission is granted to copy and distribute modified versions of
+.\" this manual under the conditions for verbatim copying, provided that
+.\" the entire resulting derived work is distributed under the terms of
+.\" a permission notice identical to this one.
+.\"
+.\" Permission is granted to copy and distribute translations of this
+.\" manual into another language, under the above conditions for
+.\" modified versions, except that this permission notice may be
+.\" included in translations approved by the Free Software Foundation
+.\" instead of in the original English.
+.
+.
+.\" Save and disable compatibility mode (for, e.g., Solaris 10/11).
+.do nr *groff_pic_1_man_C \n[.cp]
+.cp 0
+.
+.\" Define fallback for groff 1.23's MR macro if the system lacks it.
+.nr do-fallback 0
+.if !\n(.f .nr do-fallback 1 \" mandoc
+.if \n(.g .if !d MR .nr do-fallback 1 \" older groff
+.if !\n(.g .nr do-fallback 1 \" non-groff *roff
+.if \n[do-fallback] \{\
+. de MR
+. ie \\n(.$=1 \
+. I \%\\$1
+. el \
+. IR \%\\$1 (\\$2)\\$3
+. .
+.\}
+.rr do-fallback
+.
+.
+.\" ====================================================================
+.\" Definitions
+.\" ====================================================================
+.
+.ie t \{\
+. ds tx T\h'-.1667m'\v'.224m'E\v'-.224m'\h'-.125m'X
+. ds lx L\h'-0.36m'\v'-0.22v'\s-2A\s0\h'-0.15m'\v'0.22v'\*[tx]
+.\}
+.el \{\
+. ds tx TeX
+. ds lx LaTeX
+.\}
+.
+.ie \n(.g .ds ic \/
+.el .ds ic \^
+.
+.
+.\" ====================================================================
+.SH Synopsis
+.\" ====================================================================
+.
+.SY @g@pic
+.RB [ \-CnSU ]
+.RI [ file\~ .\|.\|.]
+.YS
+.
+.
+.SY @g@pic
+.B \-t
+.RB [ \-cCSUz ]
+.RI [ file\~ .\|.\|.]
+.YS
+.
+.
+.SY @g@pic
+.B \-\-help
+.YS
+.
+.
+.SY @g@pic
+.B \-v
+.
+.SY @g@pic
+.B \-\-version
+.YS
+.
+.
+.\" ====================================================================
+.SH Description
+.\" ====================================================================
+.
+The GNU implementation of
+.I pic \" generic
+is part of the
+.MR groff @MAN1EXT@
+document formatting system.
+.
+.I @g@pic
+is a
+.MR @g@troff @MAN1EXT@
+preprocessor that translates descriptions of diagrammatic pictures
+embedded in
+.MR roff @MAN7EXT@
+or \*[tx] input files into the language understood by \*[tx] or
+.IR @g@troff .
+.
+It copies the contents of each
+.I file
+to the standard output stream,
+except that lines between
+.B .PS
+and any of
+.BR .PE ,
+.BR .PF ,
+or
+.B .PY
+are interpreted as picture descriptions in the
+.I pic
+language.
+.
+End a
+.I @g@pic
+picture with
+.B .PE
+to leave the drawing position at the bottom of the picture,
+and with
+.B .PF
+or
+.B .PY
+to leave it at the top.
+.
+Normally,
+.I @g@pic
+is not executed directly by the user,
+but invoked by specifying the
+.B \-p
+option to
+.MR groff @MAN1EXT@ .
+.
+If no
+.I file
+operands are given on the command line,
+or if
+.I file
+is
+.RB \[lq] \- \[rq],
+the standard input stream is read.
+.
+.
+.P
+It is the user's responsibility to provide appropriate definitions
+of the
+.BR PS ,
+.BR PE ,
+and one or both of the
+.B PF
+and
+.B PY
+macros.
+.
+When a macro package does not supply these,
+obtain simple definitions with the
+.I groff
+option
+.BR \-mpic ;
+these will center each picture.
+.
+.
+.P
+GNU
+.I pic \" GNU
+supports
+.B PY
+as a synonym of
+.B PF
+to work around a name space collision with the
+.I mm
+macro package,
+which defines
+.B PF
+as a page footer management macro.
+.
+Use
+.B PF
+preferentially unless a similar problem faces your document.
+.
+.
+.\" ====================================================================
+.SH Options
+.\" ====================================================================
+.
+.B \-\-help
+displays a usage message,
+while
+.B \-v
+and
+.B \-\-version
+show version information;
+all exit afterward.
+.
+.
+.TP
+.B \-c
+Be more compatible with
+.IR tpic ;
+implies
+.BR \-t .
+.
+Lines beginning with
+.B \[rs]
+are not passed through transparently.
+.
+Lines beginning with
+.B .\&
+are passed through with the initial
+.B .\&
+changed to
+.BR \[rs] .
+.
+A line beginning with
+.B .ps
+is given special treatment:
+it takes an optional integer argument specifying the line thickness
+(pen size)
+in milliinches;
+a missing argument restores the previous line thickness;
+the default line thickness is 8\~milliinches.
+.
+The line thickness thus specified takes effect only when a
+non-negative line thickness has not been specified by use of the
+.B \%thickness
+attribute or by setting the
+.B \%linethick
+variable.
+.
+.
+.TP
+.B \-C
+Recognize
+.BR .PS ,
+.BR .PE ,
+.BR .PF ,
+and
+.B .PY
+even when followed by a character other than space or newline.
+.
+.
+.TP
+.B \-n
+Don't use
+.I groff
+extensions to the
+.I troff \" generic
+drawing commands.
+.
+Specify this option if a postprocessor you're using doesn't support
+these extensions,
+described in
+.MR groff_out @MAN5EXT@ .
+.
+This option also causes
+.I @g@pic
+not to use zero-length lines to draw dots in
+.I troff \" generic
+mode.
+.
+.
+.TP
+.B \-S
+Operate in
+.I safer mode;
+.B sh
+commands are ignored.
+.
+This mode,
+enabled by default,
+can be useful when operating on untrustworthy input.
+.
+.
+.TP
+.B \-t
+Produce \*[tx] output.
+.
+.
+.TP
+.B \-U
+Operate in
+.I unsafe mode;
+.B sh
+commands are interpreted.
+.
+.
+.TP
+.B \-z
+In \*[tx] mode,
+draw dots using zero-length lines.
+.
+.
+.P
+The following options supported by other versions of
+.I pic \" generic
+are ignored.
+.
+.
+.TP
+.B \-D
+Draw all lines using the \[rs]D escape sequence.
+GNU
+.I pic \" GNU
+always does this.
+.
+.TP
+.BI \-T\~ dev
+Generate output for the
+.I troff \" generic
+device
+.IR dev .
+.
+This is unnecessary because the
+.I troff \" generic
+output generated by
+GNU
+.I pic \" GNU
+is device-independent.
+.
+.
+.\" ====================================================================
+.SH Usage
+.\" ====================================================================
+.
+This section primarily discusses the differences between GNU
+.I pic \" GNU
+and the Eighth Edition Research Unix version of AT&T
+.I pic \" AT&T
+(1985).
+.
+Many of these differences also apply to later versions of AT&T
+.IR pic .
+.
+.
+.\" ====================================================================
+.SS "\*[tx] mode"
+.\" ====================================================================
+.
+\*[tx]-compatible output is produced when the
+.B \-t
+option is specified.
+.
+You must use a \*[tx] driver that supports
+.I tpic
+version 2 specials.
+.
+.RI ( tpic
+was a fork of AT&T
+.I pic \" AT&T
+by Tim Morgan of the University of California at Irvine that diverged
+from its source around 1984.
+.
+It is best known today for lending its name to a group of
+.B \[rs]special
+commands it produced for \*[tx].)
+.\" http://ftp.cs.stanford.edu/tex/texhax/texhax90.019
+.
+.
+.P
+Lines beginning with
+.B \[rs]
+are passed through transparently;
+a
+.B %
+is added to the end of the line to avoid unwanted spaces.
+.
+You can safely use this feature to change fonts or the value of
+.BR \[rs]baselineskip .
+.
+Anything else may well produce undesirable results;
+use at your own risk.
+.
+By default,
+lines beginning with a dot are not treated specially\[em]but see the
+.B \-c
+option.
+.
+.
+.P
+In \*[tx] mode,
+.I @g@pic
+will define a vbox called
+.B \[rs]graph
+for each picture.
+.
+Use GNU
+.IR pic 's \" GNU
+.B figname
+command to change the name of the vbox.
+.
+You must print that vbox yourself using the command
+.
+.RS
+.EX
+\[rs]centerline{\[rs]box\[rs]graph}
+.EE
+.RE
+.
+for instance.
+.
+Since the vbox has a height of zero
+(it is defined with
+.BR \[rs]vtop )
+this will produce slightly more vertical space above the picture than
+below it;
+.
+.RS
+.EX
+\[rs]centerline{\[rs]raise 1em\[rs]box\[rs]graph}
+.EE
+.RE
+.
+would avoid this.
+.
+To give the vbox a positive height and a depth of zero
+(as used by \*[lx]'s
+.IR \%graphics.sty ,
+for example)
+define the following macro in your document.
+.
+.RS
+.EX
+\[rs]def\[rs]gpicbox#1{%
+ \[rs]vbox{\[rs]unvbox\[rs]csname #1\[rs]endcsname\[rs]kern 0pt}}
+.EE
+.RE
+.
+You can then simply say
+.B \[rs]gpicbox{graph}
+instead of
+.BR \[rs]box\[rs]graph .
+.
+.
+.\" ====================================================================
+.SS Commands
+.\" ====================================================================
+.
+Several commands new to GNU
+.I pic \" GNU
+accept delimiters,
+shown in their synopses as braces
+.BR "{ }" .
+.
+Nesting of braces is supported.
+.
+Any other characters
+(except a space,
+tab,
+or newline)
+.\" XXX even crazy control characters, ugh--src/preproc/pic/lex.cpp:1266
+may be used as alternative delimiters,
+in which case the members of a given pair must be identical.
+.
+Strings are recognized within delimiters of either kind;
+they may contain the delimiter character or unbalanced braces.
+.
+.
+.TP
+\fBfor\fR \fIvariable\fR \fB=\fR \fIexpr1\fR \fBto\fR \fIexpr2\fR \
+[\fBby\fR [\fB*\fR]\,\fIexpr3\/\fR] \fBdo\fR \fIX\fR \fIbody\fR \fIX\fR
+Set
+.I variable
+to
+.IR expr1 .
+.
+While the value of
+.I variable
+is less than or equal to
+.IR expr2 ,
+do
+.I body
+and increment
+.I variable
+by
+.IR expr3 ;
+if
+.B by
+is not given,
+increment
+.I variable
+by 1.
+.
+If
+.I expr3
+is prefixed by
+.B *
+then
+.I variable
+will instead be multiplied by
+.IR expr3 .
+.
+The value of
+.I expr3
+can be negative for the additive case;
+.I variable
+is then tested whether it is greater than or equal to
+.IR expr2 .
+.
+For the multiplicative case,
+.I expr3
+must be greater than zero.
+.
+If the constraints aren't met,
+the loop isn't executed.
+.
+.I X
+can be any character not occurring in
+.IR body .
+.
+.TP
+\fBif\fR \fIexpr\fR \fBthen\fR \fIX\fR \fIif-true\fR \fIX\fR \
+[\fBelse\fR \fIY\fR \fIif-false\fR \fIY\fR]
+Evaluate
+.IR expr ;
+if it is non-zero then do
+.IR if-true ,
+otherwise do
+.IR if-false .
+.
+.I X
+can be any character not occurring in
+.IR if-true .
+.
+.I Y
+can be any character not occurring in
+.IR if-false .
+.
+.TP
+.BI print\~ arg\c
+\~.\|.\|.
+Concatenate and write arguments to the standard error stream followed by
+a newline.
+.
+Each
+.I arg
+must be an expression,
+a position,
+or text.
+.
+This is useful for debugging.
+.
+.TP
+.BI command\~ arg\c
+\~.\|.\|.
+.\" Move right margin to indentation since we must indent more later.
+.RS
+Concatenate arguments
+and pass them as a line to
+.I troff \" generic
+or \*[tx].
+.
+Each
+.I arg
+must be an expression,
+a position,
+or text.
+.
+.B command
+allows the values of
+.I pic
+variables to be passed to the formatter.
+.
+For example,
+.
+.RS
+.EX
+\&.PS
+x = 14
+command ".ds string x is " x "."
+\&.PE
+\[rs]*[string]
+.EE
+.RE
+.
+produces
+.
+.RS
+.EX
+x is 14.
+.EE
+.RE
+when formatted with
+.IR troff . \" generic
+.RE
+.
+.
+.TP
+\fBsh\fR \fIX\fR \fIcommand\fR \fIX\fR
+Pass
+.I command
+to a shell.
+.
+.
+.TP
+\fBcopy\fR \fB"\,\fIfilename\/\fB"\fR
+Include
+.I filename
+at this point in the file.
+.
+.
+.TP
+.BR copy\~ [ \[dq]\c
+.IB filename \[dq]\c
+.RB ]\~ thru\~\c
+.IR "X body X" \~\c \" space in roman: we must use 2-font macro with \c
+.RB [ until\~ \[dq]\c
+.IB word \[dq]\c
+]
+.TQ
+.BR copy\~ [ \[dq]\c
+.IB filename \[dq]\c
+.RB ]\~ thru\~\c
+.IR macro \~\c \" space roman because we must use 2-font macro with \c
+.RB [ until\~ \[dq]\c
+.IB word \[dq]\c
+]
+.\" Move right margin to indentation since we must indent more later.
+.RS
+This construct does
+.I body
+once for each line of
+.IR filename ;
+the line is split into blank-delimited words,
+and occurrences of
+.BI $ i
+in
+.IR body ,
+for
+.I i
+between 1 and 9,
+are replaced by the
+.IR i -th
+word of the line.
+.
+If
+.I filename
+is not given,
+lines are taken from the current input up to
+.BR .PE .
+.
+If an
+.B until
+clause is specified,
+lines will be read only until a line the first word of which is
+.IR word ;
+that line will then be discarded.
+.
+.I X
+can be any character not occurring in
+.IR body .
+.
+For example,
+.
+.RS \" now move further
+.EX
+\&.PS
+copy thru % circle at ($1,$2) % until "END"
+1 2
+3 4
+5 6
+END
+box
+\&.PE
+.EE
+.RE
+.
+and
+.
+.RS
+.EX
+\&.PS
+circle at (1,2)
+circle at (3,4)
+circle at (5,6)
+box
+\&.PE
+.EE
+.RE
+.
+are equivalent.
+.
+The commands to be performed for each line can also be taken from a
+macro defined earlier by giving the name of the macro as the argument to
+.BR thru .
+.
+The argument after
+.B thru
+is looked up as a macro name first;
+if not defined,
+its first character is interpreted as a delimiter.
+.RE
+.
+.
+.TP
+.B reset
+.TQ
+.BI reset\~ pvar1\c
+.RB [ , ]\~\c
+.IR pvar2 \~.\|.\|.
+Reset predefined variables
+.IR pvar1 ,
+.I pvar2
+\&.\|.\|.\& to their default values;
+if no arguments are given,
+reset all predefined variables to their default values.
+.
+Variable names may be separated by commas,
+spaces,
+or both.
+.
+Assigning a value to
+.B scale
+also causes all predefined variables that control dimensions to be reset
+to their default values times the new value of
+.BR scale .
+.
+.
+.TP
+\fBplot\fR \fIexpr\fR [\fB"\,\fItext\*(ic\fB"\fR]
+This is a text object which is constructed by using
+.I text
+as a format string for sprintf
+with an argument of
+.IR expr .
+.
+If
+.I text
+is omitted a format string of
+.B \[dq]%g\[dq]
+is used.
+.
+Attributes can be specified in the same way as for a normal text
+object.
+Be very careful that you specify an appropriate format string;
+.I @g@pic
+does only very limited checking of the string.
+.
+This is deprecated in favour of
+.BR sprintf .
+.
+.TP
+.IB var \~:=\~ expr
+.RS
+This syntax resembles variable assignment with
+.B =
+except that
+.I var
+must already be defined,
+and
+.I expr
+will be assigned to
+.I var
+without creating a variable local to the current block.
+.
+(By contrast,
+.B =
+defines
+.I var
+in the current block if it is not already defined there,
+and then changes the value in the current block only.)
+.
+For example,
+.
+.RS
+.EX
+.B .PS
+.B x = 3
+.B y = 3
+.B [
+.B x := 5
+.B y = 5
+.B ]
+.B print x " " y
+.B .PE
+.EE
+.RE
+.
+writes
+.
+.RS
+.EX
+5 3
+.EE
+.RE
+.
+to the standard error stream.
+.RE
+.
+.
+.\" ====================================================================
+.SS Expressions
+.\" ====================================================================
+.
+The syntax for expressions has been significantly extended.
+.
+.
+.P
+.IB x\ \[ha]\ y
+(exponentiation)
+.br
+.BI sin( x )
+.br
+.BI cos( x )
+.br
+.BI atan2( y , \ x )
+.br
+.BI log( x )
+(base 10)
+.br
+.BI exp( x )
+(base 10, i.e.\&
+.ie t 10\v'-.4m'\fIx\*(ic\fR\v'.4m')
+.el 10\[ha]\fIx\fR)
+.br
+.BI sqrt( x )
+.br
+.BI int( x )
+.br
+.B rand()
+(return a random number between 0 and 1)
+.br
+.BI rand( x )
+(return a random number between 1 and
+.IR x ;
+deprecated)
+.br
+.BI srand( x )
+(set the random number seed)
+.br
+.BI max( e1 , \ e2 )
+.br
+.BI min( e1 , \ e2 )
+.br
+.BI ! e
+.br
+\fIe1\fB && \fIe2\fR
+.br
+\fIe1\fB || \fIe2\fR
+.br
+\fIe1\fB == \fIe2\fR
+.br
+\fIe1\fB != \fIe2\fR
+.br
+\fIe1\fB >= \fIe2\fR
+.br
+\fIe1\fB > \fIe2\fR
+.br
+\fIe1\fB <= \fIe2\fR
+.br
+\fIe1\fB < \fIe2\fR
+.br
+\fB"\,\fIstr1\*(ic\fB" == "\,\fIstr2\*(ic\fB"\fR
+.br
+\fB"\,\fIstr1\*(ic\fB" != "\,\fIstr2\*(ic\fB"\fR
+.br
+.
+.
+.LP
+String comparison expressions must be parenthesised in some contexts
+to avoid ambiguity.
+.
+.
+.\" ====================================================================
+.SS "Other changes"
+.\" ====================================================================
+.
+A bare expression,
+.IR expr ,
+is acceptable as an attribute;
+it is equivalent to
+.IR dir\ expr ,
+where
+.I dir
+is the current direction.
+.
+For example
+.LP
+.RS
+.B line 2i
+.RE
+.LP
+means draw a line 2\ inches long in the current direction.
+.
+The \[oq]i\[cq]
+(or \[oq]I\[cq])
+character is ignored;
+to use another measurement unit,
+set the
+.I scale
+variable to an appropriate value.
+.
+.
+.LP
+The maximum width and height of the picture are taken from the variables
+.B maxpswid
+and
+.BR maxpsht .
+.
+Initially,
+these have values 8.5 and 11.
+.
+.
+.LP
+Scientific notation is allowed for numbers.
+For example
+.
+.
+.RS
+.LP
+.B
+x = 5e\-2
+.RE
+.
+.
+.LP
+Text attributes can be compounded.
+.
+For example,
+.
+.RS
+.LP
+.B
+"foo" above ljust
+.RE
+.
+.
+.LP
+is valid.
+.
+.
+.LP
+There is no limit to the depth to which blocks can be examined.
+.
+For example,
+.RS
+.LP
+.EX
+[A: [B: [C: box ]]] with .A.B.C.sw at 1,2
+circle at last [\^].A.B.C
+.EE
+.RE
+.
+.
+.LP
+is acceptable.
+.
+.
+.LP
+Arcs now have compass points determined by the circle of which the arc
+is a part.
+.
+.
+.LP
+Circles,
+ellipses,
+and arcs can be dotted or dashed.
+.
+In \*[tx] mode splines can be dotted or dashed also.
+.
+.
+.LP
+Boxes can have rounded corners.
+.
+The
+.B rad
+attribute specifies the radius of the quarter-circles at each corner.
+If no
+.B rad
+or
+.B diam
+attribute is given,
+a radius of
+.B boxrad
+is used.
+.
+Initially,
+.B boxrad
+has a value of\ 0.
+.
+A box with rounded corners can be dotted or dashed.
+.
+.
+.LP
+Boxes can have slanted sides.
+.
+This effectively changes the shape of a box from a rectangle to an
+arbitrary parallelogram.
+.
+The
+.B xslanted
+and
+.B yslanted
+attributes specify the x and y\~offset of the box's upper right
+corner from its default position.
+.
+.
+.LP
+The
+.B .PS
+line can have a second argument specifying a maximum height for
+the picture.
+.
+If the width of zero is specified the width will be ignored in computing
+the scaling factor for the picture.
+.
+GNU
+.I pic \" GNU
+will always scale a picture by the same amount vertically as well as
+horizontally.
+.
+This is different from DWB 2.0
+.I pic \" foreign
+which may scale a picture by a different amount vertically than
+horizontally if a height is specified.
+.
+.
+.LP
+Each text object has an invisible box associated with it.
+.
+The compass points of a text object are determined by this box.
+.
+The implicit motion associated with the object is also determined
+by this box.
+.
+The dimensions of this box are taken from the width and height
+attributes;
+if the width attribute is not supplied then the width will be taken to
+be
+.BR textwid ;
+if the height attribute is not supplied then the height will be taken to
+be the number of text strings associated with the object times
+.BR textht .
+.
+Initially,
+.B textwid
+and
+.B textht
+have a value of 0.
+.
+.
+.LP
+In
+(almost all)
+places where a quoted text string can be used,
+an expression of the form
+.
+.
+.IP
+.BI sprintf(\[dq] format \[dq],\~ arg ,\fR\~.\|.\|.\fB)
+.
+.
+.LP
+can also be used;
+this will produce the arguments formatted according to
+.IR format ,
+which should be a string as described in
+.MR printf 3
+appropriate for the number of arguments supplied.
+.
+Only the modifiers
+.RB \[lq] # \[rq],
+.RB \[lq] \- \[rq],
+.RB \[lq] + \[rq],
+and \[lq]\~\[rq] [space]),
+a minimum field width,
+an optional precision,
+and the conversion specifiers
+.BR %e ,
+.BR %E ,
+.BR %f ,
+.BR %g ,
+.BR %G ,
+and
+.B %%
+are supported.
+.
+.
+.LP
+The thickness of the lines used to draw objects is controlled by the
+.B linethick
+variable.
+.
+This gives the thickness of lines in points.
+.
+A negative value means use the default thickness:
+in \*[tx] output mode,
+this means use a thickness of 8 milliinches;
+in \*[tx] output mode with the
+.B \-c
+option,
+this means use the line thickness specified by
+.B .ps
+lines;
+in
+.I troff
+output mode,
+this means use a thickness proportional to the pointsize.
+.
+A zero value means draw the thinnest possible line supported by
+the output device.
+.
+Initially,
+it has a value of \-1.
+.
+There is also a
+.BR thick [ ness ]
+attribute.
+.
+For example,
+.
+.
+.RS
+.LP
+.B circle thickness 1.5
+.RE
+.
+.
+.LP
+would draw a circle using a line with a thickness of 1.5 points.
+.
+The thickness of lines is not affected by the
+value of the
+.B scale
+variable,
+nor by the width or height given in the
+.B .PS
+line.
+.
+.
+.LP
+Boxes
+(including boxes with rounded corners or slanted sides),
+circles and ellipses can be filled by giving them an attribute of
+.BR fill [ ed ].
+.
+This takes an optional argument of an expression with a value between
+0 and 1;
+0 will fill it with white,
+1 with black,
+values in between with a proportionally gray shade.
+.
+A value greater than 1 can also be used:
+this means fill with the
+shade of gray that is currently being used for text and lines.
+.
+Normally this will be black,
+but output devices may provide a mechanism for changing this.
+.
+Without an argument,
+then the value of the variable
+.B \%fillval
+will be used.
+.
+Initially,
+this has a value of 0.5.
+.
+The invisible attribute does not affect the filling of objects.
+.
+Any text associated with a filled object will be added after the object
+has been filled,
+so that the text will not be obscured by the filling.
+.
+.
+.P
+Additional modifiers are available to draw colored objects:
+.BR \%outline [ d ]
+sets the color of the outline,
+.B shaded
+the fill color,
+and
+.BR colo [ u ] r [ ed ]
+sets both.
+.
+All expect a subsequent string argument specifying the color.
+.
+.RS
+.EX
+circle shaded \[dq]green\[dq] outline \[dq]black\[dq]
+.EE
+.RE
+.
+Color is not yet supported in \*[tx] mode.
+.
+Device macro files like
+.I ps.tmac
+declare color names;
+you can define additional ones with the
+.B \%defcolor
+request
+(see
+.MR groff @MAN7EXT@ ).
+.
+.
+.LP
+To change the name of the vbox in \*[tx] mode,
+set the pseudo-variable
+.B \%figname
+(which is actually a specially parsed command)
+within a picture.
+.
+Example:
+.RS
+.LP
+.B .PS
+.br
+.B figname = foobar;
+.br
+.B ...
+.br
+.B .PE
+.RE
+.
+.
+.LP
+The picture is then available in the box
+.BR \[rs]foobar .
+.
+.
+.LP
+.I @g@pic
+assumes that at the beginning of a picture both glyph and fill color are
+set to the default value.
+.
+.
+.LP
+Arrow heads will be drawn as solid triangles if the variable
+.B arrowhead
+is non-zero and either \*[tx] mode is enabled or the
+.B \-n
+option has not been given.
+.
+Initially,
+.B arrowhead
+has a value of\ 1.
+.
+Solid arrow heads are always filled with the current outline color.
+.
+.
+.LP
+The
+.I troff
+output of
+.I @g@pic
+is device-independent.
+.
+The
+.B \-T
+option is therefore redundant.
+.
+All numbers are taken to be in inches;
+numbers are never interpreted to be in
+.I troff
+machine units.
+.
+.
+.LP
+Objects can have an
+.B aligned
+attribute.
+.
+This will only work if the postprocessor is
+.MR grops @MAN1EXT@
+or
+.MR gropdf @MAN1EXT@ .
+.
+Any text associated with an object having the
+.B aligned
+attribute will be rotated about the center of the object
+so that it is aligned in the direction from the start point
+to the end point of the object.
+.
+This attribute will have no effect on objects whose start and end points
+are coincident.
+.
+.
+.LP
+In places where
+.IB n th
+is allowed,
+.BI \[aq] expr \[aq]th
+is also allowed.
+.
+.RB \[lq] \[aq]th \[lq]
+is a single token:
+no space is allowed between the apostrophe and the
+.RB \[lq] th \[rq].
+.
+.
+For example,
+.IP
+.EX
+for i = 1 to 4 do {
+ line from \[aq]i\[aq]th box.nw to \[aq]i+1\[aq]th box.se
+}
+.EE
+.
+.
+.\" ====================================================================
+.SH Conversion
+.\" ====================================================================
+.
+To obtain a stand-alone picture from a
+.I @g@pic
+file,
+enclose your
+.I pic \" language
+code with
+.B .PS
+and
+.B .PE
+requests;
+.I roff
+configuration commands may be added at the beginning of the file,
+but no
+.I roff
+text.
+.
+.
+.LP
+It is necessary to feed this file into
+.I groff
+without adding any page information,
+so you must check which
+.B .PS
+and
+.B .PE
+requests are actually called.
+.
+For example,
+the
+.I mm
+macro package adds a page number,
+which is very annoying.
+.
+At the moment,
+calling standard
+.I groff
+without any macro package works.
+.
+Alternatively,
+you can define your own requests,
+e.g.,
+to do nothing:
+.
+.
+.LP
+.RS
+.EX
+\&.de PS
+\&..
+\&.de PE
+\&..
+.EE
+.RE
+.
+.
+.LP
+.I groff
+itself does not provide direct conversion into other graphics file
+formats.
+.
+But there are lots of possibilities if you first transform your
+picture into PostScript\*R format using the
+.I groff
+option
+.BR \-Tps .
+.
+Since this
+.IR ps -file
+lacks BoundingBox information it is not very useful by itself, but it
+may be fed into other conversion programs, usually named
+.BI ps2 other
+or
+.BI psto other
+or the like.
+.
+Moreover,
+the PostScript interpreter Ghostscript
+.RI ( gs (1))
+has built-in graphics conversion devices that are called with the option
+.
+.
+.LP
+.RS
+.BI "gs \-sDEVICE=" <devname>
+.RE
+.
+.
+.LP
+Call
+.
+.
+.LP
+.RS
+.B gs \-\-help
+.RE
+.
+.
+.LP
+for a list of the available devices.
+.
+.
+.LP
+An alternative may be to use the
+.B \-Tpdf
+option to convert your picture directly into
+.B PDF
+format.
+.
+The MediaBox of the file produced can be controlled by passing a
+.B \-P\-p
+papersize to
+.IR groff .
+.
+.
+.br
+.ne 3v
+.P
+As the Encapsulated PostScript File Format
+.B EPS
+is getting more and more important,
+and the conversion wasn't regarded trivial in the past you might be
+interested to know that there is a conversion tool named
+.I ps2eps
+which does the right job.
+.
+It is much better than the tool
+.I ps2epsi
+packaged with
+.IR gs .
+.
+.
+.LP
+For bitmapped graphic formats,
+you should use
+.IR pstopnm ;
+the resulting (intermediate)
+.MR pnm 5
+file can be then converted to virtually any graphics format using the
+tools of the
+.B netpbm
+package.
+.
+.
+.\" ====================================================================
+.SH Files
+.\" ====================================================================
+.
+.TP
+.I @MACRODIR@/pic.tmac
+offers simple definitions of the
+.BR PS ,
+.BR PE ,
+.BR PF ,
+and
+.B PY
+macros.
+.
+.
+.\" ====================================================================
+.SH Bugs
+.\" ====================================================================
+.
+Characters that are invalid as input to GNU
+.I troff \" GNU
+(see the
+.I groff
+Texinfo manual or
+.MR groff_char @MAN7EXT@
+for a list)
+are rejected even in \*[tx] mode.
+.
+.
+.LP
+The interpretation of
+.B \%fillval
+is incompatible with the
+.I pic \" AT&T
+in Tenth Edition Research Unix,
+which interprets 0 as black and 1 as white.
+.
+.
+.\" ====================================================================
+.SH "See also"
+.\" ====================================================================
+.
+.TP
+.I @DOCDIR@/\:pic\:.ps
+\[lq]Making Pictures with GNU pic\[rq],
+by Eric S.\& Raymond.
+.
+This file,
+together with its source,
+.IR pic.ms ,
+is part of the
+.I groff
+distribution.
+.
+.
+.P
+\[lq]PIC\[em]A Graphics Language for Typesetting: User Manual\[rq],
+by Brian W.\& Kernighan,
+1984
+(revised 1991),
+AT&T Bell Laboratories Computing Science Technical Report No.\& 116
+.
+.
+.P
+.I ps2eps
+is available from CTAN mirrors, e.g.,
+.UR ftp://\:ftp\:.dante\:.de/\:tex\-archive/\:support/\:ps2eps/
+.UE
+.
+.
+.LP
+W.\& Richard Stevens,
+.UR http://\:www\:.kohala\:.com/\:start/\:troff/\:pic2html\:.html
+.I Turning PIC into HTML
+.UE
+.
+.
+.LP
+W.\& Richard Stevens,
+.UR http://\:www\:.kohala\:.com/\:start/\:troff/\:pic\:.examples\:.ps
+.IR "Examples of " pic " Macros"
+.UE
+.
+.
+.LP
+.MR @g@troff @MAN1EXT@ ,
+.MR groff_out @MAN5EXT@ ,
+.MR tex 1 ,
+.MR gs 1 ,
+.MR ps2eps 1 ,
+.MR pstopnm 1 ,
+.MR ps2epsi 1 ,
+.MR pnm 5
+.
+.
+.\" Clean up.
+.rm tx
+.rm lx
+.rm ic
+.
+.\" Restore compatibility mode (for, e.g., Solaris 10/11).
+.cp \n[*groff_pic_1_man_C]
+.do rr *groff_pic_1_man_C
+.
+.
+.\" Local Variables:
+.\" fill-column: 72
+.\" mode: nroff
+.\" End:
+.\" vim: set filetype=groff textwidth=72:
diff --git a/src/preproc/pic/pic.am b/src/preproc/pic/pic.am
new file mode 100644
index 0000000..fae1372
--- /dev/null
+++ b/src/preproc/pic/pic.am
@@ -0,0 +1,56 @@
+# Copyright (C) 2014-2020 Free Software Foundation, Inc.
+#
+# This file is part of groff.
+#
+# groff is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# groff is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+prefixexecbin_PROGRAMS += pic
+pic_CPPFLAGS = $(AM_CPPFLAGS) \
+ -I $(top_srcdir)/src/preproc/pic \
+ -I $(top_builddir)/src/preproc/pic
+pic_LDADD = libgroff.a $(LIBM) lib/libgnu.a
+pic_SOURCES = \
+ src/preproc/pic/pic.ypp \
+ src/preproc/pic/lex.cpp \
+ src/preproc/pic/main.cpp \
+ src/preproc/pic/object.cpp \
+ src/preproc/pic/common.cpp \
+ src/preproc/pic/troff.cpp \
+ src/preproc/pic/tex.cpp \
+ src/preproc/pic/pic.h \
+ src/preproc/pic/position.h \
+ src/preproc/pic/text.h \
+ src/preproc/pic/common.h \
+ src/preproc/pic/output.h \
+ src/preproc/pic/object.h
+
+PREFIXMAN1 += src/preproc/pic/pic.1
+EXTRA_DIST += \
+ src/preproc/pic/TODO \
+ src/preproc/pic/pic.1.man
+
+# Since pic_CPPFLAGS was set, all .o files have a 'pic-' prefix.
+src/preproc/pic/pic-lex.$(OBJEXT): src/preproc/pic/pic.hpp
+
+MAINTAINERCLEANFILES += \
+ src/preproc/pic/pic.cpp \
+ src/preproc/pic/pic.hpp \
+ src/preproc/pic/pic.output
+
+
+# Local Variables:
+# fill-column: 72
+# mode: makefile-automake
+# End:
+# vim: set autoindent filetype=automake textwidth=72:
diff --git a/src/preproc/pic/pic.cpp b/src/preproc/pic/pic.cpp
new file mode 100644
index 0000000..14b15e4
--- /dev/null
+++ b/src/preproc/pic/pic.cpp
@@ -0,0 +1,5080 @@
+/* A Bison parser, made by GNU Bison 3.8.2. */
+
+/* Bison implementation for Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
+ Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* C LALR(1) parser skeleton written by Richard Stallman, by
+ simplifying the original so-called "semantic" parser. */
+
+/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
+ especially those whose name start with YY_ or yy_. They are
+ private implementation details that can be changed or removed. */
+
+/* All symbols defined below should begin with yy or YY, to avoid
+ infringing on user name space. This should be done even for local
+ variables, as they might otherwise be expanded by user macros.
+ There are some unavoidable exceptions within include files to
+ define necessary library symbols; they are noted "INFRINGES ON
+ USER NAME SPACE" below. */
+
+/* Identify Bison output, and Bison version. */
+#define YYBISON 30802
+
+/* Bison version string. */
+#define YYBISON_VERSION "3.8.2"
+
+/* Skeleton name. */
+#define YYSKELETON_NAME "yacc.c"
+
+/* Pure parsers. */
+#define YYPURE 0
+
+/* Push parsers. */
+#define YYPUSH 0
+
+/* Pull parsers. */
+#define YYPULL 1
+
+
+
+
+/* First part of user prologue. */
+#line 19 "../src/preproc/pic/pic.ypp"
+
+#include "pic.h"
+#include "ptable.h"
+#include "object.h"
+
+extern int delim_flag;
+extern void copy_rest_thru(const char *, const char *);
+extern void copy_file_thru(const char *, const char *, const char *);
+extern void push_body(const char *);
+extern void do_for(char *var, double from, double to,
+ int by_is_multiplicative, double by, char *body);
+extern void do_lookahead();
+
+/* Maximum number of characters produced by printf("%g") */
+#define GDIGITS 14
+
+int yylex();
+void yyerror(const char *);
+
+void reset(const char *nm);
+void reset_all();
+
+place *lookup_label(const char *);
+void define_label(const char *label, const place *pl);
+
+direction current_direction;
+position current_position;
+
+implement_ptable(place)
+
+PTABLE(place) top_table;
+
+PTABLE(place) *current_table = &top_table;
+saved_state *current_saved_state = 0;
+
+object_list olist;
+
+const char *ordinal_postfix(int n);
+const char *object_type_name(object_type type);
+char *format_number(const char *fmt, double n);
+char *do_sprintf(const char *fmt, const double *v, int nv);
+
+
+#line 115 "src/preproc/pic/pic.cpp"
+
+# ifndef YY_CAST
+# ifdef __cplusplus
+# define YY_CAST(Type, Val) static_cast<Type> (Val)
+# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast<Type> (Val)
+# else
+# define YY_CAST(Type, Val) ((Type) (Val))
+# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val))
+# endif
+# endif
+# ifndef YY_NULLPTR
+# if defined __cplusplus
+# if 201103L <= __cplusplus
+# define YY_NULLPTR nullptr
+# else
+# define YY_NULLPTR 0
+# endif
+# else
+# define YY_NULLPTR ((void*)0)
+# endif
+# endif
+
+/* Use api.header.include to #include this header
+ instead of duplicating it here. */
+#ifndef YY_YY_SRC_PREPROC_PIC_PIC_HPP_INCLUDED
+# define YY_YY_SRC_PREPROC_PIC_PIC_HPP_INCLUDED
+/* Debug traces. */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+#if YYDEBUG
+extern int yydebug;
+#endif
+
+/* Token kinds. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ enum yytokentype
+ {
+ YYEMPTY = -2,
+ YYEOF = 0, /* "end of file" */
+ YYerror = 256, /* error */
+ YYUNDEF = 257, /* "invalid token" */
+ LABEL = 258, /* LABEL */
+ VARIABLE = 259, /* VARIABLE */
+ NUMBER = 260, /* NUMBER */
+ TEXT = 261, /* TEXT */
+ COMMAND_LINE = 262, /* COMMAND_LINE */
+ DELIMITED = 263, /* DELIMITED */
+ ORDINAL = 264, /* ORDINAL */
+ TH = 265, /* TH */
+ LEFT_ARROW_HEAD = 266, /* LEFT_ARROW_HEAD */
+ RIGHT_ARROW_HEAD = 267, /* RIGHT_ARROW_HEAD */
+ DOUBLE_ARROW_HEAD = 268, /* DOUBLE_ARROW_HEAD */
+ LAST = 269, /* LAST */
+ BOX = 270, /* BOX */
+ CIRCLE = 271, /* CIRCLE */
+ ELLIPSE = 272, /* ELLIPSE */
+ ARC = 273, /* ARC */
+ LINE = 274, /* LINE */
+ ARROW = 275, /* ARROW */
+ MOVE = 276, /* MOVE */
+ SPLINE = 277, /* SPLINE */
+ HEIGHT = 278, /* HEIGHT */
+ RADIUS = 279, /* RADIUS */
+ FIGNAME = 280, /* FIGNAME */
+ WIDTH = 281, /* WIDTH */
+ DIAMETER = 282, /* DIAMETER */
+ UP = 283, /* UP */
+ DOWN = 284, /* DOWN */
+ RIGHT = 285, /* RIGHT */
+ LEFT = 286, /* LEFT */
+ FROM = 287, /* FROM */
+ TO = 288, /* TO */
+ AT = 289, /* AT */
+ WITH = 290, /* WITH */
+ BY = 291, /* BY */
+ THEN = 292, /* THEN */
+ SOLID = 293, /* SOLID */
+ DOTTED = 294, /* DOTTED */
+ DASHED = 295, /* DASHED */
+ CHOP = 296, /* CHOP */
+ SAME = 297, /* SAME */
+ INVISIBLE = 298, /* INVISIBLE */
+ LJUST = 299, /* LJUST */
+ RJUST = 300, /* RJUST */
+ ABOVE = 301, /* ABOVE */
+ BELOW = 302, /* BELOW */
+ OF = 303, /* OF */
+ THE = 304, /* THE */
+ WAY = 305, /* WAY */
+ BETWEEN = 306, /* BETWEEN */
+ AND = 307, /* AND */
+ HERE = 308, /* HERE */
+ DOT_N = 309, /* DOT_N */
+ DOT_E = 310, /* DOT_E */
+ DOT_W = 311, /* DOT_W */
+ DOT_S = 312, /* DOT_S */
+ DOT_NE = 313, /* DOT_NE */
+ DOT_SE = 314, /* DOT_SE */
+ DOT_NW = 315, /* DOT_NW */
+ DOT_SW = 316, /* DOT_SW */
+ DOT_C = 317, /* DOT_C */
+ DOT_START = 318, /* DOT_START */
+ DOT_END = 319, /* DOT_END */
+ DOT_X = 320, /* DOT_X */
+ DOT_Y = 321, /* DOT_Y */
+ DOT_HT = 322, /* DOT_HT */
+ DOT_WID = 323, /* DOT_WID */
+ DOT_RAD = 324, /* DOT_RAD */
+ SIN = 325, /* SIN */
+ COS = 326, /* COS */
+ ATAN2 = 327, /* ATAN2 */
+ LOG = 328, /* LOG */
+ EXP = 329, /* EXP */
+ SQRT = 330, /* SQRT */
+ K_MAX = 331, /* K_MAX */
+ K_MIN = 332, /* K_MIN */
+ INT = 333, /* INT */
+ RAND = 334, /* RAND */
+ SRAND = 335, /* SRAND */
+ COPY = 336, /* COPY */
+ THRU = 337, /* THRU */
+ TOP = 338, /* TOP */
+ BOTTOM = 339, /* BOTTOM */
+ UPPER = 340, /* UPPER */
+ LOWER = 341, /* LOWER */
+ SH = 342, /* SH */
+ PRINT = 343, /* PRINT */
+ CW = 344, /* CW */
+ CCW = 345, /* CCW */
+ FOR = 346, /* FOR */
+ DO = 347, /* DO */
+ IF = 348, /* IF */
+ ELSE = 349, /* ELSE */
+ ANDAND = 350, /* ANDAND */
+ OROR = 351, /* OROR */
+ NOTEQUAL = 352, /* NOTEQUAL */
+ EQUALEQUAL = 353, /* EQUALEQUAL */
+ LESSEQUAL = 354, /* LESSEQUAL */
+ GREATEREQUAL = 355, /* GREATEREQUAL */
+ LEFT_CORNER = 356, /* LEFT_CORNER */
+ RIGHT_CORNER = 357, /* RIGHT_CORNER */
+ NORTH = 358, /* NORTH */
+ SOUTH = 359, /* SOUTH */
+ EAST = 360, /* EAST */
+ WEST = 361, /* WEST */
+ CENTER = 362, /* CENTER */
+ END = 363, /* END */
+ START = 364, /* START */
+ RESET = 365, /* RESET */
+ UNTIL = 366, /* UNTIL */
+ PLOT = 367, /* PLOT */
+ THICKNESS = 368, /* THICKNESS */
+ FILL = 369, /* FILL */
+ COLORED = 370, /* COLORED */
+ OUTLINED = 371, /* OUTLINED */
+ SHADED = 372, /* SHADED */
+ XSLANTED = 373, /* XSLANTED */
+ YSLANTED = 374, /* YSLANTED */
+ ALIGNED = 375, /* ALIGNED */
+ SPRINTF = 376, /* SPRINTF */
+ COMMAND = 377, /* COMMAND */
+ DEFINE = 378, /* DEFINE */
+ UNDEF = 379 /* UNDEF */
+ };
+ typedef enum yytokentype yytoken_kind_t;
+#endif
+/* Token kinds. */
+#define YYEMPTY -2
+#define YYEOF 0
+#define YYerror 256
+#define YYUNDEF 257
+#define LABEL 258
+#define VARIABLE 259
+#define NUMBER 260
+#define TEXT 261
+#define COMMAND_LINE 262
+#define DELIMITED 263
+#define ORDINAL 264
+#define TH 265
+#define LEFT_ARROW_HEAD 266
+#define RIGHT_ARROW_HEAD 267
+#define DOUBLE_ARROW_HEAD 268
+#define LAST 269
+#define BOX 270
+#define CIRCLE 271
+#define ELLIPSE 272
+#define ARC 273
+#define LINE 274
+#define ARROW 275
+#define MOVE 276
+#define SPLINE 277
+#define HEIGHT 278
+#define RADIUS 279
+#define FIGNAME 280
+#define WIDTH 281
+#define DIAMETER 282
+#define UP 283
+#define DOWN 284
+#define RIGHT 285
+#define LEFT 286
+#define FROM 287
+#define TO 288
+#define AT 289
+#define WITH 290
+#define BY 291
+#define THEN 292
+#define SOLID 293
+#define DOTTED 294
+#define DASHED 295
+#define CHOP 296
+#define SAME 297
+#define INVISIBLE 298
+#define LJUST 299
+#define RJUST 300
+#define ABOVE 301
+#define BELOW 302
+#define OF 303
+#define THE 304
+#define WAY 305
+#define BETWEEN 306
+#define AND 307
+#define HERE 308
+#define DOT_N 309
+#define DOT_E 310
+#define DOT_W 311
+#define DOT_S 312
+#define DOT_NE 313
+#define DOT_SE 314
+#define DOT_NW 315
+#define DOT_SW 316
+#define DOT_C 317
+#define DOT_START 318
+#define DOT_END 319
+#define DOT_X 320
+#define DOT_Y 321
+#define DOT_HT 322
+#define DOT_WID 323
+#define DOT_RAD 324
+#define SIN 325
+#define COS 326
+#define ATAN2 327
+#define LOG 328
+#define EXP 329
+#define SQRT 330
+#define K_MAX 331
+#define K_MIN 332
+#define INT 333
+#define RAND 334
+#define SRAND 335
+#define COPY 336
+#define THRU 337
+#define TOP 338
+#define BOTTOM 339
+#define UPPER 340
+#define LOWER 341
+#define SH 342
+#define PRINT 343
+#define CW 344
+#define CCW 345
+#define FOR 346
+#define DO 347
+#define IF 348
+#define ELSE 349
+#define ANDAND 350
+#define OROR 351
+#define NOTEQUAL 352
+#define EQUALEQUAL 353
+#define LESSEQUAL 354
+#define GREATEREQUAL 355
+#define LEFT_CORNER 356
+#define RIGHT_CORNER 357
+#define NORTH 358
+#define SOUTH 359
+#define EAST 360
+#define WEST 361
+#define CENTER 362
+#define END 363
+#define START 364
+#define RESET 365
+#define UNTIL 366
+#define PLOT 367
+#define THICKNESS 368
+#define FILL 369
+#define COLORED 370
+#define OUTLINED 371
+#define SHADED 372
+#define XSLANTED 373
+#define YSLANTED 374
+#define ALIGNED 375
+#define SPRINTF 376
+#define COMMAND 377
+#define DEFINE 378
+#define UNDEF 379
+
+/* Value type. */
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+union YYSTYPE
+{
+#line 65 "../src/preproc/pic/pic.ypp"
+
+ char *str;
+ int n;
+ double x;
+ struct { double x, y; } pair;
+ struct { double x; char *body; } if_data;
+ struct { char *str; const char *filename; int lineno; } lstr;
+ struct { double *v; int nv; int maxv; } dv;
+ struct { double val; int is_multiplicative; } by;
+ place pl;
+ object *obj;
+ corner crn;
+ path *pth;
+ object_spec *spec;
+ saved_state *pstate;
+ graphics_state state;
+ object_type obtype;
+
+#line 435 "src/preproc/pic/pic.cpp"
+
+};
+typedef union YYSTYPE YYSTYPE;
+# define YYSTYPE_IS_TRIVIAL 1
+# define YYSTYPE_IS_DECLARED 1
+#endif
+
+
+extern YYSTYPE yylval;
+
+
+int yyparse (void);
+
+
+#endif /* !YY_YY_SRC_PREPROC_PIC_PIC_HPP_INCLUDED */
+/* Symbol kind. */
+enum yysymbol_kind_t
+{
+ YYSYMBOL_YYEMPTY = -2,
+ YYSYMBOL_YYEOF = 0, /* "end of file" */
+ YYSYMBOL_YYerror = 1, /* error */
+ YYSYMBOL_YYUNDEF = 2, /* "invalid token" */
+ YYSYMBOL_LABEL = 3, /* LABEL */
+ YYSYMBOL_VARIABLE = 4, /* VARIABLE */
+ YYSYMBOL_NUMBER = 5, /* NUMBER */
+ YYSYMBOL_TEXT = 6, /* TEXT */
+ YYSYMBOL_COMMAND_LINE = 7, /* COMMAND_LINE */
+ YYSYMBOL_DELIMITED = 8, /* DELIMITED */
+ YYSYMBOL_ORDINAL = 9, /* ORDINAL */
+ YYSYMBOL_TH = 10, /* TH */
+ YYSYMBOL_LEFT_ARROW_HEAD = 11, /* LEFT_ARROW_HEAD */
+ YYSYMBOL_RIGHT_ARROW_HEAD = 12, /* RIGHT_ARROW_HEAD */
+ YYSYMBOL_DOUBLE_ARROW_HEAD = 13, /* DOUBLE_ARROW_HEAD */
+ YYSYMBOL_LAST = 14, /* LAST */
+ YYSYMBOL_BOX = 15, /* BOX */
+ YYSYMBOL_CIRCLE = 16, /* CIRCLE */
+ YYSYMBOL_ELLIPSE = 17, /* ELLIPSE */
+ YYSYMBOL_ARC = 18, /* ARC */
+ YYSYMBOL_LINE = 19, /* LINE */
+ YYSYMBOL_ARROW = 20, /* ARROW */
+ YYSYMBOL_MOVE = 21, /* MOVE */
+ YYSYMBOL_SPLINE = 22, /* SPLINE */
+ YYSYMBOL_HEIGHT = 23, /* HEIGHT */
+ YYSYMBOL_RADIUS = 24, /* RADIUS */
+ YYSYMBOL_FIGNAME = 25, /* FIGNAME */
+ YYSYMBOL_WIDTH = 26, /* WIDTH */
+ YYSYMBOL_DIAMETER = 27, /* DIAMETER */
+ YYSYMBOL_UP = 28, /* UP */
+ YYSYMBOL_DOWN = 29, /* DOWN */
+ YYSYMBOL_RIGHT = 30, /* RIGHT */
+ YYSYMBOL_LEFT = 31, /* LEFT */
+ YYSYMBOL_FROM = 32, /* FROM */
+ YYSYMBOL_TO = 33, /* TO */
+ YYSYMBOL_AT = 34, /* AT */
+ YYSYMBOL_WITH = 35, /* WITH */
+ YYSYMBOL_BY = 36, /* BY */
+ YYSYMBOL_THEN = 37, /* THEN */
+ YYSYMBOL_SOLID = 38, /* SOLID */
+ YYSYMBOL_DOTTED = 39, /* DOTTED */
+ YYSYMBOL_DASHED = 40, /* DASHED */
+ YYSYMBOL_CHOP = 41, /* CHOP */
+ YYSYMBOL_SAME = 42, /* SAME */
+ YYSYMBOL_INVISIBLE = 43, /* INVISIBLE */
+ YYSYMBOL_LJUST = 44, /* LJUST */
+ YYSYMBOL_RJUST = 45, /* RJUST */
+ YYSYMBOL_ABOVE = 46, /* ABOVE */
+ YYSYMBOL_BELOW = 47, /* BELOW */
+ YYSYMBOL_OF = 48, /* OF */
+ YYSYMBOL_THE = 49, /* THE */
+ YYSYMBOL_WAY = 50, /* WAY */
+ YYSYMBOL_BETWEEN = 51, /* BETWEEN */
+ YYSYMBOL_AND = 52, /* AND */
+ YYSYMBOL_HERE = 53, /* HERE */
+ YYSYMBOL_DOT_N = 54, /* DOT_N */
+ YYSYMBOL_DOT_E = 55, /* DOT_E */
+ YYSYMBOL_DOT_W = 56, /* DOT_W */
+ YYSYMBOL_DOT_S = 57, /* DOT_S */
+ YYSYMBOL_DOT_NE = 58, /* DOT_NE */
+ YYSYMBOL_DOT_SE = 59, /* DOT_SE */
+ YYSYMBOL_DOT_NW = 60, /* DOT_NW */
+ YYSYMBOL_DOT_SW = 61, /* DOT_SW */
+ YYSYMBOL_DOT_C = 62, /* DOT_C */
+ YYSYMBOL_DOT_START = 63, /* DOT_START */
+ YYSYMBOL_DOT_END = 64, /* DOT_END */
+ YYSYMBOL_DOT_X = 65, /* DOT_X */
+ YYSYMBOL_DOT_Y = 66, /* DOT_Y */
+ YYSYMBOL_DOT_HT = 67, /* DOT_HT */
+ YYSYMBOL_DOT_WID = 68, /* DOT_WID */
+ YYSYMBOL_DOT_RAD = 69, /* DOT_RAD */
+ YYSYMBOL_SIN = 70, /* SIN */
+ YYSYMBOL_COS = 71, /* COS */
+ YYSYMBOL_ATAN2 = 72, /* ATAN2 */
+ YYSYMBOL_LOG = 73, /* LOG */
+ YYSYMBOL_EXP = 74, /* EXP */
+ YYSYMBOL_SQRT = 75, /* SQRT */
+ YYSYMBOL_K_MAX = 76, /* K_MAX */
+ YYSYMBOL_K_MIN = 77, /* K_MIN */
+ YYSYMBOL_INT = 78, /* INT */
+ YYSYMBOL_RAND = 79, /* RAND */
+ YYSYMBOL_SRAND = 80, /* SRAND */
+ YYSYMBOL_COPY = 81, /* COPY */
+ YYSYMBOL_THRU = 82, /* THRU */
+ YYSYMBOL_TOP = 83, /* TOP */
+ YYSYMBOL_BOTTOM = 84, /* BOTTOM */
+ YYSYMBOL_UPPER = 85, /* UPPER */
+ YYSYMBOL_LOWER = 86, /* LOWER */
+ YYSYMBOL_SH = 87, /* SH */
+ YYSYMBOL_PRINT = 88, /* PRINT */
+ YYSYMBOL_CW = 89, /* CW */
+ YYSYMBOL_CCW = 90, /* CCW */
+ YYSYMBOL_FOR = 91, /* FOR */
+ YYSYMBOL_DO = 92, /* DO */
+ YYSYMBOL_IF = 93, /* IF */
+ YYSYMBOL_ELSE = 94, /* ELSE */
+ YYSYMBOL_ANDAND = 95, /* ANDAND */
+ YYSYMBOL_OROR = 96, /* OROR */
+ YYSYMBOL_NOTEQUAL = 97, /* NOTEQUAL */
+ YYSYMBOL_EQUALEQUAL = 98, /* EQUALEQUAL */
+ YYSYMBOL_LESSEQUAL = 99, /* LESSEQUAL */
+ YYSYMBOL_GREATEREQUAL = 100, /* GREATEREQUAL */
+ YYSYMBOL_LEFT_CORNER = 101, /* LEFT_CORNER */
+ YYSYMBOL_RIGHT_CORNER = 102, /* RIGHT_CORNER */
+ YYSYMBOL_NORTH = 103, /* NORTH */
+ YYSYMBOL_SOUTH = 104, /* SOUTH */
+ YYSYMBOL_EAST = 105, /* EAST */
+ YYSYMBOL_WEST = 106, /* WEST */
+ YYSYMBOL_CENTER = 107, /* CENTER */
+ YYSYMBOL_END = 108, /* END */
+ YYSYMBOL_START = 109, /* START */
+ YYSYMBOL_RESET = 110, /* RESET */
+ YYSYMBOL_UNTIL = 111, /* UNTIL */
+ YYSYMBOL_PLOT = 112, /* PLOT */
+ YYSYMBOL_THICKNESS = 113, /* THICKNESS */
+ YYSYMBOL_FILL = 114, /* FILL */
+ YYSYMBOL_COLORED = 115, /* COLORED */
+ YYSYMBOL_OUTLINED = 116, /* OUTLINED */
+ YYSYMBOL_SHADED = 117, /* SHADED */
+ YYSYMBOL_XSLANTED = 118, /* XSLANTED */
+ YYSYMBOL_YSLANTED = 119, /* YSLANTED */
+ YYSYMBOL_ALIGNED = 120, /* ALIGNED */
+ YYSYMBOL_SPRINTF = 121, /* SPRINTF */
+ YYSYMBOL_COMMAND = 122, /* COMMAND */
+ YYSYMBOL_DEFINE = 123, /* DEFINE */
+ YYSYMBOL_UNDEF = 124, /* UNDEF */
+ YYSYMBOL_125_ = 125, /* '.' */
+ YYSYMBOL_126_ = 126, /* '(' */
+ YYSYMBOL_127_ = 127, /* '`' */
+ YYSYMBOL_128_ = 128, /* '[' */
+ YYSYMBOL_129_ = 129, /* ',' */
+ YYSYMBOL_130_ = 130, /* '<' */
+ YYSYMBOL_131_ = 131, /* '>' */
+ YYSYMBOL_132_ = 132, /* '+' */
+ YYSYMBOL_133_ = 133, /* '-' */
+ YYSYMBOL_134_ = 134, /* '*' */
+ YYSYMBOL_135_ = 135, /* '/' */
+ YYSYMBOL_136_ = 136, /* '%' */
+ YYSYMBOL_137_ = 137, /* '!' */
+ YYSYMBOL_138_ = 138, /* '^' */
+ YYSYMBOL_139_ = 139, /* ';' */
+ YYSYMBOL_140_ = 140, /* '=' */
+ YYSYMBOL_141_ = 141, /* ':' */
+ YYSYMBOL_142_ = 142, /* '{' */
+ YYSYMBOL_143_ = 143, /* '}' */
+ YYSYMBOL_144_ = 144, /* ']' */
+ YYSYMBOL_145_ = 145, /* ')' */
+ YYSYMBOL_YYACCEPT = 146, /* $accept */
+ YYSYMBOL_top = 147, /* top */
+ YYSYMBOL_element_list = 148, /* element_list */
+ YYSYMBOL_middle_element_list = 149, /* middle_element_list */
+ YYSYMBOL_optional_separator = 150, /* optional_separator */
+ YYSYMBOL_separator = 151, /* separator */
+ YYSYMBOL_placeless_element = 152, /* placeless_element */
+ YYSYMBOL_153_1 = 153, /* $@1 */
+ YYSYMBOL_154_2 = 154, /* $@2 */
+ YYSYMBOL_155_3 = 155, /* $@3 */
+ YYSYMBOL_156_4 = 156, /* $@4 */
+ YYSYMBOL_157_5 = 157, /* $@5 */
+ YYSYMBOL_158_6 = 158, /* $@6 */
+ YYSYMBOL_159_7 = 159, /* $@7 */
+ YYSYMBOL_macro_name = 160, /* macro_name */
+ YYSYMBOL_reset_variables = 161, /* reset_variables */
+ YYSYMBOL_print_args = 162, /* print_args */
+ YYSYMBOL_print_arg = 163, /* print_arg */
+ YYSYMBOL_simple_if = 164, /* simple_if */
+ YYSYMBOL_165_8 = 165, /* $@8 */
+ YYSYMBOL_until = 166, /* until */
+ YYSYMBOL_any_expr = 167, /* any_expr */
+ YYSYMBOL_text_expr = 168, /* text_expr */
+ YYSYMBOL_optional_by = 169, /* optional_by */
+ YYSYMBOL_element = 170, /* element */
+ YYSYMBOL_171_9 = 171, /* @9 */
+ YYSYMBOL_172_10 = 172, /* $@10 */
+ YYSYMBOL_optional_element = 173, /* optional_element */
+ YYSYMBOL_object_spec = 174, /* object_spec */
+ YYSYMBOL_175_11 = 175, /* @11 */
+ YYSYMBOL_text = 176, /* text */
+ YYSYMBOL_sprintf_args = 177, /* sprintf_args */
+ YYSYMBOL_position = 178, /* position */
+ YYSYMBOL_position_not_place = 179, /* position_not_place */
+ YYSYMBOL_between = 180, /* between */
+ YYSYMBOL_expr_pair = 181, /* expr_pair */
+ YYSYMBOL_place = 182, /* place */
+ YYSYMBOL_label = 183, /* label */
+ YYSYMBOL_ordinal = 184, /* ordinal */
+ YYSYMBOL_optional_ordinal_last = 185, /* optional_ordinal_last */
+ YYSYMBOL_nth_primitive = 186, /* nth_primitive */
+ YYSYMBOL_object_type = 187, /* object_type */
+ YYSYMBOL_label_path = 188, /* label_path */
+ YYSYMBOL_relative_path = 189, /* relative_path */
+ YYSYMBOL_path = 190, /* path */
+ YYSYMBOL_corner = 191, /* corner */
+ YYSYMBOL_expr = 192, /* expr */
+ YYSYMBOL_expr_lower_than = 193, /* expr_lower_than */
+ YYSYMBOL_expr_not_lower_than = 194 /* expr_not_lower_than */
+};
+typedef enum yysymbol_kind_t yysymbol_kind_t;
+
+
+
+
+#ifdef short
+# undef short
+#endif
+
+/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure
+ <limits.h> and (if available) <stdint.h> are included
+ so that the code can choose integer types of a good width. */
+
+#ifndef __PTRDIFF_MAX__
+# include <limits.h> /* INFRINGES ON USER NAME SPACE */
+# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
+# include <stdint.h> /* INFRINGES ON USER NAME SPACE */
+# define YY_STDINT_H
+# endif
+#endif
+
+/* Narrow types that promote to a signed type and that can represent a
+ signed or unsigned integer of at least N bits. In tables they can
+ save space and decrease cache pressure. Promoting to a signed type
+ helps avoid bugs in integer arithmetic. */
+
+#ifdef __INT_LEAST8_MAX__
+typedef __INT_LEAST8_TYPE__ yytype_int8;
+#elif defined YY_STDINT_H
+typedef int_least8_t yytype_int8;
+#else
+typedef signed char yytype_int8;
+#endif
+
+#ifdef __INT_LEAST16_MAX__
+typedef __INT_LEAST16_TYPE__ yytype_int16;
+#elif defined YY_STDINT_H
+typedef int_least16_t yytype_int16;
+#else
+typedef short yytype_int16;
+#endif
+
+/* Work around bug in HP-UX 11.23, which defines these macros
+ incorrectly for preprocessor constants. This workaround can likely
+ be removed in 2023, as HPE has promised support for HP-UX 11.23
+ (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of
+ <https://h20195.www2.hpe.com/V2/getpdf.aspx/4AA4-7673ENW.pdf>. */
+#ifdef __hpux
+# undef UINT_LEAST8_MAX
+# undef UINT_LEAST16_MAX
+# define UINT_LEAST8_MAX 255
+# define UINT_LEAST16_MAX 65535
+#endif
+
+#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__
+typedef __UINT_LEAST8_TYPE__ yytype_uint8;
+#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \
+ && UINT_LEAST8_MAX <= INT_MAX)
+typedef uint_least8_t yytype_uint8;
+#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX
+typedef unsigned char yytype_uint8;
+#else
+typedef short yytype_uint8;
+#endif
+
+#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__
+typedef __UINT_LEAST16_TYPE__ yytype_uint16;
+#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \
+ && UINT_LEAST16_MAX <= INT_MAX)
+typedef uint_least16_t yytype_uint16;
+#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX
+typedef unsigned short yytype_uint16;
+#else
+typedef int yytype_uint16;
+#endif
+
+#ifndef YYPTRDIFF_T
+# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__
+# define YYPTRDIFF_T __PTRDIFF_TYPE__
+# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__
+# elif defined PTRDIFF_MAX
+# ifndef ptrdiff_t
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# endif
+# define YYPTRDIFF_T ptrdiff_t
+# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX
+# else
+# define YYPTRDIFF_T long
+# define YYPTRDIFF_MAXIMUM LONG_MAX
+# endif
+#endif
+
+#ifndef YYSIZE_T
+# ifdef __SIZE_TYPE__
+# define YYSIZE_T __SIZE_TYPE__
+# elif defined size_t
+# define YYSIZE_T size_t
+# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__
+# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
+# define YYSIZE_T size_t
+# else
+# define YYSIZE_T unsigned
+# endif
+#endif
+
+#define YYSIZE_MAXIMUM \
+ YY_CAST (YYPTRDIFF_T, \
+ (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \
+ ? YYPTRDIFF_MAXIMUM \
+ : YY_CAST (YYSIZE_T, -1)))
+
+#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X))
+
+
+/* Stored state numbers (used for stacks). */
+typedef yytype_int16 yy_state_t;
+
+/* State numbers in computations. */
+typedef int yy_state_fast_t;
+
+#ifndef YY_
+# if defined YYENABLE_NLS && YYENABLE_NLS
+# if ENABLE_NLS
+# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
+# define YY_(Msgid) dgettext ("bison-runtime", Msgid)
+# endif
+# endif
+# ifndef YY_
+# define YY_(Msgid) Msgid
+# endif
+#endif
+
+
+#ifndef YY_ATTRIBUTE_PURE
+# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__)
+# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__))
+# else
+# define YY_ATTRIBUTE_PURE
+# endif
+#endif
+
+#ifndef YY_ATTRIBUTE_UNUSED
+# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__)
+# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__))
+# else
+# define YY_ATTRIBUTE_UNUSED
+# endif
+#endif
+
+/* Suppress unused-variable warnings by "using" E. */
+#if ! defined lint || defined __GNUC__
+# define YY_USE(E) ((void) (E))
+#else
+# define YY_USE(E) /* empty */
+#endif
+
+/* Suppress an incorrect diagnostic about yylval being uninitialized. */
+#if defined __GNUC__ && ! defined __ICC && 406 <= __GNUC__ * 100 + __GNUC_MINOR__
+# if __GNUC__ * 100 + __GNUC_MINOR__ < 407
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
+# else
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \
+ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
+# endif
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
+ _Pragma ("GCC diagnostic pop")
+#else
+# define YY_INITIAL_VALUE(Value) Value
+#endif
+#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+# define YY_IGNORE_MAYBE_UNINITIALIZED_END
+#endif
+#ifndef YY_INITIAL_VALUE
+# define YY_INITIAL_VALUE(Value) /* Nothing. */
+#endif
+
+#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__
+# define YY_IGNORE_USELESS_CAST_BEGIN \
+ _Pragma ("GCC diagnostic push") \
+ _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"")
+# define YY_IGNORE_USELESS_CAST_END \
+ _Pragma ("GCC diagnostic pop")
+#endif
+#ifndef YY_IGNORE_USELESS_CAST_BEGIN
+# define YY_IGNORE_USELESS_CAST_BEGIN
+# define YY_IGNORE_USELESS_CAST_END
+#endif
+
+
+#define YY_ASSERT(E) ((void) (0 && (E)))
+
+#if !defined yyoverflow
+
+/* The parser invokes alloca or malloc; define the necessary symbols. */
+
+# ifdef YYSTACK_USE_ALLOCA
+# if YYSTACK_USE_ALLOCA
+# ifdef __GNUC__
+# define YYSTACK_ALLOC __builtin_alloca
+# elif defined __BUILTIN_VA_ARG_INCR
+# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
+# elif defined _AIX
+# define YYSTACK_ALLOC __alloca
+# elif defined _MSC_VER
+# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
+# define alloca _alloca
+# else
+# define YYSTACK_ALLOC alloca
+# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+ /* Use EXIT_SUCCESS as a witness for stdlib.h. */
+# ifndef EXIT_SUCCESS
+# define EXIT_SUCCESS 0
+# endif
+# endif
+# endif
+# endif
+# endif
+
+# ifdef YYSTACK_ALLOC
+ /* Pacify GCC's 'empty if-body' warning. */
+# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
+# ifndef YYSTACK_ALLOC_MAXIMUM
+ /* The OS might guarantee only one guard page at the bottom of the stack,
+ and a page size can be as small as 4096 bytes. So we cannot safely
+ invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
+ to allow for a few compiler-allocated temporary stack slots. */
+# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
+# endif
+# else
+# define YYSTACK_ALLOC YYMALLOC
+# define YYSTACK_FREE YYFREE
+# ifndef YYSTACK_ALLOC_MAXIMUM
+# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
+# endif
+# if (defined __cplusplus && ! defined EXIT_SUCCESS \
+ && ! ((defined YYMALLOC || defined malloc) \
+ && (defined YYFREE || defined free)))
+# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
+# ifndef EXIT_SUCCESS
+# define EXIT_SUCCESS 0
+# endif
+# endif
+# ifndef YYMALLOC
+# define YYMALLOC malloc
+# if ! defined malloc && ! defined EXIT_SUCCESS
+void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# ifndef YYFREE
+# define YYFREE free
+# if ! defined free && ! defined EXIT_SUCCESS
+void free (void *); /* INFRINGES ON USER NAME SPACE */
+# endif
+# endif
+# endif
+#endif /* !defined yyoverflow */
+
+#if (! defined yyoverflow \
+ && (! defined __cplusplus \
+ || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
+
+/* A type that is properly aligned for any stack member. */
+union yyalloc
+{
+ yy_state_t yyss_alloc;
+ YYSTYPE yyvs_alloc;
+};
+
+/* The size of the maximum gap between one aligned stack and the next. */
+# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1)
+
+/* The size of an array large to enough to hold all stacks, each with
+ N elements. */
+# define YYSTACK_BYTES(N) \
+ ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \
+ + YYSTACK_GAP_MAXIMUM)
+
+# define YYCOPY_NEEDED 1
+
+/* Relocate STACK from its old location to the new one. The
+ local variables YYSIZE and YYSTACKSIZE give the old and new number of
+ elements in the stack, and YYPTR gives the new location of the
+ stack. Advance YYPTR to a properly aligned location for the next
+ stack. */
+# define YYSTACK_RELOCATE(Stack_alloc, Stack) \
+ do \
+ { \
+ YYPTRDIFF_T yynewbytes; \
+ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
+ Stack = &yyptr->Stack_alloc; \
+ yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \
+ yyptr += yynewbytes / YYSIZEOF (*yyptr); \
+ } \
+ while (0)
+
+#endif
+
+#if defined YYCOPY_NEEDED && YYCOPY_NEEDED
+/* Copy COUNT objects from SRC to DST. The source and destination do
+ not overlap. */
+# ifndef YYCOPY
+# if defined __GNUC__ && 1 < __GNUC__
+# define YYCOPY(Dst, Src, Count) \
+ __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src)))
+# else
+# define YYCOPY(Dst, Src, Count) \
+ do \
+ { \
+ YYPTRDIFF_T yyi; \
+ for (yyi = 0; yyi < (Count); yyi++) \
+ (Dst)[yyi] = (Src)[yyi]; \
+ } \
+ while (0)
+# endif
+# endif
+#endif /* !YYCOPY_NEEDED */
+
+/* YYFINAL -- State number of the termination state. */
+#define YYFINAL 6
+/* YYLAST -- Last index in YYTABLE. */
+#define YYLAST 2438
+
+/* YYNTOKENS -- Number of terminals. */
+#define YYNTOKENS 146
+/* YYNNTS -- Number of nonterminals. */
+#define YYNNTS 49
+/* YYNRULES -- Number of rules. */
+#define YYNRULES 260
+/* YYNSTATES -- Number of states. */
+#define YYNSTATES 454
+
+/* YYMAXUTOK -- Last valid token kind. */
+#define YYMAXUTOK 379
+
+
+/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
+ as returned by yylex, with out-of-bounds checking. */
+#define YYTRANSLATE(YYX) \
+ (0 <= (YYX) && (YYX) <= YYMAXUTOK \
+ ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \
+ : YYSYMBOL_YYUNDEF)
+
+/* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
+ as returned by yylex. */
+static const yytype_uint8 yytranslate[] =
+{
+ 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 137, 2, 2, 2, 136, 2, 2,
+ 126, 145, 134, 132, 129, 133, 125, 135, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 141, 139,
+ 130, 140, 131, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 128, 2, 144, 138, 2, 127, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 142, 2, 143, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
+ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
+ 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
+ 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
+ 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
+ 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
+ 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
+ 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
+ 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
+ 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
+ 115, 116, 117, 118, 119, 120, 121, 122, 123, 124
+};
+
+#if YYDEBUG
+/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
+static const yytype_int16 yyrline[] =
+{
+ 0, 275, 275, 276, 285, 290, 292, 296, 298, 302,
+ 303, 307, 315, 320, 332, 334, 336, 338, 340, 345,
+ 350, 357, 356, 372, 380, 382, 379, 393, 395, 392,
+ 405, 404, 413, 422, 421, 435, 436, 441, 442, 446,
+ 451, 456, 464, 466, 485, 492, 494, 505, 504, 516,
+ 517, 522, 524, 529, 535, 541, 543, 545, 547, 549,
+ 551, 553, 560, 564, 569, 577, 591, 597, 605, 612,
+ 618, 611, 627, 637, 638, 643, 645, 647, 649, 654,
+ 661, 668, 675, 682, 687, 694, 702, 701, 728, 734,
+ 740, 746, 752, 771, 778, 785, 792, 799, 806, 813,
+ 820, 827, 834, 849, 861, 867, 876, 883, 908, 912,
+ 918, 924, 930, 936, 941, 947, 953, 959, 966, 975,
+ 982, 998, 1015, 1020, 1025, 1030, 1035, 1040, 1045, 1050,
+ 1058, 1068, 1078, 1088, 1098, 1104, 1112, 1114, 1126, 1131,
+ 1161, 1163, 1169, 1178, 1180, 1185, 1190, 1195, 1200, 1205,
+ 1210, 1216, 1221, 1229, 1230, 1234, 1239, 1245, 1247, 1253,
+ 1259, 1265, 1274, 1284, 1286, 1295, 1297, 1305, 1307, 1312,
+ 1327, 1345, 1347, 1349, 1351, 1353, 1355, 1357, 1359, 1361,
+ 1366, 1368, 1376, 1380, 1382, 1390, 1392, 1398, 1404, 1410,
+ 1416, 1425, 1427, 1429, 1431, 1433, 1435, 1437, 1439, 1441,
+ 1443, 1445, 1447, 1449, 1451, 1453, 1455, 1457, 1459, 1461,
+ 1463, 1465, 1467, 1469, 1471, 1473, 1475, 1477, 1479, 1481,
+ 1483, 1485, 1487, 1492, 1494, 1499, 1504, 1512, 1514, 1521,
+ 1528, 1535, 1542, 1549, 1551, 1553, 1555, 1563, 1571, 1584,
+ 1586, 1588, 1597, 1606, 1619, 1628, 1637, 1646, 1648, 1650,
+ 1652, 1659, 1665, 1670, 1672, 1674, 1676, 1678, 1680, 1682,
+ 1684
+};
+#endif
+
+/** Accessing symbol of state STATE. */
+#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State])
+
+#if YYDEBUG || 0
+/* The user-facing name of the symbol whose (internal) number is
+ YYSYMBOL. No bounds checking. */
+static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED;
+
+/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
+ First, the terminals, then, starting at YYNTOKENS, nonterminals. */
+static const char *const yytname[] =
+{
+ "\"end of file\"", "error", "\"invalid token\"", "LABEL", "VARIABLE",
+ "NUMBER", "TEXT", "COMMAND_LINE", "DELIMITED", "ORDINAL", "TH",
+ "LEFT_ARROW_HEAD", "RIGHT_ARROW_HEAD", "DOUBLE_ARROW_HEAD", "LAST",
+ "BOX", "CIRCLE", "ELLIPSE", "ARC", "LINE", "ARROW", "MOVE", "SPLINE",
+ "HEIGHT", "RADIUS", "FIGNAME", "WIDTH", "DIAMETER", "UP", "DOWN",
+ "RIGHT", "LEFT", "FROM", "TO", "AT", "WITH", "BY", "THEN", "SOLID",
+ "DOTTED", "DASHED", "CHOP", "SAME", "INVISIBLE", "LJUST", "RJUST",
+ "ABOVE", "BELOW", "OF", "THE", "WAY", "BETWEEN", "AND", "HERE", "DOT_N",
+ "DOT_E", "DOT_W", "DOT_S", "DOT_NE", "DOT_SE", "DOT_NW", "DOT_SW",
+ "DOT_C", "DOT_START", "DOT_END", "DOT_X", "DOT_Y", "DOT_HT", "DOT_WID",
+ "DOT_RAD", "SIN", "COS", "ATAN2", "LOG", "EXP", "SQRT", "K_MAX", "K_MIN",
+ "INT", "RAND", "SRAND", "COPY", "THRU", "TOP", "BOTTOM", "UPPER",
+ "LOWER", "SH", "PRINT", "CW", "CCW", "FOR", "DO", "IF", "ELSE", "ANDAND",
+ "OROR", "NOTEQUAL", "EQUALEQUAL", "LESSEQUAL", "GREATEREQUAL",
+ "LEFT_CORNER", "RIGHT_CORNER", "NORTH", "SOUTH", "EAST", "WEST",
+ "CENTER", "END", "START", "RESET", "UNTIL", "PLOT", "THICKNESS", "FILL",
+ "COLORED", "OUTLINED", "SHADED", "XSLANTED", "YSLANTED", "ALIGNED",
+ "SPRINTF", "COMMAND", "DEFINE", "UNDEF", "'.'", "'('", "'`'", "'['",
+ "','", "'<'", "'>'", "'+'", "'-'", "'*'", "'/'", "'%'", "'!'", "'^'",
+ "';'", "'='", "':'", "'{'", "'}'", "']'", "')'", "$accept", "top",
+ "element_list", "middle_element_list", "optional_separator", "separator",
+ "placeless_element", "$@1", "$@2", "$@3", "$@4", "$@5", "$@6", "$@7",
+ "macro_name", "reset_variables", "print_args", "print_arg", "simple_if",
+ "$@8", "until", "any_expr", "text_expr", "optional_by", "element", "@9",
+ "$@10", "optional_element", "object_spec", "@11", "text", "sprintf_args",
+ "position", "position_not_place", "between", "expr_pair", "place",
+ "label", "ordinal", "optional_ordinal_last", "nth_primitive",
+ "object_type", "label_path", "relative_path", "path", "corner", "expr",
+ "expr_lower_than", "expr_not_lower_than", YY_NULLPTR
+};
+
+static const char *
+yysymbol_name (yysymbol_kind_t yysymbol)
+{
+ return yytname[yysymbol];
+}
+#endif
+
+#define YYPACT_NINF (-240)
+
+#define yypact_value_is_default(Yyn) \
+ ((Yyn) == YYPACT_NINF)
+
+#define YYTABLE_NINF (-206)
+
+#define yytable_value_is_error(Yyn) \
+ 0
+
+/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
+ STATE-NUM. */
+static const yytype_int16 yypact[] =
+{
+ -114, -240, 20, -240, 757, -107, -240, -98, -123, -240,
+ -240, -240, -240, -240, -240, -240, -240, -240, -240, -106,
+ -240, -240, -240, -240, 9, -240, 1087, 46, 1172, 49,
+ 1597, -70, 1087, -240, -240, -114, -240, 3, -33, -240,
+ 877, -240, -240, -114, 1172, -60, 36, -14, -240, 74,
+ -240, -240, -240, -240, -240, -240, -240, -240, -240, -240,
+ -240, -240, -240, -240, -240, -240, -240, -240, -240, -34,
+ -18, 8, 38, 47, 51, 65, 101, 102, 112, 122,
+ -240, -240, 21, 150, -240, -240, -240, -240, -240, -240,
+ -240, -240, -240, 1257, 1172, 1597, 1597, 1087, -240, -240,
+ -43, -240, -240, 357, 2242, 59, 258, -240, 10, 2147,
+ -240, 1, 6, 1172, 1172, 145, -1, 2, 357, 2273,
+ -240, -240, 220, 249, 1087, -114, -114, -240, 721, -240,
+ 252, -240, -240, -240, -240, 1597, 1597, 1597, 1597, 2024,
+ 2024, 1853, 1939, 1682, 1682, 1682, 1427, 1767, -240, -240,
+ 2024, 2024, 2024, -240, -240, -240, -240, -240, -240, -240,
+ -240, 1597, 2024, 23, 23, 23, 1597, 1597, -240, -240,
+ 2282, 593, -240, 1172, -240, -240, -240, -240, 250, -240,
+ 1172, 1172, 1172, 1172, 1172, 1172, 1172, 1172, 1172, 458,
+ 1172, -240, -240, -240, -240, -240, -240, -240, -240, 121,
+ 107, 123, 256, 2157, 137, 261, 134, 134, -240, 1767,
+ 1767, -240, -240, -240, -240, -240, 276, -240, -240, -240,
+ -240, -240, -240, -240, -240, -240, -240, 138, -240, -240,
+ 24, 156, 235, -240, 1597, 1597, 1597, 1597, 1597, 1597,
+ 1597, 1597, 1597, 1597, 1597, 1597, 1597, 1597, 1597, 1682,
+ 1682, 1597, -240, 134, -240, 1172, 1172, 23, 23, 1172,
+ 1172, -240, -240, 143, 757, 153, -240, -240, 280, 2282,
+ 2282, 2282, 2282, 2282, 2282, 2282, 2282, -43, 2147, -43,
+ -43, 2253, 275, 275, 295, 1002, -43, 2081, -240, -240,
+ 10, 1342, -240, 694, 2282, 2282, 2282, 2282, 2282, -240,
+ -240, -240, 2282, 2282, -98, -123, 16, 28, -240, -43,
+ 56, 302, -240, 291, -240, 155, 160, 172, 161, 164,
+ 167, 184, 185, 181, -240, 186, 188, -240, 1682, 1767,
+ 1767, -240, -240, 1682, 1682, -240, -240, -240, -240, -240,
+ 156, 279, 314, 2291, 440, 440, 413, 413, 2282, 413,
+ 413, -72, -72, 134, 134, 134, 134, -49, 117, 343,
+ 322, -240, 314, 239, 2300, -240, -240, -240, 314, 239,
+ 2300, -119, -240, -240, -240, -240, -240, 2116, 2116, -240,
+ 206, 333, -240, 123, 2131, -240, 228, -240, -240, 1172,
+ -240, -240, -240, 1172, 1172, -240, -240, -240, -110, 195,
+ 197, -47, 128, 292, 1682, 1682, 1597, -240, 1597, -240,
+ 757, -240, -240, 2116, -240, 228, 338, -240, 200, 202,
+ 212, -240, -240, -240, 1682, 1682, -240, -43, -27, 360,
+ 2282, -240, -240, 214, -240, -240, -240, -240, -240, -73,
+ 30, -240, 1512, 268, -240, -240, 216, 1597, 2282, -240,
+ -240, 2282, 354, -240
+};
+
+/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
+ Performed when YYTABLE does not specify something else to do. Zero
+ means the default is an error. */
+static const yytype_int16 yydefact[] =
+{
+ 7, 9, 0, 3, 2, 8, 1, 0, 0, 136,
+ 18, 75, 76, 77, 78, 79, 80, 81, 82, 0,
+ 14, 15, 17, 16, 0, 21, 0, 0, 0, 36,
+ 0, 0, 0, 86, 69, 7, 72, 35, 32, 5,
+ 65, 83, 10, 7, 0, 0, 0, 23, 27, 0,
+ 162, 226, 227, 165, 167, 205, 204, 161, 191, 192,
+ 193, 194, 195, 196, 197, 198, 199, 200, 201, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 202, 203, 0, 0, 210, 211, 216, 217, 218, 219,
+ 220, 222, 221, 0, 0, 0, 0, 20, 42, 45,
+ 46, 140, 143, 141, 157, 0, 0, 163, 0, 44,
+ 223, 224, 0, 0, 0, 0, 52, 0, 0, 51,
+ 224, 39, 84, 0, 19, 7, 7, 4, 8, 40,
+ 0, 33, 124, 125, 126, 0, 0, 0, 0, 93,
+ 95, 97, 99, 0, 0, 0, 0, 0, 107, 108,
+ 109, 111, 120, 122, 123, 130, 131, 132, 133, 127,
+ 128, 0, 113, 0, 0, 0, 0, 0, 135, 129,
+ 92, 0, 12, 0, 38, 37, 11, 24, 0, 22,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 208, 206, 212, 214, 209, 207, 213, 215, 0,
+ 0, 143, 141, 51, 224, 0, 239, 260, 43, 0,
+ 0, 228, 229, 230, 231, 232, 0, 158, 179, 168,
+ 171, 172, 173, 174, 175, 176, 177, 0, 169, 170,
+ 0, 159, 0, 153, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 61, 260, 47, 0, 0, 0, 0, 0,
+ 0, 85, 138, 0, 0, 0, 6, 41, 0, 88,
+ 89, 90, 91, 94, 96, 98, 100, 101, 0, 102,
+ 103, 162, 165, 167, 0, 0, 105, 183, 185, 104,
+ 182, 0, 106, 0, 110, 112, 121, 134, 114, 118,
+ 119, 117, 115, 116, 162, 226, 205, 204, 66, 0,
+ 67, 68, 13, 0, 28, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 251, 0, 0, 240, 0, 0,
+ 0, 156, 142, 0, 0, 166, 144, 146, 164, 178,
+ 160, 0, 258, 259, 257, 256, 253, 255, 155, 225,
+ 254, 233, 234, 235, 236, 237, 238, 0, 0, 0,
+ 0, 55, 56, 58, 59, 54, 53, 57, 258, 60,
+ 259, 0, 87, 70, 34, 190, 182, 0, 0, 180,
+ 0, 0, 184, 0, 51, 25, 49, 241, 242, 0,
+ 244, 245, 246, 0, 0, 249, 250, 252, 0, 144,
+ 146, 0, 0, 0, 0, 0, 0, 48, 0, 137,
+ 73, 189, 188, 0, 181, 49, 0, 29, 0, 0,
+ 0, 148, 145, 147, 0, 0, 154, 149, 0, 62,
+ 139, 74, 71, 0, 26, 50, 243, 247, 248, 149,
+ 0, 151, 0, 0, 186, 150, 151, 0, 63, 30,
+ 152, 64, 0, 31
+};
+
+/* YYPGOTO[NTERM-NUM]. */
+static const yytype_int16 yypgoto[] =
+{
+ -240, -240, 17, -240, 12, 329, -240, -240, -240, -240,
+ -240, -240, -240, -240, -240, -240, 334, -76, -240, -240,
+ -42, 13, -103, -240, -127, -240, -240, -240, -240, -240,
+ 5, -240, 99, 194, 169, -44, 4, -100, -240, -240,
+ -240, -104, -240, -239, -240, -50, -26, -240, 61
+};
+
+/* YYDEFGOTO[NTERM-NUM]. */
+static const yytype_int16 yydefgoto[] =
+{
+ 0, 2, 3, 35, 264, 5, 36, 49, 313, 415,
+ 178, 386, 452, 268, 176, 37, 97, 98, 38, 360,
+ 417, 199, 116, 443, 39, 126, 410, 432, 40, 125,
+ 117, 371, 100, 101, 249, 102, 118, 104, 105, 106,
+ 107, 228, 287, 288, 289, 108, 119, 110, 120
+};
+
+/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
+ positive, shift that token. If negative, reduce the rule whose
+ number is the opposite. If YYTABLE_NINF, syntax error. */
+static const yytype_int16 yytable[] =
+{
+ 109, 266, 229, 404, 122, 424, 109, 129, 231, 41,
+ 408, 252, 4, 50, 170, 47, -17, 44, 45, 53,
+ 6, 208, 209, 210, 54, 1, 409, 50, -16, 9,
+ 103, 99, 42, 53, 46, 421, 103, 99, 54, 174,
+ 175, 115, 375, 43, 308, 169, 380, 127, 208, 201,
+ 112, 191, 192, 121, 217, 171, 123, 172, 230, 209,
+ 210, 131, 245, 246, 247, 218, 248, 203, 177, 206,
+ 207, 109, 445, 219, 220, 221, 222, 223, 224, 225,
+ 173, 226, 179, 209, 210, 209, 210, 111, 253, 209,
+ 210, 48, 180, 111, 255, 256, 290, 202, 109, 257,
+ 258, 103, 99, 292, 441, 209, 210, 205, 181, 269,
+ 270, 271, 272, 273, 274, 275, 276, 278, 278, 278,
+ 278, 293, 193, 194, 294, 295, 296, 261, 103, 99,
+ 340, 250, 130, 41, 182, 297, 298, 94, 411, 412,
+ 302, 303, 263, 265, 31, 278, 251, 103, 103, 103,
+ 103, 94, 361, 363, 204, -17, 367, 369, 111, -17,
+ -17, 446, 209, 210, 183, 336, 337, -16, 299, 300,
+ 301, -16, -16, 184, 433, 311, 41, 185, 377, 378,
+ 195, 196, 254, 293, 293, 111, 312, 227, -140, -140,
+ 231, 186, 200, 315, 316, 317, 318, 319, 320, 321,
+ 322, 323, 325, 326, 111, 111, 111, 111, 342, 343,
+ 344, 345, 346, 347, 348, 349, 350, 351, 352, 353,
+ 354, 355, 356, 278, 278, 359, 9, 187, 188, 362,
+ 364, 376, 111, 368, 370, 290, 328, 382, 189, 329,
+ 330, 201, 277, 279, 280, 286, 405, 383, 190, 209,
+ 210, 197, 198, 103, 103, 262, 267, 425, 314, 203,
+ 209, 210, 365, 366, 218, 384, 327, 334, 331, 41,
+ 309, 335, 248, 220, 221, 222, 223, 224, 225, 338,
+ 226, 216, 339, 431, 341, 399, 400, 372, 374, 202,
+ 220, 221, 222, 223, 224, 225, 373, 226, 379, 385,
+ 387, 389, 278, 293, 293, 388, 390, 278, 278, 391,
+ 111, 111, 392, 393, 394, 234, 235, 236, 237, 238,
+ 239, 211, 212, 213, 214, 215, 395, 376, 376, 403,
+ 407, 396, 103, 397, 255, 413, 414, 103, 103, 416,
+ 422, 31, 423, 426, 435, 436, 204, 437, 357, 358,
+ 241, 242, 243, 244, 245, 246, 247, 438, 248, 444,
+ 449, 450, 453, 376, 128, 310, 124, 211, 212, 213,
+ 214, 215, 333, 434, 0, 0, 406, 0, 278, 278,
+ 429, 0, 430, 0, 200, 0, 227, 0, 0, 111,
+ 0, 0, 0, 0, 111, 111, 442, 0, 278, 278,
+ 0, 332, 418, 227, 0, 0, 419, 420, 103, 103,
+ 0, 236, 237, 238, 239, 41, 448, 0, 0, 0,
+ 0, 451, 211, 212, 213, 214, 215, 398, 103, 103,
+ 0, 0, 401, 402, -141, -141, 0, 0, 234, 235,
+ 236, 237, 238, 239, 241, 242, 243, 244, 245, 246,
+ 247, 0, 248, 0, 0, 234, 235, 236, 237, 238,
+ 239, 50, 51, 52, 9, 111, 111, 53, 0, 0,
+ 0, 0, 54, 241, 242, 243, 244, 245, 246, 247,
+ 0, 248, 0, 0, 0, 111, 111, 0, 55, 56,
+ 241, 242, 243, 244, 245, 246, 247, 0, 248, 0,
+ 0, 0, 0, 427, 428, 0, 0, 0, 0, 0,
+ 0, 57, 58, 59, 60, 61, 62, 63, 64, 65,
+ 66, 67, 68, 439, 440, 0, 0, 0, 69, 70,
+ 71, 72, 73, 74, 75, 76, 77, 78, 79, 238,
+ 239, 80, 81, 82, 83, 243, 244, 245, 246, 247,
+ 0, 248, 0, 0, 0, 0, 0, 0, 0, 84,
+ 85, 86, 87, 88, 89, 90, 91, 92, 0, 0,
+ 241, 242, 243, 244, 245, 246, 247, 0, 248, 31,
+ 0, 0, 0, 0, 113, 94, 0, 0, 0, 0,
+ 0, 95, 0, 0, 0, 114, 304, 305, 52, 9,
+ 10, 0, 53, 324, 0, 0, 0, 54, 11, 12,
+ 13, 14, 15, 16, 17, 18, 0, 0, 19, 0,
+ 0, 20, 21, 306, 307, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 57, 58, 59, 60,
+ 61, 62, 63, 64, 65, 66, 67, 68, 0, 0,
+ 0, 0, 0, 69, 70, 71, 72, 73, 74, 75,
+ 76, 77, 78, 79, 24, 0, 80, 81, 82, 83,
+ 25, 26, 0, 0, 27, 0, 28, 0, 0, 0,
+ 0, 0, 0, 0, 84, 85, 86, 87, 88, 89,
+ 90, 91, 92, 29, 0, 30, 0, 0, 0, 0,
+ 0, 0, 0, 0, 31, 32, 0, 0, 0, 93,
+ 94, 33, 0, 0, 7, 8, 95, 9, 10, 0,
+ 96, 0, 0, 0, 0, 34, 11, 12, 13, 14,
+ 15, 16, 17, 18, 0, 0, 19, 0, 0, 20,
+ 21, 22, 23, 0, 0, 0, 0, 0, 0, 0,
+ 7, 8, 0, 9, 10, 0, 0, 0, 0, 0,
+ 0, 0, 11, 12, 13, 14, 15, 16, 17, 18,
+ 0, 0, 19, 0, 0, 20, 21, 22, 23, 234,
+ 235, 236, 237, 238, 239, 0, 0, 0, 0, 0,
+ 0, 0, 24, 0, 0, 0, 0, 0, 25, 26,
+ 0, 0, 27, 0, 28, 0, 0, 0, 0, 0,
+ 0, 0, 0, 240, 241, 242, 243, 244, 245, 246,
+ 247, 29, 248, 30, 0, 0, 0, 0, 24, 0,
+ 0, 0, 31, 32, 25, 26, 0, 0, 27, 33,
+ 28, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 42, 0, 0, 34, 0, 0, 0, 29, 0, 30,
+ 0, 0, 0, 0, 0, 0, 0, 0, 31, 32,
+ 50, 51, 52, 9, 0, 33, 53, 0, 132, 133,
+ 134, 54, 0, 0, 0, 0, 0, 0, 0, 34,
+ 135, 136, 0, 137, 138, 139, 140, 141, 142, 143,
+ 144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
+ 154, 155, 156, 157, 158, 0, 0, 0, 0, 0,
+ 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
+ 67, 68, 0, 0, 0, 0, 0, 69, 70, 71,
+ 72, 73, 74, 75, 76, 77, 78, 79, 0, 0,
+ 80, 81, 82, 83, 0, 0, 159, 160, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 84, 85,
+ 86, 87, 88, 89, 90, 91, 92, 0, 0, 0,
+ 161, 162, 163, 164, 165, 166, 167, 168, 31, 0,
+ 0, 0, 0, 113, 94, 50, 51, 52, 9, 0,
+ 95, 53, 0, 0, 96, 0, 54, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 55, 56, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 57, 58, 59, 60, 61,
+ 62, 63, 64, 65, 66, 67, 68, 0, 0, 0,
+ 0, 0, 69, 70, 71, 72, 73, 74, 75, 76,
+ 77, 78, 79, 0, 0, 80, 81, 82, 83, 0,
+ 50, 51, 52, 9, 0, 0, 53, 0, 0, 0,
+ 0, 54, 0, 84, 85, 86, 87, 88, 89, 90,
+ 91, 92, 0, 0, 0, 0, 0, 55, 56, 0,
+ 0, 0, 0, 31, 0, 0, 0, 284, 93, 94,
+ 0, 0, 0, 0, 0, 95, 0, 0, 0, 114,
+ 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
+ 67, 68, 0, 0, 0, 0, 0, 69, 70, 71,
+ 72, 73, 74, 75, 76, 77, 78, 79, 0, 0,
+ 80, 81, 82, 83, 0, 50, 51, 52, 9, 0,
+ 0, 53, 0, 0, 0, 0, 54, 0, 84, 85,
+ 86, 87, 88, 89, 90, 91, 92, 0, 0, 0,
+ 0, 0, 55, 56, 0, 0, 0, 0, 31, 0,
+ 0, 0, 0, 93, 94, 0, 0, 0, 0, 0,
+ 95, 0, 0, 0, 96, 57, 58, 59, 60, 61,
+ 62, 63, 64, 65, 66, 67, 68, 0, 0, 0,
+ 0, 0, 69, 70, 71, 72, 73, 74, 75, 76,
+ 77, 78, 79, 0, 0, 80, 81, 82, 83, 0,
+ 50, 51, 52, 9, 0, 0, 53, 0, 0, 0,
+ 0, 54, 0, 84, 85, 86, 87, 88, 89, 90,
+ 91, 92, 0, 0, 0, 0, 0, 55, 56, 0,
+ 0, 0, 0, 31, 0, 0, 0, 0, 113, 94,
+ 0, 0, 0, 0, 0, 95, 0, 0, 0, 114,
+ 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
+ 67, 68, 0, 0, 0, 0, 0, 69, 70, 71,
+ 72, 73, 74, 75, 76, 77, 78, 79, 0, 0,
+ 80, 81, 82, 83, 0, 50, 51, 52, 9, 0,
+ 0, 53, 0, 0, 0, 0, 54, 0, 84, 85,
+ 86, 87, 88, 89, 90, 91, 92, 0, 0, 0,
+ 0, 0, 55, 56, 0, 0, 0, 0, 31, 0,
+ 0, 0, 0, 93, 94, 0, 0, 0, 0, 0,
+ 95, 0, 0, 0, 114, 57, 58, 59, 60, 61,
+ 62, 63, 64, 65, 66, 67, 68, 0, 0, 0,
+ 0, 0, 69, 70, 71, 72, 73, 74, 75, 76,
+ 77, 78, 79, 0, 0, 80, 81, 82, 83, 0,
+ 281, 51, 52, 0, 0, 0, 282, 0, 0, 0,
+ 0, 283, 0, 84, 85, 86, 87, 88, 89, 90,
+ 91, 92, 0, 0, 0, 0, 0, 55, 56, 0,
+ 0, 0, 0, 31, 0, 0, 0, 0, 291, 94,
+ 0, 0, 0, 0, 0, 95, 0, 0, 0, 114,
+ 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
+ 67, 68, 0, 0, 0, 0, 0, 69, 70, 71,
+ 72, 73, 74, 75, 76, 77, 78, 79, 0, 0,
+ 80, 81, 82, 83, 0, 50, 51, 52, 0, 0,
+ 0, 53, 0, 0, 0, 0, 54, 0, 84, 85,
+ 86, 87, 88, 89, 90, 91, 92, 0, 0, 0,
+ 0, 0, 55, 56, 0, 0, 0, 0, 0, 0,
+ 0, 0, 284, 285, 94, 0, 0, 0, 0, 0,
+ 95, 0, 0, 0, 96, 57, 58, 59, 60, 61,
+ 62, 63, 64, 65, 66, 67, 68, 0, 0, 0,
+ 0, 0, 69, 70, 71, 72, 73, 74, 75, 76,
+ 77, 78, 79, 0, 0, 80, 81, 82, 83, 0,
+ 50, 51, 52, 0, 0, 0, 53, 0, 0, 0,
+ 0, 54, 0, 84, 85, 86, 87, 88, 89, 90,
+ 91, 92, 0, 0, 0, 0, 0, 55, 56, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 113, 94,
+ 0, 0, 0, 0, 0, 95, 447, 0, 0, 96,
+ 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
+ 67, 68, 0, 0, 0, 0, 0, 69, 70, 71,
+ 72, 73, 74, 75, 76, 77, 78, 79, 0, 0,
+ 80, 81, 82, 83, 0, 50, 51, 52, 0, 0,
+ 0, 53, 0, 0, 0, 0, 54, 0, 84, 85,
+ 86, 87, 88, 89, 90, 91, 92, 0, 0, 0,
+ 0, 0, 55, 56, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 113, 94, 0, 0, 0, 0, 0,
+ 95, 0, 0, 0, 96, 57, 58, 59, 60, 61,
+ 62, 63, 64, 65, 66, 67, 68, 0, 0, 0,
+ 0, 0, 69, 70, 71, 72, 73, 74, 75, 76,
+ 77, 78, 79, 0, 0, 80, 81, 82, 83, 0,
+ 50, 51, 52, 0, 0, 0, 53, 0, 0, 0,
+ 0, 54, 0, 84, 85, 86, 87, 88, 89, 90,
+ 91, 92, 0, 0, 0, 0, 0, 55, 56, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 93, 94,
+ 0, 0, 0, 0, 0, 95, 0, 0, 0, 96,
+ 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
+ 67, 68, 0, 0, 0, 0, 0, 69, 70, 71,
+ 72, 73, 74, 75, 76, 77, 78, 79, 0, 0,
+ 80, 81, 82, 83, 0, 0, 50, 51, 52, 0,
+ 0, 0, 53, 0, 0, 0, 0, 54, 84, 85,
+ 86, 87, 88, 89, 90, 91, 92, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 291, 94, 0, 0, 0, 0, 0,
+ 95, -205, 0, 0, 96, 0, 57, 58, 59, 60,
+ 61, 62, 63, 64, 65, 66, 67, 68, 0, 0,
+ 0, 0, 0, 69, 70, 71, 72, 73, 74, 75,
+ 76, 77, 78, 79, 0, 0, 80, 81, 82, 83,
+ 0, 0, 50, 51, 52, 0, 0, 0, 53, 0,
+ 0, 0, 0, 54, 84, 85, 86, 87, 88, 89,
+ 90, 91, 92, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 113,
+ 94, 0, 0, 0, 0, 0, 95, -204, 0, 0,
+ 96, 0, 57, 58, 59, 60, 61, 62, 63, 64,
+ 65, 66, 67, 68, 0, 0, 0, 0, 0, 69,
+ 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
+ 0, 0, 80, 81, 82, 83, 0, 50, 51, 52,
+ 0, 0, 0, 53, 0, 0, 0, 0, 54, 0,
+ 84, 85, 86, 87, 88, 89, 90, 91, 92, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 113, 94, 0, 0, 0,
+ 0, 0, 95, 0, 0, 0, 96, 57, 58, 59,
+ 60, 61, 62, 63, 64, 65, 66, 67, 68, 0,
+ 0, 0, 0, 0, 69, 70, 71, 72, 73, 74,
+ 75, 76, 77, 78, 79, 0, 0, 80, 81, 82,
+ 83, 55, 56, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 84, 85, 86, 87, 88,
+ 89, 90, 91, 92, 0, 58, 59, 60, 61, 62,
+ 63, 64, 65, 66, 67, 68, 55, 56, 0, 0,
+ 113, 94, 0, 0, 0, 0, 0, 95, 0, 0,
+ 0, 96, 0, 0, 80, 81, 82, 83, 0, 0,
+ 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
+ 68, 0, 84, 85, 86, 87, 88, 89, 90, 91,
+ 92, 0, 0, 0, 0, 232, 0, 0, 233, 80,
+ 81, 82, 83, 0, 0, 232, 381, 0, 233, 0,
+ 0, 0, 0, 0, 0, 0, 0, 84, 85, 86,
+ 87, 88, 89, 90, 91, 92, 259, 260, 236, 237,
+ 238, 239, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 284, 234, 235, 236, 237, 238, 239, 0, 0,
+ 0, 0, 259, 260, 236, 237, 238, 239, 0, 0,
+ 240, 241, 242, 243, 244, 245, 246, 247, 0, 248,
+ 0, 0, 0, 0, 0, 0, 240, 241, 242, 243,
+ 244, 245, 246, 247, 0, 248, 240, 241, 242, 243,
+ 244, 245, 246, 247, 0, 248, 58, 59, 60, 61,
+ 62, 63, 64, 65, 66, 67, 68, 58, 59, 60,
+ 61, 62, 63, 64, 65, 66, 67, 68, 0, 0,
+ 0, 0, 0, 0, 0, 80, 81, 82, 83, 0,
+ 0, 0, 0, 0, 0, 0, 80, 81, 82, 83,
+ 0, 0, 0, 84, 85, 86, 87, 88, 89, 90,
+ 91, 92, 0, 0, 84, 85, 86, 87, 88, 89,
+ 90, 91, 92, 0, 0, 0, 0, 216, 259, 260,
+ 236, 237, 238, 239, 0, 0, 0, 234, 235, 236,
+ 237, 238, 239, 0, 0, 0, 234, 0, 236, 237,
+ 238, 239, 0, 0, 0, 259, 0, 236, 237, 238,
+ 239, 0, 0, 241, 242, 243, 244, 245, 246, 247,
+ 0, 248, 241, 242, 243, 244, 245, 246, 247, 0,
+ 248, 241, 242, 243, 244, 245, 246, 247, 0, 248,
+ 241, 242, 243, 244, 245, 246, 247, 0, 248
+};
+
+static const yytype_int16 yycheck[] =
+{
+ 26, 128, 106, 52, 30, 52, 32, 4, 108, 4,
+ 129, 114, 0, 3, 40, 6, 0, 140, 141, 9,
+ 0, 97, 132, 133, 14, 139, 145, 3, 0, 6,
+ 26, 26, 139, 9, 140, 145, 32, 32, 14, 3,
+ 4, 28, 281, 141, 171, 40, 285, 35, 124, 93,
+ 4, 30, 31, 4, 104, 43, 126, 44, 48, 132,
+ 133, 94, 134, 135, 136, 6, 138, 93, 82, 95,
+ 96, 97, 145, 14, 15, 16, 17, 18, 19, 20,
+ 140, 22, 8, 132, 133, 132, 133, 26, 114, 132,
+ 133, 82, 126, 32, 95, 96, 146, 93, 124, 97,
+ 98, 97, 97, 147, 131, 132, 133, 94, 126, 135,
+ 136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
+ 146, 147, 101, 102, 150, 151, 152, 122, 124, 124,
+ 230, 130, 129, 128, 126, 161, 162, 127, 377, 378,
+ 166, 167, 125, 126, 121, 171, 140, 143, 144, 145,
+ 146, 127, 255, 256, 93, 139, 259, 260, 97, 143,
+ 144, 131, 132, 133, 126, 209, 210, 139, 163, 164,
+ 165, 143, 144, 126, 413, 171, 171, 126, 282, 283,
+ 30, 31, 37, 209, 210, 124, 173, 128, 132, 133,
+ 290, 126, 93, 180, 181, 182, 183, 184, 185, 186,
+ 187, 188, 189, 190, 143, 144, 145, 146, 234, 235,
+ 236, 237, 238, 239, 240, 241, 242, 243, 244, 245,
+ 246, 247, 248, 249, 250, 251, 6, 126, 126, 255,
+ 256, 281, 171, 259, 260, 285, 129, 287, 126, 132,
+ 133, 285, 143, 144, 145, 146, 129, 291, 126, 132,
+ 133, 101, 102, 249, 250, 6, 4, 129, 8, 285,
+ 132, 133, 257, 258, 6, 291, 145, 130, 145, 264,
+ 171, 10, 138, 15, 16, 17, 18, 19, 20, 3,
+ 22, 125, 144, 410, 49, 329, 330, 144, 8, 285,
+ 15, 16, 17, 18, 19, 20, 143, 22, 3, 8,
+ 145, 129, 328, 329, 330, 145, 145, 333, 334, 145,
+ 249, 250, 145, 129, 129, 95, 96, 97, 98, 99,
+ 100, 65, 66, 67, 68, 69, 145, 377, 378, 50,
+ 8, 145, 328, 145, 95, 129, 3, 333, 334, 111,
+ 145, 121, 145, 51, 6, 145, 285, 145, 249, 250,
+ 130, 131, 132, 133, 134, 135, 136, 145, 138, 145,
+ 92, 145, 8, 413, 35, 171, 32, 65, 66, 67,
+ 68, 69, 203, 415, -1, -1, 33, -1, 404, 405,
+ 406, -1, 408, -1, 285, -1, 128, -1, -1, 328,
+ -1, -1, -1, -1, 333, 334, 36, -1, 424, 425,
+ -1, 145, 389, 128, -1, -1, 393, 394, 404, 405,
+ -1, 97, 98, 99, 100, 410, 442, -1, -1, -1,
+ -1, 447, 65, 66, 67, 68, 69, 328, 424, 425,
+ -1, -1, 333, 334, 132, 133, -1, -1, 95, 96,
+ 97, 98, 99, 100, 130, 131, 132, 133, 134, 135,
+ 136, -1, 138, -1, -1, 95, 96, 97, 98, 99,
+ 100, 3, 4, 5, 6, 404, 405, 9, -1, -1,
+ -1, -1, 14, 130, 131, 132, 133, 134, 135, 136,
+ -1, 138, -1, -1, -1, 424, 425, -1, 30, 31,
+ 130, 131, 132, 133, 134, 135, 136, -1, 138, -1,
+ -1, -1, -1, 404, 405, -1, -1, -1, -1, -1,
+ -1, 53, 54, 55, 56, 57, 58, 59, 60, 61,
+ 62, 63, 64, 424, 425, -1, -1, -1, 70, 71,
+ 72, 73, 74, 75, 76, 77, 78, 79, 80, 99,
+ 100, 83, 84, 85, 86, 132, 133, 134, 135, 136,
+ -1, 138, -1, -1, -1, -1, -1, -1, -1, 101,
+ 102, 103, 104, 105, 106, 107, 108, 109, -1, -1,
+ 130, 131, 132, 133, 134, 135, 136, -1, 138, 121,
+ -1, -1, -1, -1, 126, 127, -1, -1, -1, -1,
+ -1, 133, -1, -1, -1, 137, 3, 4, 5, 6,
+ 7, -1, 9, 145, -1, -1, -1, 14, 15, 16,
+ 17, 18, 19, 20, 21, 22, -1, -1, 25, -1,
+ -1, 28, 29, 30, 31, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, 53, 54, 55, 56,
+ 57, 58, 59, 60, 61, 62, 63, 64, -1, -1,
+ -1, -1, -1, 70, 71, 72, 73, 74, 75, 76,
+ 77, 78, 79, 80, 81, -1, 83, 84, 85, 86,
+ 87, 88, -1, -1, 91, -1, 93, -1, -1, -1,
+ -1, -1, -1, -1, 101, 102, 103, 104, 105, 106,
+ 107, 108, 109, 110, -1, 112, -1, -1, -1, -1,
+ -1, -1, -1, -1, 121, 122, -1, -1, -1, 126,
+ 127, 128, -1, -1, 3, 4, 133, 6, 7, -1,
+ 137, -1, -1, -1, -1, 142, 15, 16, 17, 18,
+ 19, 20, 21, 22, -1, -1, 25, -1, -1, 28,
+ 29, 30, 31, -1, -1, -1, -1, -1, -1, -1,
+ 3, 4, -1, 6, 7, -1, -1, -1, -1, -1,
+ -1, -1, 15, 16, 17, 18, 19, 20, 21, 22,
+ -1, -1, 25, -1, -1, 28, 29, 30, 31, 95,
+ 96, 97, 98, 99, 100, -1, -1, -1, -1, -1,
+ -1, -1, 81, -1, -1, -1, -1, -1, 87, 88,
+ -1, -1, 91, -1, 93, -1, -1, -1, -1, -1,
+ -1, -1, -1, 129, 130, 131, 132, 133, 134, 135,
+ 136, 110, 138, 112, -1, -1, -1, -1, 81, -1,
+ -1, -1, 121, 122, 87, 88, -1, -1, 91, 128,
+ 93, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 139, -1, -1, 142, -1, -1, -1, 110, -1, 112,
+ -1, -1, -1, -1, -1, -1, -1, -1, 121, 122,
+ 3, 4, 5, 6, -1, 128, 9, -1, 11, 12,
+ 13, 14, -1, -1, -1, -1, -1, -1, -1, 142,
+ 23, 24, -1, 26, 27, 28, 29, 30, 31, 32,
+ 33, 34, 35, 36, 37, 38, 39, 40, 41, 42,
+ 43, 44, 45, 46, 47, -1, -1, -1, -1, -1,
+ 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
+ 63, 64, -1, -1, -1, -1, -1, 70, 71, 72,
+ 73, 74, 75, 76, 77, 78, 79, 80, -1, -1,
+ 83, 84, 85, 86, -1, -1, 89, 90, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, 101, 102,
+ 103, 104, 105, 106, 107, 108, 109, -1, -1, -1,
+ 113, 114, 115, 116, 117, 118, 119, 120, 121, -1,
+ -1, -1, -1, 126, 127, 3, 4, 5, 6, -1,
+ 133, 9, -1, -1, 137, -1, 14, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, 30, 31, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, 53, 54, 55, 56, 57,
+ 58, 59, 60, 61, 62, 63, 64, -1, -1, -1,
+ -1, -1, 70, 71, 72, 73, 74, 75, 76, 77,
+ 78, 79, 80, -1, -1, 83, 84, 85, 86, -1,
+ 3, 4, 5, 6, -1, -1, 9, -1, -1, -1,
+ -1, 14, -1, 101, 102, 103, 104, 105, 106, 107,
+ 108, 109, -1, -1, -1, -1, -1, 30, 31, -1,
+ -1, -1, -1, 121, -1, -1, -1, 125, 126, 127,
+ -1, -1, -1, -1, -1, 133, -1, -1, -1, 137,
+ 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
+ 63, 64, -1, -1, -1, -1, -1, 70, 71, 72,
+ 73, 74, 75, 76, 77, 78, 79, 80, -1, -1,
+ 83, 84, 85, 86, -1, 3, 4, 5, 6, -1,
+ -1, 9, -1, -1, -1, -1, 14, -1, 101, 102,
+ 103, 104, 105, 106, 107, 108, 109, -1, -1, -1,
+ -1, -1, 30, 31, -1, -1, -1, -1, 121, -1,
+ -1, -1, -1, 126, 127, -1, -1, -1, -1, -1,
+ 133, -1, -1, -1, 137, 53, 54, 55, 56, 57,
+ 58, 59, 60, 61, 62, 63, 64, -1, -1, -1,
+ -1, -1, 70, 71, 72, 73, 74, 75, 76, 77,
+ 78, 79, 80, -1, -1, 83, 84, 85, 86, -1,
+ 3, 4, 5, 6, -1, -1, 9, -1, -1, -1,
+ -1, 14, -1, 101, 102, 103, 104, 105, 106, 107,
+ 108, 109, -1, -1, -1, -1, -1, 30, 31, -1,
+ -1, -1, -1, 121, -1, -1, -1, -1, 126, 127,
+ -1, -1, -1, -1, -1, 133, -1, -1, -1, 137,
+ 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
+ 63, 64, -1, -1, -1, -1, -1, 70, 71, 72,
+ 73, 74, 75, 76, 77, 78, 79, 80, -1, -1,
+ 83, 84, 85, 86, -1, 3, 4, 5, 6, -1,
+ -1, 9, -1, -1, -1, -1, 14, -1, 101, 102,
+ 103, 104, 105, 106, 107, 108, 109, -1, -1, -1,
+ -1, -1, 30, 31, -1, -1, -1, -1, 121, -1,
+ -1, -1, -1, 126, 127, -1, -1, -1, -1, -1,
+ 133, -1, -1, -1, 137, 53, 54, 55, 56, 57,
+ 58, 59, 60, 61, 62, 63, 64, -1, -1, -1,
+ -1, -1, 70, 71, 72, 73, 74, 75, 76, 77,
+ 78, 79, 80, -1, -1, 83, 84, 85, 86, -1,
+ 3, 4, 5, -1, -1, -1, 9, -1, -1, -1,
+ -1, 14, -1, 101, 102, 103, 104, 105, 106, 107,
+ 108, 109, -1, -1, -1, -1, -1, 30, 31, -1,
+ -1, -1, -1, 121, -1, -1, -1, -1, 126, 127,
+ -1, -1, -1, -1, -1, 133, -1, -1, -1, 137,
+ 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
+ 63, 64, -1, -1, -1, -1, -1, 70, 71, 72,
+ 73, 74, 75, 76, 77, 78, 79, 80, -1, -1,
+ 83, 84, 85, 86, -1, 3, 4, 5, -1, -1,
+ -1, 9, -1, -1, -1, -1, 14, -1, 101, 102,
+ 103, 104, 105, 106, 107, 108, 109, -1, -1, -1,
+ -1, -1, 30, 31, -1, -1, -1, -1, -1, -1,
+ -1, -1, 125, 126, 127, -1, -1, -1, -1, -1,
+ 133, -1, -1, -1, 137, 53, 54, 55, 56, 57,
+ 58, 59, 60, 61, 62, 63, 64, -1, -1, -1,
+ -1, -1, 70, 71, 72, 73, 74, 75, 76, 77,
+ 78, 79, 80, -1, -1, 83, 84, 85, 86, -1,
+ 3, 4, 5, -1, -1, -1, 9, -1, -1, -1,
+ -1, 14, -1, 101, 102, 103, 104, 105, 106, 107,
+ 108, 109, -1, -1, -1, -1, -1, 30, 31, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, 126, 127,
+ -1, -1, -1, -1, -1, 133, 134, -1, -1, 137,
+ 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
+ 63, 64, -1, -1, -1, -1, -1, 70, 71, 72,
+ 73, 74, 75, 76, 77, 78, 79, 80, -1, -1,
+ 83, 84, 85, 86, -1, 3, 4, 5, -1, -1,
+ -1, 9, -1, -1, -1, -1, 14, -1, 101, 102,
+ 103, 104, 105, 106, 107, 108, 109, -1, -1, -1,
+ -1, -1, 30, 31, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 126, 127, -1, -1, -1, -1, -1,
+ 133, -1, -1, -1, 137, 53, 54, 55, 56, 57,
+ 58, 59, 60, 61, 62, 63, 64, -1, -1, -1,
+ -1, -1, 70, 71, 72, 73, 74, 75, 76, 77,
+ 78, 79, 80, -1, -1, 83, 84, 85, 86, -1,
+ 3, 4, 5, -1, -1, -1, 9, -1, -1, -1,
+ -1, 14, -1, 101, 102, 103, 104, 105, 106, 107,
+ 108, 109, -1, -1, -1, -1, -1, 30, 31, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, 126, 127,
+ -1, -1, -1, -1, -1, 133, -1, -1, -1, 137,
+ 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
+ 63, 64, -1, -1, -1, -1, -1, 70, 71, 72,
+ 73, 74, 75, 76, 77, 78, 79, 80, -1, -1,
+ 83, 84, 85, 86, -1, -1, 3, 4, 5, -1,
+ -1, -1, 9, -1, -1, -1, -1, 14, 101, 102,
+ 103, 104, 105, 106, 107, 108, 109, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, 126, 127, -1, -1, -1, -1, -1,
+ 133, 48, -1, -1, 137, -1, 53, 54, 55, 56,
+ 57, 58, 59, 60, 61, 62, 63, 64, -1, -1,
+ -1, -1, -1, 70, 71, 72, 73, 74, 75, 76,
+ 77, 78, 79, 80, -1, -1, 83, 84, 85, 86,
+ -1, -1, 3, 4, 5, -1, -1, -1, 9, -1,
+ -1, -1, -1, 14, 101, 102, 103, 104, 105, 106,
+ 107, 108, 109, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, 126,
+ 127, -1, -1, -1, -1, -1, 133, 48, -1, -1,
+ 137, -1, 53, 54, 55, 56, 57, 58, 59, 60,
+ 61, 62, 63, 64, -1, -1, -1, -1, -1, 70,
+ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
+ -1, -1, 83, 84, 85, 86, -1, 3, 4, 5,
+ -1, -1, -1, 9, -1, -1, -1, -1, 14, -1,
+ 101, 102, 103, 104, 105, 106, 107, 108, 109, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, 126, 127, -1, -1, -1,
+ -1, -1, 133, -1, -1, -1, 137, 53, 54, 55,
+ 56, 57, 58, 59, 60, 61, 62, 63, 64, -1,
+ -1, -1, -1, -1, 70, 71, 72, 73, 74, 75,
+ 76, 77, 78, 79, 80, -1, -1, 83, 84, 85,
+ 86, 30, 31, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, 101, 102, 103, 104, 105,
+ 106, 107, 108, 109, -1, 54, 55, 56, 57, 58,
+ 59, 60, 61, 62, 63, 64, 30, 31, -1, -1,
+ 126, 127, -1, -1, -1, -1, -1, 133, -1, -1,
+ -1, 137, -1, -1, 83, 84, 85, 86, -1, -1,
+ 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
+ 64, -1, 101, 102, 103, 104, 105, 106, 107, 108,
+ 109, -1, -1, -1, -1, 48, -1, -1, 51, 83,
+ 84, 85, 86, -1, -1, 48, 125, -1, 51, -1,
+ -1, -1, -1, -1, -1, -1, -1, 101, 102, 103,
+ 104, 105, 106, 107, 108, 109, 95, 96, 97, 98,
+ 99, 100, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, 125, 95, 96, 97, 98, 99, 100, -1, -1,
+ -1, -1, 95, 96, 97, 98, 99, 100, -1, -1,
+ 129, 130, 131, 132, 133, 134, 135, 136, -1, 138,
+ -1, -1, -1, -1, -1, -1, 129, 130, 131, 132,
+ 133, 134, 135, 136, -1, 138, 129, 130, 131, 132,
+ 133, 134, 135, 136, -1, 138, 54, 55, 56, 57,
+ 58, 59, 60, 61, 62, 63, 64, 54, 55, 56,
+ 57, 58, 59, 60, 61, 62, 63, 64, -1, -1,
+ -1, -1, -1, -1, -1, 83, 84, 85, 86, -1,
+ -1, -1, -1, -1, -1, -1, 83, 84, 85, 86,
+ -1, -1, -1, 101, 102, 103, 104, 105, 106, 107,
+ 108, 109, -1, -1, 101, 102, 103, 104, 105, 106,
+ 107, 108, 109, -1, -1, -1, -1, 125, 95, 96,
+ 97, 98, 99, 100, -1, -1, -1, 95, 96, 97,
+ 98, 99, 100, -1, -1, -1, 95, -1, 97, 98,
+ 99, 100, -1, -1, -1, 95, -1, 97, 98, 99,
+ 100, -1, -1, 130, 131, 132, 133, 134, 135, 136,
+ -1, 138, 130, 131, 132, 133, 134, 135, 136, -1,
+ 138, 130, 131, 132, 133, 134, 135, 136, -1, 138,
+ 130, 131, 132, 133, 134, 135, 136, -1, 138
+};
+
+/* YYSTOS[STATE-NUM] -- The symbol kind of the accessing symbol of
+ state STATE-NUM. */
+static const yytype_uint8 yystos[] =
+{
+ 0, 139, 147, 148, 150, 151, 0, 3, 4, 6,
+ 7, 15, 16, 17, 18, 19, 20, 21, 22, 25,
+ 28, 29, 30, 31, 81, 87, 88, 91, 93, 110,
+ 112, 121, 122, 128, 142, 149, 152, 161, 164, 170,
+ 174, 176, 139, 141, 140, 141, 140, 6, 82, 153,
+ 3, 4, 5, 9, 14, 30, 31, 53, 54, 55,
+ 56, 57, 58, 59, 60, 61, 62, 63, 64, 70,
+ 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
+ 83, 84, 85, 86, 101, 102, 103, 104, 105, 106,
+ 107, 108, 109, 126, 127, 133, 137, 162, 163, 176,
+ 178, 179, 181, 182, 183, 184, 185, 186, 191, 192,
+ 193, 194, 4, 126, 137, 167, 168, 176, 182, 192,
+ 194, 4, 192, 126, 162, 175, 171, 150, 151, 4,
+ 129, 94, 11, 12, 13, 23, 24, 26, 27, 28,
+ 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
+ 39, 40, 41, 42, 43, 44, 45, 46, 47, 89,
+ 90, 113, 114, 115, 116, 117, 118, 119, 120, 176,
+ 192, 150, 167, 140, 3, 4, 160, 82, 156, 8,
+ 126, 126, 126, 126, 126, 126, 126, 126, 126, 126,
+ 126, 30, 31, 101, 102, 30, 31, 101, 102, 167,
+ 178, 181, 182, 192, 194, 167, 192, 192, 163, 132,
+ 133, 65, 66, 67, 68, 69, 125, 191, 6, 14,
+ 15, 16, 17, 18, 19, 20, 22, 128, 187, 187,
+ 48, 183, 48, 51, 95, 96, 97, 98, 99, 100,
+ 129, 130, 131, 132, 133, 134, 135, 136, 138, 180,
+ 130, 140, 168, 192, 37, 95, 96, 97, 98, 95,
+ 96, 176, 6, 148, 150, 148, 170, 4, 159, 192,
+ 192, 192, 192, 192, 192, 192, 192, 178, 192, 178,
+ 178, 3, 9, 14, 125, 126, 178, 188, 189, 190,
+ 191, 126, 181, 192, 192, 192, 192, 192, 192, 176,
+ 176, 176, 192, 192, 3, 4, 30, 31, 170, 178,
+ 179, 182, 167, 154, 8, 167, 167, 167, 167, 167,
+ 167, 167, 167, 167, 145, 167, 167, 145, 129, 132,
+ 133, 145, 145, 180, 130, 10, 181, 181, 3, 144,
+ 183, 49, 192, 192, 192, 192, 192, 192, 192, 192,
+ 192, 192, 192, 192, 192, 192, 192, 178, 178, 192,
+ 165, 168, 192, 168, 192, 176, 176, 168, 192, 168,
+ 192, 177, 144, 143, 8, 189, 191, 187, 187, 3,
+ 189, 125, 191, 181, 192, 8, 157, 145, 145, 129,
+ 145, 145, 145, 129, 129, 145, 145, 145, 178, 181,
+ 181, 178, 178, 50, 52, 129, 33, 8, 129, 145,
+ 172, 189, 189, 129, 3, 155, 111, 166, 167, 167,
+ 167, 145, 145, 145, 52, 129, 51, 178, 178, 192,
+ 192, 170, 173, 189, 166, 6, 145, 145, 145, 178,
+ 178, 131, 36, 169, 145, 145, 131, 134, 192, 92,
+ 145, 192, 158, 8
+};
+
+/* YYR1[RULE-NUM] -- Symbol kind of the left-hand side of rule RULE-NUM. */
+static const yytype_uint8 yyr1[] =
+{
+ 0, 146, 147, 147, 148, 149, 149, 150, 150, 151,
+ 151, 152, 152, 152, 152, 152, 152, 152, 152, 152,
+ 152, 153, 152, 152, 154, 155, 152, 156, 157, 152,
+ 158, 152, 152, 159, 152, 152, 152, 160, 160, 161,
+ 161, 161, 162, 162, 163, 163, 163, 165, 164, 166,
+ 166, 167, 167, 168, 168, 168, 168, 168, 168, 168,
+ 168, 168, 169, 169, 169, 170, 170, 170, 170, 171,
+ 172, 170, 170, 173, 173, 174, 174, 174, 174, 174,
+ 174, 174, 174, 174, 174, 174, 175, 174, 174, 174,
+ 174, 174, 174, 174, 174, 174, 174, 174, 174, 174,
+ 174, 174, 174, 174, 174, 174, 174, 174, 174, 174,
+ 174, 174, 174, 174, 174, 174, 174, 174, 174, 174,
+ 174, 174, 174, 174, 174, 174, 174, 174, 174, 174,
+ 174, 174, 174, 174, 174, 174, 176, 176, 177, 177,
+ 178, 178, 178, 179, 179, 179, 179, 179, 179, 179,
+ 179, 179, 179, 180, 180, 181, 181, 182, 182, 182,
+ 182, 182, 183, 183, 183, 184, 184, 185, 185, 186,
+ 186, 187, 187, 187, 187, 187, 187, 187, 187, 187,
+ 188, 188, 189, 189, 189, 190, 190, 190, 190, 190,
+ 190, 191, 191, 191, 191, 191, 191, 191, 191, 191,
+ 191, 191, 191, 191, 191, 191, 191, 191, 191, 191,
+ 191, 191, 191, 191, 191, 191, 191, 191, 191, 191,
+ 191, 191, 191, 192, 192, 193, 194, 194, 194, 194,
+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
+ 194, 194, 194, 194, 194, 194, 194, 194, 194, 194,
+ 194
+};
+
+/* YYR2[RULE-NUM] -- Number of symbols on the right-hand side of rule RULE-NUM. */
+static const yytype_int8 yyr2[] =
+{
+ 0, 2, 1, 1, 3, 1, 3, 0, 1, 1,
+ 2, 3, 3, 4, 1, 1, 1, 1, 1, 2,
+ 2, 0, 3, 2, 0, 0, 7, 0, 0, 6,
+ 0, 10, 1, 0, 4, 1, 1, 1, 1, 2,
+ 2, 3, 1, 2, 1, 1, 1, 0, 5, 0,
+ 2, 1, 1, 3, 3, 3, 3, 3, 3, 3,
+ 3, 2, 0, 2, 3, 1, 4, 4, 4, 0,
+ 0, 6, 1, 0, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 2, 3, 0, 4, 3, 3,
+ 3, 3, 2, 2, 3, 2, 3, 2, 3, 2,
+ 3, 3, 3, 3, 3, 3, 3, 2, 2, 2,
+ 3, 2, 3, 2, 3, 3, 3, 3, 3, 3,
+ 2, 3, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 3, 2, 1, 5, 0, 3,
+ 1, 1, 3, 1, 3, 5, 3, 5, 5, 5,
+ 7, 6, 8, 1, 4, 3, 3, 1, 2, 2,
+ 3, 1, 1, 1, 3, 1, 3, 1, 2, 2,
+ 2, 1, 1, 1, 1, 1, 1, 1, 2, 1,
+ 2, 3, 1, 1, 2, 1, 5, 4, 3, 3,
+ 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 2, 2, 2, 2,
+ 1, 1, 2, 2, 2, 2, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 3, 1, 1, 2, 2,
+ 2, 2, 2, 3, 3, 3, 3, 3, 3, 2,
+ 3, 4, 4, 6, 4, 4, 4, 6, 6, 4,
+ 4, 3, 4, 3, 3, 3, 3, 3, 3, 3,
+ 2
+};
+
+
+enum { YYENOMEM = -2 };
+
+#define yyerrok (yyerrstatus = 0)
+#define yyclearin (yychar = YYEMPTY)
+
+#define YYACCEPT goto yyacceptlab
+#define YYABORT goto yyabortlab
+#define YYERROR goto yyerrorlab
+#define YYNOMEM goto yyexhaustedlab
+
+
+#define YYRECOVERING() (!!yyerrstatus)
+
+#define YYBACKUP(Token, Value) \
+ do \
+ if (yychar == YYEMPTY) \
+ { \
+ yychar = (Token); \
+ yylval = (Value); \
+ YYPOPSTACK (yylen); \
+ yystate = *yyssp; \
+ goto yybackup; \
+ } \
+ else \
+ { \
+ yyerror (YY_("syntax error: cannot back up")); \
+ YYERROR; \
+ } \
+ while (0)
+
+/* Backward compatibility with an undocumented macro.
+ Use YYerror or YYUNDEF. */
+#define YYERRCODE YYUNDEF
+
+
+/* Enable debugging if requested. */
+#if YYDEBUG
+
+# ifndef YYFPRINTF
+# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
+# define YYFPRINTF fprintf
+# endif
+
+# define YYDPRINTF(Args) \
+do { \
+ if (yydebug) \
+ YYFPRINTF Args; \
+} while (0)
+
+
+
+
+# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \
+do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title); \
+ yy_symbol_print (stderr, \
+ Kind, Value); \
+ YYFPRINTF (stderr, "\n"); \
+ } \
+} while (0)
+
+
+/*-----------------------------------.
+| Print this symbol's value on YYO. |
+`-----------------------------------*/
+
+static void
+yy_symbol_value_print (FILE *yyo,
+ yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
+{
+ FILE *yyoutput = yyo;
+ YY_USE (yyoutput);
+ if (!yyvaluep)
+ return;
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ YY_USE (yykind);
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+}
+
+
+/*---------------------------.
+| Print this symbol on YYO. |
+`---------------------------*/
+
+static void
+yy_symbol_print (FILE *yyo,
+ yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep)
+{
+ YYFPRINTF (yyo, "%s %s (",
+ yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind));
+
+ yy_symbol_value_print (yyo, yykind, yyvaluep);
+ YYFPRINTF (yyo, ")");
+}
+
+/*------------------------------------------------------------------.
+| yy_stack_print -- Print the state stack from its BOTTOM up to its |
+| TOP (included). |
+`------------------------------------------------------------------*/
+
+static void
+yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop)
+{
+ YYFPRINTF (stderr, "Stack now");
+ for (; yybottom <= yytop; yybottom++)
+ {
+ int yybot = *yybottom;
+ YYFPRINTF (stderr, " %d", yybot);
+ }
+ YYFPRINTF (stderr, "\n");
+}
+
+# define YY_STACK_PRINT(Bottom, Top) \
+do { \
+ if (yydebug) \
+ yy_stack_print ((Bottom), (Top)); \
+} while (0)
+
+
+/*------------------------------------------------.
+| Report that the YYRULE is going to be reduced. |
+`------------------------------------------------*/
+
+static void
+yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp,
+ int yyrule)
+{
+ int yylno = yyrline[yyrule];
+ int yynrhs = yyr2[yyrule];
+ int yyi;
+ YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n",
+ yyrule - 1, yylno);
+ /* The symbols being reduced. */
+ for (yyi = 0; yyi < yynrhs; yyi++)
+ {
+ YYFPRINTF (stderr, " $%d = ", yyi + 1);
+ yy_symbol_print (stderr,
+ YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]),
+ &yyvsp[(yyi + 1) - (yynrhs)]);
+ YYFPRINTF (stderr, "\n");
+ }
+}
+
+# define YY_REDUCE_PRINT(Rule) \
+do { \
+ if (yydebug) \
+ yy_reduce_print (yyssp, yyvsp, Rule); \
+} while (0)
+
+/* Nonzero means print parse trace. It is left uninitialized so that
+ multiple parsers can coexist. */
+int yydebug;
+#else /* !YYDEBUG */
+# define YYDPRINTF(Args) ((void) 0)
+# define YY_SYMBOL_PRINT(Title, Kind, Value, Location)
+# define YY_STACK_PRINT(Bottom, Top)
+# define YY_REDUCE_PRINT(Rule)
+#endif /* !YYDEBUG */
+
+
+/* YYINITDEPTH -- initial size of the parser's stacks. */
+#ifndef YYINITDEPTH
+# define YYINITDEPTH 200
+#endif
+
+/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
+ if the built-in stack extension method is used).
+
+ Do not make this value too large; the results are undefined if
+ YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
+ evaluated with infinite-precision integer arithmetic. */
+
+#ifndef YYMAXDEPTH
+# define YYMAXDEPTH 10000
+#endif
+
+
+
+
+
+
+/*-----------------------------------------------.
+| Release the memory associated to this symbol. |
+`-----------------------------------------------*/
+
+static void
+yydestruct (const char *yymsg,
+ yysymbol_kind_t yykind, YYSTYPE *yyvaluep)
+{
+ YY_USE (yyvaluep);
+ if (!yymsg)
+ yymsg = "Deleting";
+ YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp);
+
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ YY_USE (yykind);
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+}
+
+
+/* Lookahead token kind. */
+int yychar;
+
+/* The semantic value of the lookahead symbol. */
+YYSTYPE yylval;
+/* Number of syntax errors so far. */
+int yynerrs;
+
+
+
+
+/*----------.
+| yyparse. |
+`----------*/
+
+int
+yyparse (void)
+{
+ yy_state_fast_t yystate = 0;
+ /* Number of tokens to shift before error messages enabled. */
+ int yyerrstatus = 0;
+
+ /* Refer to the stacks through separate pointers, to allow yyoverflow
+ to reallocate them elsewhere. */
+
+ /* Their size. */
+ YYPTRDIFF_T yystacksize = YYINITDEPTH;
+
+ /* The state stack: array, bottom, top. */
+ yy_state_t yyssa[YYINITDEPTH];
+ yy_state_t *yyss = yyssa;
+ yy_state_t *yyssp = yyss;
+
+ /* The semantic value stack: array, bottom, top. */
+ YYSTYPE yyvsa[YYINITDEPTH];
+ YYSTYPE *yyvs = yyvsa;
+ YYSTYPE *yyvsp = yyvs;
+
+ int yyn;
+ /* The return value of yyparse. */
+ int yyresult;
+ /* Lookahead symbol kind. */
+ yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY;
+ /* The variables used to return semantic value and location from the
+ action routines. */
+ YYSTYPE yyval;
+
+
+
+#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
+
+ /* The number of symbols on the RHS of the reduced rule.
+ Keep to zero when no symbol should be popped. */
+ int yylen = 0;
+
+ YYDPRINTF ((stderr, "Starting parse\n"));
+
+ yychar = YYEMPTY; /* Cause a token to be read. */
+
+ goto yysetstate;
+
+
+/*------------------------------------------------------------.
+| yynewstate -- push a new state, which is found in yystate. |
+`------------------------------------------------------------*/
+yynewstate:
+ /* In all cases, when you get here, the value and location stacks
+ have just been pushed. So pushing a state here evens the stacks. */
+ yyssp++;
+
+
+/*--------------------------------------------------------------------.
+| yysetstate -- set current state (the top of the stack) to yystate. |
+`--------------------------------------------------------------------*/
+yysetstate:
+ YYDPRINTF ((stderr, "Entering state %d\n", yystate));
+ YY_ASSERT (0 <= yystate && yystate < YYNSTATES);
+ YY_IGNORE_USELESS_CAST_BEGIN
+ *yyssp = YY_CAST (yy_state_t, yystate);
+ YY_IGNORE_USELESS_CAST_END
+ YY_STACK_PRINT (yyss, yyssp);
+
+ if (yyss + yystacksize - 1 <= yyssp)
+#if !defined yyoverflow && !defined YYSTACK_RELOCATE
+ YYNOMEM;
+#else
+ {
+ /* Get the current used size of the three stacks, in elements. */
+ YYPTRDIFF_T yysize = yyssp - yyss + 1;
+
+# if defined yyoverflow
+ {
+ /* Give user a chance to reallocate the stack. Use copies of
+ these so that the &'s don't force the real ones into
+ memory. */
+ yy_state_t *yyss1 = yyss;
+ YYSTYPE *yyvs1 = yyvs;
+
+ /* Each stack pointer address is followed by the size of the
+ data in use in that stack, in bytes. This used to be a
+ conditional around just the two extra args, but that might
+ be undefined if yyoverflow is a macro. */
+ yyoverflow (YY_("memory exhausted"),
+ &yyss1, yysize * YYSIZEOF (*yyssp),
+ &yyvs1, yysize * YYSIZEOF (*yyvsp),
+ &yystacksize);
+ yyss = yyss1;
+ yyvs = yyvs1;
+ }
+# else /* defined YYSTACK_RELOCATE */
+ /* Extend the stack our own way. */
+ if (YYMAXDEPTH <= yystacksize)
+ YYNOMEM;
+ yystacksize *= 2;
+ if (YYMAXDEPTH < yystacksize)
+ yystacksize = YYMAXDEPTH;
+
+ {
+ yy_state_t *yyss1 = yyss;
+ union yyalloc *yyptr =
+ YY_CAST (union yyalloc *,
+ YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize))));
+ if (! yyptr)
+ YYNOMEM;
+ YYSTACK_RELOCATE (yyss_alloc, yyss);
+ YYSTACK_RELOCATE (yyvs_alloc, yyvs);
+# undef YYSTACK_RELOCATE
+ if (yyss1 != yyssa)
+ YYSTACK_FREE (yyss1);
+ }
+# endif
+
+ yyssp = yyss + yysize - 1;
+ yyvsp = yyvs + yysize - 1;
+
+ YY_IGNORE_USELESS_CAST_BEGIN
+ YYDPRINTF ((stderr, "Stack size increased to %ld\n",
+ YY_CAST (long, yystacksize)));
+ YY_IGNORE_USELESS_CAST_END
+
+ if (yyss + yystacksize - 1 <= yyssp)
+ YYABORT;
+ }
+#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
+
+
+ if (yystate == YYFINAL)
+ YYACCEPT;
+
+ goto yybackup;
+
+
+/*-----------.
+| yybackup. |
+`-----------*/
+yybackup:
+ /* Do appropriate processing given the current state. Read a
+ lookahead token if we need one and don't already have one. */
+
+ /* First try to decide what to do without reference to lookahead token. */
+ yyn = yypact[yystate];
+ if (yypact_value_is_default (yyn))
+ goto yydefault;
+
+ /* Not known => get a lookahead token if don't already have one. */
+
+ /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */
+ if (yychar == YYEMPTY)
+ {
+ YYDPRINTF ((stderr, "Reading a token\n"));
+ yychar = yylex ();
+ }
+
+ if (yychar <= YYEOF)
+ {
+ yychar = YYEOF;
+ yytoken = YYSYMBOL_YYEOF;
+ YYDPRINTF ((stderr, "Now at end of input.\n"));
+ }
+ else if (yychar == YYerror)
+ {
+ /* The scanner already issued an error message, process directly
+ to error recovery. But do not keep the error token as
+ lookahead, it is too special and may lead us to an endless
+ loop in error recovery. */
+ yychar = YYUNDEF;
+ yytoken = YYSYMBOL_YYerror;
+ goto yyerrlab1;
+ }
+ else
+ {
+ yytoken = YYTRANSLATE (yychar);
+ YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
+ }
+
+ /* If the proper action on seeing token YYTOKEN is to reduce or to
+ detect an error, take that action. */
+ yyn += yytoken;
+ if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
+ goto yydefault;
+ yyn = yytable[yyn];
+ if (yyn <= 0)
+ {
+ if (yytable_value_is_error (yyn))
+ goto yyerrlab;
+ yyn = -yyn;
+ goto yyreduce;
+ }
+
+ /* Count tokens shifted since error; after three, turn off error
+ status. */
+ if (yyerrstatus)
+ yyerrstatus--;
+
+ /* Shift the lookahead token. */
+ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
+ yystate = yyn;
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ *++yyvsp = yylval;
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+
+ /* Discard the shifted token. */
+ yychar = YYEMPTY;
+ goto yynewstate;
+
+
+/*-----------------------------------------------------------.
+| yydefault -- do the default action for the current state. |
+`-----------------------------------------------------------*/
+yydefault:
+ yyn = yydefact[yystate];
+ if (yyn == 0)
+ goto yyerrlab;
+ goto yyreduce;
+
+
+/*-----------------------------.
+| yyreduce -- do a reduction. |
+`-----------------------------*/
+yyreduce:
+ /* yyn is the number of a rule to reduce with. */
+ yylen = yyr2[yyn];
+
+ /* If YYLEN is nonzero, implement the default value of the action:
+ '$$ = $1'.
+
+ Otherwise, the following line sets YYVAL to garbage.
+ This behavior is undocumented and Bison
+ users should not rely upon it. Assigning to YYVAL
+ unconditionally makes the parser a bit smaller, and it avoids a
+ GCC warning that YYVAL may be used uninitialized. */
+ yyval = yyvsp[1-yylen];
+
+
+ YY_REDUCE_PRINT (yyn);
+ switch (yyn)
+ {
+ case 3: /* top: element_list */
+#line 277 "../src/preproc/pic/pic.ypp"
+ {
+ if (olist.head)
+ print_picture(olist.head);
+ }
+#line 2343 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 4: /* element_list: optional_separator middle_element_list optional_separator */
+#line 286 "../src/preproc/pic/pic.ypp"
+ { (yyval.pl) = (yyvsp[-1].pl); }
+#line 2349 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 5: /* middle_element_list: element */
+#line 291 "../src/preproc/pic/pic.ypp"
+ { (yyval.pl) = (yyvsp[0].pl); }
+#line 2355 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 6: /* middle_element_list: middle_element_list separator element */
+#line 293 "../src/preproc/pic/pic.ypp"
+ { (yyval.pl) = (yyvsp[-2].pl); }
+#line 2361 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 11: /* placeless_element: FIGNAME '=' macro_name */
+#line 308 "../src/preproc/pic/pic.ypp"
+ {
+ delete[] graphname;
+ graphname = new char[strlen((yyvsp[0].str)) + 1];
+ strcpy(graphname, (yyvsp[0].str));
+ delete[] (yyvsp[0].str);
+ }
+#line 2372 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 12: /* placeless_element: VARIABLE '=' any_expr */
+#line 316 "../src/preproc/pic/pic.ypp"
+ {
+ define_variable((yyvsp[-2].str), (yyvsp[0].x));
+ free((yyvsp[-2].str));
+ }
+#line 2381 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 13: /* placeless_element: VARIABLE ':' '=' any_expr */
+#line 321 "../src/preproc/pic/pic.ypp"
+ {
+ place *p = lookup_label((yyvsp[-3].str));
+ if (!p) {
+ lex_error("variable '%1' not defined", (yyvsp[-3].str));
+ YYABORT;
+ }
+ p->obj = 0;
+ p->x = (yyvsp[0].x);
+ p->y = 0.0;
+ free((yyvsp[-3].str));
+ }
+#line 2397 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 14: /* placeless_element: UP */
+#line 333 "../src/preproc/pic/pic.ypp"
+ { current_direction = UP_DIRECTION; }
+#line 2403 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 15: /* placeless_element: DOWN */
+#line 335 "../src/preproc/pic/pic.ypp"
+ { current_direction = DOWN_DIRECTION; }
+#line 2409 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 16: /* placeless_element: LEFT */
+#line 337 "../src/preproc/pic/pic.ypp"
+ { current_direction = LEFT_DIRECTION; }
+#line 2415 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 17: /* placeless_element: RIGHT */
+#line 339 "../src/preproc/pic/pic.ypp"
+ { current_direction = RIGHT_DIRECTION; }
+#line 2421 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 18: /* placeless_element: COMMAND_LINE */
+#line 341 "../src/preproc/pic/pic.ypp"
+ {
+ olist.append(make_command_object((yyvsp[0].lstr).str, (yyvsp[0].lstr).filename,
+ (yyvsp[0].lstr).lineno));
+ }
+#line 2430 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 19: /* placeless_element: COMMAND print_args */
+#line 346 "../src/preproc/pic/pic.ypp"
+ {
+ olist.append(make_command_object((yyvsp[0].lstr).str, (yyvsp[0].lstr).filename,
+ (yyvsp[0].lstr).lineno));
+ }
+#line 2439 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 20: /* placeless_element: PRINT print_args */
+#line 351 "../src/preproc/pic/pic.ypp"
+ {
+ fprintf(stderr, "%s\n", (yyvsp[0].lstr).str);
+ delete[] (yyvsp[0].lstr).str;
+ fflush(stderr);
+ }
+#line 2449 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 21: /* $@1: %empty */
+#line 357 "../src/preproc/pic/pic.ypp"
+ { delim_flag = 1; }
+#line 2455 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 22: /* placeless_element: SH $@1 DELIMITED */
+#line 359 "../src/preproc/pic/pic.ypp"
+ {
+ delim_flag = 0;
+ if (safer_flag)
+ lex_error("unsafe to run command '%1'; ignoring",
+ (yyvsp[0].str));
+ else {
+ int retval = system((yyvsp[0].str));
+ if (retval < 0)
+ lex_error("error running command '%1': system()"
+ " returned %2", (yyvsp[0].str), retval);
+ }
+ delete[] (yyvsp[0].str);
+ }
+#line 2473 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 23: /* placeless_element: COPY TEXT */
+#line 373 "../src/preproc/pic/pic.ypp"
+ {
+ if (yychar < 0)
+ do_lookahead();
+ do_copy((yyvsp[0].lstr).str);
+ // do not delete the filename
+ }
+#line 2484 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 24: /* $@2: %empty */
+#line 380 "../src/preproc/pic/pic.ypp"
+ { delim_flag = 2; }
+#line 2490 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 25: /* $@3: %empty */
+#line 382 "../src/preproc/pic/pic.ypp"
+ { delim_flag = 0; }
+#line 2496 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 26: /* placeless_element: COPY TEXT THRU $@2 DELIMITED $@3 until */
+#line 384 "../src/preproc/pic/pic.ypp"
+ {
+ if (yychar < 0)
+ do_lookahead();
+ copy_file_thru((yyvsp[-5].lstr).str, (yyvsp[-2].str), (yyvsp[0].str));
+ // do not delete the filename
+ delete[] (yyvsp[-2].str);
+ delete[] (yyvsp[0].str);
+ }
+#line 2509 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 27: /* $@4: %empty */
+#line 393 "../src/preproc/pic/pic.ypp"
+ { delim_flag = 2; }
+#line 2515 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 28: /* $@5: %empty */
+#line 395 "../src/preproc/pic/pic.ypp"
+ { delim_flag = 0; }
+#line 2521 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 29: /* placeless_element: COPY THRU $@4 DELIMITED $@5 until */
+#line 397 "../src/preproc/pic/pic.ypp"
+ {
+ if (yychar < 0)
+ do_lookahead();
+ copy_rest_thru((yyvsp[-2].str), (yyvsp[0].str));
+ delete[] (yyvsp[-2].str);
+ delete[] (yyvsp[0].str);
+ }
+#line 2533 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 30: /* $@6: %empty */
+#line 405 "../src/preproc/pic/pic.ypp"
+ { delim_flag = 1; }
+#line 2539 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 31: /* placeless_element: FOR VARIABLE '=' expr TO expr optional_by DO $@6 DELIMITED */
+#line 407 "../src/preproc/pic/pic.ypp"
+ {
+ delim_flag = 0;
+ if (yychar < 0)
+ do_lookahead();
+ do_for((yyvsp[-8].str), (yyvsp[-6].x), (yyvsp[-4].x), (yyvsp[-3].by).is_multiplicative, (yyvsp[-3].by).val, (yyvsp[0].str));
+ }
+#line 2550 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 32: /* placeless_element: simple_if */
+#line 414 "../src/preproc/pic/pic.ypp"
+ {
+ if (yychar < 0)
+ do_lookahead();
+ if ((yyvsp[0].if_data).x != 0.0)
+ push_body((yyvsp[0].if_data).body);
+ delete[] (yyvsp[0].if_data).body;
+ }
+#line 2562 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 33: /* $@7: %empty */
+#line 422 "../src/preproc/pic/pic.ypp"
+ { delim_flag = 1; }
+#line 2568 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 34: /* placeless_element: simple_if ELSE $@7 DELIMITED */
+#line 424 "../src/preproc/pic/pic.ypp"
+ {
+ delim_flag = 0;
+ if (yychar < 0)
+ do_lookahead();
+ if ((yyvsp[-3].if_data).x != 0.0)
+ push_body((yyvsp[-3].if_data).body);
+ else
+ push_body((yyvsp[0].str));
+ free((yyvsp[-3].if_data).body);
+ free((yyvsp[0].str));
+ }
+#line 2584 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 36: /* placeless_element: RESET */
+#line 437 "../src/preproc/pic/pic.ypp"
+ { define_variable("scale", 1.0); }
+#line 2590 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 39: /* reset_variables: RESET VARIABLE */
+#line 447 "../src/preproc/pic/pic.ypp"
+ {
+ reset((yyvsp[0].str));
+ delete[] (yyvsp[0].str);
+ }
+#line 2599 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 40: /* reset_variables: reset_variables VARIABLE */
+#line 452 "../src/preproc/pic/pic.ypp"
+ {
+ reset((yyvsp[0].str));
+ delete[] (yyvsp[0].str);
+ }
+#line 2608 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 41: /* reset_variables: reset_variables ',' VARIABLE */
+#line 457 "../src/preproc/pic/pic.ypp"
+ {
+ reset((yyvsp[0].str));
+ delete[] (yyvsp[0].str);
+ }
+#line 2617 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 42: /* print_args: print_arg */
+#line 465 "../src/preproc/pic/pic.ypp"
+ { (yyval.lstr) = (yyvsp[0].lstr); }
+#line 2623 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 43: /* print_args: print_args print_arg */
+#line 467 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.lstr).str = new char[strlen((yyvsp[-1].lstr).str) + strlen((yyvsp[0].lstr).str) + 1];
+ strcpy((yyval.lstr).str, (yyvsp[-1].lstr).str);
+ strcat((yyval.lstr).str, (yyvsp[0].lstr).str);
+ delete[] (yyvsp[-1].lstr).str;
+ delete[] (yyvsp[0].lstr).str;
+ if ((yyvsp[-1].lstr).filename) {
+ (yyval.lstr).filename = (yyvsp[-1].lstr).filename;
+ (yyval.lstr).lineno = (yyvsp[-1].lstr).lineno;
+ }
+ else if ((yyvsp[0].lstr).filename) {
+ (yyval.lstr).filename = (yyvsp[0].lstr).filename;
+ (yyval.lstr).lineno = (yyvsp[0].lstr).lineno;
+ }
+ }
+#line 2643 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 44: /* print_arg: expr */
+#line 486 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.lstr).str = new char[GDIGITS + 1];
+ sprintf((yyval.lstr).str, "%g", (yyvsp[0].x));
+ (yyval.lstr).filename = 0;
+ (yyval.lstr).lineno = 0;
+ }
+#line 2654 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 45: /* print_arg: text */
+#line 493 "../src/preproc/pic/pic.ypp"
+ { (yyval.lstr) = (yyvsp[0].lstr); }
+#line 2660 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 46: /* print_arg: position */
+#line 495 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.lstr).str = new char[GDIGITS + 2 + GDIGITS + 1];
+ sprintf((yyval.lstr).str, "%g, %g", (yyvsp[0].pair).x, (yyvsp[0].pair).y);
+ (yyval.lstr).filename = 0;
+ (yyval.lstr).lineno = 0;
+ }
+#line 2671 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 47: /* $@8: %empty */
+#line 505 "../src/preproc/pic/pic.ypp"
+ { delim_flag = 1; }
+#line 2677 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 48: /* simple_if: IF any_expr THEN $@8 DELIMITED */
+#line 507 "../src/preproc/pic/pic.ypp"
+ {
+ delim_flag = 0;
+ (yyval.if_data).x = (yyvsp[-3].x);
+ (yyval.if_data).body = (yyvsp[0].str);
+ }
+#line 2687 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 49: /* until: %empty */
+#line 516 "../src/preproc/pic/pic.ypp"
+ { (yyval.str) = 0; }
+#line 2693 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 50: /* until: UNTIL TEXT */
+#line 518 "../src/preproc/pic/pic.ypp"
+ { (yyval.str) = (yyvsp[0].lstr).str; }
+#line 2699 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 51: /* any_expr: expr */
+#line 523 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = (yyvsp[0].x); }
+#line 2705 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 52: /* any_expr: text_expr */
+#line 525 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = (yyvsp[0].x); }
+#line 2711 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 53: /* text_expr: text EQUALEQUAL text */
+#line 530 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.x) = strcmp((yyvsp[-2].lstr).str, (yyvsp[0].lstr).str) == 0;
+ delete[] (yyvsp[-2].lstr).str;
+ delete[] (yyvsp[0].lstr).str;
+ }
+#line 2721 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 54: /* text_expr: text NOTEQUAL text */
+#line 536 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.x) = strcmp((yyvsp[-2].lstr).str, (yyvsp[0].lstr).str) != 0;
+ delete[] (yyvsp[-2].lstr).str;
+ delete[] (yyvsp[0].lstr).str;
+ }
+#line 2731 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 55: /* text_expr: text_expr ANDAND text_expr */
+#line 542 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[-2].x) != 0.0 && (yyvsp[0].x) != 0.0); }
+#line 2737 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 56: /* text_expr: text_expr ANDAND expr */
+#line 544 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[-2].x) != 0.0 && (yyvsp[0].x) != 0.0); }
+#line 2743 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 57: /* text_expr: expr ANDAND text_expr */
+#line 546 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[-2].x) != 0.0 && (yyvsp[0].x) != 0.0); }
+#line 2749 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 58: /* text_expr: text_expr OROR text_expr */
+#line 548 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[-2].x) != 0.0 || (yyvsp[0].x) != 0.0); }
+#line 2755 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 59: /* text_expr: text_expr OROR expr */
+#line 550 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[-2].x) != 0.0 || (yyvsp[0].x) != 0.0); }
+#line 2761 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 60: /* text_expr: expr OROR text_expr */
+#line 552 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[-2].x) != 0.0 || (yyvsp[0].x) != 0.0); }
+#line 2767 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 61: /* text_expr: '!' text_expr */
+#line 554 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[0].x) == 0.0); }
+#line 2773 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 62: /* optional_by: %empty */
+#line 560 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.by).val = 1.0;
+ (yyval.by).is_multiplicative = 0;
+ }
+#line 2782 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 63: /* optional_by: BY expr */
+#line 565 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.by).val = (yyvsp[0].x);
+ (yyval.by).is_multiplicative = 0;
+ }
+#line 2791 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 64: /* optional_by: BY '*' expr */
+#line 570 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.by).val = (yyvsp[0].x);
+ (yyval.by).is_multiplicative = 1;
+ }
+#line 2800 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 65: /* element: object_spec */
+#line 578 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pl).obj = (yyvsp[0].spec)->make_object(&current_position,
+ &current_direction);
+ if ((yyval.pl).obj == 0)
+ YYABORT;
+ delete (yyvsp[0].spec);
+ if ((yyval.pl).obj)
+ olist.append((yyval.pl).obj);
+ else {
+ (yyval.pl).x = current_position.x;
+ (yyval.pl).y = current_position.y;
+ }
+ }
+#line 2818 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 66: /* element: LABEL ':' optional_separator element */
+#line 592 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pl) = (yyvsp[0].pl);
+ define_label((yyvsp[-3].str), & (yyval.pl));
+ free((yyvsp[-3].str));
+ }
+#line 2828 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 67: /* element: LABEL ':' optional_separator position_not_place */
+#line 598 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pl).obj = 0;
+ (yyval.pl).x = (yyvsp[0].pair).x;
+ (yyval.pl).y = (yyvsp[0].pair).y;
+ define_label((yyvsp[-3].str), & (yyval.pl));
+ free((yyvsp[-3].str));
+ }
+#line 2840 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 68: /* element: LABEL ':' optional_separator place */
+#line 606 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pl) = (yyvsp[0].pl);
+ define_label((yyvsp[-3].str), & (yyval.pl));
+ free((yyvsp[-3].str));
+ }
+#line 2850 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 69: /* @9: %empty */
+#line 612 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.state).x = current_position.x;
+ (yyval.state).y = current_position.y;
+ (yyval.state).dir = current_direction;
+ }
+#line 2860 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 70: /* $@10: %empty */
+#line 618 "../src/preproc/pic/pic.ypp"
+ {
+ current_position.x = (yyvsp[-2].state).x;
+ current_position.y = (yyvsp[-2].state).y;
+ current_direction = (yyvsp[-2].state).dir;
+ }
+#line 2870 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 71: /* element: '{' @9 element_list '}' $@10 optional_element */
+#line 624 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pl) = (yyvsp[-3].pl);
+ }
+#line 2878 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 72: /* element: placeless_element */
+#line 628 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pl).obj = 0;
+ (yyval.pl).x = current_position.x;
+ (yyval.pl).y = current_position.y;
+ }
+#line 2888 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 73: /* optional_element: %empty */
+#line 637 "../src/preproc/pic/pic.ypp"
+ {}
+#line 2894 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 74: /* optional_element: element */
+#line 639 "../src/preproc/pic/pic.ypp"
+ {}
+#line 2900 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 75: /* object_spec: BOX */
+#line 644 "../src/preproc/pic/pic.ypp"
+ { (yyval.spec) = new object_spec(BOX_OBJECT); }
+#line 2906 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 76: /* object_spec: CIRCLE */
+#line 646 "../src/preproc/pic/pic.ypp"
+ { (yyval.spec) = new object_spec(CIRCLE_OBJECT); }
+#line 2912 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 77: /* object_spec: ELLIPSE */
+#line 648 "../src/preproc/pic/pic.ypp"
+ { (yyval.spec) = new object_spec(ELLIPSE_OBJECT); }
+#line 2918 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 78: /* object_spec: ARC */
+#line 650 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = new object_spec(ARC_OBJECT);
+ (yyval.spec)->dir = current_direction;
+ }
+#line 2927 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 79: /* object_spec: LINE */
+#line 655 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = new object_spec(LINE_OBJECT);
+ lookup_variable("lineht", & (yyval.spec)->segment_height);
+ lookup_variable("linewid", & (yyval.spec)->segment_width);
+ (yyval.spec)->dir = current_direction;
+ }
+#line 2938 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 80: /* object_spec: ARROW */
+#line 662 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = new object_spec(ARROW_OBJECT);
+ lookup_variable("lineht", & (yyval.spec)->segment_height);
+ lookup_variable("linewid", & (yyval.spec)->segment_width);
+ (yyval.spec)->dir = current_direction;
+ }
+#line 2949 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 81: /* object_spec: MOVE */
+#line 669 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = new object_spec(MOVE_OBJECT);
+ lookup_variable("moveht", & (yyval.spec)->segment_height);
+ lookup_variable("movewid", & (yyval.spec)->segment_width);
+ (yyval.spec)->dir = current_direction;
+ }
+#line 2960 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 82: /* object_spec: SPLINE */
+#line 676 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = new object_spec(SPLINE_OBJECT);
+ lookup_variable("lineht", & (yyval.spec)->segment_height);
+ lookup_variable("linewid", & (yyval.spec)->segment_width);
+ (yyval.spec)->dir = current_direction;
+ }
+#line 2971 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 83: /* object_spec: text */
+#line 683 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = new object_spec(TEXT_OBJECT);
+ (yyval.spec)->text = new text_item((yyvsp[0].lstr).str, (yyvsp[0].lstr).filename, (yyvsp[0].lstr).lineno);
+ }
+#line 2980 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 84: /* object_spec: PLOT expr */
+#line 688 "../src/preproc/pic/pic.ypp"
+ {
+ lex_warning("'plot' is deprecated; use 'sprintf'"
+ " instead");
+ (yyval.spec) = new object_spec(TEXT_OBJECT);
+ (yyval.spec)->text = new text_item(format_number(0, (yyvsp[0].x)), 0, -1);
+ }
+#line 2991 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 85: /* object_spec: PLOT expr text */
+#line 695 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = new object_spec(TEXT_OBJECT);
+ (yyval.spec)->text = new text_item(format_number((yyvsp[0].lstr).str, (yyvsp[-1].x)),
+ (yyvsp[0].lstr).filename, (yyvsp[0].lstr).lineno);
+ delete[] (yyvsp[0].lstr).str;
+ }
+#line 3002 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 86: /* @11: %empty */
+#line 702 "../src/preproc/pic/pic.ypp"
+ {
+ saved_state *p = new saved_state;
+ (yyval.pstate) = p;
+ p->x = current_position.x;
+ p->y = current_position.y;
+ p->dir = current_direction;
+ p->tbl = current_table;
+ p->prev = current_saved_state;
+ current_position.x = 0.0;
+ current_position.y = 0.0;
+ current_table = new PTABLE(place);
+ current_saved_state = p;
+ olist.append(make_mark_object());
+ }
+#line 3021 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 87: /* object_spec: '[' @11 element_list ']' */
+#line 717 "../src/preproc/pic/pic.ypp"
+ {
+ current_position.x = (yyvsp[-2].pstate)->x;
+ current_position.y = (yyvsp[-2].pstate)->y;
+ current_direction = (yyvsp[-2].pstate)->dir;
+ (yyval.spec) = new object_spec(BLOCK_OBJECT);
+ olist.wrap_up_block(& (yyval.spec)->oblist);
+ (yyval.spec)->tbl = current_table;
+ current_table = (yyvsp[-2].pstate)->tbl;
+ current_saved_state = (yyvsp[-2].pstate)->prev;
+ delete (yyvsp[-2].pstate);
+ }
+#line 3037 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 88: /* object_spec: object_spec HEIGHT expr */
+#line 729 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->height = (yyvsp[0].x);
+ (yyval.spec)->flags |= HAS_HEIGHT;
+ }
+#line 3047 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 89: /* object_spec: object_spec RADIUS expr */
+#line 735 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->radius = (yyvsp[0].x);
+ (yyval.spec)->flags |= HAS_RADIUS;
+ }
+#line 3057 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 90: /* object_spec: object_spec WIDTH expr */
+#line 741 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->width = (yyvsp[0].x);
+ (yyval.spec)->flags |= HAS_WIDTH;
+ }
+#line 3067 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 91: /* object_spec: object_spec DIAMETER expr */
+#line 747 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->radius = (yyvsp[0].x)/2.0;
+ (yyval.spec)->flags |= HAS_RADIUS;
+ }
+#line 3077 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 92: /* object_spec: object_spec expr */
+#line 753 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->flags |= HAS_SEGMENT;
+ switch ((yyval.spec)->dir) {
+ case UP_DIRECTION:
+ (yyval.spec)->segment_pos.y += (yyvsp[0].x);
+ break;
+ case DOWN_DIRECTION:
+ (yyval.spec)->segment_pos.y -= (yyvsp[0].x);
+ break;
+ case RIGHT_DIRECTION:
+ (yyval.spec)->segment_pos.x += (yyvsp[0].x);
+ break;
+ case LEFT_DIRECTION:
+ (yyval.spec)->segment_pos.x -= (yyvsp[0].x);
+ break;
+ }
+ }
+#line 3100 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 93: /* object_spec: object_spec UP */
+#line 772 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->dir = UP_DIRECTION;
+ (yyval.spec)->flags |= HAS_SEGMENT;
+ (yyval.spec)->segment_pos.y += (yyval.spec)->segment_height;
+ }
+#line 3111 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 94: /* object_spec: object_spec UP expr */
+#line 779 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->dir = UP_DIRECTION;
+ (yyval.spec)->flags |= HAS_SEGMENT;
+ (yyval.spec)->segment_pos.y += (yyvsp[0].x);
+ }
+#line 3122 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 95: /* object_spec: object_spec DOWN */
+#line 786 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->dir = DOWN_DIRECTION;
+ (yyval.spec)->flags |= HAS_SEGMENT;
+ (yyval.spec)->segment_pos.y -= (yyval.spec)->segment_height;
+ }
+#line 3133 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 96: /* object_spec: object_spec DOWN expr */
+#line 793 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->dir = DOWN_DIRECTION;
+ (yyval.spec)->flags |= HAS_SEGMENT;
+ (yyval.spec)->segment_pos.y -= (yyvsp[0].x);
+ }
+#line 3144 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 97: /* object_spec: object_spec RIGHT */
+#line 800 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->dir = RIGHT_DIRECTION;
+ (yyval.spec)->flags |= HAS_SEGMENT;
+ (yyval.spec)->segment_pos.x += (yyval.spec)->segment_width;
+ }
+#line 3155 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 98: /* object_spec: object_spec RIGHT expr */
+#line 807 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->dir = RIGHT_DIRECTION;
+ (yyval.spec)->flags |= HAS_SEGMENT;
+ (yyval.spec)->segment_pos.x += (yyvsp[0].x);
+ }
+#line 3166 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 99: /* object_spec: object_spec LEFT */
+#line 814 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->dir = LEFT_DIRECTION;
+ (yyval.spec)->flags |= HAS_SEGMENT;
+ (yyval.spec)->segment_pos.x -= (yyval.spec)->segment_width;
+ }
+#line 3177 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 100: /* object_spec: object_spec LEFT expr */
+#line 821 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->dir = LEFT_DIRECTION;
+ (yyval.spec)->flags |= HAS_SEGMENT;
+ (yyval.spec)->segment_pos.x -= (yyvsp[0].x);
+ }
+#line 3188 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 101: /* object_spec: object_spec FROM position */
+#line 828 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->flags |= HAS_FROM;
+ (yyval.spec)->from.x = (yyvsp[0].pair).x;
+ (yyval.spec)->from.y = (yyvsp[0].pair).y;
+ }
+#line 3199 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 102: /* object_spec: object_spec TO position */
+#line 835 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ if ((yyval.spec)->flags & HAS_SEGMENT)
+ (yyval.spec)->segment_list = new segment((yyval.spec)->segment_pos,
+ (yyval.spec)->segment_is_absolute,
+ (yyval.spec)->segment_list);
+ (yyval.spec)->flags |= HAS_SEGMENT;
+ (yyval.spec)->segment_pos.x = (yyvsp[0].pair).x;
+ (yyval.spec)->segment_pos.y = (yyvsp[0].pair).y;
+ (yyval.spec)->segment_is_absolute = 1;
+ (yyval.spec)->flags |= HAS_TO;
+ (yyval.spec)->to.x = (yyvsp[0].pair).x;
+ (yyval.spec)->to.y = (yyvsp[0].pair).y;
+ }
+#line 3218 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 103: /* object_spec: object_spec AT position */
+#line 850 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->flags |= HAS_AT;
+ (yyval.spec)->at.x = (yyvsp[0].pair).x;
+ (yyval.spec)->at.y = (yyvsp[0].pair).y;
+ if ((yyval.spec)->type != ARC_OBJECT) {
+ (yyval.spec)->flags |= HAS_FROM;
+ (yyval.spec)->from.x = (yyvsp[0].pair).x;
+ (yyval.spec)->from.y = (yyvsp[0].pair).y;
+ }
+ }
+#line 3234 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 104: /* object_spec: object_spec WITH path */
+#line 862 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->flags |= HAS_WITH;
+ (yyval.spec)->with = (yyvsp[0].pth);
+ }
+#line 3244 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 105: /* object_spec: object_spec WITH position */
+#line 868 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->flags |= HAS_WITH;
+ position pos;
+ pos.x = (yyvsp[0].pair).x;
+ pos.y = (yyvsp[0].pair).y;
+ (yyval.spec)->with = new path(pos);
+ }
+#line 3257 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 106: /* object_spec: object_spec BY expr_pair */
+#line 877 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->flags |= HAS_SEGMENT;
+ (yyval.spec)->segment_pos.x += (yyvsp[0].pair).x;
+ (yyval.spec)->segment_pos.y += (yyvsp[0].pair).y;
+ }
+#line 3268 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 107: /* object_spec: object_spec THEN */
+#line 884 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ if (!((yyval.spec)->flags & HAS_SEGMENT))
+ switch ((yyval.spec)->dir) {
+ case UP_DIRECTION:
+ (yyval.spec)->segment_pos.y += (yyval.spec)->segment_width;
+ break;
+ case DOWN_DIRECTION:
+ (yyval.spec)->segment_pos.y -= (yyval.spec)->segment_width;
+ break;
+ case RIGHT_DIRECTION:
+ (yyval.spec)->segment_pos.x += (yyval.spec)->segment_width;
+ break;
+ case LEFT_DIRECTION:
+ (yyval.spec)->segment_pos.x -= (yyval.spec)->segment_width;
+ break;
+ }
+ (yyval.spec)->segment_list = new segment((yyval.spec)->segment_pos,
+ (yyval.spec)->segment_is_absolute,
+ (yyval.spec)->segment_list);
+ (yyval.spec)->flags &= ~HAS_SEGMENT;
+ (yyval.spec)->segment_pos.x = (yyval.spec)->segment_pos.y = 0.0;
+ (yyval.spec)->segment_is_absolute = 0;
+ }
+#line 3297 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 108: /* object_spec: object_spec SOLID */
+#line 909 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec); // nothing
+ }
+#line 3305 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 109: /* object_spec: object_spec DOTTED */
+#line 913 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->flags |= IS_DOTTED;
+ lookup_variable("dashwid", & (yyval.spec)->dash_width);
+ }
+#line 3315 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 110: /* object_spec: object_spec DOTTED expr */
+#line 919 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->flags |= IS_DOTTED;
+ (yyval.spec)->dash_width = (yyvsp[0].x);
+ }
+#line 3325 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 111: /* object_spec: object_spec DASHED */
+#line 925 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->flags |= IS_DASHED;
+ lookup_variable("dashwid", & (yyval.spec)->dash_width);
+ }
+#line 3335 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 112: /* object_spec: object_spec DASHED expr */
+#line 931 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->flags |= IS_DASHED;
+ (yyval.spec)->dash_width = (yyvsp[0].x);
+ }
+#line 3345 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 113: /* object_spec: object_spec FILL */
+#line 937 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->flags |= IS_DEFAULT_FILLED;
+ }
+#line 3354 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 114: /* object_spec: object_spec FILL expr */
+#line 942 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->flags |= IS_FILLED;
+ (yyval.spec)->fill = (yyvsp[0].x);
+ }
+#line 3364 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 115: /* object_spec: object_spec XSLANTED expr */
+#line 948 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->flags |= IS_XSLANTED;
+ (yyval.spec)->xslanted = (yyvsp[0].x);
+ }
+#line 3374 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 116: /* object_spec: object_spec YSLANTED expr */
+#line 954 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->flags |= IS_YSLANTED;
+ (yyval.spec)->yslanted = (yyvsp[0].x);
+ }
+#line 3384 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 117: /* object_spec: object_spec SHADED text */
+#line 960 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->flags |= (IS_SHADED | IS_FILLED);
+ (yyval.spec)->shaded = new char[strlen((yyvsp[0].lstr).str)+1];
+ strcpy((yyval.spec)->shaded, (yyvsp[0].lstr).str);
+ }
+#line 3395 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 118: /* object_spec: object_spec COLORED text */
+#line 967 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->flags |= (IS_SHADED | IS_OUTLINED | IS_FILLED);
+ (yyval.spec)->shaded = new char[strlen((yyvsp[0].lstr).str)+1];
+ strcpy((yyval.spec)->shaded, (yyvsp[0].lstr).str);
+ (yyval.spec)->outlined = new char[strlen((yyvsp[0].lstr).str)+1];
+ strcpy((yyval.spec)->outlined, (yyvsp[0].lstr).str);
+ }
+#line 3408 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 119: /* object_spec: object_spec OUTLINED text */
+#line 976 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->flags |= IS_OUTLINED;
+ (yyval.spec)->outlined = new char[strlen((yyvsp[0].lstr).str)+1];
+ strcpy((yyval.spec)->outlined, (yyvsp[0].lstr).str);
+ }
+#line 3419 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 120: /* object_spec: object_spec CHOP */
+#line 983 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ // line chop chop means line chop 0 chop 0
+ if ((yyval.spec)->flags & IS_DEFAULT_CHOPPED) {
+ (yyval.spec)->flags |= IS_CHOPPED;
+ (yyval.spec)->flags &= ~IS_DEFAULT_CHOPPED;
+ (yyval.spec)->start_chop = (yyval.spec)->end_chop = 0.0;
+ }
+ else if ((yyval.spec)->flags & IS_CHOPPED) {
+ (yyval.spec)->end_chop = 0.0;
+ }
+ else {
+ (yyval.spec)->flags |= IS_DEFAULT_CHOPPED;
+ }
+ }
+#line 3439 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 121: /* object_spec: object_spec CHOP expr */
+#line 999 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ if ((yyval.spec)->flags & IS_DEFAULT_CHOPPED) {
+ (yyval.spec)->flags |= IS_CHOPPED;
+ (yyval.spec)->flags &= ~IS_DEFAULT_CHOPPED;
+ (yyval.spec)->start_chop = 0.0;
+ (yyval.spec)->end_chop = (yyvsp[0].x);
+ }
+ else if ((yyval.spec)->flags & IS_CHOPPED) {
+ (yyval.spec)->end_chop = (yyvsp[0].x);
+ }
+ else {
+ (yyval.spec)->start_chop = (yyval.spec)->end_chop = (yyvsp[0].x);
+ (yyval.spec)->flags |= IS_CHOPPED;
+ }
+ }
+#line 3460 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 122: /* object_spec: object_spec SAME */
+#line 1016 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->flags |= IS_SAME;
+ }
+#line 3469 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 123: /* object_spec: object_spec INVISIBLE */
+#line 1021 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->flags |= IS_INVISIBLE;
+ }
+#line 3478 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 124: /* object_spec: object_spec LEFT_ARROW_HEAD */
+#line 1026 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->flags |= HAS_LEFT_ARROW_HEAD;
+ }
+#line 3487 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 125: /* object_spec: object_spec RIGHT_ARROW_HEAD */
+#line 1031 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->flags |= HAS_RIGHT_ARROW_HEAD;
+ }
+#line 3496 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 126: /* object_spec: object_spec DOUBLE_ARROW_HEAD */
+#line 1036 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->flags |= (HAS_LEFT_ARROW_HEAD|HAS_RIGHT_ARROW_HEAD);
+ }
+#line 3505 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 127: /* object_spec: object_spec CW */
+#line 1041 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->flags |= IS_CLOCKWISE;
+ }
+#line 3514 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 128: /* object_spec: object_spec CCW */
+#line 1046 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->flags &= ~IS_CLOCKWISE;
+ }
+#line 3523 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 129: /* object_spec: object_spec text */
+#line 1051 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ text_item **p;
+ for (p = & (yyval.spec)->text; *p; p = &(*p)->next)
+ ;
+ *p = new text_item((yyvsp[0].lstr).str, (yyvsp[0].lstr).filename, (yyvsp[0].lstr).lineno);
+ }
+#line 3535 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 130: /* object_spec: object_spec LJUST */
+#line 1059 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ if ((yyval.spec)->text) {
+ text_item *p;
+ for (p = (yyval.spec)->text; p->next; p = p->next)
+ ;
+ p->adj.h = LEFT_ADJUST;
+ }
+ }
+#line 3549 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 131: /* object_spec: object_spec RJUST */
+#line 1069 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ if ((yyval.spec)->text) {
+ text_item *p;
+ for (p = (yyval.spec)->text; p->next; p = p->next)
+ ;
+ p->adj.h = RIGHT_ADJUST;
+ }
+ }
+#line 3563 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 132: /* object_spec: object_spec ABOVE */
+#line 1079 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ if ((yyval.spec)->text) {
+ text_item *p;
+ for (p = (yyval.spec)->text; p->next; p = p->next)
+ ;
+ p->adj.v = ABOVE_ADJUST;
+ }
+ }
+#line 3577 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 133: /* object_spec: object_spec BELOW */
+#line 1089 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ if ((yyval.spec)->text) {
+ text_item *p;
+ for (p = (yyval.spec)->text; p->next; p = p->next)
+ ;
+ p->adj.v = BELOW_ADJUST;
+ }
+ }
+#line 3591 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 134: /* object_spec: object_spec THICKNESS expr */
+#line 1099 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-2].spec);
+ (yyval.spec)->flags |= HAS_THICKNESS;
+ (yyval.spec)->thickness = (yyvsp[0].x);
+ }
+#line 3601 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 135: /* object_spec: object_spec ALIGNED */
+#line 1105 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.spec) = (yyvsp[-1].spec);
+ (yyval.spec)->flags |= IS_ALIGNED;
+ }
+#line 3610 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 136: /* text: TEXT */
+#line 1113 "../src/preproc/pic/pic.ypp"
+ { (yyval.lstr) = (yyvsp[0].lstr); }
+#line 3616 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 137: /* text: SPRINTF '(' TEXT sprintf_args ')' */
+#line 1115 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.lstr).filename = (yyvsp[-2].lstr).filename;
+ (yyval.lstr).lineno = (yyvsp[-2].lstr).lineno;
+ (yyval.lstr).str = do_sprintf((yyvsp[-2].lstr).str, (yyvsp[-1].dv).v, (yyvsp[-1].dv).nv);
+ delete[] (yyvsp[-1].dv).v;
+ free((yyvsp[-2].lstr).str);
+ }
+#line 3628 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 138: /* sprintf_args: %empty */
+#line 1126 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.dv).v = 0;
+ (yyval.dv).nv = 0;
+ (yyval.dv).maxv = 0;
+ }
+#line 3638 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 139: /* sprintf_args: sprintf_args ',' expr */
+#line 1132 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.dv) = (yyvsp[-2].dv);
+ if ((yyval.dv).nv >= (yyval.dv).maxv) {
+ if ((yyval.dv).nv == 0) {
+ (yyval.dv).v = new double[4];
+ (yyval.dv).maxv = 4;
+ }
+ else {
+ double *oldv = (yyval.dv).v;
+ (yyval.dv).maxv *= 2;
+#if 0
+ (yyval.dv).v = new double[(yyval.dv).maxv];
+ memcpy((yyval.dv).v, oldv, (yyval.dv).nv*sizeof(double));
+#else
+ // workaround for bug in Compaq C++ V6.5-033
+ // for Compaq Tru64 UNIX V5.1A (Rev. 1885)
+ double *foo = new double[(yyval.dv).maxv];
+ memcpy(foo, oldv, (yyval.dv).nv*sizeof(double));
+ (yyval.dv).v = foo;
+#endif
+ delete[] oldv;
+ }
+ }
+ (yyval.dv).v[(yyval.dv).nv] = (yyvsp[0].x);
+ (yyval.dv).nv += 1;
+ }
+#line 3669 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 140: /* position: position_not_place */
+#line 1162 "../src/preproc/pic/pic.ypp"
+ { (yyval.pair) = (yyvsp[0].pair); }
+#line 3675 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 141: /* position: place */
+#line 1164 "../src/preproc/pic/pic.ypp"
+ {
+ position pos = (yyvsp[0].pl);
+ (yyval.pair).x = pos.x;
+ (yyval.pair).y = pos.y;
+ }
+#line 3685 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 142: /* position: '(' place ')' */
+#line 1170 "../src/preproc/pic/pic.ypp"
+ {
+ position pos = (yyvsp[-1].pl);
+ (yyval.pair).x = pos.x;
+ (yyval.pair).y = pos.y;
+ }
+#line 3695 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 143: /* position_not_place: expr_pair */
+#line 1179 "../src/preproc/pic/pic.ypp"
+ { (yyval.pair) = (yyvsp[0].pair); }
+#line 3701 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 144: /* position_not_place: position '+' expr_pair */
+#line 1181 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pair).x = (yyvsp[-2].pair).x + (yyvsp[0].pair).x;
+ (yyval.pair).y = (yyvsp[-2].pair).y + (yyvsp[0].pair).y;
+ }
+#line 3710 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 145: /* position_not_place: '(' position '+' expr_pair ')' */
+#line 1186 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pair).x = (yyvsp[-3].pair).x + (yyvsp[-1].pair).x;
+ (yyval.pair).y = (yyvsp[-3].pair).y + (yyvsp[-1].pair).y;
+ }
+#line 3719 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 146: /* position_not_place: position '-' expr_pair */
+#line 1191 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pair).x = (yyvsp[-2].pair).x - (yyvsp[0].pair).x;
+ (yyval.pair).y = (yyvsp[-2].pair).y - (yyvsp[0].pair).y;
+ }
+#line 3728 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 147: /* position_not_place: '(' position '-' expr_pair ')' */
+#line 1196 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pair).x = (yyvsp[-3].pair).x - (yyvsp[-1].pair).x;
+ (yyval.pair).y = (yyvsp[-3].pair).y - (yyvsp[-1].pair).y;
+ }
+#line 3737 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 148: /* position_not_place: '(' position ',' position ')' */
+#line 1201 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pair).x = (yyvsp[-3].pair).x;
+ (yyval.pair).y = (yyvsp[-1].pair).y;
+ }
+#line 3746 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 149: /* position_not_place: expr between position AND position */
+#line 1206 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pair).x = (1.0 - (yyvsp[-4].x))*(yyvsp[-2].pair).x + (yyvsp[-4].x)*(yyvsp[0].pair).x;
+ (yyval.pair).y = (1.0 - (yyvsp[-4].x))*(yyvsp[-2].pair).y + (yyvsp[-4].x)*(yyvsp[0].pair).y;
+ }
+#line 3755 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 150: /* position_not_place: '(' expr between position AND position ')' */
+#line 1211 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pair).x = (1.0 - (yyvsp[-5].x))*(yyvsp[-3].pair).x + (yyvsp[-5].x)*(yyvsp[-1].pair).x;
+ (yyval.pair).y = (1.0 - (yyvsp[-5].x))*(yyvsp[-3].pair).y + (yyvsp[-5].x)*(yyvsp[-1].pair).y;
+ }
+#line 3764 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 151: /* position_not_place: expr_not_lower_than '<' position ',' position '>' */
+#line 1217 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pair).x = (1.0 - (yyvsp[-5].x))*(yyvsp[-3].pair).x + (yyvsp[-5].x)*(yyvsp[-1].pair).x;
+ (yyval.pair).y = (1.0 - (yyvsp[-5].x))*(yyvsp[-3].pair).y + (yyvsp[-5].x)*(yyvsp[-1].pair).y;
+ }
+#line 3773 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 152: /* position_not_place: '(' expr_not_lower_than '<' position ',' position '>' ')' */
+#line 1222 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pair).x = (1.0 - (yyvsp[-6].x))*(yyvsp[-4].pair).x + (yyvsp[-6].x)*(yyvsp[-2].pair).x;
+ (yyval.pair).y = (1.0 - (yyvsp[-6].x))*(yyvsp[-4].pair).y + (yyvsp[-6].x)*(yyvsp[-2].pair).y;
+ }
+#line 3782 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 155: /* expr_pair: expr ',' expr */
+#line 1235 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pair).x = (yyvsp[-2].x);
+ (yyval.pair).y = (yyvsp[0].x);
+ }
+#line 3791 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 156: /* expr_pair: '(' expr_pair ')' */
+#line 1240 "../src/preproc/pic/pic.ypp"
+ { (yyval.pair) = (yyvsp[-1].pair); }
+#line 3797 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 157: /* place: label */
+#line 1246 "../src/preproc/pic/pic.ypp"
+ { (yyval.pl) = (yyvsp[0].pl); }
+#line 3803 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 158: /* place: label corner */
+#line 1248 "../src/preproc/pic/pic.ypp"
+ {
+ path pth((yyvsp[0].crn));
+ if (!pth.follow((yyvsp[-1].pl), & (yyval.pl)))
+ YYABORT;
+ }
+#line 3813 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 159: /* place: corner label */
+#line 1254 "../src/preproc/pic/pic.ypp"
+ {
+ path pth((yyvsp[-1].crn));
+ if (!pth.follow((yyvsp[0].pl), & (yyval.pl)))
+ YYABORT;
+ }
+#line 3823 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 160: /* place: corner OF label */
+#line 1260 "../src/preproc/pic/pic.ypp"
+ {
+ path pth((yyvsp[-2].crn));
+ if (!pth.follow((yyvsp[0].pl), & (yyval.pl)))
+ YYABORT;
+ }
+#line 3833 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 161: /* place: HERE */
+#line 1266 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pl).x = current_position.x;
+ (yyval.pl).y = current_position.y;
+ (yyval.pl).obj = 0;
+ }
+#line 3843 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 162: /* label: LABEL */
+#line 1275 "../src/preproc/pic/pic.ypp"
+ {
+ place *p = lookup_label((yyvsp[0].str));
+ if (!p) {
+ lex_error("there is no place '%1'", (yyvsp[0].str));
+ YYABORT;
+ }
+ (yyval.pl) = *p;
+ free((yyvsp[0].str));
+ }
+#line 3857 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 163: /* label: nth_primitive */
+#line 1285 "../src/preproc/pic/pic.ypp"
+ { (yyval.pl).obj = (yyvsp[0].obj); }
+#line 3863 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 164: /* label: label '.' LABEL */
+#line 1287 "../src/preproc/pic/pic.ypp"
+ {
+ path pth((yyvsp[0].str));
+ if (!pth.follow((yyvsp[-2].pl), & (yyval.pl)))
+ YYABORT;
+ }
+#line 3873 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 165: /* ordinal: ORDINAL */
+#line 1296 "../src/preproc/pic/pic.ypp"
+ { (yyval.n) = (yyvsp[0].n); }
+#line 3879 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 166: /* ordinal: '`' any_expr TH */
+#line 1298 "../src/preproc/pic/pic.ypp"
+ {
+ // XXX Check for overflow (and non-integers?).
+ (yyval.n) = (int)(yyvsp[-1].x);
+ }
+#line 3888 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 167: /* optional_ordinal_last: LAST */
+#line 1306 "../src/preproc/pic/pic.ypp"
+ { (yyval.n) = 1; }
+#line 3894 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 168: /* optional_ordinal_last: ordinal LAST */
+#line 1308 "../src/preproc/pic/pic.ypp"
+ { (yyval.n) = (yyvsp[-1].n); }
+#line 3900 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 169: /* nth_primitive: ordinal object_type */
+#line 1313 "../src/preproc/pic/pic.ypp"
+ {
+ int count = 0;
+ object *p;
+ for (p = olist.head; p != 0; p = p->next)
+ if (p->type() == (yyvsp[0].obtype) && ++count == (yyvsp[-1].n)) {
+ (yyval.obj) = p;
+ break;
+ }
+ if (p == 0) {
+ lex_error("there is no %1%2 %3", (yyvsp[-1].n), ordinal_postfix((yyvsp[-1].n)),
+ object_type_name((yyvsp[0].obtype)));
+ YYABORT;
+ }
+ }
+#line 3919 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 170: /* nth_primitive: optional_ordinal_last object_type */
+#line 1328 "../src/preproc/pic/pic.ypp"
+ {
+ int count = 0;
+ object *p;
+ for (p = olist.tail; p != 0; p = p->prev)
+ if (p->type() == (yyvsp[0].obtype) && ++count == (yyvsp[-1].n)) {
+ (yyval.obj) = p;
+ break;
+ }
+ if (p == 0) {
+ lex_error("there is no %1%2 last %3", (yyvsp[-1].n),
+ ordinal_postfix((yyvsp[-1].n)), object_type_name((yyvsp[0].obtype)));
+ YYABORT;
+ }
+ }
+#line 3938 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 171: /* object_type: BOX */
+#line 1346 "../src/preproc/pic/pic.ypp"
+ { (yyval.obtype) = BOX_OBJECT; }
+#line 3944 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 172: /* object_type: CIRCLE */
+#line 1348 "../src/preproc/pic/pic.ypp"
+ { (yyval.obtype) = CIRCLE_OBJECT; }
+#line 3950 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 173: /* object_type: ELLIPSE */
+#line 1350 "../src/preproc/pic/pic.ypp"
+ { (yyval.obtype) = ELLIPSE_OBJECT; }
+#line 3956 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 174: /* object_type: ARC */
+#line 1352 "../src/preproc/pic/pic.ypp"
+ { (yyval.obtype) = ARC_OBJECT; }
+#line 3962 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 175: /* object_type: LINE */
+#line 1354 "../src/preproc/pic/pic.ypp"
+ { (yyval.obtype) = LINE_OBJECT; }
+#line 3968 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 176: /* object_type: ARROW */
+#line 1356 "../src/preproc/pic/pic.ypp"
+ { (yyval.obtype) = ARROW_OBJECT; }
+#line 3974 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 177: /* object_type: SPLINE */
+#line 1358 "../src/preproc/pic/pic.ypp"
+ { (yyval.obtype) = SPLINE_OBJECT; }
+#line 3980 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 178: /* object_type: '[' ']' */
+#line 1360 "../src/preproc/pic/pic.ypp"
+ { (yyval.obtype) = BLOCK_OBJECT; }
+#line 3986 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 179: /* object_type: TEXT */
+#line 1362 "../src/preproc/pic/pic.ypp"
+ { (yyval.obtype) = TEXT_OBJECT; }
+#line 3992 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 180: /* label_path: '.' LABEL */
+#line 1367 "../src/preproc/pic/pic.ypp"
+ { (yyval.pth) = new path((yyvsp[0].str)); }
+#line 3998 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 181: /* label_path: label_path '.' LABEL */
+#line 1369 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pth) = (yyvsp[-2].pth);
+ (yyval.pth)->append((yyvsp[0].str));
+ }
+#line 4007 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 182: /* relative_path: corner */
+#line 1377 "../src/preproc/pic/pic.ypp"
+ { (yyval.pth) = new path((yyvsp[0].crn)); }
+#line 4013 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 183: /* relative_path: label_path */
+#line 1381 "../src/preproc/pic/pic.ypp"
+ { (yyval.pth) = (yyvsp[0].pth); }
+#line 4019 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 184: /* relative_path: label_path corner */
+#line 1383 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pth) = (yyvsp[-1].pth);
+ (yyval.pth)->append((yyvsp[0].crn));
+ }
+#line 4028 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 185: /* path: relative_path */
+#line 1391 "../src/preproc/pic/pic.ypp"
+ { (yyval.pth) = (yyvsp[0].pth); }
+#line 4034 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 186: /* path: '(' relative_path ',' relative_path ')' */
+#line 1393 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.pth) = (yyvsp[-3].pth);
+ (yyval.pth)->set_ypath((yyvsp[-1].pth));
+ }
+#line 4043 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 187: /* path: ORDINAL LAST object_type relative_path */
+#line 1399 "../src/preproc/pic/pic.ypp"
+ {
+ lex_warning("'%1%2 last %3' in 'with' argument ignored",
+ (yyvsp[-3].n), ordinal_postfix((yyvsp[-3].n)), object_type_name((yyvsp[-1].obtype)));
+ (yyval.pth) = (yyvsp[0].pth);
+ }
+#line 4053 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 188: /* path: LAST object_type relative_path */
+#line 1405 "../src/preproc/pic/pic.ypp"
+ {
+ lex_warning("'last %1' in 'with' argument ignored",
+ object_type_name((yyvsp[-1].obtype)));
+ (yyval.pth) = (yyvsp[0].pth);
+ }
+#line 4063 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 189: /* path: ORDINAL object_type relative_path */
+#line 1411 "../src/preproc/pic/pic.ypp"
+ {
+ lex_warning("'%1%2 %3' in 'with' argument ignored",
+ (yyvsp[-2].n), ordinal_postfix((yyvsp[-2].n)), object_type_name((yyvsp[-1].obtype)));
+ (yyval.pth) = (yyvsp[0].pth);
+ }
+#line 4073 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 190: /* path: LABEL relative_path */
+#line 1417 "../src/preproc/pic/pic.ypp"
+ {
+ lex_warning("initial '%1' in 'with' argument ignored", (yyvsp[-1].str));
+ delete[] (yyvsp[-1].str);
+ (yyval.pth) = (yyvsp[0].pth);
+ }
+#line 4083 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 191: /* corner: DOT_N */
+#line 1426 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::north; }
+#line 4089 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 192: /* corner: DOT_E */
+#line 1428 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::east; }
+#line 4095 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 193: /* corner: DOT_W */
+#line 1430 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::west; }
+#line 4101 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 194: /* corner: DOT_S */
+#line 1432 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::south; }
+#line 4107 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 195: /* corner: DOT_NE */
+#line 1434 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::north_east; }
+#line 4113 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 196: /* corner: DOT_SE */
+#line 1436 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object:: south_east; }
+#line 4119 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 197: /* corner: DOT_NW */
+#line 1438 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::north_west; }
+#line 4125 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 198: /* corner: DOT_SW */
+#line 1440 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::south_west; }
+#line 4131 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 199: /* corner: DOT_C */
+#line 1442 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::center; }
+#line 4137 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 200: /* corner: DOT_START */
+#line 1444 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::start; }
+#line 4143 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 201: /* corner: DOT_END */
+#line 1446 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::end; }
+#line 4149 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 202: /* corner: TOP */
+#line 1448 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::north; }
+#line 4155 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 203: /* corner: BOTTOM */
+#line 1450 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::south; }
+#line 4161 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 204: /* corner: LEFT */
+#line 1452 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::west; }
+#line 4167 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 205: /* corner: RIGHT */
+#line 1454 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::east; }
+#line 4173 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 206: /* corner: UPPER LEFT */
+#line 1456 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::north_west; }
+#line 4179 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 207: /* corner: LOWER LEFT */
+#line 1458 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::south_west; }
+#line 4185 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 208: /* corner: UPPER RIGHT */
+#line 1460 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::north_east; }
+#line 4191 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 209: /* corner: LOWER RIGHT */
+#line 1462 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::south_east; }
+#line 4197 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 210: /* corner: LEFT_CORNER */
+#line 1464 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::west; }
+#line 4203 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 211: /* corner: RIGHT_CORNER */
+#line 1466 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::east; }
+#line 4209 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 212: /* corner: UPPER LEFT_CORNER */
+#line 1468 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::north_west; }
+#line 4215 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 213: /* corner: LOWER LEFT_CORNER */
+#line 1470 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::south_west; }
+#line 4221 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 214: /* corner: UPPER RIGHT_CORNER */
+#line 1472 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::north_east; }
+#line 4227 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 215: /* corner: LOWER RIGHT_CORNER */
+#line 1474 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::south_east; }
+#line 4233 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 216: /* corner: NORTH */
+#line 1476 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::north; }
+#line 4239 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 217: /* corner: SOUTH */
+#line 1478 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::south; }
+#line 4245 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 218: /* corner: EAST */
+#line 1480 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::east; }
+#line 4251 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 219: /* corner: WEST */
+#line 1482 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::west; }
+#line 4257 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 220: /* corner: CENTER */
+#line 1484 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::center; }
+#line 4263 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 221: /* corner: START */
+#line 1486 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::start; }
+#line 4269 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 222: /* corner: END */
+#line 1488 "../src/preproc/pic/pic.ypp"
+ { (yyval.crn) = &object::end; }
+#line 4275 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 223: /* expr: expr_lower_than */
+#line 1493 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = (yyvsp[0].x); }
+#line 4281 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 224: /* expr: expr_not_lower_than */
+#line 1495 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = (yyvsp[0].x); }
+#line 4287 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 225: /* expr_lower_than: expr '<' expr */
+#line 1500 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[-2].x) < (yyvsp[0].x)); }
+#line 4293 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 226: /* expr_not_lower_than: VARIABLE */
+#line 1505 "../src/preproc/pic/pic.ypp"
+ {
+ if (!lookup_variable((yyvsp[0].str), & (yyval.x))) {
+ lex_error("there is no variable '%1'", (yyvsp[0].str));
+ YYABORT;
+ }
+ free((yyvsp[0].str));
+ }
+#line 4305 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 227: /* expr_not_lower_than: NUMBER */
+#line 1513 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = (yyvsp[0].x); }
+#line 4311 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 228: /* expr_not_lower_than: place DOT_X */
+#line 1515 "../src/preproc/pic/pic.ypp"
+ {
+ if ((yyvsp[-1].pl).obj != 0)
+ (yyval.x) = (yyvsp[-1].pl).obj->origin().x;
+ else
+ (yyval.x) = (yyvsp[-1].pl).x;
+ }
+#line 4322 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 229: /* expr_not_lower_than: place DOT_Y */
+#line 1522 "../src/preproc/pic/pic.ypp"
+ {
+ if ((yyvsp[-1].pl).obj != 0)
+ (yyval.x) = (yyvsp[-1].pl).obj->origin().y;
+ else
+ (yyval.x) = (yyvsp[-1].pl).y;
+ }
+#line 4333 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 230: /* expr_not_lower_than: place DOT_HT */
+#line 1529 "../src/preproc/pic/pic.ypp"
+ {
+ if ((yyvsp[-1].pl).obj != 0)
+ (yyval.x) = (yyvsp[-1].pl).obj->height();
+ else
+ (yyval.x) = 0.0;
+ }
+#line 4344 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 231: /* expr_not_lower_than: place DOT_WID */
+#line 1536 "../src/preproc/pic/pic.ypp"
+ {
+ if ((yyvsp[-1].pl).obj != 0)
+ (yyval.x) = (yyvsp[-1].pl).obj->width();
+ else
+ (yyval.x) = 0.0;
+ }
+#line 4355 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 232: /* expr_not_lower_than: place DOT_RAD */
+#line 1543 "../src/preproc/pic/pic.ypp"
+ {
+ if ((yyvsp[-1].pl).obj != 0)
+ (yyval.x) = (yyvsp[-1].pl).obj->radius();
+ else
+ (yyval.x) = 0.0;
+ }
+#line 4366 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 233: /* expr_not_lower_than: expr '+' expr */
+#line 1550 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = (yyvsp[-2].x) + (yyvsp[0].x); }
+#line 4372 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 234: /* expr_not_lower_than: expr '-' expr */
+#line 1552 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = (yyvsp[-2].x) - (yyvsp[0].x); }
+#line 4378 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 235: /* expr_not_lower_than: expr '*' expr */
+#line 1554 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = (yyvsp[-2].x) * (yyvsp[0].x); }
+#line 4384 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 236: /* expr_not_lower_than: expr '/' expr */
+#line 1556 "../src/preproc/pic/pic.ypp"
+ {
+ if ((yyvsp[0].x) == 0.0) {
+ lex_error("division by zero");
+ YYABORT;
+ }
+ (yyval.x) = (yyvsp[-2].x)/(yyvsp[0].x);
+ }
+#line 4396 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 237: /* expr_not_lower_than: expr '%' expr */
+#line 1564 "../src/preproc/pic/pic.ypp"
+ {
+ if ((yyvsp[0].x) == 0.0) {
+ lex_error("modulus by zero");
+ YYABORT;
+ }
+ (yyval.x) = fmod((yyvsp[-2].x), (yyvsp[0].x));
+ }
+#line 4408 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 238: /* expr_not_lower_than: expr '^' expr */
+#line 1572 "../src/preproc/pic/pic.ypp"
+ {
+ errno = 0;
+ (yyval.x) = pow((yyvsp[-2].x), (yyvsp[0].x));
+ if (errno == EDOM) {
+ lex_error("arguments to '^' operator out of domain");
+ YYABORT;
+ }
+ if (errno == ERANGE) {
+ lex_error("result of '^' operator out of range");
+ YYABORT;
+ }
+ }
+#line 4425 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 239: /* expr_not_lower_than: '-' expr */
+#line 1585 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = -(yyvsp[0].x); }
+#line 4431 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 240: /* expr_not_lower_than: '(' any_expr ')' */
+#line 1587 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = (yyvsp[-1].x); }
+#line 4437 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 241: /* expr_not_lower_than: SIN '(' any_expr ')' */
+#line 1589 "../src/preproc/pic/pic.ypp"
+ {
+ errno = 0;
+ (yyval.x) = sin((yyvsp[-1].x));
+ if (errno == ERANGE) {
+ lex_error("sin result out of range");
+ YYABORT;
+ }
+ }
+#line 4450 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 242: /* expr_not_lower_than: COS '(' any_expr ')' */
+#line 1598 "../src/preproc/pic/pic.ypp"
+ {
+ errno = 0;
+ (yyval.x) = cos((yyvsp[-1].x));
+ if (errno == ERANGE) {
+ lex_error("cos result out of range");
+ YYABORT;
+ }
+ }
+#line 4463 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 243: /* expr_not_lower_than: ATAN2 '(' any_expr ',' any_expr ')' */
+#line 1607 "../src/preproc/pic/pic.ypp"
+ {
+ errno = 0;
+ (yyval.x) = atan2((yyvsp[-3].x), (yyvsp[-1].x));
+ if (errno == EDOM) {
+ lex_error("atan2 argument out of domain");
+ YYABORT;
+ }
+ if (errno == ERANGE) {
+ lex_error("atan2 result out of range");
+ YYABORT;
+ }
+ }
+#line 4480 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 244: /* expr_not_lower_than: LOG '(' any_expr ')' */
+#line 1620 "../src/preproc/pic/pic.ypp"
+ {
+ errno = 0;
+ (yyval.x) = log10((yyvsp[-1].x));
+ if (errno == ERANGE) {
+ lex_error("log result out of range");
+ YYABORT;
+ }
+ }
+#line 4493 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 245: /* expr_not_lower_than: EXP '(' any_expr ')' */
+#line 1629 "../src/preproc/pic/pic.ypp"
+ {
+ errno = 0;
+ (yyval.x) = pow(10.0, (yyvsp[-1].x));
+ if (errno == ERANGE) {
+ lex_error("exp result out of range");
+ YYABORT;
+ }
+ }
+#line 4506 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 246: /* expr_not_lower_than: SQRT '(' any_expr ')' */
+#line 1638 "../src/preproc/pic/pic.ypp"
+ {
+ errno = 0;
+ (yyval.x) = sqrt((yyvsp[-1].x));
+ if (errno == EDOM) {
+ lex_error("sqrt argument out of domain");
+ YYABORT;
+ }
+ }
+#line 4519 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 247: /* expr_not_lower_than: K_MAX '(' any_expr ',' any_expr ')' */
+#line 1647 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = (yyvsp[-3].x) > (yyvsp[-1].x) ? (yyvsp[-3].x) : (yyvsp[-1].x); }
+#line 4525 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 248: /* expr_not_lower_than: K_MIN '(' any_expr ',' any_expr ')' */
+#line 1649 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = (yyvsp[-3].x) < (yyvsp[-1].x) ? (yyvsp[-3].x) : (yyvsp[-1].x); }
+#line 4531 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 249: /* expr_not_lower_than: INT '(' any_expr ')' */
+#line 1651 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = (yyvsp[-1].x) < 0 ? -floor(-(yyvsp[-1].x)) : floor((yyvsp[-1].x)); }
+#line 4537 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 250: /* expr_not_lower_than: RAND '(' any_expr ')' */
+#line 1653 "../src/preproc/pic/pic.ypp"
+ {
+ lex_error("use of 'rand' with an argument is"
+ " deprecated; shift and scale 'rand()' with"
+ " arithmetic instead");
+ (yyval.x) = 1.0 + floor(((rand()&0x7fff)/double(0x7fff))*(yyvsp[-1].x));
+ }
+#line 4548 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 251: /* expr_not_lower_than: RAND '(' ')' */
+#line 1660 "../src/preproc/pic/pic.ypp"
+ {
+ /* return a random number in the range [0,1) */
+ /* portable, but not very random */
+ (yyval.x) = (rand() & 0x7fff) / double(0x8000);
+ }
+#line 4558 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 252: /* expr_not_lower_than: SRAND '(' any_expr ')' */
+#line 1666 "../src/preproc/pic/pic.ypp"
+ {
+ (yyval.x) = 0;
+ srand((unsigned int)(yyvsp[-1].x));
+ }
+#line 4567 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 253: /* expr_not_lower_than: expr LESSEQUAL expr */
+#line 1671 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[-2].x) <= (yyvsp[0].x)); }
+#line 4573 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 254: /* expr_not_lower_than: expr '>' expr */
+#line 1673 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[-2].x) > (yyvsp[0].x)); }
+#line 4579 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 255: /* expr_not_lower_than: expr GREATEREQUAL expr */
+#line 1675 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[-2].x) >= (yyvsp[0].x)); }
+#line 4585 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 256: /* expr_not_lower_than: expr EQUALEQUAL expr */
+#line 1677 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[-2].x) == (yyvsp[0].x)); }
+#line 4591 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 257: /* expr_not_lower_than: expr NOTEQUAL expr */
+#line 1679 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[-2].x) != (yyvsp[0].x)); }
+#line 4597 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 258: /* expr_not_lower_than: expr ANDAND expr */
+#line 1681 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[-2].x) != 0.0 && (yyvsp[0].x) != 0.0); }
+#line 4603 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 259: /* expr_not_lower_than: expr OROR expr */
+#line 1683 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[-2].x) != 0.0 || (yyvsp[0].x) != 0.0); }
+#line 4609 "src/preproc/pic/pic.cpp"
+ break;
+
+ case 260: /* expr_not_lower_than: '!' expr */
+#line 1685 "../src/preproc/pic/pic.ypp"
+ { (yyval.x) = ((yyvsp[0].x) == 0.0); }
+#line 4615 "src/preproc/pic/pic.cpp"
+ break;
+
+
+#line 4619 "src/preproc/pic/pic.cpp"
+
+ default: break;
+ }
+ /* User semantic actions sometimes alter yychar, and that requires
+ that yytoken be updated with the new translation. We take the
+ approach of translating immediately before every use of yytoken.
+ One alternative is translating here after every semantic action,
+ but that translation would be missed if the semantic action invokes
+ YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
+ if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
+ incorrect destructor might then be invoked immediately. In the
+ case of YYERROR or YYBACKUP, subsequent parser actions might lead
+ to an incorrect destructor call or verbose syntax error message
+ before the lookahead is translated. */
+ YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc);
+
+ YYPOPSTACK (yylen);
+ yylen = 0;
+
+ *++yyvsp = yyval;
+
+ /* Now 'shift' the result of the reduction. Determine what state
+ that goes to, based on the state we popped back to and the rule
+ number reduced by. */
+ {
+ const int yylhs = yyr1[yyn] - YYNTOKENS;
+ const int yyi = yypgoto[yylhs] + *yyssp;
+ yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
+ ? yytable[yyi]
+ : yydefgoto[yylhs]);
+ }
+
+ goto yynewstate;
+
+
+/*--------------------------------------.
+| yyerrlab -- here on detecting error. |
+`--------------------------------------*/
+yyerrlab:
+ /* Make sure we have latest lookahead translation. See comments at
+ user semantic actions for why this is necessary. */
+ yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar);
+ /* If not already recovering from an error, report this error. */
+ if (!yyerrstatus)
+ {
+ ++yynerrs;
+ yyerror (YY_("syntax error"));
+ }
+
+ if (yyerrstatus == 3)
+ {
+ /* If just tried and failed to reuse lookahead token after an
+ error, discard it. */
+
+ if (yychar <= YYEOF)
+ {
+ /* Return failure if at end of input. */
+ if (yychar == YYEOF)
+ YYABORT;
+ }
+ else
+ {
+ yydestruct ("Error: discarding",
+ yytoken, &yylval);
+ yychar = YYEMPTY;
+ }
+ }
+
+ /* Else will try to reuse lookahead token after shifting the error
+ token. */
+ goto yyerrlab1;
+
+
+/*---------------------------------------------------.
+| yyerrorlab -- error raised explicitly by YYERROR. |
+`---------------------------------------------------*/
+yyerrorlab:
+ /* Pacify compilers when the user code never invokes YYERROR and the
+ label yyerrorlab therefore never appears in user code. */
+ if (0)
+ YYERROR;
+ ++yynerrs;
+
+ /* Do not reclaim the symbols of the rule whose action triggered
+ this YYERROR. */
+ YYPOPSTACK (yylen);
+ yylen = 0;
+ YY_STACK_PRINT (yyss, yyssp);
+ yystate = *yyssp;
+ goto yyerrlab1;
+
+
+/*-------------------------------------------------------------.
+| yyerrlab1 -- common code for both syntax error and YYERROR. |
+`-------------------------------------------------------------*/
+yyerrlab1:
+ yyerrstatus = 3; /* Each real token shifted decrements this. */
+
+ /* Pop stack until we find a state that shifts the error token. */
+ for (;;)
+ {
+ yyn = yypact[yystate];
+ if (!yypact_value_is_default (yyn))
+ {
+ yyn += YYSYMBOL_YYerror;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror)
+ {
+ yyn = yytable[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
+
+ /* Pop the current state because it cannot handle the error token. */
+ if (yyssp == yyss)
+ YYABORT;
+
+
+ yydestruct ("Error: popping",
+ YY_ACCESSING_SYMBOL (yystate), yyvsp);
+ YYPOPSTACK (1);
+ yystate = *yyssp;
+ YY_STACK_PRINT (yyss, yyssp);
+ }
+
+ YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
+ *++yyvsp = yylval;
+ YY_IGNORE_MAYBE_UNINITIALIZED_END
+
+
+ /* Shift the error token. */
+ YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp);
+
+ yystate = yyn;
+ goto yynewstate;
+
+
+/*-------------------------------------.
+| yyacceptlab -- YYACCEPT comes here. |
+`-------------------------------------*/
+yyacceptlab:
+ yyresult = 0;
+ goto yyreturnlab;
+
+
+/*-----------------------------------.
+| yyabortlab -- YYABORT comes here. |
+`-----------------------------------*/
+yyabortlab:
+ yyresult = 1;
+ goto yyreturnlab;
+
+
+/*-----------------------------------------------------------.
+| yyexhaustedlab -- YYNOMEM (memory exhaustion) comes here. |
+`-----------------------------------------------------------*/
+yyexhaustedlab:
+ yyerror (YY_("memory exhausted"));
+ yyresult = 2;
+ goto yyreturnlab;
+
+
+/*----------------------------------------------------------.
+| yyreturnlab -- parsing is finished, clean up and return. |
+`----------------------------------------------------------*/
+yyreturnlab:
+ if (yychar != YYEMPTY)
+ {
+ /* Make sure we have latest lookahead translation. See comments at
+ user semantic actions for why this is necessary. */
+ yytoken = YYTRANSLATE (yychar);
+ yydestruct ("Cleanup: discarding lookahead",
+ yytoken, &yylval);
+ }
+ /* Do not reclaim the symbols of the rule whose action triggered
+ this YYABORT or YYACCEPT. */
+ YYPOPSTACK (yylen);
+ YY_STACK_PRINT (yyss, yyssp);
+ while (yyssp != yyss)
+ {
+ yydestruct ("Cleanup: popping",
+ YY_ACCESSING_SYMBOL (+*yyssp), yyvsp);
+ YYPOPSTACK (1);
+ }
+#ifndef yyoverflow
+ if (yyss != yyssa)
+ YYSTACK_FREE (yyss);
+#endif
+
+ return yyresult;
+}
+
+#line 1689 "../src/preproc/pic/pic.ypp"
+
+
+/* bison defines const to be empty unless __STDC__ is defined, which it
+isn't under cfront */
+
+#ifdef const
+#undef const
+#endif
+
+static struct {
+ const char *name;
+ double val;
+ int scaled; // non-zero if val should be multiplied by scale
+} defaults_table[] = {
+ { "arcrad", .25, 1 },
+ { "arrowht", .1, 1 },
+ { "arrowwid", .05, 1 },
+ { "circlerad", .25, 1 },
+ { "boxht", .5, 1 },
+ { "boxwid", .75, 1 },
+ { "boxrad", 0.0, 1 },
+ { "dashwid", .05, 1 },
+ { "ellipseht", .5, 1 },
+ { "ellipsewid", .75, 1 },
+ { "moveht", .5, 1 },
+ { "movewid", .5, 1 },
+ { "lineht", .5, 1 },
+ { "linewid", .5, 1 },
+ { "textht", 0.0, 1 },
+ { "textwid", 0.0, 1 },
+ { "scale", 1.0, 0 },
+ { "linethick", -1.0, 0 }, // in points
+ { "fillval", .5, 0 },
+ { "arrowhead", 1.0, 0 },
+ { "maxpswid", 8.5, 0 },
+ { "maxpsht", 11.0, 0 },
+};
+
+place *lookup_label(const char *label)
+{
+ saved_state *state = current_saved_state;
+ PTABLE(place) *tbl = current_table;
+ for (;;) {
+ place *pl = tbl->lookup(label);
+ if (pl)
+ return pl;
+ if (!state)
+ return 0;
+ tbl = state->tbl;
+ state = state->prev;
+ }
+}
+
+void define_label(const char *label, const place *pl)
+{
+ place *p = new place[1];
+ *p = *pl;
+ current_table->define(label, p);
+}
+
+int lookup_variable(const char *name, double *val)
+{
+ place *pl = lookup_label(name);
+ if (pl) {
+ *val = pl->x;
+ return 1;
+ }
+ return 0;
+}
+
+void define_variable(const char *name, double val)
+{
+ place *p = new place[1];
+ p->obj = 0;
+ p->x = val;
+ p->y = 0.0;
+ current_table->define(name, p);
+ if (strcmp(name, "scale") == 0) {
+ // When the scale changes, reset all scaled predefined variables to
+ // their default values.
+ for (unsigned int i = 0;
+ i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++)
+ if (defaults_table[i].scaled)
+ define_variable(defaults_table[i].name, val*defaults_table[i].val);
+ }
+}
+
+// called once only (not once per parse)
+
+void parse_init()
+{
+ current_direction = RIGHT_DIRECTION;
+ current_position.x = 0.0;
+ current_position.y = 0.0;
+ // This resets everything to its default value.
+ reset_all();
+}
+
+void reset(const char *nm)
+{
+ for (unsigned int i = 0;
+ i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++)
+ if (strcmp(nm, defaults_table[i].name) == 0) {
+ double val = defaults_table[i].val;
+ if (defaults_table[i].scaled) {
+ double scale;
+ lookup_variable("scale", &scale);
+ val *= scale;
+ }
+ define_variable(defaults_table[i].name, val);
+ return;
+ }
+ lex_error("'%1' is not a predefined variable", nm);
+}
+
+void reset_all()
+{
+ // We only have to explicitly reset the predefined variables that
+ // aren't scaled because 'scale' is not scaled, and changing the
+ // value of 'scale' will reset all the predefined variables that
+ // are scaled.
+ for (unsigned int i = 0;
+ i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++)
+ if (!defaults_table[i].scaled)
+ define_variable(defaults_table[i].name, defaults_table[i].val);
+}
+
+// called after each parse
+
+void parse_cleanup()
+{
+ while (current_saved_state != 0) {
+ delete current_table;
+ current_table = current_saved_state->tbl;
+ saved_state *tem = current_saved_state;
+ current_saved_state = current_saved_state->prev;
+ delete tem;
+ }
+ assert(current_table == &top_table);
+ PTABLE_ITERATOR(place) iter(current_table);
+ const char *key;
+ place *pl;
+ while (iter.next(&key, &pl))
+ if (pl->obj != 0) {
+ position pos = pl->obj->origin();
+ pl->obj = 0;
+ pl->x = pos.x;
+ pl->y = pos.y;
+ }
+ while (olist.head != 0) {
+ object *tem = olist.head;
+ olist.head = olist.head->next;
+ delete tem;
+ }
+ olist.tail = 0;
+ current_direction = RIGHT_DIRECTION;
+ current_position.x = 0.0;
+ current_position.y = 0.0;
+}
+
+const char *ordinal_postfix(int n)
+{
+ if (n < 10 || n > 20)
+ switch (n % 10) {
+ case 1:
+ return "st";
+ case 2:
+ return "nd";
+ case 3:
+ return "rd";
+ }
+ return "th";
+}
+
+const char *object_type_name(object_type type)
+{
+ switch (type) {
+ case BOX_OBJECT:
+ return "box";
+ case CIRCLE_OBJECT:
+ return "circle";
+ case ELLIPSE_OBJECT:
+ return "ellipse";
+ case ARC_OBJECT:
+ return "arc";
+ case SPLINE_OBJECT:
+ return "spline";
+ case LINE_OBJECT:
+ return "line";
+ case ARROW_OBJECT:
+ return "arrow";
+ case MOVE_OBJECT:
+ return "move";
+ case TEXT_OBJECT:
+ return "\"\"";
+ case BLOCK_OBJECT:
+ return "[]";
+ case OTHER_OBJECT:
+ case MARK_OBJECT:
+ default:
+ break;
+ }
+ return "object";
+}
+
+static char sprintf_buf[1024];
+
+char *format_number(const char *fmt, double n)
+{
+ if (0 /* nullptr */ == fmt)
+ fmt = "%g";
+ return do_sprintf(fmt, &n, 1);
+}
+
+char *do_sprintf(const char *fmt, const double *v, int nv)
+{
+ // Define valid conversion specifiers and modifiers.
+ static const char spcs[] = "eEfgG%";
+ static const char mods[] = "#-+ 0123456789.";
+ string result;
+ int i = 0;
+ string one_format;
+ while (*fmt) {
+ if ('%' == *fmt) {
+ one_format += *fmt++;
+ for (; *fmt != '\0' && strchr(mods, *fmt) != 0; fmt++)
+ one_format += *fmt;
+ if ('\0' == *fmt || strchr(spcs, *fmt) == 0) {
+ lex_error("invalid sprintf conversion specifier '%1'", *fmt);
+ result += one_format;
+ result += fmt;
+ break;
+ }
+ if ('%' == *fmt) {
+ fmt++;
+ snprintf(sprintf_buf, sizeof(sprintf_buf), "%%");
+ }
+ else {
+ if (i >= nv) {
+ lex_error("too few arguments to sprintf");
+ result += one_format;
+ result += fmt;
+ break;
+ }
+ one_format += *fmt++;
+ one_format += '\0';
+// We validated the format string above. Most conversion specifiers are
+// rejected, including `n`.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+ snprintf(sprintf_buf, sizeof(sprintf_buf),
+ one_format.contents(), v[i++]);
+#pragma GCC diagnostic pop
+ }
+ one_format.clear();
+ result += sprintf_buf;
+ }
+ else
+ result += *fmt++;
+ }
+ result += '\0';
+ return strsave(result.contents());
+}
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/preproc/pic/pic.h b/src/preproc/pic/pic.h
new file mode 100644
index 0000000..1a99498
--- /dev/null
+++ b/src/preproc/pic/pic.h
@@ -0,0 +1,122 @@
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+ Written by James Clark (jjc@jclark.com)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+groff is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "lib.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <math.h>
+#include <stdlib.h>
+
+#ifdef NEED_DECLARATION_RAND
+#undef rand
+extern "C" {
+ int rand();
+}
+#endif /* NEED_DECLARATION_RAND */
+
+#ifdef NEED_DECLARATION_SRAND
+#undef srand
+extern "C" {
+#ifdef RET_TYPE_SRAND_IS_VOID
+ void srand(unsigned int);
+#else
+ int srand(unsigned int);
+#endif
+}
+#endif /* NEED_DECLARATION_SRAND */
+
+#ifndef HAVE_FMOD
+extern "C" {
+ double fmod(double, double);
+}
+#endif
+
+#include "cset.h"
+#include "stringclass.h"
+#include "lf.h"
+#include "errarg.h"
+#include "error.h"
+#include "position.h"
+#include "text.h"
+#include "output.h"
+
+#ifndef M_SQRT2
+#define M_SQRT2 1.41421356237309504880
+#endif
+
+#ifndef M_PI
+#define M_PI 3.14159265358979323846
+#endif
+
+class input {
+ input *next;
+public:
+ input();
+ virtual ~input();
+ virtual int get() = 0;
+ virtual int peek() = 0;
+ virtual int get_location(const char **, int *);
+ friend class input_stack;
+ friend class copy_rest_thru_input;
+};
+
+class file_input : public input {
+ FILE *fp;
+ const char *filename;
+ int lineno;
+ string line;
+ const char *ptr;
+ int read_line();
+public:
+ file_input(FILE *, const char *);
+ ~file_input();
+ int get();
+ int peek();
+ int get_location(const char **, int *);
+};
+
+void lex_init(input *);
+int get_location(char **, int *);
+
+void do_copy(const char *file);
+void parse_init();
+void parse_cleanup();
+
+void lex_error(const char *message,
+ const errarg &arg1 = empty_errarg,
+ const errarg &arg2 = empty_errarg,
+ const errarg &arg3 = empty_errarg);
+
+void lex_warning(const char *message,
+ const errarg &arg1 = empty_errarg,
+ const errarg &arg2 = empty_errarg,
+ const errarg &arg3 = empty_errarg);
+
+void lex_cleanup();
+
+extern bool want_flyback;
+extern bool want_alternate_flyback;
+extern int command_char;
+// zero_length_line_flag is non-zero if zero-length lines are drawn
+// as dots by the output device
+extern int zero_length_line_flag;
+extern int driver_extension_flag;
+extern int compatible_flag;
+extern int safer_flag;
+extern char *graphname;
diff --git a/src/preproc/pic/pic.hpp b/src/preproc/pic/pic.hpp
new file mode 100644
index 0000000..c162496
--- /dev/null
+++ b/src/preproc/pic/pic.hpp
@@ -0,0 +1,348 @@
+/* A Bison parser, made by GNU Bison 3.8.2. */
+
+/* Bison interface for Yacc-like parsers in C
+
+ Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation,
+ Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+/* As a special exception, you may create a larger work that contains
+ part or all of the Bison parser skeleton and distribute that work
+ under terms of your choice, so long as that work isn't itself a
+ parser generator using the skeleton or a modified version thereof
+ as a parser skeleton. Alternatively, if you modify or redistribute
+ the parser skeleton itself, you may (at your option) remove this
+ special exception, which will cause the skeleton and the resulting
+ Bison output files to be licensed under the GNU General Public
+ License without this special exception.
+
+ This special exception was added by the Free Software Foundation in
+ version 2.2 of Bison. */
+
+/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual,
+ especially those whose name start with YY_ or yy_. They are
+ private implementation details that can be changed or removed. */
+
+#ifndef YY_YY_SRC_PREPROC_PIC_PIC_HPP_INCLUDED
+# define YY_YY_SRC_PREPROC_PIC_PIC_HPP_INCLUDED
+/* Debug traces. */
+#ifndef YYDEBUG
+# define YYDEBUG 0
+#endif
+#if YYDEBUG
+extern int yydebug;
+#endif
+
+/* Token kinds. */
+#ifndef YYTOKENTYPE
+# define YYTOKENTYPE
+ enum yytokentype
+ {
+ YYEMPTY = -2,
+ YYEOF = 0, /* "end of file" */
+ YYerror = 256, /* error */
+ YYUNDEF = 257, /* "invalid token" */
+ LABEL = 258, /* LABEL */
+ VARIABLE = 259, /* VARIABLE */
+ NUMBER = 260, /* NUMBER */
+ TEXT = 261, /* TEXT */
+ COMMAND_LINE = 262, /* COMMAND_LINE */
+ DELIMITED = 263, /* DELIMITED */
+ ORDINAL = 264, /* ORDINAL */
+ TH = 265, /* TH */
+ LEFT_ARROW_HEAD = 266, /* LEFT_ARROW_HEAD */
+ RIGHT_ARROW_HEAD = 267, /* RIGHT_ARROW_HEAD */
+ DOUBLE_ARROW_HEAD = 268, /* DOUBLE_ARROW_HEAD */
+ LAST = 269, /* LAST */
+ BOX = 270, /* BOX */
+ CIRCLE = 271, /* CIRCLE */
+ ELLIPSE = 272, /* ELLIPSE */
+ ARC = 273, /* ARC */
+ LINE = 274, /* LINE */
+ ARROW = 275, /* ARROW */
+ MOVE = 276, /* MOVE */
+ SPLINE = 277, /* SPLINE */
+ HEIGHT = 278, /* HEIGHT */
+ RADIUS = 279, /* RADIUS */
+ FIGNAME = 280, /* FIGNAME */
+ WIDTH = 281, /* WIDTH */
+ DIAMETER = 282, /* DIAMETER */
+ UP = 283, /* UP */
+ DOWN = 284, /* DOWN */
+ RIGHT = 285, /* RIGHT */
+ LEFT = 286, /* LEFT */
+ FROM = 287, /* FROM */
+ TO = 288, /* TO */
+ AT = 289, /* AT */
+ WITH = 290, /* WITH */
+ BY = 291, /* BY */
+ THEN = 292, /* THEN */
+ SOLID = 293, /* SOLID */
+ DOTTED = 294, /* DOTTED */
+ DASHED = 295, /* DASHED */
+ CHOP = 296, /* CHOP */
+ SAME = 297, /* SAME */
+ INVISIBLE = 298, /* INVISIBLE */
+ LJUST = 299, /* LJUST */
+ RJUST = 300, /* RJUST */
+ ABOVE = 301, /* ABOVE */
+ BELOW = 302, /* BELOW */
+ OF = 303, /* OF */
+ THE = 304, /* THE */
+ WAY = 305, /* WAY */
+ BETWEEN = 306, /* BETWEEN */
+ AND = 307, /* AND */
+ HERE = 308, /* HERE */
+ DOT_N = 309, /* DOT_N */
+ DOT_E = 310, /* DOT_E */
+ DOT_W = 311, /* DOT_W */
+ DOT_S = 312, /* DOT_S */
+ DOT_NE = 313, /* DOT_NE */
+ DOT_SE = 314, /* DOT_SE */
+ DOT_NW = 315, /* DOT_NW */
+ DOT_SW = 316, /* DOT_SW */
+ DOT_C = 317, /* DOT_C */
+ DOT_START = 318, /* DOT_START */
+ DOT_END = 319, /* DOT_END */
+ DOT_X = 320, /* DOT_X */
+ DOT_Y = 321, /* DOT_Y */
+ DOT_HT = 322, /* DOT_HT */
+ DOT_WID = 323, /* DOT_WID */
+ DOT_RAD = 324, /* DOT_RAD */
+ SIN = 325, /* SIN */
+ COS = 326, /* COS */
+ ATAN2 = 327, /* ATAN2 */
+ LOG = 328, /* LOG */
+ EXP = 329, /* EXP */
+ SQRT = 330, /* SQRT */
+ K_MAX = 331, /* K_MAX */
+ K_MIN = 332, /* K_MIN */
+ INT = 333, /* INT */
+ RAND = 334, /* RAND */
+ SRAND = 335, /* SRAND */
+ COPY = 336, /* COPY */
+ THRU = 337, /* THRU */
+ TOP = 338, /* TOP */
+ BOTTOM = 339, /* BOTTOM */
+ UPPER = 340, /* UPPER */
+ LOWER = 341, /* LOWER */
+ SH = 342, /* SH */
+ PRINT = 343, /* PRINT */
+ CW = 344, /* CW */
+ CCW = 345, /* CCW */
+ FOR = 346, /* FOR */
+ DO = 347, /* DO */
+ IF = 348, /* IF */
+ ELSE = 349, /* ELSE */
+ ANDAND = 350, /* ANDAND */
+ OROR = 351, /* OROR */
+ NOTEQUAL = 352, /* NOTEQUAL */
+ EQUALEQUAL = 353, /* EQUALEQUAL */
+ LESSEQUAL = 354, /* LESSEQUAL */
+ GREATEREQUAL = 355, /* GREATEREQUAL */
+ LEFT_CORNER = 356, /* LEFT_CORNER */
+ RIGHT_CORNER = 357, /* RIGHT_CORNER */
+ NORTH = 358, /* NORTH */
+ SOUTH = 359, /* SOUTH */
+ EAST = 360, /* EAST */
+ WEST = 361, /* WEST */
+ CENTER = 362, /* CENTER */
+ END = 363, /* END */
+ START = 364, /* START */
+ RESET = 365, /* RESET */
+ UNTIL = 366, /* UNTIL */
+ PLOT = 367, /* PLOT */
+ THICKNESS = 368, /* THICKNESS */
+ FILL = 369, /* FILL */
+ COLORED = 370, /* COLORED */
+ OUTLINED = 371, /* OUTLINED */
+ SHADED = 372, /* SHADED */
+ XSLANTED = 373, /* XSLANTED */
+ YSLANTED = 374, /* YSLANTED */
+ ALIGNED = 375, /* ALIGNED */
+ SPRINTF = 376, /* SPRINTF */
+ COMMAND = 377, /* COMMAND */
+ DEFINE = 378, /* DEFINE */
+ UNDEF = 379 /* UNDEF */
+ };
+ typedef enum yytokentype yytoken_kind_t;
+#endif
+/* Token kinds. */
+#define YYEMPTY -2
+#define YYEOF 0
+#define YYerror 256
+#define YYUNDEF 257
+#define LABEL 258
+#define VARIABLE 259
+#define NUMBER 260
+#define TEXT 261
+#define COMMAND_LINE 262
+#define DELIMITED 263
+#define ORDINAL 264
+#define TH 265
+#define LEFT_ARROW_HEAD 266
+#define RIGHT_ARROW_HEAD 267
+#define DOUBLE_ARROW_HEAD 268
+#define LAST 269
+#define BOX 270
+#define CIRCLE 271
+#define ELLIPSE 272
+#define ARC 273
+#define LINE 274
+#define ARROW 275
+#define MOVE 276
+#define SPLINE 277
+#define HEIGHT 278
+#define RADIUS 279
+#define FIGNAME 280
+#define WIDTH 281
+#define DIAMETER 282
+#define UP 283
+#define DOWN 284
+#define RIGHT 285
+#define LEFT 286
+#define FROM 287
+#define TO 288
+#define AT 289
+#define WITH 290
+#define BY 291
+#define THEN 292
+#define SOLID 293
+#define DOTTED 294
+#define DASHED 295
+#define CHOP 296
+#define SAME 297
+#define INVISIBLE 298
+#define LJUST 299
+#define RJUST 300
+#define ABOVE 301
+#define BELOW 302
+#define OF 303
+#define THE 304
+#define WAY 305
+#define BETWEEN 306
+#define AND 307
+#define HERE 308
+#define DOT_N 309
+#define DOT_E 310
+#define DOT_W 311
+#define DOT_S 312
+#define DOT_NE 313
+#define DOT_SE 314
+#define DOT_NW 315
+#define DOT_SW 316
+#define DOT_C 317
+#define DOT_START 318
+#define DOT_END 319
+#define DOT_X 320
+#define DOT_Y 321
+#define DOT_HT 322
+#define DOT_WID 323
+#define DOT_RAD 324
+#define SIN 325
+#define COS 326
+#define ATAN2 327
+#define LOG 328
+#define EXP 329
+#define SQRT 330
+#define K_MAX 331
+#define K_MIN 332
+#define INT 333
+#define RAND 334
+#define SRAND 335
+#define COPY 336
+#define THRU 337
+#define TOP 338
+#define BOTTOM 339
+#define UPPER 340
+#define LOWER 341
+#define SH 342
+#define PRINT 343
+#define CW 344
+#define CCW 345
+#define FOR 346
+#define DO 347
+#define IF 348
+#define ELSE 349
+#define ANDAND 350
+#define OROR 351
+#define NOTEQUAL 352
+#define EQUALEQUAL 353
+#define LESSEQUAL 354
+#define GREATEREQUAL 355
+#define LEFT_CORNER 356
+#define RIGHT_CORNER 357
+#define NORTH 358
+#define SOUTH 359
+#define EAST 360
+#define WEST 361
+#define CENTER 362
+#define END 363
+#define START 364
+#define RESET 365
+#define UNTIL 366
+#define PLOT 367
+#define THICKNESS 368
+#define FILL 369
+#define COLORED 370
+#define OUTLINED 371
+#define SHADED 372
+#define XSLANTED 373
+#define YSLANTED 374
+#define ALIGNED 375
+#define SPRINTF 376
+#define COMMAND 377
+#define DEFINE 378
+#define UNDEF 379
+
+/* Value type. */
+#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
+union YYSTYPE
+{
+#line 65 "../src/preproc/pic/pic.ypp"
+
+ char *str;
+ int n;
+ double x;
+ struct { double x, y; } pair;
+ struct { double x; char *body; } if_data;
+ struct { char *str; const char *filename; int lineno; } lstr;
+ struct { double *v; int nv; int maxv; } dv;
+ struct { double val; int is_multiplicative; } by;
+ place pl;
+ object *obj;
+ corner crn;
+ path *pth;
+ object_spec *spec;
+ saved_state *pstate;
+ graphics_state state;
+ object_type obtype;
+
+#line 334 "src/preproc/pic/pic.hpp"
+
+};
+typedef union YYSTYPE YYSTYPE;
+# define YYSTYPE_IS_TRIVIAL 1
+# define YYSTYPE_IS_DECLARED 1
+#endif
+
+
+extern YYSTYPE yylval;
+
+
+int yyparse (void);
+
+
+#endif /* !YY_YY_SRC_PREPROC_PIC_PIC_HPP_INCLUDED */
diff --git a/src/preproc/pic/pic.ypp b/src/preproc/pic/pic.ypp
new file mode 100644
index 0000000..b2fa6dc
--- /dev/null
+++ b/src/preproc/pic/pic.ypp
@@ -0,0 +1,1957 @@
+/* Copyright (C) 1989-2022 Free Software Foundation, Inc.
+ Written by James Clark (jjc@jclark.com)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+groff is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+%{
+#include "pic.h"
+#include "ptable.h"
+#include "object.h"
+
+extern int delim_flag;
+extern void copy_rest_thru(const char *, const char *);
+extern void copy_file_thru(const char *, const char *, const char *);
+extern void push_body(const char *);
+extern void do_for(char *var, double from, double to,
+ int by_is_multiplicative, double by, char *body);
+extern void do_lookahead();
+
+/* Maximum number of characters produced by printf("%g") */
+#define GDIGITS 14
+
+int yylex();
+void yyerror(const char *);
+
+void reset(const char *nm);
+void reset_all();
+
+place *lookup_label(const char *);
+void define_label(const char *label, const place *pl);
+
+direction current_direction;
+position current_position;
+
+implement_ptable(place)
+
+PTABLE(place) top_table;
+
+PTABLE(place) *current_table = &top_table;
+saved_state *current_saved_state = 0;
+
+object_list olist;
+
+const char *ordinal_postfix(int n);
+const char *object_type_name(object_type type);
+char *format_number(const char *fmt, double n);
+char *do_sprintf(const char *fmt, const double *v, int nv);
+
+%}
+
+%expect 2
+
+%union {
+ char *str;
+ int n;
+ double x;
+ struct { double x, y; } pair;
+ struct { double x; char *body; } if_data;
+ struct { char *str; const char *filename; int lineno; } lstr;
+ struct { double *v; int nv; int maxv; } dv;
+ struct { double val; int is_multiplicative; } by;
+ place pl;
+ object *obj;
+ corner crn;
+ path *pth;
+ object_spec *spec;
+ saved_state *pstate;
+ graphics_state state;
+ object_type obtype;
+}
+
+%token <str> LABEL
+%token <str> VARIABLE
+%token <x> NUMBER
+%token <lstr> TEXT
+%token <lstr> COMMAND_LINE
+%token <str> DELIMITED
+%token <n> ORDINAL
+%token TH
+%token LEFT_ARROW_HEAD
+%token RIGHT_ARROW_HEAD
+%token DOUBLE_ARROW_HEAD
+%token LAST
+%token BOX
+%token CIRCLE
+%token ELLIPSE
+%token ARC
+%token LINE
+%token ARROW
+%token MOVE
+%token SPLINE
+%token HEIGHT
+%token RADIUS
+%token FIGNAME
+%token WIDTH
+%token DIAMETER
+%token UP
+%token DOWN
+%token RIGHT
+%token LEFT
+%token FROM
+%token TO
+%token AT
+%token WITH
+%token BY
+%token THEN
+%token SOLID
+%token DOTTED
+%token DASHED
+%token CHOP
+%token SAME
+%token INVISIBLE
+%token LJUST
+%token RJUST
+%token ABOVE
+%token BELOW
+%token OF
+%token THE
+%token WAY
+%token BETWEEN
+%token AND
+%token HERE
+%token DOT_N
+%token DOT_E
+%token DOT_W
+%token DOT_S
+%token DOT_NE
+%token DOT_SE
+%token DOT_NW
+%token DOT_SW
+%token DOT_C
+%token DOT_START
+%token DOT_END
+%token DOT_X
+%token DOT_Y
+%token DOT_HT
+%token DOT_WID
+%token DOT_RAD
+%token SIN
+%token COS
+%token ATAN2
+%token LOG
+%token EXP
+%token SQRT
+%token K_MAX
+%token K_MIN
+%token INT
+%token RAND
+%token SRAND
+%token COPY
+%token THRU
+%token TOP
+%token BOTTOM
+%token UPPER
+%token LOWER
+%token SH
+%token PRINT
+%token CW
+%token CCW
+%token FOR
+%token DO
+%token IF
+%token ELSE
+%token ANDAND
+%token OROR
+%token NOTEQUAL
+%token EQUALEQUAL
+%token LESSEQUAL
+%token GREATEREQUAL
+%token LEFT_CORNER
+%token RIGHT_CORNER
+%token NORTH
+%token SOUTH
+%token EAST
+%token WEST
+%token CENTER
+%token END
+%token START
+%token RESET
+%token UNTIL
+%token PLOT
+%token THICKNESS
+%token FILL
+%token COLORED
+%token OUTLINED
+%token SHADED
+%token XSLANTED
+%token YSLANTED
+%token ALIGNED
+%token SPRINTF
+%token COMMAND
+
+%token DEFINE
+%token UNDEF
+
+%left '.'
+
+/* this ensures that plot 17 "%g" parses as (plot 17 "%g") */
+%left PLOT
+%left TEXT SPRINTF
+
+/* give text adjustments higher precedence than TEXT, so that
+box "foo" above ljust == box ("foo" above ljust)
+*/
+
+%left LJUST RJUST ABOVE BELOW
+
+%left LEFT RIGHT
+/* Give attributes that take an optional expression a higher
+precedence than left and right, so that, e.g., 'line chop left'
+parses properly. */
+%left CHOP SOLID DASHED DOTTED UP DOWN FILL COLORED OUTLINED
+%left XSLANTED YSLANTED
+%left LABEL
+
+%left VARIABLE NUMBER '(' SIN COS ATAN2 LOG EXP SQRT K_MAX K_MIN INT RAND SRAND LAST
+%left ORDINAL HERE '`'
+
+%left BOX CIRCLE ELLIPSE ARC LINE ARROW SPLINE '['
+
+/* these need to be lower than '-' */
+%left HEIGHT RADIUS WIDTH DIAMETER FROM TO AT THICKNESS
+
+/* these must have higher precedence than CHOP so that 'label %prec CHOP'
+works */
+%left DOT_N DOT_E DOT_W DOT_S DOT_NE DOT_SE DOT_NW DOT_SW DOT_C
+%left DOT_START DOT_END TOP BOTTOM LEFT_CORNER RIGHT_CORNER
+%left UPPER LOWER NORTH SOUTH EAST WEST CENTER START END
+
+%left ','
+%left OROR
+%left ANDAND
+%left EQUALEQUAL NOTEQUAL
+%left '<' '>' LESSEQUAL GREATEREQUAL
+
+%left BETWEEN OF
+%left AND
+
+%left '+' '-'
+%left '*' '/' '%'
+%right '!'
+%right '^'
+
+%type <x> expr expr_lower_than expr_not_lower_than any_expr text_expr
+%type <by> optional_by
+%type <pair> expr_pair position_not_place
+%type <if_data> simple_if
+%type <obj> nth_primitive
+%type <crn> corner
+%type <pth> path label_path relative_path
+%type <pl> place label element element_list middle_element_list
+%type <spec> object_spec
+%type <pair> position
+%type <obtype> object_type
+%type <n> optional_ordinal_last ordinal
+%type <str> macro_name until
+%type <dv> sprintf_args
+%type <lstr> text print_args print_arg
+
+%%
+
+top:
+ optional_separator
+ | element_list
+ {
+ if (olist.head)
+ print_picture(olist.head);
+ }
+ ;
+
+
+element_list:
+ optional_separator middle_element_list optional_separator
+ { $$ = $2; }
+ ;
+
+middle_element_list:
+ element
+ { $$ = $1; }
+ | middle_element_list separator element
+ { $$ = $1; }
+ ;
+
+optional_separator:
+ /* empty */
+ | separator
+ ;
+
+separator:
+ ';'
+ | separator ';'
+ ;
+
+placeless_element:
+ FIGNAME '=' macro_name
+ {
+ delete[] graphname;
+ graphname = new char[strlen($3) + 1];
+ strcpy(graphname, $3);
+ delete[] $3;
+ }
+ |
+ VARIABLE '=' any_expr
+ {
+ define_variable($1, $3);
+ free($1);
+ }
+ | VARIABLE ':' '=' any_expr
+ {
+ place *p = lookup_label($1);
+ if (!p) {
+ lex_error("variable '%1' not defined", $1);
+ YYABORT;
+ }
+ p->obj = 0;
+ p->x = $4;
+ p->y = 0.0;
+ free($1);
+ }
+ | UP
+ { current_direction = UP_DIRECTION; }
+ | DOWN
+ { current_direction = DOWN_DIRECTION; }
+ | LEFT
+ { current_direction = LEFT_DIRECTION; }
+ | RIGHT
+ { current_direction = RIGHT_DIRECTION; }
+ | COMMAND_LINE
+ {
+ olist.append(make_command_object($1.str, $1.filename,
+ $1.lineno));
+ }
+ | COMMAND print_args
+ {
+ olist.append(make_command_object($2.str, $2.filename,
+ $2.lineno));
+ }
+ | PRINT print_args
+ {
+ fprintf(stderr, "%s\n", $2.str);
+ delete[] $2.str;
+ fflush(stderr);
+ }
+ | SH
+ { delim_flag = 1; }
+ DELIMITED
+ {
+ delim_flag = 0;
+ if (safer_flag)
+ lex_error("unsafe to run command '%1'; ignoring",
+ $3);
+ else {
+ int retval = system($3);
+ if (retval < 0)
+ lex_error("error running command '%1': system()"
+ " returned %2", $3, retval);
+ }
+ delete[] $3;
+ }
+ | COPY TEXT
+ {
+ if (yychar < 0)
+ do_lookahead();
+ do_copy($2.str);
+ // do not delete the filename
+ }
+ | COPY TEXT THRU
+ { delim_flag = 2; }
+ DELIMITED
+ { delim_flag = 0; }
+ until
+ {
+ if (yychar < 0)
+ do_lookahead();
+ copy_file_thru($2.str, $5, $7);
+ // do not delete the filename
+ delete[] $5;
+ delete[] $7;
+ }
+ | COPY THRU
+ { delim_flag = 2; }
+ DELIMITED
+ { delim_flag = 0; }
+ until
+ {
+ if (yychar < 0)
+ do_lookahead();
+ copy_rest_thru($4, $6);
+ delete[] $4;
+ delete[] $6;
+ }
+ | FOR VARIABLE '=' expr TO expr optional_by DO
+ { delim_flag = 1; }
+ DELIMITED
+ {
+ delim_flag = 0;
+ if (yychar < 0)
+ do_lookahead();
+ do_for($2, $4, $6, $7.is_multiplicative, $7.val, $10);
+ }
+ | simple_if
+ {
+ if (yychar < 0)
+ do_lookahead();
+ if ($1.x != 0.0)
+ push_body($1.body);
+ delete[] $1.body;
+ }
+ | simple_if ELSE
+ { delim_flag = 1; }
+ DELIMITED
+ {
+ delim_flag = 0;
+ if (yychar < 0)
+ do_lookahead();
+ if ($1.x != 0.0)
+ push_body($1.body);
+ else
+ push_body($4);
+ free($1.body);
+ free($4);
+ }
+ | reset_variables
+ | RESET
+ { define_variable("scale", 1.0); }
+ ;
+
+macro_name:
+ VARIABLE
+ | LABEL
+ ;
+
+reset_variables:
+ RESET VARIABLE
+ {
+ reset($2);
+ delete[] $2;
+ }
+ | reset_variables VARIABLE
+ {
+ reset($2);
+ delete[] $2;
+ }
+ | reset_variables ',' VARIABLE
+ {
+ reset($3);
+ delete[] $3;
+ }
+ ;
+
+print_args:
+ print_arg
+ { $$ = $1; }
+ | print_args print_arg
+ {
+ $$.str = new char[strlen($1.str) + strlen($2.str) + 1];
+ strcpy($$.str, $1.str);
+ strcat($$.str, $2.str);
+ delete[] $1.str;
+ delete[] $2.str;
+ if ($1.filename) {
+ $$.filename = $1.filename;
+ $$.lineno = $1.lineno;
+ }
+ else if ($2.filename) {
+ $$.filename = $2.filename;
+ $$.lineno = $2.lineno;
+ }
+ }
+ ;
+
+print_arg:
+ expr %prec ','
+ {
+ $$.str = new char[GDIGITS + 1];
+ sprintf($$.str, "%g", $1);
+ $$.filename = 0;
+ $$.lineno = 0;
+ }
+ | text
+ { $$ = $1; }
+ | position %prec ','
+ {
+ $$.str = new char[GDIGITS + 2 + GDIGITS + 1];
+ sprintf($$.str, "%g, %g", $1.x, $1.y);
+ $$.filename = 0;
+ $$.lineno = 0;
+ }
+ ;
+
+simple_if:
+ IF any_expr THEN
+ { delim_flag = 1; }
+ DELIMITED
+ {
+ delim_flag = 0;
+ $$.x = $2;
+ $$.body = $5;
+ }
+ ;
+
+until:
+ /* empty */
+ { $$ = 0; }
+ | UNTIL TEXT
+ { $$ = $2.str; }
+ ;
+
+any_expr:
+ expr
+ { $$ = $1; }
+ | text_expr
+ { $$ = $1; }
+ ;
+
+text_expr:
+ text EQUALEQUAL text
+ {
+ $$ = strcmp($1.str, $3.str) == 0;
+ delete[] $1.str;
+ delete[] $3.str;
+ }
+ | text NOTEQUAL text
+ {
+ $$ = strcmp($1.str, $3.str) != 0;
+ delete[] $1.str;
+ delete[] $3.str;
+ }
+ | text_expr ANDAND text_expr
+ { $$ = ($1 != 0.0 && $3 != 0.0); }
+ | text_expr ANDAND expr
+ { $$ = ($1 != 0.0 && $3 != 0.0); }
+ | expr ANDAND text_expr
+ { $$ = ($1 != 0.0 && $3 != 0.0); }
+ | text_expr OROR text_expr
+ { $$ = ($1 != 0.0 || $3 != 0.0); }
+ | text_expr OROR expr
+ { $$ = ($1 != 0.0 || $3 != 0.0); }
+ | expr OROR text_expr
+ { $$ = ($1 != 0.0 || $3 != 0.0); }
+ | '!' text_expr
+ { $$ = ($2 == 0.0); }
+ ;
+
+
+optional_by:
+ /* empty */
+ {
+ $$.val = 1.0;
+ $$.is_multiplicative = 0;
+ }
+ | BY expr
+ {
+ $$.val = $2;
+ $$.is_multiplicative = 0;
+ }
+ | BY '*' expr
+ {
+ $$.val = $3;
+ $$.is_multiplicative = 1;
+ }
+ ;
+
+element:
+ object_spec
+ {
+ $$.obj = $1->make_object(&current_position,
+ &current_direction);
+ if ($$.obj == 0)
+ YYABORT;
+ delete $1;
+ if ($$.obj)
+ olist.append($$.obj);
+ else {
+ $$.x = current_position.x;
+ $$.y = current_position.y;
+ }
+ }
+ | LABEL ':' optional_separator element
+ {
+ $$ = $4;
+ define_label($1, & $$);
+ free($1);
+ }
+ | LABEL ':' optional_separator position_not_place
+ {
+ $$.obj = 0;
+ $$.x = $4.x;
+ $$.y = $4.y;
+ define_label($1, & $$);
+ free($1);
+ }
+ | LABEL ':' optional_separator place
+ {
+ $$ = $4;
+ define_label($1, & $$);
+ free($1);
+ }
+ | '{'
+ {
+ $<state>$.x = current_position.x;
+ $<state>$.y = current_position.y;
+ $<state>$.dir = current_direction;
+ }
+ element_list '}'
+ {
+ current_position.x = $<state>2.x;
+ current_position.y = $<state>2.y;
+ current_direction = $<state>2.dir;
+ }
+ optional_element
+ {
+ $$ = $3;
+ }
+ | placeless_element
+ {
+ $$.obj = 0;
+ $$.x = current_position.x;
+ $$.y = current_position.y;
+ }
+ ;
+
+optional_element:
+ /* empty */
+ {}
+ | element
+ {}
+ ;
+
+object_spec:
+ BOX
+ { $$ = new object_spec(BOX_OBJECT); }
+ | CIRCLE
+ { $$ = new object_spec(CIRCLE_OBJECT); }
+ | ELLIPSE
+ { $$ = new object_spec(ELLIPSE_OBJECT); }
+ | ARC
+ {
+ $$ = new object_spec(ARC_OBJECT);
+ $$->dir = current_direction;
+ }
+ | LINE
+ {
+ $$ = new object_spec(LINE_OBJECT);
+ lookup_variable("lineht", & $$->segment_height);
+ lookup_variable("linewid", & $$->segment_width);
+ $$->dir = current_direction;
+ }
+ | ARROW
+ {
+ $$ = new object_spec(ARROW_OBJECT);
+ lookup_variable("lineht", & $$->segment_height);
+ lookup_variable("linewid", & $$->segment_width);
+ $$->dir = current_direction;
+ }
+ | MOVE
+ {
+ $$ = new object_spec(MOVE_OBJECT);
+ lookup_variable("moveht", & $$->segment_height);
+ lookup_variable("movewid", & $$->segment_width);
+ $$->dir = current_direction;
+ }
+ | SPLINE
+ {
+ $$ = new object_spec(SPLINE_OBJECT);
+ lookup_variable("lineht", & $$->segment_height);
+ lookup_variable("linewid", & $$->segment_width);
+ $$->dir = current_direction;
+ }
+ | text %prec TEXT
+ {
+ $$ = new object_spec(TEXT_OBJECT);
+ $$->text = new text_item($1.str, $1.filename, $1.lineno);
+ }
+ | PLOT expr
+ {
+ lex_warning("'plot' is deprecated; use 'sprintf'"
+ " instead");
+ $$ = new object_spec(TEXT_OBJECT);
+ $$->text = new text_item(format_number(0, $2), 0, -1);
+ }
+ | PLOT expr text
+ {
+ $$ = new object_spec(TEXT_OBJECT);
+ $$->text = new text_item(format_number($3.str, $2),
+ $3.filename, $3.lineno);
+ delete[] $3.str;
+ }
+ | '['
+ {
+ saved_state *p = new saved_state;
+ $<pstate>$ = p;
+ p->x = current_position.x;
+ p->y = current_position.y;
+ p->dir = current_direction;
+ p->tbl = current_table;
+ p->prev = current_saved_state;
+ current_position.x = 0.0;
+ current_position.y = 0.0;
+ current_table = new PTABLE(place);
+ current_saved_state = p;
+ olist.append(make_mark_object());
+ }
+ element_list ']'
+ {
+ current_position.x = $<pstate>2->x;
+ current_position.y = $<pstate>2->y;
+ current_direction = $<pstate>2->dir;
+ $$ = new object_spec(BLOCK_OBJECT);
+ olist.wrap_up_block(& $$->oblist);
+ $$->tbl = current_table;
+ current_table = $<pstate>2->tbl;
+ current_saved_state = $<pstate>2->prev;
+ delete $<pstate>2;
+ }
+ | object_spec HEIGHT expr
+ {
+ $$ = $1;
+ $$->height = $3;
+ $$->flags |= HAS_HEIGHT;
+ }
+ | object_spec RADIUS expr
+ {
+ $$ = $1;
+ $$->radius = $3;
+ $$->flags |= HAS_RADIUS;
+ }
+ | object_spec WIDTH expr
+ {
+ $$ = $1;
+ $$->width = $3;
+ $$->flags |= HAS_WIDTH;
+ }
+ | object_spec DIAMETER expr
+ {
+ $$ = $1;
+ $$->radius = $3/2.0;
+ $$->flags |= HAS_RADIUS;
+ }
+ | object_spec expr %prec HEIGHT
+ {
+ $$ = $1;
+ $$->flags |= HAS_SEGMENT;
+ switch ($$->dir) {
+ case UP_DIRECTION:
+ $$->segment_pos.y += $2;
+ break;
+ case DOWN_DIRECTION:
+ $$->segment_pos.y -= $2;
+ break;
+ case RIGHT_DIRECTION:
+ $$->segment_pos.x += $2;
+ break;
+ case LEFT_DIRECTION:
+ $$->segment_pos.x -= $2;
+ break;
+ }
+ }
+ | object_spec UP
+ {
+ $$ = $1;
+ $$->dir = UP_DIRECTION;
+ $$->flags |= HAS_SEGMENT;
+ $$->segment_pos.y += $$->segment_height;
+ }
+ | object_spec UP expr
+ {
+ $$ = $1;
+ $$->dir = UP_DIRECTION;
+ $$->flags |= HAS_SEGMENT;
+ $$->segment_pos.y += $3;
+ }
+ | object_spec DOWN
+ {
+ $$ = $1;
+ $$->dir = DOWN_DIRECTION;
+ $$->flags |= HAS_SEGMENT;
+ $$->segment_pos.y -= $$->segment_height;
+ }
+ | object_spec DOWN expr
+ {
+ $$ = $1;
+ $$->dir = DOWN_DIRECTION;
+ $$->flags |= HAS_SEGMENT;
+ $$->segment_pos.y -= $3;
+ }
+ | object_spec RIGHT
+ {
+ $$ = $1;
+ $$->dir = RIGHT_DIRECTION;
+ $$->flags |= HAS_SEGMENT;
+ $$->segment_pos.x += $$->segment_width;
+ }
+ | object_spec RIGHT expr
+ {
+ $$ = $1;
+ $$->dir = RIGHT_DIRECTION;
+ $$->flags |= HAS_SEGMENT;
+ $$->segment_pos.x += $3;
+ }
+ | object_spec LEFT
+ {
+ $$ = $1;
+ $$->dir = LEFT_DIRECTION;
+ $$->flags |= HAS_SEGMENT;
+ $$->segment_pos.x -= $$->segment_width;
+ }
+ | object_spec LEFT expr
+ {
+ $$ = $1;
+ $$->dir = LEFT_DIRECTION;
+ $$->flags |= HAS_SEGMENT;
+ $$->segment_pos.x -= $3;
+ }
+ | object_spec FROM position
+ {
+ $$ = $1;
+ $$->flags |= HAS_FROM;
+ $$->from.x = $3.x;
+ $$->from.y = $3.y;
+ }
+ | object_spec TO position
+ {
+ $$ = $1;
+ if ($$->flags & HAS_SEGMENT)
+ $$->segment_list = new segment($$->segment_pos,
+ $$->segment_is_absolute,
+ $$->segment_list);
+ $$->flags |= HAS_SEGMENT;
+ $$->segment_pos.x = $3.x;
+ $$->segment_pos.y = $3.y;
+ $$->segment_is_absolute = 1;
+ $$->flags |= HAS_TO;
+ $$->to.x = $3.x;
+ $$->to.y = $3.y;
+ }
+ | object_spec AT position
+ {
+ $$ = $1;
+ $$->flags |= HAS_AT;
+ $$->at.x = $3.x;
+ $$->at.y = $3.y;
+ if ($$->type != ARC_OBJECT) {
+ $$->flags |= HAS_FROM;
+ $$->from.x = $3.x;
+ $$->from.y = $3.y;
+ }
+ }
+ | object_spec WITH path
+ {
+ $$ = $1;
+ $$->flags |= HAS_WITH;
+ $$->with = $3;
+ }
+ | object_spec WITH position %prec ','
+ {
+ $$ = $1;
+ $$->flags |= HAS_WITH;
+ position pos;
+ pos.x = $3.x;
+ pos.y = $3.y;
+ $$->with = new path(pos);
+ }
+ | object_spec BY expr_pair
+ {
+ $$ = $1;
+ $$->flags |= HAS_SEGMENT;
+ $$->segment_pos.x += $3.x;
+ $$->segment_pos.y += $3.y;
+ }
+ | object_spec THEN
+ {
+ $$ = $1;
+ if (!($$->flags & HAS_SEGMENT))
+ switch ($$->dir) {
+ case UP_DIRECTION:
+ $$->segment_pos.y += $$->segment_width;
+ break;
+ case DOWN_DIRECTION:
+ $$->segment_pos.y -= $$->segment_width;
+ break;
+ case RIGHT_DIRECTION:
+ $$->segment_pos.x += $$->segment_width;
+ break;
+ case LEFT_DIRECTION:
+ $$->segment_pos.x -= $$->segment_width;
+ break;
+ }
+ $$->segment_list = new segment($$->segment_pos,
+ $$->segment_is_absolute,
+ $$->segment_list);
+ $$->flags &= ~HAS_SEGMENT;
+ $$->segment_pos.x = $$->segment_pos.y = 0.0;
+ $$->segment_is_absolute = 0;
+ }
+ | object_spec SOLID
+ {
+ $$ = $1; // nothing
+ }
+ | object_spec DOTTED
+ {
+ $$ = $1;
+ $$->flags |= IS_DOTTED;
+ lookup_variable("dashwid", & $$->dash_width);
+ }
+ | object_spec DOTTED expr
+ {
+ $$ = $1;
+ $$->flags |= IS_DOTTED;
+ $$->dash_width = $3;
+ }
+ | object_spec DASHED
+ {
+ $$ = $1;
+ $$->flags |= IS_DASHED;
+ lookup_variable("dashwid", & $$->dash_width);
+ }
+ | object_spec DASHED expr
+ {
+ $$ = $1;
+ $$->flags |= IS_DASHED;
+ $$->dash_width = $3;
+ }
+ | object_spec FILL
+ {
+ $$ = $1;
+ $$->flags |= IS_DEFAULT_FILLED;
+ }
+ | object_spec FILL expr
+ {
+ $$ = $1;
+ $$->flags |= IS_FILLED;
+ $$->fill = $3;
+ }
+ | object_spec XSLANTED expr
+ {
+ $$ = $1;
+ $$->flags |= IS_XSLANTED;
+ $$->xslanted = $3;
+ }
+ | object_spec YSLANTED expr
+ {
+ $$ = $1;
+ $$->flags |= IS_YSLANTED;
+ $$->yslanted = $3;
+ }
+ | object_spec SHADED text
+ {
+ $$ = $1;
+ $$->flags |= (IS_SHADED | IS_FILLED);
+ $$->shaded = new char[strlen($3.str)+1];
+ strcpy($$->shaded, $3.str);
+ }
+ | object_spec COLORED text
+ {
+ $$ = $1;
+ $$->flags |= (IS_SHADED | IS_OUTLINED | IS_FILLED);
+ $$->shaded = new char[strlen($3.str)+1];
+ strcpy($$->shaded, $3.str);
+ $$->outlined = new char[strlen($3.str)+1];
+ strcpy($$->outlined, $3.str);
+ }
+ | object_spec OUTLINED text
+ {
+ $$ = $1;
+ $$->flags |= IS_OUTLINED;
+ $$->outlined = new char[strlen($3.str)+1];
+ strcpy($$->outlined, $3.str);
+ }
+ | object_spec CHOP
+ {
+ $$ = $1;
+ // line chop chop means line chop 0 chop 0
+ if ($$->flags & IS_DEFAULT_CHOPPED) {
+ $$->flags |= IS_CHOPPED;
+ $$->flags &= ~IS_DEFAULT_CHOPPED;
+ $$->start_chop = $$->end_chop = 0.0;
+ }
+ else if ($$->flags & IS_CHOPPED) {
+ $$->end_chop = 0.0;
+ }
+ else {
+ $$->flags |= IS_DEFAULT_CHOPPED;
+ }
+ }
+ | object_spec CHOP expr
+ {
+ $$ = $1;
+ if ($$->flags & IS_DEFAULT_CHOPPED) {
+ $$->flags |= IS_CHOPPED;
+ $$->flags &= ~IS_DEFAULT_CHOPPED;
+ $$->start_chop = 0.0;
+ $$->end_chop = $3;
+ }
+ else if ($$->flags & IS_CHOPPED) {
+ $$->end_chop = $3;
+ }
+ else {
+ $$->start_chop = $$->end_chop = $3;
+ $$->flags |= IS_CHOPPED;
+ }
+ }
+ | object_spec SAME
+ {
+ $$ = $1;
+ $$->flags |= IS_SAME;
+ }
+ | object_spec INVISIBLE
+ {
+ $$ = $1;
+ $$->flags |= IS_INVISIBLE;
+ }
+ | object_spec LEFT_ARROW_HEAD
+ {
+ $$ = $1;
+ $$->flags |= HAS_LEFT_ARROW_HEAD;
+ }
+ | object_spec RIGHT_ARROW_HEAD
+ {
+ $$ = $1;
+ $$->flags |= HAS_RIGHT_ARROW_HEAD;
+ }
+ | object_spec DOUBLE_ARROW_HEAD
+ {
+ $$ = $1;
+ $$->flags |= (HAS_LEFT_ARROW_HEAD|HAS_RIGHT_ARROW_HEAD);
+ }
+ | object_spec CW
+ {
+ $$ = $1;
+ $$->flags |= IS_CLOCKWISE;
+ }
+ | object_spec CCW
+ {
+ $$ = $1;
+ $$->flags &= ~IS_CLOCKWISE;
+ }
+ | object_spec text %prec TEXT
+ {
+ $$ = $1;
+ text_item **p;
+ for (p = & $$->text; *p; p = &(*p)->next)
+ ;
+ *p = new text_item($2.str, $2.filename, $2.lineno);
+ }
+ | object_spec LJUST
+ {
+ $$ = $1;
+ if ($$->text) {
+ text_item *p;
+ for (p = $$->text; p->next; p = p->next)
+ ;
+ p->adj.h = LEFT_ADJUST;
+ }
+ }
+ | object_spec RJUST
+ {
+ $$ = $1;
+ if ($$->text) {
+ text_item *p;
+ for (p = $$->text; p->next; p = p->next)
+ ;
+ p->adj.h = RIGHT_ADJUST;
+ }
+ }
+ | object_spec ABOVE
+ {
+ $$ = $1;
+ if ($$->text) {
+ text_item *p;
+ for (p = $$->text; p->next; p = p->next)
+ ;
+ p->adj.v = ABOVE_ADJUST;
+ }
+ }
+ | object_spec BELOW
+ {
+ $$ = $1;
+ if ($$->text) {
+ text_item *p;
+ for (p = $$->text; p->next; p = p->next)
+ ;
+ p->adj.v = BELOW_ADJUST;
+ }
+ }
+ | object_spec THICKNESS expr
+ {
+ $$ = $1;
+ $$->flags |= HAS_THICKNESS;
+ $$->thickness = $3;
+ }
+ | object_spec ALIGNED
+ {
+ $$ = $1;
+ $$->flags |= IS_ALIGNED;
+ }
+ ;
+
+text:
+ TEXT
+ { $$ = $1; }
+ | SPRINTF '(' TEXT sprintf_args ')'
+ {
+ $$.filename = $3.filename;
+ $$.lineno = $3.lineno;
+ $$.str = do_sprintf($3.str, $4.v, $4.nv);
+ delete[] $4.v;
+ free($3.str);
+ }
+ ;
+
+sprintf_args:
+ /* empty */
+ {
+ $$.v = 0;
+ $$.nv = 0;
+ $$.maxv = 0;
+ }
+ | sprintf_args ',' expr
+ {
+ $$ = $1;
+ if ($$.nv >= $$.maxv) {
+ if ($$.nv == 0) {
+ $$.v = new double[4];
+ $$.maxv = 4;
+ }
+ else {
+ double *oldv = $$.v;
+ $$.maxv *= 2;
+#if 0
+ $$.v = new double[$$.maxv];
+ memcpy($$.v, oldv, $$.nv*sizeof(double));
+#else
+ // workaround for bug in Compaq C++ V6.5-033
+ // for Compaq Tru64 UNIX V5.1A (Rev. 1885)
+ double *foo = new double[$$.maxv];
+ memcpy(foo, oldv, $$.nv*sizeof(double));
+ $$.v = foo;
+#endif
+ delete[] oldv;
+ }
+ }
+ $$.v[$$.nv] = $3;
+ $$.nv += 1;
+ }
+ ;
+
+position:
+ position_not_place
+ { $$ = $1; }
+ | place
+ {
+ position pos = $1;
+ $$.x = pos.x;
+ $$.y = pos.y;
+ }
+ | '(' place ')'
+ {
+ position pos = $2;
+ $$.x = pos.x;
+ $$.y = pos.y;
+ }
+ ;
+
+position_not_place:
+ expr_pair
+ { $$ = $1; }
+ | position '+' expr_pair
+ {
+ $$.x = $1.x + $3.x;
+ $$.y = $1.y + $3.y;
+ }
+ | '(' position '+' expr_pair ')'
+ {
+ $$.x = $2.x + $4.x;
+ $$.y = $2.y + $4.y;
+ }
+ | position '-' expr_pair
+ {
+ $$.x = $1.x - $3.x;
+ $$.y = $1.y - $3.y;
+ }
+ | '(' position '-' expr_pair ')'
+ {
+ $$.x = $2.x - $4.x;
+ $$.y = $2.y - $4.y;
+ }
+ | '(' position ',' position ')'
+ {
+ $$.x = $2.x;
+ $$.y = $4.y;
+ }
+ | expr between position AND position
+ {
+ $$.x = (1.0 - $1)*$3.x + $1*$5.x;
+ $$.y = (1.0 - $1)*$3.y + $1*$5.y;
+ }
+ | '(' expr between position AND position ')'
+ {
+ $$.x = (1.0 - $2)*$4.x + $2*$6.x;
+ $$.y = (1.0 - $2)*$4.y + $2*$6.y;
+ }
+ /* the next two rules cause harmless shift/reduce warnings */
+ | expr_not_lower_than '<' position ',' position '>'
+ {
+ $$.x = (1.0 - $1)*$3.x + $1*$5.x;
+ $$.y = (1.0 - $1)*$3.y + $1*$5.y;
+ }
+ | '(' expr_not_lower_than '<' position ',' position '>' ')'
+ {
+ $$.x = (1.0 - $2)*$4.x + $2*$6.x;
+ $$.y = (1.0 - $2)*$4.y + $2*$6.y;
+ }
+ ;
+
+between:
+ BETWEEN
+ | OF THE WAY BETWEEN
+ ;
+
+expr_pair:
+ expr ',' expr
+ {
+ $$.x = $1;
+ $$.y = $3;
+ }
+ | '(' expr_pair ')'
+ { $$ = $2; }
+ ;
+
+place:
+ /* line at A left == line (at A) left */
+ label %prec CHOP
+ { $$ = $1; }
+ | label corner
+ {
+ path pth($2);
+ if (!pth.follow($1, & $$))
+ YYABORT;
+ }
+ | corner label
+ {
+ path pth($1);
+ if (!pth.follow($2, & $$))
+ YYABORT;
+ }
+ | corner OF label
+ {
+ path pth($1);
+ if (!pth.follow($3, & $$))
+ YYABORT;
+ }
+ | HERE
+ {
+ $$.x = current_position.x;
+ $$.y = current_position.y;
+ $$.obj = 0;
+ }
+ ;
+
+label:
+ LABEL
+ {
+ place *p = lookup_label($1);
+ if (!p) {
+ lex_error("there is no place '%1'", $1);
+ YYABORT;
+ }
+ $$ = *p;
+ free($1);
+ }
+ | nth_primitive
+ { $$.obj = $1; }
+ | label '.' LABEL
+ {
+ path pth($3);
+ if (!pth.follow($1, & $$))
+ YYABORT;
+ }
+ ;
+
+ordinal:
+ ORDINAL
+ { $$ = $1; }
+ | '`' any_expr TH
+ {
+ // XXX Check for overflow (and non-integers?).
+ $$ = (int)$2;
+ }
+ ;
+
+optional_ordinal_last:
+ LAST
+ { $$ = 1; }
+ | ordinal LAST
+ { $$ = $1; }
+ ;
+
+nth_primitive:
+ ordinal object_type
+ {
+ int count = 0;
+ object *p;
+ for (p = olist.head; p != 0; p = p->next)
+ if (p->type() == $2 && ++count == $1) {
+ $$ = p;
+ break;
+ }
+ if (p == 0) {
+ lex_error("there is no %1%2 %3", $1, ordinal_postfix($1),
+ object_type_name($2));
+ YYABORT;
+ }
+ }
+ | optional_ordinal_last object_type
+ {
+ int count = 0;
+ object *p;
+ for (p = olist.tail; p != 0; p = p->prev)
+ if (p->type() == $2 && ++count == $1) {
+ $$ = p;
+ break;
+ }
+ if (p == 0) {
+ lex_error("there is no %1%2 last %3", $1,
+ ordinal_postfix($1), object_type_name($2));
+ YYABORT;
+ }
+ }
+ ;
+
+object_type:
+ BOX
+ { $$ = BOX_OBJECT; }
+ | CIRCLE
+ { $$ = CIRCLE_OBJECT; }
+ | ELLIPSE
+ { $$ = ELLIPSE_OBJECT; }
+ | ARC
+ { $$ = ARC_OBJECT; }
+ | LINE
+ { $$ = LINE_OBJECT; }
+ | ARROW
+ { $$ = ARROW_OBJECT; }
+ | SPLINE
+ { $$ = SPLINE_OBJECT; }
+ | '[' ']'
+ { $$ = BLOCK_OBJECT; }
+ | TEXT
+ { $$ = TEXT_OBJECT; }
+ ;
+
+label_path:
+ '.' LABEL
+ { $$ = new path($2); }
+ | label_path '.' LABEL
+ {
+ $$ = $1;
+ $$->append($3);
+ }
+ ;
+
+relative_path:
+ corner %prec CHOP
+ { $$ = new path($1); }
+ /* give this a lower precedence than LEFT and RIGHT so that
+ [A: box] with .A left == [A: box] with (.A left) */
+ | label_path %prec TEXT
+ { $$ = $1; }
+ | label_path corner
+ {
+ $$ = $1;
+ $$->append($2);
+ }
+ ;
+
+path:
+ relative_path
+ { $$ = $1; }
+ | '(' relative_path ',' relative_path ')'
+ {
+ $$ = $2;
+ $$->set_ypath($4);
+ }
+ /* The rest of these rules are a compatibility sop. */
+ | ORDINAL LAST object_type relative_path
+ {
+ lex_warning("'%1%2 last %3' in 'with' argument ignored",
+ $1, ordinal_postfix($1), object_type_name($3));
+ $$ = $4;
+ }
+ | LAST object_type relative_path
+ {
+ lex_warning("'last %1' in 'with' argument ignored",
+ object_type_name($2));
+ $$ = $3;
+ }
+ | ORDINAL object_type relative_path
+ {
+ lex_warning("'%1%2 %3' in 'with' argument ignored",
+ $1, ordinal_postfix($1), object_type_name($2));
+ $$ = $3;
+ }
+ | LABEL relative_path
+ {
+ lex_warning("initial '%1' in 'with' argument ignored", $1);
+ delete[] $1;
+ $$ = $2;
+ }
+ ;
+
+corner:
+ DOT_N
+ { $$ = &object::north; }
+ | DOT_E
+ { $$ = &object::east; }
+ | DOT_W
+ { $$ = &object::west; }
+ | DOT_S
+ { $$ = &object::south; }
+ | DOT_NE
+ { $$ = &object::north_east; }
+ | DOT_SE
+ { $$ = &object:: south_east; }
+ | DOT_NW
+ { $$ = &object::north_west; }
+ | DOT_SW
+ { $$ = &object::south_west; }
+ | DOT_C
+ { $$ = &object::center; }
+ | DOT_START
+ { $$ = &object::start; }
+ | DOT_END
+ { $$ = &object::end; }
+ | TOP
+ { $$ = &object::north; }
+ | BOTTOM
+ { $$ = &object::south; }
+ | LEFT
+ { $$ = &object::west; }
+ | RIGHT
+ { $$ = &object::east; }
+ | UPPER LEFT
+ { $$ = &object::north_west; }
+ | LOWER LEFT
+ { $$ = &object::south_west; }
+ | UPPER RIGHT
+ { $$ = &object::north_east; }
+ | LOWER RIGHT
+ { $$ = &object::south_east; }
+ | LEFT_CORNER
+ { $$ = &object::west; }
+ | RIGHT_CORNER
+ { $$ = &object::east; }
+ | UPPER LEFT_CORNER
+ { $$ = &object::north_west; }
+ | LOWER LEFT_CORNER
+ { $$ = &object::south_west; }
+ | UPPER RIGHT_CORNER
+ { $$ = &object::north_east; }
+ | LOWER RIGHT_CORNER
+ { $$ = &object::south_east; }
+ | NORTH
+ { $$ = &object::north; }
+ | SOUTH
+ { $$ = &object::south; }
+ | EAST
+ { $$ = &object::east; }
+ | WEST
+ { $$ = &object::west; }
+ | CENTER
+ { $$ = &object::center; }
+ | START
+ { $$ = &object::start; }
+ | END
+ { $$ = &object::end; }
+ ;
+
+expr:
+ expr_lower_than
+ { $$ = $1; }
+ | expr_not_lower_than
+ { $$ = $1; }
+ ;
+
+expr_lower_than:
+ expr '<' expr
+ { $$ = ($1 < $3); }
+ ;
+
+expr_not_lower_than:
+ VARIABLE
+ {
+ if (!lookup_variable($1, & $$)) {
+ lex_error("there is no variable '%1'", $1);
+ YYABORT;
+ }
+ free($1);
+ }
+ | NUMBER
+ { $$ = $1; }
+ | place DOT_X
+ {
+ if ($1.obj != 0)
+ $$ = $1.obj->origin().x;
+ else
+ $$ = $1.x;
+ }
+ | place DOT_Y
+ {
+ if ($1.obj != 0)
+ $$ = $1.obj->origin().y;
+ else
+ $$ = $1.y;
+ }
+ | place DOT_HT
+ {
+ if ($1.obj != 0)
+ $$ = $1.obj->height();
+ else
+ $$ = 0.0;
+ }
+ | place DOT_WID
+ {
+ if ($1.obj != 0)
+ $$ = $1.obj->width();
+ else
+ $$ = 0.0;
+ }
+ | place DOT_RAD
+ {
+ if ($1.obj != 0)
+ $$ = $1.obj->radius();
+ else
+ $$ = 0.0;
+ }
+ | expr '+' expr
+ { $$ = $1 + $3; }
+ | expr '-' expr
+ { $$ = $1 - $3; }
+ | expr '*' expr
+ { $$ = $1 * $3; }
+ | expr '/' expr
+ {
+ if ($3 == 0.0) {
+ lex_error("division by zero");
+ YYABORT;
+ }
+ $$ = $1/$3;
+ }
+ | expr '%' expr
+ {
+ if ($3 == 0.0) {
+ lex_error("modulus by zero");
+ YYABORT;
+ }
+ $$ = fmod($1, $3);
+ }
+ | expr '^' expr
+ {
+ errno = 0;
+ $$ = pow($1, $3);
+ if (errno == EDOM) {
+ lex_error("arguments to '^' operator out of domain");
+ YYABORT;
+ }
+ if (errno == ERANGE) {
+ lex_error("result of '^' operator out of range");
+ YYABORT;
+ }
+ }
+ | '-' expr %prec '!'
+ { $$ = -$2; }
+ | '(' any_expr ')'
+ { $$ = $2; }
+ | SIN '(' any_expr ')'
+ {
+ errno = 0;
+ $$ = sin($3);
+ if (errno == ERANGE) {
+ lex_error("sin result out of range");
+ YYABORT;
+ }
+ }
+ | COS '(' any_expr ')'
+ {
+ errno = 0;
+ $$ = cos($3);
+ if (errno == ERANGE) {
+ lex_error("cos result out of range");
+ YYABORT;
+ }
+ }
+ | ATAN2 '(' any_expr ',' any_expr ')'
+ {
+ errno = 0;
+ $$ = atan2($3, $5);
+ if (errno == EDOM) {
+ lex_error("atan2 argument out of domain");
+ YYABORT;
+ }
+ if (errno == ERANGE) {
+ lex_error("atan2 result out of range");
+ YYABORT;
+ }
+ }
+ | LOG '(' any_expr ')'
+ {
+ errno = 0;
+ $$ = log10($3);
+ if (errno == ERANGE) {
+ lex_error("log result out of range");
+ YYABORT;
+ }
+ }
+ | EXP '(' any_expr ')'
+ {
+ errno = 0;
+ $$ = pow(10.0, $3);
+ if (errno == ERANGE) {
+ lex_error("exp result out of range");
+ YYABORT;
+ }
+ }
+ | SQRT '(' any_expr ')'
+ {
+ errno = 0;
+ $$ = sqrt($3);
+ if (errno == EDOM) {
+ lex_error("sqrt argument out of domain");
+ YYABORT;
+ }
+ }
+ | K_MAX '(' any_expr ',' any_expr ')'
+ { $$ = $3 > $5 ? $3 : $5; }
+ | K_MIN '(' any_expr ',' any_expr ')'
+ { $$ = $3 < $5 ? $3 : $5; }
+ | INT '(' any_expr ')'
+ { $$ = $3 < 0 ? -floor(-$3) : floor($3); }
+ | RAND '(' any_expr ')'
+ {
+ lex_error("use of 'rand' with an argument is"
+ " deprecated; shift and scale 'rand()' with"
+ " arithmetic instead");
+ $$ = 1.0 + floor(((rand()&0x7fff)/double(0x7fff))*$3);
+ }
+ | RAND '(' ')'
+ {
+ /* return a random number in the range [0,1) */
+ /* portable, but not very random */
+ $$ = (rand() & 0x7fff) / double(0x8000);
+ }
+ | SRAND '(' any_expr ')'
+ {
+ $$ = 0;
+ srand((unsigned int)$3);
+ }
+ | expr LESSEQUAL expr
+ { $$ = ($1 <= $3); }
+ | expr '>' expr
+ { $$ = ($1 > $3); }
+ | expr GREATEREQUAL expr
+ { $$ = ($1 >= $3); }
+ | expr EQUALEQUAL expr
+ { $$ = ($1 == $3); }
+ | expr NOTEQUAL expr
+ { $$ = ($1 != $3); }
+ | expr ANDAND expr
+ { $$ = ($1 != 0.0 && $3 != 0.0); }
+ | expr OROR expr
+ { $$ = ($1 != 0.0 || $3 != 0.0); }
+ | '!' expr
+ { $$ = ($2 == 0.0); }
+
+ ;
+
+%%
+
+/* bison defines const to be empty unless __STDC__ is defined, which it
+isn't under cfront */
+
+#ifdef const
+#undef const
+#endif
+
+static struct {
+ const char *name;
+ double val;
+ int scaled; // non-zero if val should be multiplied by scale
+} defaults_table[] = {
+ { "arcrad", .25, 1 },
+ { "arrowht", .1, 1 },
+ { "arrowwid", .05, 1 },
+ { "circlerad", .25, 1 },
+ { "boxht", .5, 1 },
+ { "boxwid", .75, 1 },
+ { "boxrad", 0.0, 1 },
+ { "dashwid", .05, 1 },
+ { "ellipseht", .5, 1 },
+ { "ellipsewid", .75, 1 },
+ { "moveht", .5, 1 },
+ { "movewid", .5, 1 },
+ { "lineht", .5, 1 },
+ { "linewid", .5, 1 },
+ { "textht", 0.0, 1 },
+ { "textwid", 0.0, 1 },
+ { "scale", 1.0, 0 },
+ { "linethick", -1.0, 0 }, // in points
+ { "fillval", .5, 0 },
+ { "arrowhead", 1.0, 0 },
+ { "maxpswid", 8.5, 0 },
+ { "maxpsht", 11.0, 0 },
+};
+
+place *lookup_label(const char *label)
+{
+ saved_state *state = current_saved_state;
+ PTABLE(place) *tbl = current_table;
+ for (;;) {
+ place *pl = tbl->lookup(label);
+ if (pl)
+ return pl;
+ if (!state)
+ return 0;
+ tbl = state->tbl;
+ state = state->prev;
+ }
+}
+
+void define_label(const char *label, const place *pl)
+{
+ place *p = new place[1];
+ *p = *pl;
+ current_table->define(label, p);
+}
+
+int lookup_variable(const char *name, double *val)
+{
+ place *pl = lookup_label(name);
+ if (pl) {
+ *val = pl->x;
+ return 1;
+ }
+ return 0;
+}
+
+void define_variable(const char *name, double val)
+{
+ place *p = new place[1];
+ p->obj = 0;
+ p->x = val;
+ p->y = 0.0;
+ current_table->define(name, p);
+ if (strcmp(name, "scale") == 0) {
+ // When the scale changes, reset all scaled predefined variables to
+ // their default values.
+ for (unsigned int i = 0;
+ i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++)
+ if (defaults_table[i].scaled)
+ define_variable(defaults_table[i].name, val*defaults_table[i].val);
+ }
+}
+
+// called once only (not once per parse)
+
+void parse_init()
+{
+ current_direction = RIGHT_DIRECTION;
+ current_position.x = 0.0;
+ current_position.y = 0.0;
+ // This resets everything to its default value.
+ reset_all();
+}
+
+void reset(const char *nm)
+{
+ for (unsigned int i = 0;
+ i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++)
+ if (strcmp(nm, defaults_table[i].name) == 0) {
+ double val = defaults_table[i].val;
+ if (defaults_table[i].scaled) {
+ double scale;
+ lookup_variable("scale", &scale);
+ val *= scale;
+ }
+ define_variable(defaults_table[i].name, val);
+ return;
+ }
+ lex_error("'%1' is not a predefined variable", nm);
+}
+
+void reset_all()
+{
+ // We only have to explicitly reset the predefined variables that
+ // aren't scaled because 'scale' is not scaled, and changing the
+ // value of 'scale' will reset all the predefined variables that
+ // are scaled.
+ for (unsigned int i = 0;
+ i < sizeof(defaults_table)/sizeof(defaults_table[0]); i++)
+ if (!defaults_table[i].scaled)
+ define_variable(defaults_table[i].name, defaults_table[i].val);
+}
+
+// called after each parse
+
+void parse_cleanup()
+{
+ while (current_saved_state != 0) {
+ delete current_table;
+ current_table = current_saved_state->tbl;
+ saved_state *tem = current_saved_state;
+ current_saved_state = current_saved_state->prev;
+ delete tem;
+ }
+ assert(current_table == &top_table);
+ PTABLE_ITERATOR(place) iter(current_table);
+ const char *key;
+ place *pl;
+ while (iter.next(&key, &pl))
+ if (pl->obj != 0) {
+ position pos = pl->obj->origin();
+ pl->obj = 0;
+ pl->x = pos.x;
+ pl->y = pos.y;
+ }
+ while (olist.head != 0) {
+ object *tem = olist.head;
+ olist.head = olist.head->next;
+ delete tem;
+ }
+ olist.tail = 0;
+ current_direction = RIGHT_DIRECTION;
+ current_position.x = 0.0;
+ current_position.y = 0.0;
+}
+
+const char *ordinal_postfix(int n)
+{
+ if (n < 10 || n > 20)
+ switch (n % 10) {
+ case 1:
+ return "st";
+ case 2:
+ return "nd";
+ case 3:
+ return "rd";
+ }
+ return "th";
+}
+
+const char *object_type_name(object_type type)
+{
+ switch (type) {
+ case BOX_OBJECT:
+ return "box";
+ case CIRCLE_OBJECT:
+ return "circle";
+ case ELLIPSE_OBJECT:
+ return "ellipse";
+ case ARC_OBJECT:
+ return "arc";
+ case SPLINE_OBJECT:
+ return "spline";
+ case LINE_OBJECT:
+ return "line";
+ case ARROW_OBJECT:
+ return "arrow";
+ case MOVE_OBJECT:
+ return "move";
+ case TEXT_OBJECT:
+ return "\"\"";
+ case BLOCK_OBJECT:
+ return "[]";
+ case OTHER_OBJECT:
+ case MARK_OBJECT:
+ default:
+ break;
+ }
+ return "object";
+}
+
+static char sprintf_buf[1024];
+
+char *format_number(const char *fmt, double n)
+{
+ if (0 /* nullptr */ == fmt)
+ fmt = "%g";
+ return do_sprintf(fmt, &n, 1);
+}
+
+char *do_sprintf(const char *fmt, const double *v, int nv)
+{
+ // Define valid conversion specifiers and modifiers.
+ static const char spcs[] = "eEfgG%";
+ static const char mods[] = "#-+ 0123456789.";
+ string result;
+ int i = 0;
+ string one_format;
+ while (*fmt) {
+ if ('%' == *fmt) {
+ one_format += *fmt++;
+ for (; *fmt != '\0' && strchr(mods, *fmt) != 0; fmt++)
+ one_format += *fmt;
+ if ('\0' == *fmt || strchr(spcs, *fmt) == 0) {
+ lex_error("invalid sprintf conversion specifier '%1'", *fmt);
+ result += one_format;
+ result += fmt;
+ break;
+ }
+ if ('%' == *fmt) {
+ fmt++;
+ snprintf(sprintf_buf, sizeof(sprintf_buf), "%%");
+ }
+ else {
+ if (i >= nv) {
+ lex_error("too few arguments to sprintf");
+ result += one_format;
+ result += fmt;
+ break;
+ }
+ one_format += *fmt++;
+ one_format += '\0';
+// We validated the format string above. Most conversion specifiers are
+// rejected, including `n`.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+ snprintf(sprintf_buf, sizeof(sprintf_buf),
+ one_format.contents(), v[i++]);
+#pragma GCC diagnostic pop
+ }
+ one_format.clear();
+ result += sprintf_buf;
+ }
+ else
+ result += *fmt++;
+ }
+ result += '\0';
+ return strsave(result.contents());
+}
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/preproc/pic/position.h b/src/preproc/pic/position.h
new file mode 100644
index 0000000..fb32737
--- /dev/null
+++ b/src/preproc/pic/position.h
@@ -0,0 +1,46 @@
+// -*- C++ -*-
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+ Written by James Clark (jjc@jclark.com)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+groff is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+struct place;
+struct position {
+ double x;
+ double y;
+ position(double, double );
+ position();
+ position(const place &);
+ position &operator+=(const position &);
+ position &operator-=(const position &);
+ position &operator*=(double);
+ position &operator/=(double);
+};
+
+position operator-(const position &);
+position operator+(const position &, const position &);
+position operator-(const position &, const position &);
+position operator/(const position &, double);
+position operator*(const position &, double);
+// dot product
+double operator*(const position &, const position &);
+int operator==(const position &, const position &);
+int operator!=(const position &, const position &);
+
+double hypot(const position &a);
+
+typedef position distance;
+
diff --git a/src/preproc/pic/tex.cpp b/src/preproc/pic/tex.cpp
new file mode 100644
index 0000000..c6071af
--- /dev/null
+++ b/src/preproc/pic/tex.cpp
@@ -0,0 +1,458 @@
+// -*- C++ -*-
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+ Written by James Clark (jjc@jclark.com)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+groff is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "pic.h"
+
+#ifdef TEX_SUPPORT
+
+#include "common.h"
+
+class tex_output : public common_output {
+public:
+ tex_output();
+ ~tex_output();
+ void start_picture(double, const position &ll, const position &ur);
+ void finish_picture();
+ void text(const position &, text_piece *, int, double);
+ void line(const position &, const position *, int n,
+ const line_type &);
+ void polygon(const position *, int n,
+ const line_type &, double);
+ void spline(const position &, const position *, int n,
+ const line_type &);
+ void arc(const position &, const position &, const position &,
+ const line_type &);
+ void circle(const position &, double rad, const line_type &, double);
+ void ellipse(const position &, const distance &, const line_type &, double);
+ void command(const char *, const char *, int);
+ void set_color(char *, char *);
+ void reset_color();
+ char *get_last_filled();
+ char *get_outline_color();
+ int supports_filled_polygons();
+private:
+ position upper_left;
+ double height;
+ double width;
+ double scale;
+ double pen_size;
+
+ void point(const position &);
+ void dot(const position &, const line_type &);
+ void solid_arc(const position &cent, double rad, double start_angle,
+ double end_angle, const line_type &lt);
+ position transform(const position &);
+protected:
+ virtual void set_pen_size(double ps);
+};
+
+// convert inches to milliinches
+
+inline int milliinches(double x)
+{
+ return int(x*1000.0 + .5);
+}
+
+inline position tex_output::transform(const position &pos)
+{
+ return position((pos.x - upper_left.x)/scale,
+ (upper_left.y - pos.y)/scale);
+}
+
+output *make_tex_output()
+{
+ return new tex_output;
+}
+
+tex_output::tex_output()
+{
+}
+
+tex_output::~tex_output()
+{
+}
+
+const int DEFAULT_PEN_SIZE = 8;
+
+void tex_output::set_pen_size(double ps)
+{
+ if (ps < 0.0)
+ ps = -1.0;
+ if (ps != pen_size) {
+ pen_size = ps;
+ printf(" \\special{pn %d}%%\n",
+ ps < 0.0 ? DEFAULT_PEN_SIZE : int(ps*(1000.0/72.0) + .5));
+ }
+}
+
+void tex_output::start_picture(double sc, const position &ll,
+ const position &ur)
+{
+ upper_left.x = ll.x;
+ upper_left.y = ur.y;
+ scale = compute_scale(sc, ll, ur);
+ height = (ur.y - ll.y)/scale;
+ width = (ur.x - ll.x)/scale;
+ /* The point of \vskip 0pt is to ensure that the vtop gets
+ a height of 0 rather than the height of the hbox; this
+ might be non-zero if text from text attributes lies outside pic's
+ idea of the bounding box of the picture. */
+ /* \newbox and \newdimen are defined with \outer in plain.tex and can't
+ be used directly in an \if clause. */
+ printf("\\expandafter\\ifx\\csname %s\\endcsname\\relax\n"
+ " \\csname newbox\\expandafter\\endcsname\\csname %s\\endcsname\n"
+ "\\fi\n"
+ "\\ifx\\graphtemp\\undefined\n"
+ " \\csname newdimen\\endcsname\\graphtemp\n"
+ "\\fi\n"
+ "\\expandafter\\setbox\\csname %s\\endcsname\n"
+ " =\\vtop{\\vskip 0pt\\hbox{%%\n",
+ graphname, graphname, graphname);
+ pen_size = -2.0;
+}
+
+void tex_output::finish_picture()
+{
+ printf(" \\hbox{\\vrule depth%.3fin width0pt height 0pt}%%\n"
+ " \\kern %.3fin\n"
+ " }%%\n"
+ "}%%\n",
+ height, width);
+}
+
+void tex_output::text(const position &center, text_piece *v, int n, double)
+{
+ position c = transform(center);
+ for (int i = 0; i < n; i++)
+ if (v[i].text != 0 && *v[i].text != '\0') {
+ int j = 2*i - n + 1;
+ if (v[i].adj.v == ABOVE_ADJUST)
+ j--;
+ else if (v[i].adj.v == BELOW_ADJUST)
+ j++;
+ if (j == 0) {
+ printf(" \\graphtemp=.5ex\n"
+ " \\advance\\graphtemp by %.3fin\n", c.y);
+ }
+ else {
+ printf(" \\graphtemp=\\baselineskip\n"
+ " \\multiply\\graphtemp by %d\n"
+ " \\divide\\graphtemp by 2\n"
+ " \\advance\\graphtemp by .5ex\n"
+ " \\advance\\graphtemp by %.3fin\n",
+ j, c.y);
+ }
+ printf(" \\rlap{\\kern %.3fin\\lower\\graphtemp", c.x);
+ fputs("\\hbox to 0pt{", stdout);
+ if (v[i].adj.h != LEFT_ADJUST)
+ fputs("\\hss ", stdout);
+ fputs(v[i].text, stdout);
+ if (v[i].adj.h != RIGHT_ADJUST)
+ fputs("\\hss", stdout);
+ fputs("}}%\n", stdout);
+ }
+}
+
+void tex_output::point(const position &pos)
+{
+ position p = transform(pos);
+ printf(" \\special{pa %d %d}%%\n", milliinches(p.x), milliinches(p.y));
+}
+
+void tex_output::line(const position &start, const position *v, int n,
+ const line_type &lt)
+{
+ set_pen_size(lt.thickness);
+ point(start);
+ for (int i = 0; i < n; i++)
+ point(v[i]);
+ fputs(" \\special{", stdout);
+ switch(lt.type) {
+ case line_type::invisible:
+ fputs("ip", stdout);
+ break;
+ case line_type::solid:
+ fputs("fp", stdout);
+ break;
+ case line_type::dotted:
+ printf("dt %.3f", lt.dash_width/scale);
+ break;
+ case line_type::dashed:
+ printf("da %.3f", lt.dash_width/scale);
+ break;
+ }
+ fputs("}%\n", stdout);
+}
+
+void tex_output::polygon(const position *v, int n,
+ const line_type &lt, double fill)
+{
+ if (fill >= 0.0) {
+ if (fill > 1.0)
+ fill = 1.0;
+ printf(" \\special{sh %.3f}%%\n", fill);
+ }
+ line(v[n-1], v, n, lt);
+}
+
+void tex_output::spline(const position &start, const position *v, int n,
+ const line_type &lt)
+{
+ if (lt.type == line_type::invisible)
+ return;
+ set_pen_size(lt.thickness);
+ point(start);
+ for (int i = 0; i < n; i++)
+ point(v[i]);
+ fputs(" \\special{sp", stdout);
+ switch(lt.type) {
+ case line_type::solid:
+ break;
+ case line_type::dotted:
+ printf(" %.3f", -lt.dash_width/scale);
+ break;
+ case line_type::dashed:
+ printf(" %.3f", lt.dash_width/scale);
+ break;
+ case line_type::invisible:
+ assert(0);
+ }
+ fputs("}%\n", stdout);
+}
+
+void tex_output::solid_arc(const position &cent, double rad,
+ double start_angle, double end_angle,
+ const line_type &lt)
+{
+ set_pen_size(lt.thickness);
+ position c = transform(cent);
+ printf(" \\special{ar %d %d %d %d %f %f}%%\n",
+ milliinches(c.x),
+ milliinches(c.y),
+ milliinches(rad/scale),
+ milliinches(rad/scale),
+ -end_angle,
+ (-end_angle > -start_angle) ? (double)M_PI * 2 - start_angle
+ : -start_angle);
+}
+
+void tex_output::arc(const position &start, const position &cent,
+ const position &end, const line_type &lt)
+{
+ switch (lt.type) {
+ case line_type::invisible:
+ break;
+ case line_type::dashed:
+ dashed_arc(start, cent, end, lt);
+ break;
+ case line_type::dotted:
+ dotted_arc(start, cent, end, lt);
+ break;
+ case line_type::solid:
+ {
+ position c;
+ if (!compute_arc_center(start, cent, end, &c)) {
+ line(start, &end, 1, lt);
+ break;
+ }
+ solid_arc(c,
+ hypot(cent - start),
+ atan2(start.y - c.y, start.x - c.x),
+ atan2(end.y - c.y, end.x - c.x),
+ lt);
+ break;
+ }
+ }
+}
+
+void tex_output::circle(const position &cent, double rad,
+ const line_type &lt, double fill)
+{
+ if (fill >= 0.0 && lt.type != line_type::solid) {
+ if (fill > 1.0)
+ fill = 1.0;
+ line_type ilt;
+ ilt.type = line_type::invisible;
+ ellipse(cent, position(rad*2.0, rad*2.0), ilt, fill);
+ }
+ switch (lt.type) {
+ case line_type::dashed:
+ dashed_circle(cent, rad, lt);
+ break;
+ case line_type::invisible:
+ break;
+ case line_type::solid:
+ ellipse(cent, position(rad*2.0,rad*2.0), lt, fill);
+ break;
+ case line_type::dotted:
+ dotted_circle(cent, rad, lt);
+ break;
+ default:
+ assert(0);
+ }
+}
+
+void tex_output::ellipse(const position &cent, const distance &dim,
+ const line_type &lt, double fill)
+{
+ if (lt.type == line_type::invisible) {
+ if (fill < 0.0)
+ return;
+ }
+ else
+ set_pen_size(lt.thickness);
+ if (fill >= 0.0) {
+ if (fill > 1.0)
+ fill = 1.0;
+ printf(" \\special{sh %.3f}%%\n", fill);
+ }
+ position c = transform(cent);
+ switch (lt.type) {
+ case line_type::solid:
+ case line_type::invisible:
+ printf(" \\special{%s %d %d %d %d 0 6.28319}%%\n",
+ (lt.type == line_type::invisible ? "ia" : "ar"),
+ milliinches(c.x),
+ milliinches(c.y),
+ milliinches(dim.x/(2.0*scale)),
+ milliinches(dim.y/(2.0*scale)));
+ break;
+ case line_type::dashed:
+ dashed_ellipse(cent, dim / scale, lt);
+ break;
+ case line_type::dotted:
+ dotted_ellipse(cent, dim / scale, lt);
+ break;
+ default:
+ assert(0);
+ }
+}
+
+void tex_output::command(const char *s, const char *, int)
+{
+ fputs(s, stdout);
+ putchar('%'); // avoid unwanted spaces
+ putchar('\n');
+}
+
+int tex_output::supports_filled_polygons()
+{
+ return 1;
+}
+
+void tex_output::dot(const position &pos, const line_type &lt)
+{
+ if (zero_length_line_flag) {
+ line_type slt = lt;
+ slt.type = line_type::solid;
+ line(pos, &pos, 1, slt);
+ }
+ else {
+ int dot_rad = int(lt.thickness*(1000.0/(72.0*2)) + .5);
+ if (dot_rad == 0)
+ dot_rad = 1;
+ position p = transform(pos);
+ printf(" \\special{sh 1}%%\n"
+ " \\special{ia %d %d %d %d 0 6.28319}%%\n",
+ milliinches(p.x), milliinches(p.y), dot_rad, dot_rad);
+ }
+}
+
+void tex_output::set_color(char *, char *)
+{
+ /* not implemented yet */
+}
+
+void tex_output::reset_color()
+{
+ /* not implemented yet */
+}
+
+char *tex_output::get_last_filled()
+{
+ /* not implemented yet */
+ return NULL;
+}
+
+char *tex_output::get_outline_color()
+{
+ /* not implemented yet */
+ return NULL;
+}
+
+class tpic_output : public tex_output {
+public:
+ tpic_output();
+ void command(const char *, const char *, int);
+private:
+ void set_pen_size(double ps);
+ int default_pen_size;
+ int prev_default_pen_size;
+};
+
+tpic_output::tpic_output()
+: default_pen_size(DEFAULT_PEN_SIZE), prev_default_pen_size(DEFAULT_PEN_SIZE)
+{
+}
+
+void tpic_output::command(const char *s, const char *filename, int lineno)
+{
+ assert(s[0] == '.');
+ if (s[1] == 'p' && s[2] == 's' && (s[3] == '\0' || !csalpha(s[3]))) {
+ const char *p = s + 3;
+ while (csspace(*p))
+ p++;
+ if (*p == '\0') {
+ int temp = default_pen_size;
+ default_pen_size = prev_default_pen_size;
+ prev_default_pen_size = temp;
+ }
+ else {
+ char *ptr;
+ int temp = (int)strtol(p, &ptr, 10);
+ if (temp == 0 && ptr == p)
+ error_with_file_and_line(filename, lineno,
+ "argument to '.ps' not an integer");
+ else if (temp < 0)
+ error_with_file_and_line(filename, lineno,
+ "negative pen size");
+ else {
+ prev_default_pen_size = default_pen_size;
+ default_pen_size = temp;
+ }
+ }
+ }
+ else
+ printf("\\%s%%\n", s + 1);
+}
+
+void tpic_output::set_pen_size(double ps)
+{
+ if (ps < 0.0)
+ printf(" \\special{pn %d}%%\n", default_pen_size);
+ else
+ tex_output::set_pen_size(ps);
+}
+
+output *make_tpic_output()
+{
+ return new tpic_output;
+}
+
+#endif
diff --git a/src/preproc/pic/text.h b/src/preproc/pic/text.h
new file mode 100644
index 0000000..9b9353f
--- /dev/null
+++ b/src/preproc/pic/text.h
@@ -0,0 +1,46 @@
+// -*- C++ -*-
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+ Written by James Clark (jjc@jclark.com)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+groff is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+
+enum hadjustment {
+ CENTER_ADJUST,
+ LEFT_ADJUST,
+ RIGHT_ADJUST
+ };
+
+enum vadjustment {
+ NONE_ADJUST,
+ ABOVE_ADJUST,
+ BELOW_ADJUST
+ };
+
+struct adjustment {
+ hadjustment h;
+ vadjustment v;
+};
+
+struct text_piece {
+ char *text;
+ adjustment adj;
+ const char *filename;
+ int lineno;
+
+ text_piece();
+ ~text_piece();
+};
diff --git a/src/preproc/pic/troff.cpp b/src/preproc/pic/troff.cpp
new file mode 100644
index 0000000..3dc87a7
--- /dev/null
+++ b/src/preproc/pic/troff.cpp
@@ -0,0 +1,579 @@
+/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
+ Written by James Clark (jjc@jclark.com)
+
+This file is part of groff.
+
+groff is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+groff is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "pic.h"
+#include "common.h"
+
+
+const double RELATIVE_THICKNESS = -1.0;
+const double BAD_THICKNESS = -2.0;
+
+class simple_output : public common_output {
+ virtual void simple_line(const position &, const position &) = 0;
+ virtual void simple_spline(const position &, const position *, int n) = 0;
+ virtual void simple_arc(const position &, const position &,
+ const position &) = 0;
+ virtual void simple_circle(int, const position &, double rad) = 0;
+ virtual void simple_ellipse(int, const position &, const distance &) = 0;
+ virtual void simple_polygon(int, const position *, int) = 0;
+ virtual void line_thickness(double) = 0;
+ virtual void set_fill(double) = 0;
+ virtual void set_color(char *, char *) = 0;
+ virtual void reset_color() = 0;
+ virtual char *get_last_filled() = 0;
+ void dot(const position &, const line_type &) = 0;
+public:
+ void start_picture(double sc, const position &ll, const position &ur) = 0;
+ void finish_picture() = 0;
+ void text(const position &, text_piece *, int, double) = 0;
+ void line(const position &, const position *, int n,
+ const line_type &);
+ void polygon(const position *, int n,
+ const line_type &, double);
+ void spline(const position &, const position *, int n,
+ const line_type &);
+ void arc(const position &, const position &, const position &,
+ const line_type &);
+ void circle(const position &, double rad, const line_type &, double);
+ void ellipse(const position &, const distance &, const line_type &, double);
+ int supports_filled_polygons();
+};
+
+int simple_output::supports_filled_polygons()
+{
+ return driver_extension_flag != 0;
+}
+
+void simple_output::arc(const position &start, const position &cent,
+ const position &end, const line_type &lt)
+{
+ switch (lt.type) {
+ case line_type::solid:
+ line_thickness(lt.thickness);
+ simple_arc(start, cent, end);
+ break;
+ case line_type::invisible:
+ break;
+ case line_type::dashed:
+ dashed_arc(start, cent, end, lt);
+ break;
+ case line_type::dotted:
+ dotted_arc(start, cent, end, lt);
+ break;
+ }
+}
+
+void simple_output::line(const position &start, const position *v, int n,
+ const line_type &lt)
+{
+ position pos = start;
+ line_thickness(lt.thickness);
+ for (int i = 0; i < n; i++) {
+ switch (lt.type) {
+ case line_type::solid:
+ simple_line(pos, v[i]);
+ break;
+ case line_type::dotted:
+ {
+ distance vec(v[i] - pos);
+ double dist = hypot(vec);
+ int ndots = int(dist/lt.dash_width + .5);
+ if (ndots == 0)
+ dot(pos, lt);
+ else {
+ vec /= double(ndots);
+ for (int j = 0; j <= ndots; j++)
+ dot(pos + vec*j, lt);
+ }
+ }
+ break;
+ case line_type::dashed:
+ {
+ distance vec(v[i] - pos);
+ double dist = hypot(vec);
+ if (dist <= lt.dash_width*2.0)
+ simple_line(pos, v[i]);
+ else {
+ int ndashes = int((dist - lt.dash_width)/(lt.dash_width*2.0) + .5);
+ distance dash_vec = vec*(lt.dash_width/dist);
+ double dash_gap = (dist - lt.dash_width)/ndashes;
+ distance dash_gap_vec = vec*(dash_gap/dist);
+ for (int j = 0; j <= ndashes; j++) {
+ position s(pos + dash_gap_vec*j);
+ simple_line(s, s + dash_vec);
+ }
+ }
+ }
+ break;
+ case line_type::invisible:
+ break;
+ default:
+ assert(0);
+ }
+ pos = v[i];
+ }
+}
+
+void simple_output::spline(const position &start, const position *v, int n,
+ const line_type &lt)
+{
+ line_thickness(lt.thickness);
+ simple_spline(start, v, n);
+}
+
+void simple_output::polygon(const position *v, int n,
+ const line_type &lt, double fill)
+{
+ if (driver_extension_flag && ((fill >= 0.0) || (get_last_filled() != 0))) {
+ if (get_last_filled() == 0)
+ set_fill(fill);
+ simple_polygon(1, v, n);
+ }
+ if (lt.type == line_type::solid && driver_extension_flag) {
+ line_thickness(lt.thickness);
+ simple_polygon(0, v, n);
+ }
+ else if (lt.type != line_type::invisible) {
+ line_thickness(lt.thickness);
+ line(v[n - 1], v, n, lt);
+ }
+}
+
+void simple_output::circle(const position &cent, double rad,
+ const line_type &lt, double fill)
+{
+ if (driver_extension_flag && ((fill >= 0.0) || (get_last_filled() != 0))) {
+ if (get_last_filled() == 0)
+ set_fill(fill);
+ simple_circle(1, cent, rad);
+ }
+ line_thickness(lt.thickness);
+ switch (lt.type) {
+ case line_type::invisible:
+ break;
+ case line_type::dashed:
+ dashed_circle(cent, rad, lt);
+ break;
+ case line_type::dotted:
+ dotted_circle(cent, rad, lt);
+ break;
+ case line_type::solid:
+ simple_circle(0, cent, rad);
+ break;
+ default:
+ assert(0);
+ }
+}
+
+void simple_output::ellipse(const position &cent, const distance &dim,
+ const line_type &lt, double fill)
+{
+ if (driver_extension_flag && ((fill >= 0.0) || (get_last_filled() != 0))) {
+ if (get_last_filled() == 0)
+ set_fill(fill);
+ simple_ellipse(1, cent, dim);
+ }
+ if (lt.type != line_type::invisible)
+ line_thickness(lt.thickness);
+ switch (lt.type) {
+ case line_type::invisible:
+ break;
+ case line_type::dotted:
+ dotted_ellipse(cent, dim, lt);
+ break;
+ case line_type::dashed:
+ dashed_ellipse(cent, dim, lt);
+ break;
+ case line_type::solid:
+ simple_ellipse(0, cent, dim);
+ break;
+ default:
+ assert(0);
+ }
+}
+
+class troff_output : public simple_output {
+ const char *last_filename;
+ position upper_left;
+ double height;
+ double scale;
+ double last_line_thickness;
+ double last_fill;
+ char *last_filled; // color
+ char *last_outlined; // color
+public:
+ troff_output();
+ ~troff_output();
+ void start_picture(double, const position &ll, const position &ur);
+ void finish_picture();
+ void text(const position &, text_piece *, int, double);
+ void dot(const position &, const line_type &);
+ void command(const char *, const char *, int);
+ void set_location(const char *, int);
+ void simple_line(const position &, const position &);
+ void simple_spline(const position &, const position *, int n);
+ void simple_arc(const position &, const position &, const position &);
+ void simple_circle(int, const position &, double rad);
+ void simple_ellipse(int, const position &, const distance &);
+ void simple_polygon(int, const position *, int);
+ void line_thickness(double p);
+ void set_fill(double);
+ void set_color(char *, char *);
+ void reset_color();
+ char *get_last_filled();
+ char *get_outline_color();
+ position transform(const position &);
+};
+
+output *make_troff_output()
+{
+ return new troff_output;
+}
+
+troff_output::troff_output()
+: last_filename(0), last_line_thickness(BAD_THICKNESS),
+ last_fill(-1.0), last_filled(0), last_outlined(0)
+{
+}
+
+troff_output::~troff_output()
+{
+ free((char *)last_filename);
+}
+
+inline position troff_output::transform(const position &pos)
+{
+ return position((pos.x - upper_left.x)/scale,
+ (upper_left.y - pos.y)/scale);
+}
+
+#define FILL_REG "00"
+
+// If this register > 0, then pic will generate \X'ps: ...' commands
+// if the aligned attribute is used.
+#define GROPS_REG "0p"
+
+// If this register is defined, geqn won't produce '\x's.
+#define EQN_NO_EXTRA_SPACE_REG "0x"
+
+void troff_output::start_picture(double sc,
+ const position &ll, const position &ur)
+{
+ upper_left.x = ll.x;
+ upper_left.y = ur.y;
+ scale = compute_scale(sc, ll, ur);
+ height = (ur.y - ll.y)/scale;
+ double width = (ur.x - ll.x)/scale;
+ printf(".PS %.3fi %.3fi", height, width);
+ if (args)
+ printf(" %s\n", args);
+ else
+ putchar('\n');
+ printf(".\\\" %g %g %g %g\n", ll.x, ll.y, ur.x, ur.y);
+ printf(".\\\" %.3fi %.3fi %.3fi %.3fi\n", 0.0, height, width, 0.0);
+ printf(".nr " FILL_REG " \\n(.u\n.nf\n");
+ printf(".nr " EQN_NO_EXTRA_SPACE_REG " 1\n");
+ // This guarantees that if the picture is used in a diversion it will
+ // have the right width.
+ printf("\\h'%.3fi'\n.sp -1\n", width);
+}
+
+void troff_output::finish_picture()
+{
+ line_thickness(BAD_THICKNESS);
+ last_fill = -1.0; // force it to be reset for each picture
+ reset_color();
+ if (!(want_flyback || want_alternate_flyback))
+ printf(".sp %.3fi+1\n", height);
+ printf(".if \\n(" FILL_REG " .fi\n");
+ printf(".br\n");
+ printf(".nr " EQN_NO_EXTRA_SPACE_REG " 0\n");
+ // this is a little gross
+ set_location(current_filename, current_lineno);
+ if (want_flyback)
+ fputs(".PF\n", stdout);
+ else if (want_alternate_flyback)
+ fputs(".PY\n", stdout);
+ else
+ fputs(".PE\n", stdout);
+}
+
+void troff_output::command(const char *s,
+ const char *filename, int lineno)
+{
+ if (filename != 0)
+ set_location(filename, lineno);
+ fputs(s, stdout);
+ putchar('\n');
+}
+
+void troff_output::simple_circle(int filled, const position &cent, double rad)
+{
+ position c = transform(cent);
+ printf("\\h'%.3fi'"
+ "\\v'%.3fi'"
+ "\\D'%c %.3fi'"
+ "\n.sp -1\n",
+ c.x - rad/scale,
+ c.y,
+ (filled ? 'C' : 'c'),
+ rad*2.0/scale);
+}
+
+void troff_output::simple_ellipse(int filled, const position &cent,
+ const distance &dim)
+{
+ position c = transform(cent);
+ printf("\\h'%.3fi'"
+ "\\v'%.3fi'"
+ "\\D'%c %.3fi %.3fi'"
+ "\n.sp -1\n",
+ c.x - dim.x/(2.0*scale),
+ c.y,
+ (filled ? 'E' : 'e'),
+ dim.x/scale, dim.y/scale);
+}
+
+void troff_output::simple_arc(const position &start, const distance &cent,
+ const distance &end)
+{
+ position s = transform(start);
+ position c = transform(cent);
+ distance cv = c - s;
+ distance ev = transform(end) - c;
+ printf("\\h'%.3fi'"
+ "\\v'%.3fi'"
+ "\\D'a %.3fi %.3fi %.3fi %.3fi'"
+ "\n.sp -1\n",
+ s.x, s.y, cv.x, cv.y, ev.x, ev.y);
+}
+
+void troff_output::simple_line(const position &start, const position &end)
+{
+ position s = transform(start);
+ distance ev = transform(end) - s;
+ printf("\\h'%.3fi'"
+ "\\v'%.3fi'"
+ "\\D'l %.3fi %.3fi'"
+ "\n.sp -1\n",
+ s.x, s.y, ev.x, ev.y);
+}
+
+void troff_output::simple_spline(const position &start,
+ const position *v, int n)
+{
+ position pos = transform(start);
+ printf("\\h'%.3fi'"
+ "\\v'%.3fi'",
+ pos.x, pos.y);
+ fputs("\\D'~ ", stdout);
+ for (int i = 0; i < n; i++) {
+ position temp = transform(v[i]);
+ distance d = temp - pos;
+ pos = temp;
+ if (i != 0)
+ putchar(' ');
+ printf("%.3fi %.3fi", d.x, d.y);
+ }
+ printf("'\n.sp -1\n");
+}
+
+// a solid polygon
+
+void troff_output::simple_polygon(int filled, const position *v, int n)
+{
+ position pos = transform(v[0]);
+ printf("\\h'%.3fi'"
+ "\\v'%.3fi'",
+ pos.x, pos.y);
+ printf("\\D'%c ", (filled ? 'P' : 'p'));
+ for (int i = 1; i < n; i++) {
+ position temp = transform(v[i]);
+ distance d = temp - pos;
+ pos = temp;
+ if (i != 1)
+ putchar(' ');
+ printf("%.3fi %.3fi", d.x, d.y);
+ }
+ printf("'\n.sp -1\n");
+}
+
+const double TEXT_AXIS = 0.22; // in ems
+
+static const char *choose_delimiter(const char *text)
+{
+ if (strchr(text, '\'') == 0)
+ return "'";
+ else
+ return "\\(ts";
+}
+
+void troff_output::text(const position &center, text_piece *v, int n,
+ double ang)
+{
+ line_thickness(BAD_THICKNESS); // text might use lines (e.g., in equations)
+ int rotate_flag = 0;
+ if (driver_extension_flag && ang != 0.0) {
+ rotate_flag = 1;
+ position c = transform(center);
+ printf(".if \\n(" GROPS_REG " \\{\\\n"
+ "\\h'%.3fi'"
+ "\\v'%.3fi'"
+ "\\X'ps: exec gsave currentpoint 2 copy translate %.4f rotate neg exch neg exch translate'"
+ "\n.sp -1\n"
+ ".\\}\n",
+ c.x, c.y, -ang*180.0/M_PI);
+ }
+ for (int i = 0; i < n; i++)
+ if (v[i].text != 0 && *v[i].text != '\0') {
+ position c = transform(center);
+ if (v[i].filename != 0)
+ set_location(v[i].filename, v[i].lineno);
+ printf("\\h'%.3fi", c.x);
+ const char *delim = choose_delimiter(v[i].text);
+ if (v[i].adj.h == RIGHT_ADJUST)
+ printf("-\\w%s%s%su", delim, v[i].text, delim);
+ else if (v[i].adj.h != LEFT_ADJUST)
+ printf("-(\\w%s%s%su/2u)", delim, v[i].text, delim);
+ putchar('\'');
+ printf("\\v'%.3fi-(%dv/2u)+%dv+%.2fm",
+ c.y,
+ n - 1,
+ i,
+ TEXT_AXIS);
+ if (v[i].adj.v == ABOVE_ADJUST)
+ printf("-.5v");
+ else if (v[i].adj.v == BELOW_ADJUST)
+ printf("+.5v");
+ putchar('\'');
+ fputs(v[i].text, stdout);
+ fputs("\n.sp -1\n", stdout);
+ }
+ if (rotate_flag)
+ printf(".if \\n(" GROPS_REG " \\{\\\n"
+ "\\X'ps: exec grestore'\n.sp -1\n"
+ ".\\}\n");
+}
+
+void troff_output::line_thickness(double p)
+{
+ if (p < 0.0)
+ p = RELATIVE_THICKNESS;
+ if (driver_extension_flag && p != last_line_thickness) {
+ printf("\\D't %.3fp'\\h'%.3fp'\n.sp -1\n", p, -p);
+ last_line_thickness = p;
+ }
+}
+
+void troff_output::set_fill(double f)
+{
+ if (driver_extension_flag && f != last_fill) {
+ // \D'Fg ...' emits a node only in compatibility mode,
+ // thus we add a dummy node
+ printf("\\&\\D'Fg %.3f'\n.sp -1\n", 1.0 - f);
+ last_fill = f;
+ }
+ if (last_filled) {
+ free(last_filled);
+ last_filled = 0;
+ printf(".fcolor\n");
+ }
+}
+
+void troff_output::set_color(char *color_fill, char *color_outlined)
+{
+ if (driver_extension_flag) {
+ if (last_filled || last_outlined) {
+ reset_color();
+ }
+ // .gcolor and .fcolor emit a node in compatibility mode only,
+ // but that won't work anyway
+ if (color_fill) {
+ printf(".fcolor %s\n", color_fill);
+ last_filled = strsave(color_fill);
+ }
+ if (color_outlined) {
+ printf(".gcolor %s\n", color_outlined);
+ last_outlined = strsave(color_outlined);
+ }
+ }
+}
+
+void troff_output::reset_color()
+{
+ if (driver_extension_flag) {
+ if (last_filled) {
+ printf(".fcolor\n");
+ free(last_filled);
+ last_filled = 0;
+ }
+ if (last_outlined) {
+ printf(".gcolor\n");
+ free(last_outlined);
+ last_outlined = 0;
+ }
+ }
+}
+
+char *troff_output::get_last_filled()
+{
+ return last_filled;
+}
+
+char *troff_output::get_outline_color()
+{
+ return last_outlined;
+}
+
+const double DOT_AXIS = .044;
+
+void troff_output::dot(const position &cent, const line_type &lt)
+{
+ if (driver_extension_flag) {
+ line_thickness(lt.thickness);
+ simple_line(cent, cent);
+ }
+ else {
+ position c = transform(cent);
+ printf("\\h'%.3fi-(\\w'.'u/2u)'"
+ "\\v'%.3fi+%.2fm'"
+ ".\n.sp -1\n",
+ c.x,
+ c.y,
+ DOT_AXIS);
+ }
+}
+
+void troff_output::set_location(const char *s, int n)
+{
+ if (last_filename != 0 && strcmp(s, last_filename) == 0)
+ printf(".lf %d\n", n);
+ else {
+ printf(".lf %d %s\n", n, s);
+ char *lfn = strdup(s);
+ if (0 == lfn)
+ fatal("memory allocation failure while copying file name");
+ last_filename = lfn;
+ }
+}
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72: