From 3c376371a6094b613d85f485d896c325c8e2acd6 Mon Sep 17 00:00:00 2001 From: Werner LEMBERG Date: Wed, 7 Jan 2004 08:28:56 +0000 Subject: [PATCH] Implement string-valued registers \n[.m] and \n[.M] to return the name of the current drawing and background color, respectively. * src/roff/troff/symbol.h: Moved to... * src/include/symbol.h: Here. Small fixes to make it work outside of the `troff' directory. * src/roff/troff/symbol.cpp: Moved to... * src/libs/libgroff/symbol.cpp: Here. Small fixes to make it work outside of the `troff' directory. * src/include/Makefile.sub (HDRS), src/libs/libgroff/Makefile.sub (OBJS, CCSRCS), src/roff/troff/Makefile.sub (OBJS, CCSRCS, HDRS): Updated. * src/include/color.h: Include symbol.h. (color): Add new field `nm'. * src/libs/libgroff/color.cpp (color::color): Updated. * src/roff/troff/dictionary.cpp, src/roff/troff/div.cpp, src/roff/troff/node.cpp, src/roff/troff/number.cpp, src/roff/troff/reg.cpp: Don't include symbol.h. * src/roff/troff/env.cpp: Don't include symbol.h. (environment::get_glyph_color_string, environment_get_fill_color_string): New member functions. (init_env_requests): Handle `.m' and `.M' registers. * src/roff/troff/input.cpp: Don't include symbol.h. (default_symbol): Moved to symbol.cpp/symbol.h. (do_glyph_color, do_fill_color, define_color): Pass symbol name to color constructor. * src/roff/troff/env.h: Updated. * NEWS, man/groff_diff.man, man/groff.man, doc/groff.texinfo: Document new registers. --- ChangeLog | 39 +++++++++++++++++++++++++++- NEWS | 3 +++ doc/groff.texinfo | 24 +++++++++++++---- man/groff.man | 12 ++++++--- man/groff_diff.man | 18 ++++++++++--- src/include/Makefile.sub | 1 + src/include/color.h | 4 ++- src/{roff/troff => include}/symbol.h | 5 +++- src/libs/libgroff/Makefile.sub | 2 ++ src/libs/libgroff/color.cpp | 5 ++-- src/{roff/troff => libs/libgroff}/symbol.cpp | 9 +++++-- src/roff/troff/Makefile.sub | 7 ++--- src/roff/troff/dictionary.cpp | 5 ++-- src/roff/troff/div.cpp | 3 +-- src/roff/troff/env.cpp | 15 +++++++++-- src/roff/troff/env.h | 4 ++- src/roff/troff/input.cpp | 12 ++++----- src/roff/troff/node.cpp | 3 +-- src/roff/troff/number.cpp | 3 +-- src/roff/troff/reg.cpp | 3 +-- 20 files changed, 134 insertions(+), 43 deletions(-) rename src/{roff/troff => include}/symbol.h (93%) rename src/{roff/troff => libs/libgroff}/symbol.cpp (95%) diff --git a/ChangeLog b/ChangeLog index b12f0342..2bce1c65 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,41 @@ -2003-01-05 Werner LEMBERG +2004-01-06 Werner LEMBERG + + Implement string-valued registers \n[.m] and \n[.M] to return the + name of the current drawing and background color, respectively. + + * src/roff/troff/symbol.h: Moved to... + * src/include/symbol.h: Here. + Small fixes to make it work outside of the `troff' directory. + * src/roff/troff/symbol.cpp: Moved to... + * src/libs/libgroff/symbol.cpp: Here. + Small fixes to make it work outside of the `troff' directory. + + * src/include/Makefile.sub (HDRS), src/libs/libgroff/Makefile.sub + (OBJS, CCSRCS), src/roff/troff/Makefile.sub (OBJS, CCSRCS, HDRS): + Updated. + + * src/include/color.h: Include symbol.h. + (color): Add new field `nm'. + * src/libs/libgroff/color.cpp (color::color): Updated. + + * src/roff/troff/dictionary.cpp, src/roff/troff/div.cpp, + src/roff/troff/node.cpp, src/roff/troff/number.cpp, + src/roff/troff/reg.cpp: Don't include symbol.h. + + * src/roff/troff/env.cpp: Don't include symbol.h. + (environment::get_glyph_color_string, + environment_get_fill_color_string): New member functions. + (init_env_requests): Handle `.m' and `.M' registers. + * src/roff/troff/input.cpp: Don't include symbol.h. + (default_symbol): Moved to symbol.cpp/symbol.h. + (do_glyph_color, do_fill_color, define_color): Pass symbol name + to color constructor. + * src/roff/troff/env.h: Updated. + + * NEWS, man/groff_diff.man, man/groff.man, doc/groff.texinfo: + Document new registers. + +2004-01-05 Werner LEMBERG * src/roff/troff/nroff.cpp (space_node::get_breakpoints, space_node::nbreaks): Protect against zero `next' field. diff --git a/NEWS b/NEWS index 83c81aea..9fc97631 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,9 @@ o If option `-V' is used more than once, the commands will be both printed Troff ----- +o Two new read-only, string-valued registers `.m' and `.M' return the + name of the current drawing and background color, respectively. + o An input encoding file for latin-5 (a.k.a. ISO 8859-9) has been added. Example use: diff --git a/doc/groff.texinfo b/doc/groff.texinfo index 02d7166c..bad38eea 100644 --- a/doc/groff.texinfo +++ b/doc/groff.texinfo @@ -23,7 +23,7 @@ @copying This manual documents GNU @code{troff} version 1.19. -Copyright @copyright{} 1994-2000, 2001, 2002, 2003 +Copyright @copyright{} 1994-2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. @quotation @@ -370,8 +370,8 @@ Software Foundation raise funds for GNU development.'' @titlepage @title groff @subtitle The GNU implementation of @code{troff} -@subtitle Edition 1.19 -@subtitle Spring 2003 +@subtitle Edition 1.19.1 +@subtitle Spring 2004 @author by Trent A.@tie{}Fisher @author and Werner Lemberg (@email{bug-groff@@gnu.org}) @@ -12217,7 +12217,8 @@ Note that @code{f} is the default scaling indicator for the @DefescList {\\m, , c, } @DefescItem {\\m, @lparen{}, co, } -@DefescListEnd {\\m, @lbrack{}, color, @rbrack} +@DefescItem {\\m, @lbrack{}, color, @rbrack} +@DefregListEnd {.m} Set drawing color. The following example shows how to turn the next four words red. @@ -12227,6 +12228,12 @@ words red. The escape @code{\m[]} returns to the previous color. +@cindex drawing color name register (@code{.m}) +@cindex name, drawing color, register (@code{.m}) +@cindex color name, drawing, register (@code{.m}) +The name of the current drawing color is available in the read-only, +string-valued number register @samp{.m}. + The drawing color is associated with the current environment (@pxref{Environments}). @@ -12242,7 +12249,8 @@ the fly: @DefescList {\\M, , c, } @DefescItem {\\M, @lparen{}, co, } -@DefescListEnd {\\M, @lbrack{}, color, @rbrack} +@DefescItem {\\M, @lbrack{}, color, @rbrack} +@DefregListEnd {.M} Set background color for filled objects drawn with the @code{\D'@dots{}'} commands. @@ -12254,6 +12262,12 @@ A red ellipse can be created with the following code: The escape @code{\M[]} returns to the previous fill color. +@cindex background color name register (@code{.M}) +@cindex name, background color, register (@code{.M}) +@cindex color name, background, register (@code{.M}) +The name of the current background color is available in the read-only, +string-valued number register @samp{.M}. + The fill color is associated with the current environment (@pxref{Environments}). diff --git a/man/groff.man b/man/groff.man index e9a63941..57adb3d6 100644 --- a/man/groff.man +++ b/man/groff.man @@ -2,11 +2,11 @@ .ig groff.man -Last update: 23 Jul 2003 +Last update: 07 Jan 2004 This file is part of groff, the GNU roff type-setting system. -Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc. +Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. written by Bernd Warken maintained by Werner Lemberg @@ -3164,6 +3164,12 @@ The title length (as set by the .request lt request). . +.REG .m +The current drawing color (string-valued). +. +.REG .M +The current background color (string-valued). +. .REG .n Length of text portion on previous output line. . @@ -3451,7 +3457,7 @@ be reproduced, and say which version of groff you are using. .SH AUTHORS .\" -------------------------------------------------------------------- . -Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc. +Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. . .P This document is distributed under the terms of the FDL (GNU Free diff --git a/man/groff_diff.man b/man/groff_diff.man index bd19db80..a9a176a2 100644 --- a/man/groff_diff.man +++ b/man/groff_diff.man @@ -3,12 +3,12 @@ .ig groff_diff.man -Last update : 23 Jul 2003 +Last update : 07 Jan 2004 This file is part of groff, the GNU roff type-setting system. It is the source of the man-page groff_diff(7). -Copyright (C) 1989, 2001, 2002, 2003 Free Software Foundation, Inc. +Copyright (C) 1989, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. written by James Clark modified by Werner Lemberg @@ -2693,6 +2693,18 @@ The title length as set by the request. . .TP +.B \[rs]n[.m] +The name of the current drawing color. +. +This is a string-valued register. +. +.TP +.B \[rs]n[.M] +The name of the current background color. +. +This is a string-valued register. +. +.TP .B \[rs]n[.ne] The amount of space that was needed in the last .B ne @@ -3680,7 +3692,7 @@ classical "device-independent" troff did. .SH AUTHORS .\" -------------------------------------------------------------------- . -Copyright (C) 1989, 2001, 2002, 2003 Free Software Foundation, Inc. +Copyright (C) 1989, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. . .P This document is distributed under the terms of the FDL (GNU Free diff --git a/src/include/Makefile.sub b/src/include/Makefile.sub index ef9c4648..a0ab6e14 100644 --- a/src/include/Makefile.sub +++ b/src/include/Makefile.sub @@ -23,6 +23,7 @@ HDRS=\ search.h \ searchpath.h \ stringclass.h \ + symbol.h \ unicode.h GENHDRS=defs.h diff --git a/src/include/color.h b/src/include/color.h index 205f70ef..2a1c62f0 100644 --- a/src/include/color.h +++ b/src/include/color.h @@ -24,6 +24,7 @@ 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 +#include "symbol.h" enum color_scheme {DEFAULT, CMY, CMYK, RGB, GRAY}; @@ -38,8 +39,9 @@ private: const size_t); public: + symbol nm; enum {MAX_COLOR_VAL = 0xffff}; - color() : scheme(DEFAULT){} + color(symbol s = default_symbol) : scheme(DEFAULT), nm(s) {} color(const color * const); ~color(); void *operator new(size_t); diff --git a/src/roff/troff/symbol.h b/src/include/symbol.h similarity index 93% rename from src/roff/troff/symbol.h rename to src/include/symbol.h index 5b7c9b19..af4a4c09 100644 --- a/src/roff/troff/symbol.h +++ b/src/include/symbol.h @@ -1,5 +1,6 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1989, 1990, 1991, 1992, 2002, 2004 + Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) This file is part of groff. @@ -78,3 +79,5 @@ inline int symbol::is_empty() const } symbol concat(symbol, symbol); + +extern symbol default_symbol; diff --git a/src/libs/libgroff/Makefile.sub b/src/libs/libgroff/Makefile.sub index 51eb84ab..b0a97518 100644 --- a/src/libs/libgroff/Makefile.sub +++ b/src/libs/libgroff/Makefile.sub @@ -35,6 +35,7 @@ OBJS=\ searchpath.$(OBJEXT) \ string.$(OBJEXT) \ strsave.$(OBJEXT) \ + symbol.$(OBJEXT) \ tmpfile.$(OBJEXT) \ tmpname.$(OBJEXT) \ unicode.$(OBJEXT) \ @@ -74,6 +75,7 @@ CCSRCS=\ $(srcdir)/searchpath.cpp \ $(srcdir)/string.cpp \ $(srcdir)/strsave.cpp \ + $(srcdir)/symbol.cpp \ $(srcdir)/tmpfile.cpp \ $(srcdir)/tmpname.cpp \ $(srcdir)/unicode.cpp \ diff --git a/src/libs/libgroff/color.cpp b/src/libs/libgroff/color.cpp index da138dc4..2a01ae5e 100644 --- a/src/libs/libgroff/color.cpp +++ b/src/libs/libgroff/color.cpp @@ -2,9 +2,9 @@ /* /src/libs/libgroff/color.cpp -Last update: 13 Apr 2003 +Last update: 07 Jan 2004 -Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc. +Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. Written by Gaius Mulley This file is part of groff. @@ -73,6 +73,7 @@ void color::operator delete(void *p) color::color(const color * const c) { + nm = c->nm; scheme = c->scheme; components[0] = c->components[0]; components[1] = c->components[1]; diff --git a/src/roff/troff/symbol.cpp b/src/libs/libgroff/symbol.cpp similarity index 95% rename from src/roff/troff/symbol.cpp rename to src/libs/libgroff/symbol.cpp index 09f4c98c..b7b3b9e9 100644 --- a/src/roff/troff/symbol.cpp +++ b/src/libs/libgroff/symbol.cpp @@ -1,5 +1,6 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2002 Free Software Foundation, Inc. +/* Copyright (C) 1989, 1990, 1991, 1992, 2002, 2004 + Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) This file is part of groff. @@ -18,8 +19,10 @@ 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 "lib.h" -#include "troff.h" +#include "errarg.h" +#include "error.h" #include "symbol.h" const char **symbol::table = 0; @@ -152,3 +155,5 @@ symbol concat(symbol s1, symbol s2) a_delete buf; return res; } + +symbol default_symbol("default"); diff --git a/src/roff/troff/Makefile.sub b/src/roff/troff/Makefile.sub index 7ecf154f..54c55e18 100644 --- a/src/roff/troff/Makefile.sub +++ b/src/roff/troff/Makefile.sub @@ -10,8 +10,7 @@ OBJS=\ majorminor.$(OBJEXT) \ node.$(OBJEXT) \ number.$(OBJEXT) \ - reg.$(OBJEXT) \ - symbol.$(OBJEXT) + reg.$(OBJEXT) CCSRCS=\ $(srcdir)/dictionary.cpp \ $(srcdir)/div.cpp \ @@ -20,8 +19,7 @@ CCSRCS=\ majorminor.cpp \ $(srcdir)/node.cpp \ $(srcdir)/number.cpp \ - $(srcdir)/reg.cpp \ - $(srcdir)/symbol.cpp + $(srcdir)/reg.cpp HDRS=\ $(srcdir)/charinfo.h \ $(srcdir)/dictionary.h \ @@ -32,7 +30,6 @@ HDRS=\ $(srcdir)/node.h \ $(srcdir)/reg.h \ $(srcdir)/request.h \ - $(srcdir)/symbol.h \ $(srcdir)/token.h \ $(srcdir)/troff.h GENSRCS=majorminor.cpp diff --git a/src/roff/troff/dictionary.cpp b/src/roff/troff/dictionary.cpp index a70ebb0e..e4cce22c 100644 --- a/src/roff/troff/dictionary.cpp +++ b/src/roff/troff/dictionary.cpp @@ -1,5 +1,6 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2001 Free Software Foundation, Inc. +/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2004 + Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) This file is part of groff. @@ -20,7 +21,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "troff.h" -#include "symbol.h" #include "dictionary.h" // is `p' a good size for a hash table @@ -209,4 +209,3 @@ int object_dictionary::alias(symbol newnm, symbol oldnm) } return 0; } - diff --git a/src/roff/troff/div.cpp b/src/roff/troff/div.cpp index 1bbbe450..df4df4f5 100644 --- a/src/roff/troff/div.cpp +++ b/src/roff/troff/div.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002 +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2004 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -23,7 +23,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // diversions #include "troff.h" -#include "symbol.h" #include "dictionary.h" #include "hvunits.h" #include "env.h" diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp index 3c7ff02e..b78ebd5c 100644 --- a/src/roff/troff/env.cpp +++ b/src/roff/troff/env.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003 +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -20,7 +20,6 @@ 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 "troff.h" -#include "symbol.h" #include "dictionary.h" #include "hvunits.h" #include "env.h" @@ -3091,6 +3090,16 @@ const char *environment::get_font_family_string() return family->nm.contents(); } +const char *environment::get_glyph_color_string() +{ + return glyph_color->nm.contents(); +} + +const char *environment::get_fill_color_string() +{ + return fill_color->nm.contents(); +} + const char *environment::get_font_name_string() { symbol f = get_font_name(fontno, this); @@ -3247,6 +3256,8 @@ void init_env_requests() init_int_env_reg(".L", get_line_spacing); init_hunits_env_reg(".l", get_line_length); init_hunits_env_reg(".ll", get_saved_line_length); + init_string_env_reg(".M", get_fill_color_string); + init_string_env_reg(".m", get_glyph_color_string); init_hunits_env_reg(".n", get_prev_text_length); init_int_env_reg(".ps", get_point_size); init_int_env_reg(".psr", get_requested_point_size); diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h index 43a4c97f..902ff037 100644 --- a/src/roff/troff/env.h +++ b/src/roff/troff/env.h @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002 +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2004 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -303,6 +303,8 @@ public: void space(); void space(hunits, hunits); void space_newline(); + const char *get_glyph_color_string(); + const char *get_fill_color_string(); const char *get_font_family_string(); const char *get_font_name_string(); const char *get_name_string(); diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp index 5ee302d0..abe54f31 100644 --- a/src/roff/troff/input.cpp +++ b/src/roff/troff/input.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003 +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -20,7 +20,6 @@ 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 "troff.h" -#include "symbol.h" #include "dictionary.h" #include "hvunits.h" #include "env.h" @@ -1039,7 +1038,6 @@ static node *do_suppress(symbol nm); static void do_register(); dictionary color_dictionary(501); -static symbol default_symbol("default"); static color *lookup_color(symbol nm) { @@ -1063,7 +1061,7 @@ void do_glyph_color(symbol nm) if (tem) curenv->set_glyph_color(tem); else - (void)color_dictionary.lookup(nm, new color); + (void)color_dictionary.lookup(nm, new color(nm)); } } @@ -1078,7 +1076,7 @@ void do_fill_color(symbol nm) if (tem) curenv->set_fill_color(tem); else - (void)color_dictionary.lookup(nm, new color); + (void)color_dictionary.lookup(nm, new color(nm)); } } @@ -1262,8 +1260,10 @@ static void define_color() skip_line(); return; } - if (col) + if (col) { + col->nm = color_name; (void)color_dictionary.lookup(color_name, col); + } skip_line(); } diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp index 35f2d60c..fd263756 100644 --- a/src/roff/troff/node.cpp +++ b/src/roff/troff/node.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003 +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -25,7 +25,6 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #endif -#include "symbol.h" #include "dictionary.h" #include "hvunits.h" #include "env.h" diff --git a/src/roff/troff/number.cpp b/src/roff/troff/number.cpp index 8fed342e..8a5c7e44 100644 --- a/src/roff/troff/number.cpp +++ b/src/roff/troff/number.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002 +/* Copyright (C) 1989, 1990, 1991, 1992, 2001, 2002, 2004 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 "troff.h" -#include "symbol.h" #include "hvunits.h" #include "env.h" #include "token.h" diff --git a/src/roff/troff/reg.cpp b/src/roff/troff/reg.cpp index 8ac20c9b..9c4b5b7c 100644 --- a/src/roff/troff/reg.cpp +++ b/src/roff/troff/reg.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001 +/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2004 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) @@ -20,7 +20,6 @@ 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 "troff.h" -#include "symbol.h" #include "dictionary.h" #include "token.h" #include "request.h" -- 2.11.4.GIT