summaryrefslogtreecommitdiffstats
path: root/contrib/groff/src/preproc/pic
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/groff/src/preproc/pic')
-rw-r--r--contrib/groff/src/preproc/pic/Makefile.sub22
-rw-r--r--contrib/groff/src/preproc/pic/common.cc1
-rw-r--r--contrib/groff/src/preproc/pic/common.h4
-rw-r--r--contrib/groff/src/preproc/pic/lex.cc70
-rw-r--r--contrib/groff/src/preproc/pic/main.cc18
-rw-r--r--contrib/groff/src/preproc/pic/object.cc141
-rw-r--r--contrib/groff/src/preproc/pic/object.h9
-rw-r--r--contrib/groff/src/preproc/pic/output.h8
-rw-r--r--contrib/groff/src/preproc/pic/pic.h8
-rw-r--r--contrib/groff/src/preproc/pic/pic.man221
-rw-r--r--contrib/groff/src/preproc/pic/pic.y196
-rw-r--r--contrib/groff/src/preproc/pic/tex.cc26
-rw-r--r--contrib/groff/src/preproc/pic/troff.cc83
13 files changed, 604 insertions, 203 deletions
diff --git a/contrib/groff/src/preproc/pic/Makefile.sub b/contrib/groff/src/preproc/pic/Makefile.sub
index f1e2927..05c47a1 100644
--- a/contrib/groff/src/preproc/pic/Makefile.sub
+++ b/contrib/groff/src/preproc/pic/Makefile.sub
@@ -1,16 +1,16 @@
-PROG=pic
+PROG=pic$(EXEEXT)
MAN1=pic.n
XLIBS=$(LIBGROFF)
MLIB=$(LIBM)
OBJS=\
- pic.o \
- lex.o \
- main.o \
- object.o \
- common.o \
- troff.o \
- tex.o
- # fig.o
+ pic.$(OBJEXT) \
+ lex.$(OBJEXT) \
+ main.$(OBJEXT) \
+ object.$(OBJEXT) \
+ common.$(OBJEXT) \
+ troff.$(OBJEXT) \
+ tex.$(OBJEXT)
+ # fig.$(OBJEXT)
CCSRCS=\
$(srcdir)/lex.cc \
$(srcdir)/main.cc \
@@ -26,6 +26,6 @@ HDRS=\
$(srcdir)/position.h \
$(srcdir)/text.h
GRAM=$(srcdir)/pic.y
-YTABC=$(srcdir)/pic.cc
-YTABH=$(srcdir)/pic_tab.h
+YTABC=pic.cc
+YTABH=pic_tab.h
NAMEPREFIX=$(g)
diff --git a/contrib/groff/src/preproc/pic/common.cc b/contrib/groff/src/preproc/pic/common.cc
index e83ef31..5075e93 100644
--- a/contrib/groff/src/preproc/pic/common.cc
+++ b/contrib/groff/src/preproc/pic/common.cc
@@ -437,7 +437,6 @@ void common_output::dot_line(const position &start, const position &end,
}
}
-
void common_output::solid_rounded_box(const position &cent,
const distance &dim, double rad,
const line_type &lt)
diff --git a/contrib/groff/src/preproc/pic/common.h b/contrib/groff/src/preproc/pic/common.h
index 25a6e10..90b65fa 100644
--- a/contrib/groff/src/preproc/pic/common.h
+++ b/contrib/groff/src/preproc/pic/common.h
@@ -63,6 +63,10 @@ public:
const line_type &, double) = 0;
void rounded_box(const position &, const distance &, double,
const line_type &, double);
+ 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,
diff --git a/contrib/groff/src/preproc/pic/lex.cc b/contrib/groff/src/preproc/pic/lex.cc
index 5b6d439..14a4cc3 100644
--- a/contrib/groff/src/preproc/pic/lex.cc
+++ b/contrib/groff/src/preproc/pic/lex.cc
@@ -1,5 +1,6 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2002
+ Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
@@ -83,8 +84,8 @@ int file_input::read_line()
int c = getc(fp);
if (c == EOF)
break;
- else if (illegal_input_char(c))
- lex_error("illegal input character code %1", c);
+ else if (invalid_input_char(c))
+ lex_error("invalid input character code %1", c);
else {
line += char(c);
if (c == '\n')
@@ -153,7 +154,7 @@ int macro_input::peek()
return (unsigned char)*p;
}
-// Character representing $1. Must be illegal input character.
+// Character representing $1. Must be invalid input character.
#define ARG1 14
char *process_body(const char *body)
@@ -446,6 +447,10 @@ int lookup_keyword(const char *str, int len)
{ "center", CENTER },
{ "chop", CHOP },
{ "circle", CIRCLE },
+ { "color", COLORED },
+ { "colored", COLORED },
+ { "colour", COLORED },
+ { "coloured", COLORED },
{ "command", COMMAND },
{ "copy", COPY },
{ "cos", COS },
@@ -457,6 +462,7 @@ int lookup_keyword(const char *str, int len)
{ "do", DO },
{ "dotted", DOTTED },
{ "down", DOWN },
+ { "east", EAST },
{ "ellipse", ELLIPSE },
{ "else", ELSE },
{ "end", END },
@@ -480,7 +486,10 @@ int lookup_keyword(const char *str, int len)
{ "max", K_MAX },
{ "min", K_MIN },
{ "move", MOVE },
+ { "north", NORTH },
{ "of", OF },
+ { "outline", OUTLINED },
+ { "outlined", OUTLINED },
{ "plot", PLOT },
{ "print", PRINT },
{ "rad", RADIUS },
@@ -491,8 +500,10 @@ int lookup_keyword(const char *str, int len)
{ "rjust", RJUST },
{ "same", SAME },
{ "sh", SH },
+ { "shaded", SHADED },
{ "sin", SIN },
{ "solid", SOLID },
+ { "south", SOUTH },
{ "spline", SPLINE },
{ "sprintf", SPRINTF },
{ "sqrt", SQRT },
@@ -510,6 +521,7 @@ int lookup_keyword(const char *str, int len)
{ "up", UP },
{ "upper", UPPER },
{ "way", WAY },
+ { "west", WEST },
{ "wid", WIDTH },
{ "width", WIDTH },
{ "with", WITH },
@@ -953,7 +965,7 @@ int get_token(int lookup_flag)
double factor = 1.0;
for (;;) {
c = input_stack::peek_char();
- if (!c == EOF || !csdigit(c))
+ if (c == EOF || !csdigit(c))
break;
input_stack::get_char();
context_buffer += char(c);
@@ -1618,8 +1630,8 @@ simple_file_input::~simple_file_input()
int simple_file_input::get()
{
int c = getc(fp);
- while (illegal_input_char(c)) {
- error("illegal input character code %1", c);
+ while (invalid_input_char(c)) {
+ error("invalid input character code %1", c);
c = getc(fp);
}
if (c == '\n')
@@ -1630,8 +1642,8 @@ int simple_file_input::get()
int simple_file_input::peek()
{
int c = getc(fp);
- while (illegal_input_char(c)) {
- error("illegal input character code %1", c);
+ while (invalid_input_char(c)) {
+ error("invalid input character code %1", c);
c = getc(fp);
}
if (c != EOF)
@@ -1816,6 +1828,46 @@ int yylex()
}
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;
diff --git a/contrib/groff/src/preproc/pic/main.cc b/contrib/groff/src/preproc/pic/main.cc
index b795d48..124cbd5 100644
--- a/contrib/groff/src/preproc/pic/main.cc
+++ b/contrib/groff/src/preproc/pic/main.cc
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1989-1992, 2000, 2001 Free Software Foundation, Inc.
+/* Copyright (C) 1989-1992, 2000, 2001, 2002 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
@@ -80,8 +80,8 @@ int top_input::get()
return c;
}
int c = getc(fp);
- while (illegal_input_char(c)) {
- error("illegal input character code %1", int(c));
+ while (invalid_input_char(c)) {
+ error("invalid input character code %1", int(c));
c = getc(fp);
bol = 0;
}
@@ -152,8 +152,8 @@ int top_input::peek()
if (push_back[0] != EOF)
return push_back[0];
int c = getc(fp);
- while (illegal_input_char(c)) {
- error("illegal input character code %1", int(c));
+ while (invalid_input_char(c)) {
+ error("invalid input character code %1", int(c));
c = getc(fp);
bol = 0;
}
@@ -476,7 +476,7 @@ void usage(FILE *stream)
#endif
}
-#ifdef __MSDOS__
+#if defined(__MSDOS__) || defined(__EMX__)
static char *fix_program_name(char *arg, char *dflt)
{
if (!arg)
@@ -499,13 +499,13 @@ static char *fix_program_name(char *arg, char *dflt)
*p = 'a' + (*p - 'A');
return prog;
}
-#endif /* __MSDOS__ */
+#endif /* __MSDOS__ || __EMX__ */
int main(int argc, char **argv)
{
-#ifdef __MSDOS__
+#if defined(__MSDOS__) || defined(__EMX__)
argv[0] = fix_program_name(argv[0], "pic");
-#endif /* __MSDOS__ */
+#endif /* __MSDOS__ || __EMX__ */
program_name = argv[0];
static char stderr_buf[BUFSIZ];
setbuf(stderr, stderr_buf);
diff --git a/contrib/groff/src/preproc/pic/object.cc b/contrib/groff/src/preproc/pic/object.cc
index 6b34633..fd25371 100644
--- a/contrib/groff/src/preproc/pic/object.cc
+++ b/contrib/groff/src/preproc/pic/object.cc
@@ -1,5 +1,6 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002
+ Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
@@ -53,14 +54,6 @@ void output::set_args(const char *s)
args = strsave(s);
}
-void output::command(const char *, const char *, int)
-{
-}
-
-void output::set_location(const char *, int)
-{
-}
-
int output::supports_filled_polygons()
{
return 0;
@@ -219,7 +212,8 @@ struct arrow_head_type {
};
void draw_arrow(const position &pos, const distance &dir,
- const arrow_head_type &aht, const line_type &lt)
+ const arrow_head_type &aht, const line_type &lt,
+ char *outline_color_for_fill)
{
double hyp = hypot(dir);
if (hyp == 0.0) {
@@ -237,8 +231,9 @@ void draw_arrow(const position &pos, const distance &dir,
v[0] = pos;
v[1] = pos + base + n;
v[2] = pos + base - n;
- // A value > 1 means fill with the current color.
- out->polygon(v, 3, slt, 2.0);
+ // fill with outline color
+ out->set_color(outline_color_for_fill, outline_color_for_fill);
+ out->polygon(v, 3, slt, 1);
}
else {
position v[2];
@@ -549,6 +544,8 @@ class graphic_object : public object {
int aligned;
protected:
line_type lt;
+ char *outline_color;
+ char *color_fill;
public:
graphic_object();
~graphic_object();
@@ -559,10 +556,14 @@ public:
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_fill_color(char *);
};
-graphic_object::graphic_object() : ntext(0), text(0), aligned(0)
+graphic_object::graphic_object()
+: ntext(0), text(0), aligned(0), outline_color(0), color_fill(0)
{
}
@@ -587,6 +588,21 @@ void graphic_object::set_fill(double)
{
}
+void graphic_object::set_fill_color(char *c)
+{
+ color_fill = c;
+}
+
+void graphic_object::set_outline_color(char *c)
+{
+ outline_color = c;
+}
+
+char *graphic_object::get_outline_color()
+{
+ return outline_color;
+}
+
void graphic_object::set_invisible()
{
lt.type = line_type::invisible;
@@ -622,8 +638,11 @@ void graphic_object::print_text()
if (d.x != 0.0 || d.y != 0.0)
angle = atan2(d.y, d.x);
}
- if (text != 0)
+ if (text != 0) {
+ out->set_color(color_fill, get_outline_color());
out->text(center(), text, ntext, angle);
+ out->reset_color();
+ }
}
graphic_object::~graphic_object()
@@ -676,12 +695,14 @@ public:
closed_object(const position &);
object_type type() = 0;
void set_fill(double);
+ void set_fill_color(char *fill);
protected:
double fill; // < 0 if not filled
+ char *color_fill; // = 0 if not colored
};
closed_object::closed_object(const position &pos)
-: rectangle_object(pos), fill(-1.0)
+: rectangle_object(pos), fill(-1.0), color_fill(0)
{
}
@@ -691,6 +712,10 @@ void closed_object::set_fill(double f)
fill = f;
}
+void closed_object::set_fill_color(char *fill)
+{
+ color_fill = fill;
+}
class box_object : public closed_object {
double xrad;
@@ -738,8 +763,9 @@ position box_object::south_west()
void box_object::print()
{
- if (lt.type == line_type::invisible && fill < 0.0)
+ 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];
@@ -753,6 +779,7 @@ void box_object::print()
distance abs_dim(fabs(dim.x), fabs(dim.y));
out->rounded_box(cent, abs_dim, fabs(xrad), lt, fill);
}
+ out->reset_color();
}
graphic_object *object_spec::make_box(position *curpos, direction *dirp)
@@ -990,9 +1017,11 @@ ellipse_object::ellipse_object(const position &d)
void ellipse_object::print()
{
- if (lt.type == line_type::invisible && fill < 0.0)
+ 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)
@@ -1037,9 +1066,11 @@ circle_object::circle_object(double diam)
void circle_object::print()
{
- if (lt.type == line_type::invisible && fill < 0.0)
+ 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)
@@ -1098,7 +1129,7 @@ graphic_object *object_spec::make_move(position *curpos, direction *dirp)
// 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)
+ if ((flags & IS_SAME) && have_last_move)
segment_pos = last_move;
else {
switch (dir) {
@@ -1222,11 +1253,14 @@ void line_object::print()
{
if (lt.type == line_type::invisible)
return;
+ out->set_color(0, graphic_object::get_outline_color());
out->line(strt, v, n, lt);
if (arrow_at_start)
- draw_arrow(strt, strt-v[0], aht, lt);
+ draw_arrow(strt, strt-v[0], aht, lt, graphic_object::get_outline_color());
if (arrow_at_end)
- draw_arrow(en, v[n-1] - (n > 1 ? v[n - 2] : strt), aht, lt);
+ draw_arrow(en, v[n-1] - (n > 1 ? v[n - 2] : strt), aht, lt,
+ graphic_object::get_outline_color());
+ out->reset_color();
}
void line_object::update_bounding_box(bounding_box *p)
@@ -1289,11 +1323,14 @@ void spline_object::print()
{
if (lt.type == line_type::invisible)
return;
+ out->set_color(0, graphic_object::get_outline_color());
out->spline(strt, v, n, lt);
if (arrow_at_start)
- draw_arrow(strt, strt-v[0], aht, lt);
+ draw_arrow(strt, strt-v[0], aht, lt, graphic_object::get_outline_color());
if (arrow_at_end)
- draw_arrow(en, v[n-1] - (n > 1 ? v[n - 2] : strt), aht, lt);
+ draw_arrow(en, v[n-1] - (n > 1 ? v[n - 2] : strt), aht, lt,
+ graphic_object::get_outline_color());
+ out->reset_color();
}
line_object::~line_object()
@@ -1500,6 +1537,7 @@ void arc_object::print()
{
if (lt.type == line_type::invisible)
return;
+ out->set_color(0, graphic_object::get_outline_color());
if (clockwise)
out->arc(en, cent, strt, lt);
else
@@ -1508,14 +1546,15 @@ void arc_object::print()
position c = cent - strt;
draw_arrow(strt,
(clockwise ? position(c.y, -c.x) : position(-c.y, c.x)),
- aht, lt);
+ aht, lt, graphic_object::get_outline_color());
}
if (arrow_at_end) {
position e = en - cent;
draw_arrow(en,
(clockwise ? position(e.y, -e.x) : position(-e.y, e.x)),
- aht, lt);
+ aht, lt, graphic_object::get_outline_color());
}
+ out->reset_color();
}
inline double max(double a, double b)
@@ -1708,13 +1747,19 @@ object *object_spec::make_object(position *curpos, direction *dirp)
else
lookup_variable("linethick", &th);
obj->set_thickness(th);
+ if (flags & IS_OUTLINED)
+ obj->set_outline_color(outlined);
if (flags & (IS_DEFAULT_FILLED|IS_FILLED)) {
- if (flags & IS_DEFAULT_FILLED)
- lookup_variable("fillval", &fill);
- if (fill < 0.0)
- error("bad fill value %1", fill);
- else
- obj->set_fill(fill);
+ 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;
@@ -1737,18 +1782,28 @@ string_list::~string_list()
a_delete 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. */
+/* 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)
+: 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)
+: crn(c), ypath(0), is_position(0)
{
label_list = new string_list(l);
}
@@ -1786,6 +1841,12 @@ void path::set_ypath(path *p)
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) {
@@ -1795,9 +1856,9 @@ int path::follow(const place &pl, place *result) const
if (crn == 0 || p->obj == 0)
*result = *p;
else {
- position pos = ((p->obj)->*(crn))();
- result->x = pos.x;
- result->y = pos.y;
+ position ps = ((p->obj)->*(crn))();
+ result->x = ps.x;
+ result->y = ps.y;
result->obj = 0;
}
if (ypath) {
diff --git a/contrib/groff/src/preproc/pic/object.h b/contrib/groff/src/preproc/pic/object.h
index 2748e81..98937f93 100644
--- a/contrib/groff/src/preproc/pic/object.h
+++ b/contrib/groff/src/preproc/pic/object.h
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
+/* Copyright (C) 1989, 1990, 1991, 1992, 2002 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
@@ -76,11 +76,14 @@ struct place {
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);
@@ -150,6 +153,8 @@ 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;
struct segment {
int is_absolute;
@@ -183,6 +188,8 @@ struct object_spec {
double end_chop;
double thickness;
double fill;
+ char *shaded;
+ char *outlined;
direction dir;
segment *segment_list;
position segment_pos;
diff --git a/contrib/groff/src/preproc/pic/output.h b/contrib/groff/src/preproc/pic/output.h
index ac490db..a0a8331 100644
--- a/contrib/groff/src/preproc/pic/output.h
+++ b/contrib/groff/src/preproc/pic/output.h
@@ -55,8 +55,12 @@ public:
const line_type &, double) = 0;
virtual void rounded_box(const position &, const distance &, double,
const line_type &, double) = 0;
- virtual void command(const char *, const char *, int);
- virtual void set_location(const char *, int);
+ 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();
diff --git a/contrib/groff/src/preproc/pic/pic.h b/contrib/groff/src/preproc/pic/pic.h
index 36c36d1..0a092fe 100644
--- a/contrib/groff/src/preproc/pic/pic.h
+++ b/contrib/groff/src/preproc/pic/pic.h
@@ -1,5 +1,6 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001
+ Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
This file is part of groff.
@@ -18,8 +19,8 @@ You should have received a copy of the GNU General Public License along
with groff; see the file COPYING. If not, write to the Free Software
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-#include <stdio.h>
-#include <string.h>
+#include "lib.h"
+
#include <math.h>
#include <stdlib.h>
#include <errno.h>
@@ -32,7 +33,6 @@ extern "C" {
#include "assert.h"
#include "cset.h"
-#include "lib.h"
#include "stringclass.h"
#include "errarg.h"
#include "error.h"
diff --git a/contrib/groff/src/preproc/pic/pic.man b/contrib/groff/src/preproc/pic/pic.man
index ea53074..406246f 100644
--- a/contrib/groff/src/preproc/pic/pic.man
+++ b/contrib/groff/src/preproc/pic/pic.man
@@ -1,5 +1,5 @@
.ig
-Copyright (C) 1989-2000, 2001 Free Software Foundation, Inc.
+Copyright (C) 1989-2000, 2001, 2002 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
@@ -16,30 +16,43 @@ versions, except that this permission notice may be included in
translations approved by the Free Software Foundation instead of in
the original English.
..
+.
+.
.\" Like TP, but if specified indent is more than half
.\" the current line-length - indent, use the default indent.
.de Tp
.ie \\n(.$=0:((0\\$1)*2u>(\\n(.lu-\\n(.iu)) .TP
.el .TP "\\$1"
..
+.
.ie t .ds tx T\h'-.1667m'\v'.224m'E\v'-.224m'\h'-.125m'X
-.el .ds tx TeX
+.el .ds tx TeX
+.
.ie \n(.g .ds ic \/
-.el .ds ic \^
+.el .ds ic \^
+.
.\" The BSD man macros can't handle " in arguments to font change macros,
.\" so use \(ts instead of ".
.tr \(ts"
+.
+.
.TH @G@PIC @MAN1EXT@ "@MDATE@" "Groff Version @VERSION@"
+.
+.
.SH NAME
+.
@g@pic \- compile pictures for troff or TeX
+.
+.
.SH SYNOPSIS
+.
.B @g@pic
[
.B \-nvCSU
]
[
.I filename
-\&.\|.\|.
+\&.\|.\|.\&
]
.br
.B @g@pic
@@ -49,9 +62,12 @@ the original English.
]
[
.I filename
-\&.\|.\|.
+\&.\|.\|.\&
]
+.
+.
.SH DESCRIPTION
+.
This manual page describes the GNU version of
.BR pic ,
which is part of the groff document formatting system.
@@ -80,7 +96,10 @@ When the macro package being used does not supply such definitions
appropriate definitions can be obtained with
.BR \-mpic :
these will center each picture.
+.
+.
.SH OPTIONS
+.
Options that do not take arguments may be grouped behind a single
.BR \- .
The special option
@@ -89,6 +108,7 @@ can be used to mark the end of the options.
A filename of
.B \-
refers to the standard input.
+.
.TP
.B \-C
Recognize
@@ -96,6 +116,7 @@ Recognize
and
.B .PE
even when followed by a character other than space or newline.
+.
.TP
.B \-S
Safer mode; do not execute
@@ -103,10 +124,12 @@ Safer mode; do not execute
commands.
This can be useful when operating on untrustworthy input.
(enabled by default)
+.
.TP
.B \-U
Unsafe mode; revert the default option
.BR \-S .
+.
.TP
.B \-n
Don't use the groff extensions to the troff drawing commands.
@@ -119,9 +142,11 @@ The
option also causes
.B pic
not to use zero-length lines to draw dots in troff mode.
+.
.TP
.B \-t
\*(tx mode.
+.
.TP
.B \-c
Be more compatible with
@@ -151,21 +176,26 @@ specified by use of the
attribute or by setting the
.B linethick
variable.
+.
.TP
.B \-v
Print the version number.
+.
.TP
.B \-z
In \*(tx mode draw dots using zero-length lines.
+.
.LP
The following options supported by other versions of
.B pic
are ignored:
+.
.TP
.B \-D
Draw all lines using the \eD escape sequence.
.B pic
always does this.
+.
.TP
.BI \-T \ dev
Generate output for the
@@ -177,15 +207,24 @@ This is unnecessary because the
output generated by
.B pic
is device-independent.
+.
+.
.SH USAGE
+.
This section describes only the differences between GNU
.B pic
and the original version of
.BR pic .
Many of these differences also apply to newer versions of Unix
.BR pic .
-.SS \*(tx mode
+A complete documentation is available in the file
.LP
+.RS
+.B @DOCDIR@/pic.ms
+.RE
+.
+.SS \*(tx mode
+.
\*(tx mode is enabled by the
.B \-t
option.
@@ -225,7 +264,9 @@ change the value of
.BR \ebaselineskip .
Anything else may well produce undesirable results; use at your own risk.
Lines beginning with a period are not given any special treatment.
+.
.SS Commands
+.
.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
@@ -259,6 +300,7 @@ will instead be multiplied by
.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]
@@ -274,6 +316,7 @@ can be any character not occurring in
.I Y
can be any character not occurring in
.IR if-false .
+.
.TP
\fBprint\fR \fIarg\fR\|.\|.\|.
Concatenate the arguments and print as a line on stderr.
@@ -281,18 +324,20 @@ Each
.I arg
must be an expression, a position, or text.
This is useful for debugging.
+.
.TP
\fBcommand\fR \fIarg\fR\|.\|.\|.
Concatenate the arguments
-and pass them through as a line to troff or\*(tx.
+and pass them through as a line to troff or \*(tx.
Each
.I arg
must be an expression, a position, or text.
This has a similar effect to a line beginning with
-.B .
+.B .\&
or
.BR \e ,
but allows the values of variables to be passed through.
+.
.TP
\fBsh\fR \fIX\fR \fIcommand\fR \fIX\fR
Pass
@@ -301,11 +346,13 @@ to a shell.
.I X
can be any character not occurring in
.IR command .
+.
.TP
\fBcopy\fR \fB"\fIfilename\fB"\fR
Include
.I filename
at this point in the file.
+.
.TP
\fBcopy\fR [\fB"\fIfilename\fB"\fR] \fBthru\fR \fIX\fR \fIbody\fR \fIX\fR \
[\fBuntil\fR \fB"\fIword\*(ic\fB"\fR]
@@ -377,12 +424,13 @@ 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 .
+.
.LP
.B reset
.br
.ns
.TP
-\fBreset\fI variable1\fB,\fI variable2 .\^.\^.
+\fBreset\fI variable1\fR[\fB,\fR]\fI variable2 .\^.\^.
Reset pre-defined variables
.IR variable1 ,
.I variable2
@@ -393,6 +441,7 @@ Note that assigning a value to
.B scale
also causes all pre-defined variables that control dimensions
to be reset to their default values times the new value of scale.
+.
.TP
\fBplot\fR \fIexpr\fR [\fB"\fItext\*(ic\fB"\fR]
This is a text object which is constructed by using
@@ -412,24 +461,48 @@ Be very careful that you specify an appropriate format string;
does only very limited checking of the string.
This is deprecated in favour of
.BR sprintf .
+.
.TP
-.IB variable := expr
+.IB variable\ := \ expr
This is similar to
.B =
except
.I variable
must already be defined,
-and the value of
+and
+.I expr
+will be assigned to
.I variable
-will be changed only in the innermost block in which it is defined.
+without creating a variable local to the current block.
(By contrast,
.B =
defines the variable in the current block if it is not already defined there,
-and then changes the value in the current block.)
+and then changes the value in the current block only.)
+For example, the following:
+.RS
+.IP
+.ft B
+.nf
+\&.PS
+x = 3
+y = 3
+[
+ x := 5
+ y = 5
+]
+print x " " y
+\&.PE
+.ft
+.fi
+.RE
+.IP
+prints
+.BR 5\ 3 .
+.
.LP
Arguments of the form
.IP
-.IR X\ anything\ X
+.I X anything X
.LP
are also allowed to be of the form
.IP
@@ -447,8 +520,11 @@ or imbalanced occurrences of
.B {
and
.BR } .
+.
.SS Expressions
+.
The syntax for expressions has been significantly extended:
+.
.LP
.IB x\ ^\ y
(exponentiation)
@@ -463,7 +539,9 @@ The syntax for expressions has been significantly extended:
(base 10)
.br
.BI exp( x )
-(base 10, ie 10\v'-.4m'\fIx\*(ic\fR\v'.4m')
+(base 10, ie
+.ie t 10\v'-.4m'\fIx\*(ic\fR\v'.4m')
+.el 10^\fIx\fR)
.br
.BI sqrt( x )
.br
@@ -506,11 +584,13 @@ deprecated)
.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
-.LP
+.
A bare expression,
.IR expr ,
is acceptable as an attribute;
@@ -523,13 +603,19 @@ For example
.IP
.B line 2i
.LP
-means draw a line 2 inches long in the current direction.
+means draw a line 2\ inches long in the current direction.
+The `i' (or `I') 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
@@ -537,6 +623,7 @@ For example
.B
x = 5e\-2
.RE
+.
.LP
Text attributes can be compounded.
For example,
@@ -545,6 +632,7 @@ For example,
"foo" above ljust
.RE
is legal.
+.
.LP
There is no limit to the depth to which blocks can be examined.
For example,
@@ -556,12 +644,15 @@ For example,
circle at last [\^].A.B.C
.RE
is acceptable.
+.
.LP
Arcs now have compass points
determined by the circle of which the arc is a part.
+.
.LP
Circles and arcs can be dotted or dashed.
In \*(tx mode splines can be dotted or dashed.
+.
.LP
Boxes can have rounded corners.
The
@@ -576,8 +667,9 @@ attribute is given, a radius of
is used.
Initially,
.B boxrad
-has a value of 0.
+has a value of\ 0.
A box with rounded corners can be dotted or dashed.
+.
.LP
The
.B .PS
@@ -587,13 +679,15 @@ If the width of zero is specified the width will be ignored in computing
the scaling factor for the picture.
Note that GNU
.B pic
-will always scale a picture by the same amount vertically as horizontally.
+will always scale a picture by the same amount vertically as well as
+horizontally.
This is different from the
.SM DWB
2.0
.B pic
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.
@@ -611,8 +705,9 @@ Initially
and
.B textht
have a value of 0.
+.
.LP
-In places where a quoted text string can be used,
+In (almost all) places where a quoted text string can be used,
an expression of the form
.IP
.BI sprintf(\(ts format \(ts,\ arg ,\fR.\|.\|.\fB)
@@ -622,14 +717,8 @@ this will produce the arguments formatted according to
.IR format ,
which should be a string as described in
.BR printf (3)
-appropriate for the number of arguments supplied,
-using only the
-.BR e ,
-.BR f ,
-.B g
-or
-.B %
-format characters.
+appropriate for the number of arguments supplied.
+.
.LP
The thickness of the lines used to draw objects is controlled by the
.B linethick
@@ -663,9 +752,10 @@ value of the
variable, nor by the width or height given in the
.B .PS
line.
+.
.LP
Boxes (including boxes with rounded corners),
-circles and ellipses can be filled by giving then an attribute of
+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
@@ -683,16 +773,48 @@ 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.
+.
+.LP
+Three additional modifiers are available to specify 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 three keywords expect a suffix specifying the color, for example
+.RS
+.LP
+.B circle shaded """green""" outline """black"""
+.RE
+.LP
+Currently, color support isn't available in \*(tx mode.
+Predefined color names for
+.B groff
+are in the device macro files, for example
+.BR ps.tmac ;
+additional colors can be defined with the
+.B .defcolor
+request (see the manual page of
+.BR @g@troff (@MAN1EXT@)
+for more details).
+.LP
+.B 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 \-x
-option has been given.
+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.
+has a value of\ 1.
+Note that solid arrow heads are always filled with the current outline
+color.
+.
.LP
The troff output of
.B pic
@@ -702,11 +824,12 @@ The
option is therefore redundant.
All numbers are taken to be in inches; numbers are never interpreted
to be in troff machine units.
+.
.LP
Objects can have an
.B aligned
attribute.
-This will only work when the postprocessor is
+This will only work if the postprocessor is
.BR grops .
Any text associated with an object having the
.B aligned
@@ -715,6 +838,7 @@ so that it is aligned in the direction from the start point
to the end point of the object.
Note that this attribute will have no effect for objects whose start and
end points are coincident.
+.
.LP
In places where
.IB n th
@@ -729,13 +853,17 @@ and the
.BR th .
For example,
.IP
-.B
+.ft B
.nf
for i = 1 to 4 do {
line from `i'th box.nw to `i+1'th box.se
}
+.ft
.fi
+.
+.
.SH CONVERSION
+.
To obtain a stand-alone picture from a
.B pic
file, enclose your
@@ -749,6 +877,7 @@ requests;
configuration commands may be added at the beginning of the file, but no
.B roff
text.
+.
.LP
It is necessary to feed this file into
.B groff
@@ -774,6 +903,7 @@ Alternatively, you can define your own requests, e.g. to do nothing:
.ft
.fi
.RE
+.
.LP
.B groff
itself does not provide direct conversion into other graphics file
@@ -806,6 +936,7 @@ Call
.RE
.LP
for a list of the available devices.
+.
.LP
As the Encapsulated PostScript File Format
.B EPS
@@ -827,7 +958,10 @@ file can be then converted to virtually any graphics format using the tools
of the
.B netpbm
package .
+.
+.
.SH FILES
+.
.Tp \w'\fB@MACRODIR@/pic.tmac'u+3n
.B
@MACRODIR@/pic.tmac
@@ -836,7 +970,10 @@ Example definitions of the
and
.B PE
macros.
+.
+.
.SH "SEE ALSO"
+.
.BR @g@troff (@MAN1EXT@),
.BR groff_out (@MAN5EXT@),
.BR tex (1),
@@ -851,7 +988,7 @@ Tpic: Pic for \*(tx
Brian W. Kernighan,
PIC \(em A Graphics Language for Typesetting (User Manual).
AT&T Bell Laboratories, Computing Science Technical Report No.\ 116
-<URL:http://cm.bell-labs.com/cm/cs/cstr/116.ps.gz>
+<http://cm.bell-labs.com/cm/cs/cstr/116.ps.gz>
(revised May, 1991).
.LP
.B ps2eps
@@ -866,14 +1003,16 @@ W. Richard Stevens - Turning PIC Into HTML
W. Richard Stevens - Examples of picMacros
.br
<http://www.kohala.com/start/troff/pic.examples.ps>
+.
+.
.SH BUGS
-.LP
-Input characters that are illegal for
+.
+Input characters that are invalid for
.B groff
(ie those with
.SM ASCII
-code 0 or between 013 and 037 octal or between 0200 and 0237 octal)
-are rejected even in \*(tx mode.
+code 0, or 013 octal, or between 015 and 037 octal, or between 0200 and 0237
+octal) are rejected even in \*(tx mode.
.LP
The interpretation of
.B fillval
diff --git a/contrib/groff/src/preproc/pic/pic.y b/contrib/groff/src/preproc/pic/pic.y
index c0a7315..15b6b3f 100644
--- a/contrib/groff/src/preproc/pic/pic.y
+++ b/contrib/groff/src/preproc/pic/pic.y
@@ -1,4 +1,4 @@
-/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001
+/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002
Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
@@ -202,6 +202,10 @@ char *do_sprintf(const char *form, const double *v, int nv);
%token GREATEREQUAL
%token LEFT_CORNER
%token RIGHT_CORNER
+%token NORTH
+%token SOUTH
+%token EAST
+%token WEST
%token CENTER
%token END
%token START
@@ -210,6 +214,9 @@ char *do_sprintf(const char *form, const double *v, int nv);
%token PLOT
%token THICKNESS
%token FILL
+%token COLORED
+%token OUTLINED
+%token SHADED
%token ALIGNED
%token SPRINTF
%token COMMAND
@@ -217,6 +224,8 @@ char *do_sprintf(const char *form, const double *v, int nv);
%token DEFINE
%token UNDEF
+%left '.'
+
/* this ensures that plot 17 "%g" parses as (plot 17 "%g") */
%left PLOT
%left TEXT SPRINTF
@@ -231,12 +240,14 @@ box "foo" above ljust == box ("foo" above ljust)
/* Give attributes that take an optional expression a higher
precedence than left and right, so that eg `line chop left'
parses properly. */
-%left CHOP SOLID DASHED DOTTED UP DOWN FILL
+%left CHOP SOLID DASHED DOTTED UP DOWN FILL COLORED OUTLINED
%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
@@ -244,7 +255,7 @@ parses properly. */
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 CENTER START END
+%left UPPER LOWER NORTH SOUTH EAST WEST CENTER START END
%left ','
%left OROR
@@ -350,7 +361,7 @@ placeless_element:
{
fprintf(stderr, "%s\n", $2.str);
a_delete $2.str;
- fflush(stderr);
+ fflush(stderr);
}
| SH
{ delim_flag = 1; }
@@ -433,11 +444,20 @@ placeless_element:
reset_variables:
RESET VARIABLE
- { reset($2); a_delete $2; }
+ {
+ reset($2);
+ a_delete $2;
+ }
| reset_variables VARIABLE
- { reset($2); a_delete $2; }
+ {
+ reset($2);
+ a_delete $2;
+ }
| reset_variables ',' VARIABLE
- { reset($3); a_delete $3; }
+ {
+ reset($3);
+ a_delete $3;
+ }
;
print_args:
@@ -462,7 +482,7 @@ print_args:
;
print_arg:
- expr %prec ','
+ expr %prec ','
{
$$.str = new char[GDIGITS + 1];
sprintf($$.str, "%g", $1);
@@ -471,19 +491,24 @@ print_arg:
}
| text
{ $$ = $1; }
- | position %prec ','
+ | 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; }
+ {
+ delim_flag = 0;
+ $$.x = $2;
+ $$.body = $5;
+ }
;
until:
@@ -532,11 +557,20 @@ text_expr:
optional_by:
/* empty */
- { $$.val = 1.0; $$.is_multiplicative = 0; }
+ {
+ $$.val = 1.0;
+ $$.is_multiplicative = 0;
+ }
| BY expr
- { $$.val = $2; $$.is_multiplicative = 0; }
+ {
+ $$.val = $2;
+ $$.is_multiplicative = 0;
+ }
| BY '*' expr
- { $$.val = $3; $$.is_multiplicative = 1; }
+ {
+ $$.val = $3;
+ $$.is_multiplicative = 1;
+ }
;
element:
@@ -555,7 +589,11 @@ element:
}
}
| LABEL ':' optional_separator element
- { $$ = $4; define_label($1, & $$); a_delete $1; }
+ {
+ $$ = $4;
+ define_label($1, & $$);
+ a_delete $1;
+ }
| LABEL ':' optional_separator position_not_place
{
$$.obj = 0;
@@ -603,17 +641,11 @@ optional_element:
object_spec:
BOX
- {
- $$ = new object_spec(BOX_OBJECT);
- }
+ { $$ = new object_spec(BOX_OBJECT); }
| CIRCLE
- {
- $$ = new object_spec(CIRCLE_OBJECT);
- }
+ { $$ = new object_spec(CIRCLE_OBJECT); }
| ELLIPSE
- {
- $$ = new object_spec(ELLIPSE_OBJECT);
- }
+ { $$ = new object_spec(ELLIPSE_OBJECT); }
| ARC
{
$$ = new object_spec(ARC_OBJECT);
@@ -647,7 +679,7 @@ object_spec:
lookup_variable("linewid", & $$->segment_width);
$$->dir = current_direction;
}
- | text %prec TEXT
+ | text %prec TEXT
{
$$ = new object_spec(TEXT_OBJECT);
$$->text = new text_item($1.str, $1.filename, $1.lineno);
@@ -715,7 +747,7 @@ object_spec:
$$->radius = $3/2.0;
$$->flags |= HAS_RADIUS;
}
- | object_spec expr %prec HEIGHT
+ | object_spec expr %prec HEIGHT
{
$$ = $1;
$$->flags |= HAS_SEGMENT;
@@ -830,6 +862,15 @@ object_spec:
$$->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;
@@ -888,6 +929,29 @@ object_spec:
$$->flags |= IS_FILLED;
$$->fill = $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;
@@ -956,7 +1020,7 @@ object_spec:
$$ = $1;
$$->flags &= ~IS_CLOCKWISE;
}
- | object_spec text %prec TEXT
+ | object_spec text %prec TEXT
{
$$ = $1;
text_item **p;
@@ -1019,9 +1083,7 @@ object_spec:
text:
TEXT
- {
- $$ = $1;
- }
+ { $$ = $1; }
| SPRINTF '(' TEXT sprintf_args ')'
{
$$.filename = $3.filename;
@@ -1108,13 +1170,17 @@ between:
expr_pair:
expr ',' expr
- { $$.x = $1; $$.y = $3; }
+ {
+ $$.x = $1;
+ $$.y = $3;
+ }
| '(' expr_pair ')'
{ $$ = $2; }
;
place:
- label %prec CHOP /* line at A left == line (at A) left */
+ /* line at A left == line (at A) left */
+ label %prec CHOP
{ $$ = $1; }
| label corner
{
@@ -1154,9 +1220,7 @@ label:
a_delete $1;
}
| nth_primitive
- {
- $$.obj = $1;
- }
+ { $$.obj = $1; }
| label '.' LABEL
{
path pth($3);
@@ -1176,7 +1240,7 @@ ordinal:
;
optional_ordinal_last:
- LAST
+ LAST
{ $$ = 1; }
| ordinal LAST
{ $$ = $1; }
@@ -1238,9 +1302,7 @@ object_type:
label_path:
'.' LABEL
- {
- $$ = new path($2);
- }
+ { $$ = new path($2); }
| label_path '.' LABEL
{
$$ = $1;
@@ -1249,17 +1311,12 @@ label_path:
;
relative_path:
- corner
- {
- $$ = new path($1);
- }
+ 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 %prec TEXT
+ { $$ = $1; }
| label_path corner
{
$$ = $1;
@@ -1269,9 +1326,7 @@ relative_path:
path:
relative_path
- {
- $$ = $1;
- }
+ { $$ = $1; }
| '(' relative_path ',' relative_path ')'
{
$$ = $2;
@@ -1355,6 +1410,14 @@ 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
@@ -1444,7 +1507,7 @@ expr:
YYABORT;
}
}
- | '-' expr %prec '!'
+ | '-' expr %prec '!'
{ $$ = -$2; }
| '(' any_expr ')'
{ $$ = $2; }
@@ -1521,7 +1584,10 @@ expr:
$$ = (rand() & 0x7fff) / double(0x8000);
}
| SRAND '(' any_expr ')'
- { $$ = 0; srand((unsigned int)$3); }
+ {
+ $$ = 0;
+ srand((unsigned int)$3);
+ }
| expr '<' expr
{ $$ = ($1 < $3); }
| expr LESSEQUAL expr
@@ -1754,23 +1820,7 @@ char *format_number(const char *form, double n)
{
if (form == 0)
form = "%g";
- else {
- // this is a fairly feeble attempt at validation of the format
- int nspecs = 0;
- for (const char *p = form; *p != '\0'; p++)
- if (*p == '%') {
- if (p[1] == '%')
- p++;
- else
- nspecs++;
- }
- if (nspecs > 1) {
- lex_error("bad format `%1'", form);
- return strsave(form);
- }
- }
- sprintf(sprintf_buf, form, n);
- return strsave(sprintf_buf);
+ return do_sprintf(form, &n, 1);
}
char *do_sprintf(const char *form, const double *v, int nv)
@@ -1792,18 +1842,20 @@ char *do_sprintf(const char *form, const double *v, int nv)
if (*form == '%') {
one_format += *form++;
one_format += '\0';
- sprintf(sprintf_buf, one_format.contents());
+ snprintf(sprintf_buf, sizeof(sprintf_buf),
+ "%s", one_format.contents());
}
else {
if (i >= nv) {
- lex_error("too few arguments to sprintf");
+ lex_error("too few arguments to snprintf");
result += one_format;
result += form;
break;
}
one_format += *form++;
one_format += '\0';
- sprintf(sprintf_buf, one_format.contents(), v[i++]);
+ snprintf(sprintf_buf, sizeof(sprintf_buf),
+ one_format.contents(), v[i++]);
}
one_format.clear();
result += sprintf_buf;
diff --git a/contrib/groff/src/preproc/pic/tex.cc b/contrib/groff/src/preproc/pic/tex.cc
index 2a91b62..a9192ac 100644
--- a/contrib/groff/src/preproc/pic/tex.cc
+++ b/contrib/groff/src/preproc/pic/tex.cc
@@ -42,6 +42,10 @@ public:
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;
@@ -350,6 +354,28 @@ void tex_output::dot(const position &pos, const line_type &lt)
}
}
+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();
diff --git a/contrib/groff/src/preproc/pic/troff.cc b/contrib/groff/src/preproc/pic/troff.cc
index 62fe540..7ee7293 100644
--- a/contrib/groff/src/preproc/pic/troff.cc
+++ b/contrib/groff/src/preproc/pic/troff.cc
@@ -1,5 +1,5 @@
// -*- C++ -*-
-/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001
+/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002
Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
@@ -21,7 +21,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "pic.h"
#include "common.h"
-#include "htmlindicate.h"
const double RELATIVE_THICKNESS = -1.0;
@@ -37,6 +36,9 @@ class simple_output : public common_output {
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;
@@ -140,11 +142,10 @@ void simple_output::spline(const position &start, const position *v, int n,
void simple_output::polygon(const position *v, int n,
const line_type &lt, double fill)
{
- if (driver_extension_flag) {
- if (fill >= 0.0) {
+ if (driver_extension_flag && ((fill >= 0.0) || (get_last_filled() != 0))) {
+ if (get_last_filled() == 0)
set_fill(fill);
- simple_polygon(1, v, n);
- }
+ simple_polygon(1, v, n);
}
if (lt.type == line_type::solid && driver_extension_flag) {
line_thickness(lt.thickness);
@@ -159,8 +160,9 @@ void simple_output::polygon(const position *v, int n,
void simple_output::circle(const position &cent, double rad,
const line_type &lt, double fill)
{
- if (driver_extension_flag && fill >= 0.0) {
- set_fill(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);
@@ -184,8 +186,9 @@ void simple_output::circle(const position &cent, double rad,
void simple_output::ellipse(const position &cent, const distance &dim,
const line_type &lt, double fill)
{
- if (driver_extension_flag && fill >= 0.0) {
- set_fill(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)
@@ -212,6 +215,8 @@ class troff_output : public simple_output {
double scale;
double last_line_thickness;
double last_fill;
+ char *last_filled; // color
+ char *last_outlined; // color
public:
troff_output();
~troff_output();
@@ -229,6 +234,10 @@ public:
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 &);
};
@@ -238,7 +247,8 @@ output *make_troff_output()
}
troff_output::troff_output()
-: last_filename(0), last_line_thickness(BAD_THICKNESS), last_fill(-1.0)
+: last_filename(0), last_line_thickness(BAD_THICKNESS),
+ last_fill(-1.0), last_filled(0), last_outlined(0)
{
}
@@ -269,7 +279,6 @@ void troff_output::start_picture(double sc,
scale = compute_scale(sc, ll, ur);
height = (ur.y - ll.y)/scale;
double width = (ur.x - ll.x)/scale;
- graphic_start(0);
printf(".PS %.3fi %.3fi", height, width);
if (args)
printf(" %s\n", args);
@@ -288,6 +297,7 @@ void troff_output::finish_picture()
{
line_thickness(BAD_THICKNESS);
last_fill = -1.0; // force it to be reset for each picture
+ reset_color();
if (!flyback_flag)
printf(".sp %.3fi+1\n", height);
printf(".if \\n(" FILL_REG " .fi\n");
@@ -296,7 +306,6 @@ void troff_output::finish_picture()
// this is a little gross
set_location(current_filename, current_lineno);
fputs(flyback_flag ? ".PF\n" : ".PE\n", stdout);
- graphic_end();
}
void troff_output::command(const char *s,
@@ -472,6 +481,54 @@ void troff_output::set_fill(double f)
printf("\\D'f %du'\\h'%du'\n.sp -1\n", int(f*FILL_MAX), -int(f*FILL_MAX));
last_fill = f;
}
+ if (last_filled) {
+ free(last_filled);
+ last_filled = 0;
+ printf("\\M[]\n.sp -1\n");
+ }
+}
+
+void troff_output::set_color(char *color_fill, char *color_outlined)
+{
+ if (driver_extension_flag) {
+ if (last_filled || last_outlined) {
+ reset_color();
+ }
+ if (color_fill) {
+ printf("\\M[%s]\n.sp -1\n", color_fill);
+ last_filled = strdup(color_fill);
+ }
+ if (color_outlined) {
+ printf("\\m[%s]\n.sp -1\n", color_outlined);
+ last_outlined = strdup(color_outlined);
+ }
+ }
+}
+
+void troff_output::reset_color()
+{
+ if (driver_extension_flag) {
+ if (last_filled) {
+ printf("\\M[]\n.sp -1\n");
+ free(last_filled);
+ last_filled = 0;
+ }
+ if (last_outlined) {
+ printf("\\m[]\n.sp -1\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;
OpenPOWER on IntegriCloud