diff options
author | wlemb <wlemb> | 2002-02-07 08:36:51 +0000 |
---|---|---|
committer | wlemb <wlemb> | 2002-02-07 08:36:51 +0000 |
commit | d0c923a77924549197bdc0721443d2234e147708 (patch) | |
tree | 7b1f728472c615aca71a84cef2ac4f55c3cef4ed | |
parent | 667abc70b96432fdeb64dd899a85b5d4ccd24e13 (diff) | |
download | groff-d0c923a77924549197bdc0721443d2234e147708.tar.gz |
Adding options -C (compatibility mode) and -c (grotty's old output
scheme) to nroff.
* src/roff/nroff/nroff.sh: Implement it.
Remove `-Wall'.
* NEWS, src/roff/nroff/nroff.man: Updated.
Implementing color support in grotty. The new switch -c activates
the old drawing scheme, disabling color at the same time. The new
switch `-i' selects italic instead of underlining (SGR only).
* src/devices/grotty/tty.cc (putstring): New define instead of
`fputs'. Updated all callers.
(old_drawing_scheme): New global variable.
(COLOR_CHANGE): New enum value.
(SGR_*): New defines containing color handling escape sequences.
(TTY_MAX_COLORS, DEFAULT_COLOR_IDX): New defines.
(glyph): New members `back_color_idx' and `fore_color_idx'.
(glyph::order): Add COLOR_CHANGE.
(tty_printer): New members `cur_fore_idx', `curr_back_idx',
`is_underline', `is_bold', `cu_flag', `tty_colors'.
New methods `make_underline', `make_bold', `color_to_idx',
`change_color', `put_color'.
(cu_flag): Moved into `tty_printer' class.
(tty_printer::tty_printer): Initialize colors.
(tty_printer::add_char, tty_printer::set_char, tty_printer::special,
tty_printer::draw, tty_printer::end_page): Handle colors also.
(main): Add options `-c' and `-i'.
(usage): Updated.
* NEWS, src/devices/grotty/grotty.man: Updated.
* src/include/errarg.h (errarg): Add support for `unsigned int'.
* src/libs/libgroff/errarg.c: Implement it.
* src/include/printer.h (printer): Add `change_color' method
(currently used by grotty only).
* src/libs/libdriver/printer.cc: Implement it.
* src/libs/libdriver/input.cc (parse_D_command, do_file): Add
call to `pr->change_color'.
* src/roff/troff/node.cc (troff_output_file::fill_color,
troff_output_file::glyph_color): Call `do_motion'.
* tmac/tty.tmac: Add color definitions.
* src/roff/groff/groff.man: Minor fixes.
-rw-r--r-- | ChangeLog | 54 | ||||
-rw-r--r-- | NEWS | 50 | ||||
-rw-r--r-- | man/roff.man | 3 | ||||
-rw-r--r-- | src/devices/grotty/grotty.man | 201 | ||||
-rw-r--r-- | src/devices/grotty/tty.cc | 264 | ||||
-rw-r--r-- | src/include/errarg.h | 7 | ||||
-rw-r--r-- | src/include/printer.h | 4 | ||||
-rw-r--r-- | src/libs/libdriver/input.cc | 2 | ||||
-rw-r--r-- | src/libs/libdriver/printer.cc | 12 | ||||
-rw-r--r-- | src/libs/libgroff/errarg.cc | 20 | ||||
-rw-r--r-- | src/roff/groff/groff.man | 18 | ||||
-rw-r--r-- | src/roff/nroff/nroff.man | 20 | ||||
-rw-r--r-- | src/roff/nroff/nroff.sh | 15 | ||||
-rw-r--r-- | src/roff/troff/node.cc | 4 | ||||
-rw-r--r-- | tmac/tty.tmac | 9 |
15 files changed, 558 insertions, 125 deletions
@@ -1,3 +1,54 @@ +2002-02-07 Werner LEMBERG <wl@gnu.org> + + Adding options -C (compatibility mode) and -c (grotty's old output + scheme) to nroff. + + * src/roff/nroff/nroff.sh: Implement it. + Remove `-Wall'. + * NEWS, src/roff/nroff/nroff.man: Updated. + +2002-02-06 Werner LEMBERG <wl@gnu.org> + + Implementing color support in grotty. The new switch -c activates + the old drawing scheme, disabling color at the same time. The new + switch `-i' selects italic instead of underlining (SGR only). + + * src/devices/grotty/tty.cc (putstring): New define instead of + `fputs'. Updated all callers. + (old_drawing_scheme): New global variable. + (COLOR_CHANGE): New enum value. + (SGR_*): New defines containing color handling escape sequences. + (TTY_MAX_COLORS, DEFAULT_COLOR_IDX): New defines. + (glyph): New members `back_color_idx' and `fore_color_idx'. + (glyph::order): Add COLOR_CHANGE. + (tty_printer): New members `cur_fore_idx', `curr_back_idx', + `is_underline', `is_bold', `cu_flag', `tty_colors'. + New methods `make_underline', `make_bold', `color_to_idx', + `change_color', `put_color'. + (cu_flag): Moved into `tty_printer' class. + (tty_printer::tty_printer): Initialize colors. + (tty_printer::add_char, tty_printer::set_char, tty_printer::special, + tty_printer::draw, tty_printer::end_page): Handle colors also. + (main): Add options `-c' and `-i'. + (usage): Updated. + * NEWS, src/devices/grotty/grotty.man: Updated. + + * src/include/errarg.h (errarg): Add support for `unsigned int'. + * src/libs/libgroff/errarg.c: Implement it. + + * src/include/printer.h (printer): Add `change_color' method + (currently used by grotty only). + * src/libs/libdriver/printer.cc: Implement it. + * src/libs/libdriver/input.cc (parse_D_command, do_file): Add + call to `pr->change_color'. + + * src/roff/troff/node.cc (troff_output_file::fill_color, + troff_output_file::glyph_color): Call `do_motion'. + + * tmac/tty.tmac: Add color definitions. + + * src/roff/groff/groff.man: Minor fixes. + 2002-02-05 Bernd Warken <bwarken@mayn.de> * src/libs/libdriver/input.cc: Introduce `EnvInt' typedef and use @@ -9,6 +60,9 @@ where leading spaces are followed by \f or \s; previously, an incorrect space width has been used. + * doc/roff.man (quoted_char): Fix argument. + (comment): Define string. + 2002-02-04 Larry Kollar <kollar@alltel.net> * doc/groff.texinfo: More fixes. @@ -7,14 +7,14 @@ VERSION 1.18 Troff ----- -o Color support has been added to troff and pic (and to two device drivers, - grops and grohtml -- other preprocessors and drivers will follow). A new - function `defcolor' defines colors; the escape sequence `\m' sets the - drawing color, the escape sequence `\M' specifies the background color for - closed objects created with \D'...' commands. Similar to fonts, `\mP' and - `\MP' switch back to the previous color. `\m' and `\M' correspond to the - new troff output commands `m' and `DF'. The device-specific default color - is called `default' and can't be redefined. +o Color support has been added to troff and pic (and to the device drivers + grops, grotty, and grohtml -- other preprocessors and drivers will + follow). A new function `defcolor' defines colors; the escape sequence + `\m' sets the drawing color, the escape sequence `\M' specifies the + background color for closed objects created with \D'...' commands. + Similar to fonts, `\mP' and `\MP' switch back to the previous color. `\m' + and `\M' correspond to the new troff output commands `m' and `DF'. The + device-specific default color is called `default' and can't be redefined. Outputting color can be disabled in troff and groff with the option -c (it is always disabled in compatibility mode). @@ -100,6 +100,13 @@ Groff o The new command line option `-c' disables color output (which is always disabled in compatibility mode). +Nroff +----- + +o Two new command line options `-c' and `-C'; the former passes `-c' to + grotty (switching to the old output scheme); the latter passes `-C' to + groff (enabling compatibility mode). + Pic --- @@ -132,6 +139,33 @@ Grops o Color support has been added. + +Grotty +------ + +o Color support has been added, using the SGR (ISO 6429, sometimes called + ANSI color) escape sequences. + +o SGR escape sequences are now used by default for underlining and bold + printing also, no longer using the backspace character trick. To revert + to the old behaviour, use the `-c' switch. + + Note that you have to use the `-R' option of `less' to make SGR escapes + display correctly. On the other hand, terminal programs and consoles like + `xterm' which support SGR sequences natively can directly display the + output of grotty. Consequently, the options `-b', `-B', `-u', and `-U' + work only in combination with `-c' and are ignored silently otherwise. + + For the `man' program, it may be necessary to add the `-R' option of + `less' to the $PAGER environment variable; alternatively, you can use + `man's `-P' option (or adapt its configuration file accordingly). See + man(1) for more details. + +o If the new option `-i' is used (only in SGR mode), grotty sends escape + sequences to set the italic font attribute instead of the underline + attribute for italic fonts. Note that many terminals don't have support + for this (including xterm). + Grohtml ------- diff --git a/man/roff.man b/man/roff.man index 280b8f00..f700137d 100644 --- a/man/roff.man +++ b/man/roff.man @@ -62,7 +62,7 @@ FDL in the main directory of the groff source package. .de quoted_char . ds @1 \$1 . shift -. nop `\fB\*[@arg1]\fP'\$* +. nop `\fB\*[@1]\fP'\$* . rm @1 .. .de ShellCommand @@ -78,6 +78,7 @@ FDL in the main directory of the groff source package. . TP 2m . Text \[bu] .. +.ds comment \[rs]" .ec .\" End of macro definitions . diff --git a/src/devices/grotty/grotty.man b/src/devices/grotty/grotty.man index 4f23ca02..27195763 100644 --- a/src/devices/grotty/grotty.man +++ b/src/devices/grotty/grotty.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,22 +16,28 @@ versions, except that this permission notice may be included in translations approved by the Free Software Foundation instead of in the original English. .. +. +. .TH GROTTY @MAN1EXT@ "@MDATE@" "Groff Version @VERSION@" .SH NAME grotty \- groff driver for typewriter-like devices +. +. .SH SYNOPSIS .B grotty [ -.B \-hfbuodBUv +.B \-bBcdfhiouUv ] [ .BI \-F dir ] [ -.IR files \|.\|.\|. +.IR files \|.\|.\|.\& ] .PP It is possible to have whitespace between the .B \-F option and its parameter. +. +. .SH DESCRIPTION .B grotty translates the output of GNU @@ -60,21 +66,72 @@ will also cause to read the standard input. Output is written to the standard output. .LP -Normally +By default, .B grotty -prints a bold character +emits SGR escape sequences (from ISO 6429, also called ANSI color escapes) +to change text attributes (bold, italic, colors). +This makes it possible to have have eight different \M[green]background\M[P] +and \m[red]foreground\m[P] colors; additionally, bold and italic +attributes can be used \f[BI]at the same time\f[P] (by using the BI font). +.LP +The following colors are defined in +.BR tty.tmac : +black, white, red, green, blue, yellow, magenta, cyan. +Unknown colors are mapped to the default color (which is dependent on the +settings of the terminal; in most cases, this is black for the foreground +and white for the background). +.LP +Use the +.B \-c +switch to revert to the old behaviour, printing a bold character .I c -using the sequence +with the sequence .RI ` c .SM BACKSPACE .IR c ' -and a italic character +and an italic character .I c by the sequence .RB ` _ .SM BACKSPACE .IR c '. -These sequences can be displayed on a terminal +At the same time, color output is disabled. +.LP +For SGR support, it is necessary to use the +.B \-R +option of +.BR less (1) +to disable the interpretation of +.BR grotty 's +old output format. +Consequently, all programs which use +.B less +as the pager program have to pass this option to it. +For +.BR man (1) +in particular, either add +.B \-R +to the +.B $PAGER +environment variable, e.g.\& +.RS +.LP +.B PAGER="/usr/bin/less -R" +.br +.B export PAGER +.RE +.LP +or use the +.B \-P +option of +.B man +to set the pager executable and its options, or modify the configuration +file of +.B man +in a similar fashion. +.LP +.BR grotty 's +old output format can be displayed on a terminal by piping through .BR ul (1). Pagers such as @@ -114,11 +171,58 @@ then it will be treated as a bold font. The code field in the font description field gives the code which will be used to output the character. This code can also be used in the -.B \eN +.B \[rs]N escape sequence in .BR troff . +. +. .SH OPTIONS .TP +.B \-b +Suppress the use of overstriking for bold characters. +Ignored if +.B \-c +isn't used. +. +.TP +.B \-B +Use only overstriking for bold-italic characters. +Ignored if +.B \-c +isn't used. +. +.TP +.B \-c +Use +.BR grotty 's +old output format (see above). +This also disables color output. +. +.TP +.B \-d +Ignore all +.B \[rs]D +commands. +Without this +.B grotty +will render +.B \[rs]D'l\|.\|.\|.\&' +commands that have at least one zero argument +(and so are either horizontal or vertical) +using +.BR \- , +.BR | , +and +.B + +characters. +. +.TP +.B \-f +Use form feeds in the output. +A form feed will be output at the end of each page that has no output +on its last line. +. +.TP .BI \-F dir Prepend directory .IB dir /dev name @@ -134,52 +238,48 @@ or .B \-h Use horizontal tabs in the output. Tabs are assumed to be set every 8 columns. +. .TP -.B \-f -Use form feeds in the output. -A form feed will be output at the end of each page that has no output -on its last line. +.B \-i +Use escape sequences to set the italic text attribute instead of the +underline attribute for italic fonts (`I' and `BI'). +Note that most terminals (including xterm) don't support this. +Ignored if +.B \-c +is active. +. .TP -.B \-b -Suppress the use of overstriking for bold characters. +.B \-o +Suppress overstriking (other than for bold or underlined characters in +case the old output format has been activated with +.BR \-c ). +. .TP .B \-u Suppress the use of underlining for italic characters. -.TP -.B \-B -Use only overstriking for bold-italic characters. +Ignored if +.B \-c +isn't used. +. .TP .B \-U Use only underlining for bold-italic characters. -.TP -.B \-o -Suppress overstriking (other than for bold or underlined characters). -.TP -.B \-d -Ignore all -.B \eD -commands. -Without this -.B grotty -will render -.B \eD'l\|.\|.\|.' -commands that have at least at least one zero argument -(and so are either horizontal or vertical) -using -.BR \- , -.B | -and -.B + -characters. +Ignored if +.B \-c +isn't used. +. .TP .B \-v Print the version number. +. +. .SH FILES .TP .B @FONTDIR@/devascii/DESC Device description file for .B ascii device. +. .TP .BI @FONTDIR@/devascii/ F Font description file for font @@ -187,11 +287,13 @@ Font description file for font of .B ascii device. +. .TP .B @FONTDIR@/devlatin1/DESC Device description file for .B latin1 device. +. .TP .BI @FONTDIR@/devlatin1/ F Font description file for font @@ -199,11 +301,13 @@ Font description file for font of .B latin1 device. +. .TP .B @FONTDIR@/devutf8/DESC Device description file for .B utf8 device. +. .TP .BI @FONTDIR@/devutf8/ F Font description file for font @@ -211,11 +315,13 @@ Font description file for font of .B utf8 device. +. .TP .B @FONTDIR@/devcp1047/DESC Device description file for .B cp1047 device. +. .TP .BI @FONTDIR@/devcp1047/ F Font description file for font @@ -223,10 +329,12 @@ Font description file for font of .B cp1047 device. +. .TP .B @MACRODIR@/tty.tmac Macros for use with .BR grotty . +. .TP .B @MACRODIR@/tty-char.tmac Additional klugdey character definitions for use with @@ -235,6 +343,8 @@ Additional klugdey character definitions for use with Note that on EBCDIC hosts, only files for the .B cp1047 device will be installed. +. +. .SH BUGS .LP .B grotty @@ -243,12 +353,22 @@ is intended only for simple documents. There is no support for fractional horizontal or vertical motions. .LP There is no support for -.B \eD +.B \[rs]D commands other than horizontal and vertical lines. .LP -Characters above the first line (ie with a vertical position of 0) +Characters above the first line (ie with a vertical position of\~0) cannot be printed. +.LP +Color handling is different compared to +.BR grops (@MAN1EXT@). +.B \[rs]M +doesn't set the fill color for closed graphic objects (which +.B grotty +doesn't support anyway) but changes the background color of the character +cell, affecting all subsequent operations. +. +. .SH "SEE ALSO" .BR groff (@MAN1EXT@), .BR @g@troff (@MAN1EXT@), @@ -257,6 +377,7 @@ cannot be printed. .BR groff_char (@MAN7EXT@), .BR ul (1), .BR more (1), +.BR man (1), .BR less (1) . .\" Local Variables: diff --git a/src/devices/grotty/tty.cc b/src/devices/grotty/tty.cc index d13adbfe..674e6051 100644 --- a/src/devices/grotty/tty.cc +++ b/src/devices/grotty/tty.cc @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989-2000, 2001 Free Software Foundation, Inc. +/* Copyright (C) 1989-2000, 2001, 2002 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) This file is part of groff. @@ -23,6 +23,8 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ extern "C" const char *Version_string; +#define putstring(s) fputs(s, stdout) + #ifndef SHRT_MIN #define SHRT_MIN (-32768) #endif @@ -39,18 +41,34 @@ static int bold_flag = 1; static int underline_flag = 1; static int overstrike_flag = 1; static int draw_flag = 1; +static int italic_flag = 0; +static int old_drawing_scheme = 0; enum { UNDERLINE_MODE = 0x01, BOLD_MODE = 0x02, VDRAW_MODE = 0x04, HDRAW_MODE = 0x08, - CU_MODE = 0x10 + CU_MODE = 0x10, + COLOR_CHANGE = 0x20 }; // Mode to use for bold-underlining. static unsigned char bold_underline_mode = BOLD_MODE|UNDERLINE_MODE; +// SGR handling (ISO 6429) +#define SGR_BOLD "\033[1m" +#define SGR_NO_BOLD "\033[22m" +#define SGR_ITALIC "\033[3m" +#define SGR_NO_ITALIC "\033[23m" +#define SGR_UNDERLINE "\033[4m" +#define SGR_NO_UNDERLINE "\033[24m" +#define SGR_DEFAULT_COLOR "\033[39m" +#define SGR_BACK_DEFAULT_COLOR "\033[49m" + +#define TTY_MAX_COLORS 8 +#define DEFAULT_COLOR_IDX TTY_MAX_COLORS + class tty_font : public font { tty_font(const char *); unsigned char mode; @@ -109,10 +127,13 @@ public: short hpos; unsigned int code; unsigned char mode; + unsigned char back_color_idx; + unsigned char fore_color_idx; void *operator new(size_t); void operator delete(void *); inline int draw_mode() { return mode & (VDRAW_MODE|HDRAW_MODE); } - inline int order() { return mode & (VDRAW_MODE|HDRAW_MODE|CU_MODE); } + inline int order() { + return mode & (VDRAW_MODE|HDRAW_MODE|CU_MODE|COLOR_CHANGE); } }; glyph *glyph::free_list = 0; @@ -146,14 +167,25 @@ class tty_printer : public printer { int nlines; int cached_v; int cached_vpos; - void add_char(unsigned int, int, int, unsigned char); + unsigned char curr_fore_idx; + unsigned char curr_back_idx; + int is_underline; + int is_bold; + int cu_flag; + color tty_colors[TTY_MAX_COLORS]; + void make_underline(); + void make_bold(unsigned int); + unsigned char color_to_idx(color *col); + void add_char(unsigned int, int, int, color *, color *, unsigned char); public: tty_printer(const char *device); ~tty_printer(); void set_char(int, font *, const environment *, int, const char *name); void draw(int code, int *p, int np, const environment *env); void special(char *arg, const environment *env, char type); + void change_color(const environment *env); void put_char(unsigned int); + void put_color(unsigned char, int); void begin_page(int) { } void end_page(int page_length); font *make_font(const char *); @@ -162,10 +194,35 @@ public: tty_printer::tty_printer(const char *device) : cached_v(0) { is_utf8 = !strcmp(device, "utf8"); + tty_colors[0].set_rgb(0, // black + 0, + 0); + tty_colors[1].set_rgb(color::MAX_COLOR_VAL, // red + 0, + 0); + tty_colors[2].set_rgb(0, // green + color::MAX_COLOR_VAL, + 0); + tty_colors[3].set_rgb(color::MAX_COLOR_VAL, // yellow + color::MAX_COLOR_VAL, + 0); + tty_colors[4].set_rgb(0, // blue + 0, + color::MAX_COLOR_VAL); + tty_colors[5].set_rgb(color::MAX_COLOR_VAL, // magenta + 0, + color::MAX_COLOR_VAL); + tty_colors[6].set_rgb(0, // cyan + color::MAX_COLOR_VAL, + color::MAX_COLOR_VAL); + tty_colors[7].set_rgb(color::MAX_COLOR_VAL, // white + color::MAX_COLOR_VAL, + color::MAX_COLOR_VAL); nlines = 66; lines = new glyph *[nlines]; for (int i = 0; i < nlines; i++) lines[i] = 0; + cu_flag = 0; } tty_printer::~tty_printer() @@ -173,15 +230,64 @@ tty_printer::~tty_printer() a_delete lines; } +void tty_printer::make_underline() +{ + if (old_drawing_scheme) { + putchar('_'); + putchar('\b'); + } + else { + if (!is_underline) { + if (italic_flag) + putstring(SGR_ITALIC); + else + putstring(SGR_UNDERLINE); + } + is_underline = 1; + } +} + +void tty_printer::make_bold(unsigned int c) +{ + if (old_drawing_scheme) { + put_char(c); + putchar('\b'); + } + else { + if (!is_bold) + putstring(SGR_BOLD); + is_bold = 1; + } +} + +unsigned char tty_printer::color_to_idx(color *col) +{ + if (col->is_default()) + return DEFAULT_COLOR_IDX; + for (int i = 0; i < TTY_MAX_COLORS; i++) + if (*col == tty_colors[i]) + return (unsigned char)i; + unsigned r, g, b; + col->get_rgb(&r, &g, &b); + error("Unknown color (%1, %2, %3) mapped to default", r, g, b); + return DEFAULT_COLOR_IDX; +} + void tty_printer::set_char(int i, font *f, const environment *env, int w, const char *name) { if (w != font::hor) fatal("width of character not equal to horizontal resolution"); - add_char(f->get_code(i), env->hpos, env->vpos, ((tty_font *)f)->get_mode()); + add_char(f->get_code(i), + env->hpos, env->vpos, + env->col, env->fill, + ((tty_font *)f)->get_mode()); } -void tty_printer::add_char(unsigned int c, int h, int v, unsigned char mode) +void tty_printer::add_char(unsigned int c, + int h, int v, + color *fore, color *back, + unsigned char mode) { #if 0 // This is too expensive. @@ -221,12 +327,14 @@ void tty_printer::add_char(unsigned int c, int h, int v, unsigned char mode) glyph *g = new glyph; g->hpos = hpos; g->code = c; + g->fore_color_idx = color_to_idx(fore); + g->back_color_idx = color_to_idx(back); g->mode = mode; // The list will be reversed later. After reversal, it must be in - // increasing order of hpos, with CU specials before HDRAW characters - // before VDRAW characters before normal characters at each hpos, and - // otherwise in order of occurrence. + // increasing order of hpos, with COLOR_CHANGE and CU specials before + // HDRAW characters before VDRAW characters before normal characters + // at each hpos, and otherwise in order of occurrence. glyph **pp; for (pp = lines + (vpos - 1); *pp; pp = &(*pp)->next) @@ -240,7 +348,12 @@ void tty_printer::add_char(unsigned int c, int h, int v, unsigned char mode) void tty_printer::special(char *arg, const environment *env, char type) { if (type == 'u') - add_char(*arg - '0', env->hpos, env->vpos, CU_MODE); + add_char(*arg - '0', env->hpos, env->vpos, env->col, env->fill, CU_MODE); +} + +void tty_printer::change_color(const environment *env) +{ + add_char(0, env->hpos, env->vpos, env->col, env->fill, COLOR_CHANGE); } void tty_printer::draw(int code, int *p, int np, const environment *env) @@ -260,7 +373,7 @@ void tty_printer::draw(int code, int *p, int np, const environment *env) len = -len; } while (len >= 0) { - add_char('|', env->hpos, v, VDRAW_MODE); + add_char('|', env->hpos, v, env->col, env->fill, VDRAW_MODE); len -= font::vert; v += font::vert; } @@ -274,7 +387,7 @@ void tty_printer::draw(int code, int *p, int np, const environment *env) len = -len; } while (len >= 0) { - add_char('-', h, env->vpos, HDRAW_MODE); + add_char('-', h, env->vpos, env->col, env->fill, HDRAW_MODE); len -= font::hor; h += font::hor; } @@ -302,14 +415,24 @@ void tty_printer::put_char(unsigned int wc) do *++p = (unsigned char)(((wc >> (6 * --count)) & 0x3f) | 0x80); while (count > 0); *++p = '\0'; - fputs(buf, stdout); + putstring(buf); } - else { + else putchar(wc); - } } -int cu_flag = 0; +void tty_printer::put_color(unsigned char color_index, int back) +{ + if (color_index == DEFAULT_COLOR_IDX) + color_index = 9; + putstring("\033["); + if (back) + putchar('4'); + else + putchar('3'); + putchar(color_index + '0'); + putchar('m'); +} void tty_printer::end_page(int page_length) { @@ -345,6 +468,10 @@ void tty_printer::end_page(int page_length) } int hpos = 0; glyph *nextp; + curr_fore_idx = DEFAULT_COLOR_IDX; + curr_back_idx = DEFAULT_COLOR_IDX; + is_underline = 0; + is_bold = 0; for (p = g; p; delete p, p = nextp) { nextp = p->next; if (p->mode & CU_MODE) { @@ -376,34 +503,88 @@ void tty_printer::end_page(int page_length) int next_tab_pos = ((hpos + TAB_WIDTH) / TAB_WIDTH) * TAB_WIDTH; if (next_tab_pos > p->hpos) break; - if (cu_flag) { - putchar('_'); - putchar('\b'); + if (cu_flag) + make_underline(); + else if (!old_drawing_scheme && is_underline) { + if (italic_flag) + putstring(SGR_NO_ITALIC); + else + putstring(SGR_NO_UNDERLINE); + is_underline = 0; } putchar('\t'); hpos = next_tab_pos; } } for (; hpos < p->hpos; hpos++) { - if (cu_flag) { - putchar('_'); - putchar('\b'); + if (cu_flag) + make_underline(); + else if (!old_drawing_scheme && is_underline) { + if (italic_flag) + putstring(SGR_NO_ITALIC); + else + putstring(SGR_NO_UNDERLINE); + is_underline = 0; } putchar(' '); } } assert(hpos == p->hpos); - if (p->mode & UNDERLINE_MODE) { - putchar('_'); - putchar('\b'); + if (p->mode & COLOR_CHANGE) { + if (!old_drawing_scheme) { + if (p->fore_color_idx != curr_fore_idx) { + put_color(p->fore_color_idx, 0); + curr_fore_idx = p->fore_color_idx; + } + if (p->back_color_idx != curr_back_idx) { + put_color(p->back_color_idx, 1); + curr_back_idx = p->back_color_idx; + } + } + continue; + } + if (p->mode & UNDERLINE_MODE) + make_underline(); + else if (!old_drawing_scheme && is_underline) { + if (italic_flag) + putstring(SGR_NO_ITALIC); + else + putstring(SGR_NO_UNDERLINE); + is_underline = 0; } - if (p->mode & BOLD_MODE) { - put_char(p->code); - putchar('\b'); + if (p->mode & BOLD_MODE) + make_bold(p->code); + else if (!old_drawing_scheme && is_bold) { + putstring(SGR_NO_BOLD); + is_bold = 0; + } + if (!old_drawing_scheme) { + if (p->fore_color_idx != curr_fore_idx) { + put_color(p->fore_color_idx, 0); + curr_fore_idx = p->fore_color_idx; + } + if (p->back_color_idx != curr_back_idx) { + put_color(p->back_color_idx, 1); + curr_back_idx = p->back_color_idx; + } } put_char(p->code); hpos++; } + if (!old_drawing_scheme) { + if (is_underline) { + if (italic_flag) + putstring(SGR_NO_ITALIC); + else + putstring(SGR_NO_UNDERLINE); + } + if (is_bold) + putstring(SGR_NO_BOLD); + if (curr_fore_idx != DEFAULT_COLOR_IDX) + putstring(SGR_DEFAULT_COLOR); + if (curr_back_idx != DEFAULT_COLOR_IDX) + putstring(SGR_BACK_DEFAULT_COLOR); + } putchar('\n'); } if (form_feed_flag) { @@ -439,19 +620,25 @@ int main(int argc, char **argv) { "version", no_argument, 0, 'v' }, { NULL, 0, 0, 0 } }; - while ((c = getopt_long(argc, argv, "F:vhfbuoBUd", long_options, NULL)) + while ((c = getopt_long(argc, argv, "F:vhfbciuoBUd", long_options, NULL)) != EOF) switch(c) { case 'v': - { - printf("GNU grotty (groff) version %s\n", Version_string); - exit(0); - break; - } + printf("GNU grotty (groff) version %s\n", Version_string); + exit(0); + break; + case 'i': + // Use italic font instead of underlining. + italic_flag = 1; + break; case 'b': // Do not embolden by overstriking. bold_flag = 0; break; + case 'c': + // Use old scheme for emboldening and underline. + old_drawing_scheme = 1; + break; case 'u': // Do not underline. underline_flag = 0; @@ -493,6 +680,13 @@ int main(int argc, char **argv) default: assert(0); } + if (old_drawing_scheme) + italic_flag = 0; + else { + bold_underline_mode = BOLD_MODE|UNDERLINE_MODE; + bold_flag = 1; + underline_flag = 1; + } if (optind >= argc) do_file("-"); else { @@ -505,6 +699,6 @@ int main(int argc, char **argv) static void usage(FILE *stream) { - fprintf(stream, "usage: %s [-hfvbuodBU] [-F dir] [files ...]\n", + fprintf(stream, "usage: %s [-hfvbciuodBU] [-F dir] [files ...]\n", program_name); } diff --git a/src/include/errarg.h b/src/include/errarg.h index 0c7957c8..08af44ae 100644 --- a/src/include/errarg.h +++ b/src/include/errarg.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. @@ -19,10 +19,11 @@ with groff; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ class errarg { - enum { EMPTY, STRING, CHAR, INTEGER, DOUBLE } type; + enum { EMPTY, STRING, CHAR, INTEGER, UNSIGNED_INTEGER, DOUBLE } type; union { const char *s; int n; + unsigned int u; char c; double d; }; @@ -32,6 +33,7 @@ class errarg { errarg(char); errarg(unsigned char); errarg(int); + errarg(unsigned int); errarg(double); int empty() const; void print() const; @@ -43,4 +45,3 @@ extern void errprint(const char *, const errarg &arg1 = empty_errarg, const errarg &arg2 = empty_errarg, const errarg &arg3 = empty_errarg); - diff --git a/src/include/printer.h b/src/include/printer.h index 8ad8e719..726277b9 100644 --- a/src/include/printer.h +++ b/src/include/printer.h @@ -1,5 +1,6 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2001 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. @@ -54,6 +55,7 @@ public: int *widthp, font **f); font *get_font_from_index(int fontno); virtual void draw(int code, int *p, int np, const environment *env); + virtual void change_color(const environment *env); virtual void begin_page(int) = 0; virtual void end_page(int page_length) = 0; virtual font *make_font(const char *nm); diff --git a/src/libs/libdriver/input.cc b/src/libs/libdriver/input.cc index 5dfb713f..c5758252 100644 --- a/src/libs/libdriver/input.cc +++ b/src/libs/libdriver/input.cc @@ -1352,6 +1352,7 @@ parse_D_command() } case 'F': // DF: set fill color, several formats parse_color_command(current_env->fill); + pr->change_color(current_env); // no positioning (setting-only command) skip_line_x(); break; @@ -1704,6 +1705,7 @@ do_file(const char *filename) break; case 'm': // m: glyph color parse_color_command(current_env->col); + pr->change_color(current_env); break; case 'n': // n: print end of line // ignore two arguments (historically) diff --git a/src/libs/libdriver/printer.cc b/src/libs/libdriver/printer.cc index 171ee9fd..922f0b5f 100644 --- a/src/libs/libdriver/printer.cc +++ b/src/libs/libdriver/printer.cc @@ -1,5 +1,6 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992, 2001 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. @@ -105,6 +106,10 @@ void printer::draw(int, int *, int, const environment *) { } +void printer::change_color(const environment *) +{ +} + void printer::set_ascii_char(unsigned char c, const environment *env, int *widthp) { @@ -126,13 +131,12 @@ void printer::set_special_char(const char *nm, const environment *env, int *widthp) { font *f; - int w; + int w; int i = set_char_and_width(nm, env, &w, &f); if (i != -1) { set_char(i, f, env, w, nm); - if (widthp) { + if (widthp) *widthp = w; - } } } diff --git a/src/libs/libgroff/errarg.cc b/src/libs/libgroff/errarg.cc index f8075ea7..2ddc0cc5 100644 --- a/src/libs/libgroff/errarg.cc +++ b/src/libs/libgroff/errarg.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. @@ -31,14 +32,14 @@ errarg::errarg() : type(EMPTY) { } -errarg::errarg(unsigned char cc) : type(CHAR) +errarg::errarg(int nn) : type(INTEGER) { - c = cc; + n = nn; } -errarg::errarg(int nn) : type(INTEGER) +errarg::errarg(unsigned int uu) : type(UNSIGNED_INTEGER) { - n = nn; + u = uu; } errarg::errarg(char cc) : type(CHAR) @@ -46,6 +47,11 @@ errarg::errarg(char cc) : type(CHAR) c = cc; } +errarg::errarg(unsigned char cc) : type(CHAR) +{ + c = cc; +} + errarg::errarg(double dd) : type(DOUBLE) { d = dd; @@ -58,6 +64,7 @@ int errarg::empty() const extern "C" { const char *i_to_a(int); + const char *ui_to_a(unsigned int); } void errarg::print() const @@ -66,6 +73,9 @@ void errarg::print() const case INTEGER: fputs(i_to_a(n), stderr); break; + case UNSIGNED_INTEGER: + fputs(ui_to_a(u), stderr); + break; case CHAR: putc(c, stderr); break; diff --git a/src/roff/groff/groff.man b/src/roff/groff/groff.man index 96b761b8..648177a1 100644 --- a/src/roff/groff/groff.man +++ b/src/roff/groff/groff.man @@ -678,7 +678,7 @@ format a file. .P The .BR \%groffer (@MAN1EXT@) -program is an allround-viewer for groff files and man-pages. +program is an allround-viewer for groff files and man pages. . . .\" -------------------------------------------------------------------- @@ -738,7 +738,7 @@ Actually, the following macro packages come with . .TP .B man -The traditional man-page format; see +The traditional man page format; see .BR \%groff_man (@MAN7EXT@). It can be specified on the command line as .ShortOpt man @@ -748,7 +748,7 @@ or . .TP .B mandoc -The general package for man-pages; it automatically recognizes +The general package for man pages; it automatically recognizes whether the documents uses the .I man or the @@ -763,7 +763,7 @@ or . .TP .B mdoc -The BSD-style man-page format; see +The BSD-style man page format; see .BR \%groff_mdoc (@MAN7EXT@). It can be specified on the command line as .ShortOpt mdoc @@ -1018,7 +1018,7 @@ Create font description files for PostScript device. . .TP .BR \%groffer (@MAN1EXT@) -General viewer program for groff files and man-pages. +General viewer program for groff files and man pages. . .TP .BR \%gxditview (@MAN1EXT@) @@ -1363,7 +1363,7 @@ for reporting bugs, for general discussion of groff, . .TP -.URL "" mailto:groff-commit@ffii.org +.MAILTO groff-commit@ffii.org a read-only list showing logs of commitments to the CVS repository. . .P @@ -1399,7 +1399,7 @@ available on-line at the .URL "GNU copyleft site" http://\:www.gnu.org/\:copyleft/\:fdl.html . . .P -This document is based on the original groff man-page written by +This document is based on the original groff man page written by .MAILTO jjc@jclark.com "James Clark" . . It was rewritten, enhanced, and put under the FDL license by @@ -1437,7 +1437,7 @@ See on how to read it. . .P -Due to its complex structure, the groff system has many man-pages. +Due to its complex structure, the groff system has many man pages. . They can be read with .BR man (1) @@ -1508,7 +1508,7 @@ Groff macro packages and macro-specific utilities: .BR \%mmroff (@MAN7EXT@). . .TP -The following utilities are available +The following utilities are available: .BR \%addftinfo (@MAN1EXT@), .BR \%afmtodit (@MAN1EXT@), .BR \%groffer (@MAN1EXT@), diff --git a/src/roff/nroff/nroff.man b/src/roff/nroff/nroff.man index fade08ef..eb070b0e 100644 --- a/src/roff/nroff/nroff.man +++ b/src/roff/nroff/nroff.man @@ -37,12 +37,12 @@ the original English. .OP \-o list .OP \-p .OP \-r cn -.OP \-t .OP \-S +.OP \-t .OP \-T name .OP \-U .OP \-v -.RI "[\ " file\|.\|.\|. "\ ]" +.RI "[\ " "file" "\ .\|.\|.\ ]" .br .ad \na .SH DESCRIPTION @@ -78,16 +78,22 @@ environment variable. .PP The .B \-h -option -is equivalent to the +and +.B \-c +options +are equivalent to .BR grotty 's +options .B \-h -option (i.e., using tabs in the output). +(using tabs in the output) and +.B \-c +(using the old output scheme instead of SGR escape sequences). The +.BR \-C , .BR \-i , .BR \-n , .BR \-m , -.B \-o +.BR \-o , and .B \-r options have the effect described in @@ -111,8 +117,6 @@ Options .B \-U (unsafe) are passed to .BR groff . -.B \-S -is passed by default. .B \-v shows the version number. .SH ENVIRONMENT diff --git a/src/roff/nroff/nroff.sh b/src/roff/nroff/nroff.sh index cdc221f0..ed1df0b9 100644 --- a/src/roff/nroff/nroff.sh +++ b/src/roff/nroff/nroff.sh @@ -34,13 +34,14 @@ case "`locale charmap 2>/dev/null`" in esac ;; esac opts= -safer=-S # `for i; do' doesn't work with some versions of sh for i do case $1 in + -c) + opts="$opts -P-c" ;; -h) opts="$opts -P-h" ;; -[eq] | -s*) @@ -49,19 +50,13 @@ for i -[mrnoT]) echo "$prog: option $1 requires an argument" >&2 exit 1 ;; - -[ipt] | -[mrno]*) + -[iptSUC] | -[mrno]*) opts="$opts $1" ;; -Tascii | -Tlatin1 | -Tutf8 | -Tcp1047) T=$1 ;; -T*) # ignore other devices ;; - -S) - # safer behaviour - safer=-S ;; - -U) - # unsafe behaviour - safer=-U ;; -u*) # Solaris 2.2 `man' uses -u0; ignore it, # since `less' and `more' can use the emboldening info. @@ -70,7 +65,7 @@ for i echo "GNU nroff (groff) version @VERSION@" exit 0 ;; --help) - echo "usage: nroff [-h] [-i] [-mNAME] [-nNUM] [-oLIST] [-p] [-rCN] [-t] [-Tname] [FILE...]" + echo "usage: nroff [-cChipt] [-mNAME] [-nNUM] [-oLIST] [-rCN] [-Tname] [FILE...]" exit 0 ;; --) shift @@ -91,6 +86,6 @@ done : ${GROFF_BIN_PATH=@BINDIR@} export GROFF_BIN_PATH -PATH=$GROFF_BIN_PATH:$PATH groff $safer -Wall -mtty-char $T $opts ${1+"$@"} +PATH=$GROFF_BIN_PATH:$PATH groff -mtty-char $T $opts ${1+"$@"} # eof diff --git a/src/roff/troff/node.cc b/src/roff/troff/node.cc index a0a48e09..159104bd 100644 --- a/src/roff/troff/node.cc +++ b/src/roff/troff/node.cc @@ -821,6 +821,7 @@ inline void troff_output_file::put(unsigned int i) void troff_output_file::start_special(tfont *tf, int no_init_string) { flush_tbuf(); + do_motion(); /* * although this is extremely unlikely to have an effect on other devices @@ -830,7 +831,6 @@ void troff_output_file::start_special(tfont *tf, int no_init_string) if (tf != current_tfont) set_font(tf); } - do_motion(); if (!no_init_string) put("x X "); } @@ -1139,6 +1139,7 @@ void troff_output_file::fill_color(color *col) if ((current_pagecolor == col) || disable_color_flag) return; flush_tbuf(); + do_motion(); put("DF"); unsigned int components[4]; color_scheme cs; @@ -1187,6 +1188,7 @@ void troff_output_file::glyph_color(color *col) if ((current_glyphcolor == col) || disable_color_flag) return; flush_tbuf(); + do_motion(); put("m"); unsigned int components[4]; color_scheme cs; diff --git a/tmac/tty.tmac b/tmac/tty.tmac index 5da0607d..1c3f14fa 100644 --- a/tmac/tty.tmac +++ b/tmac/tty.tmac @@ -46,6 +46,15 @@ .tty-char \(an - .tty-char \(eu EUR .tty-char \(Eu EUR +.\" color definitions +.defcolor black rgb #000000 +.defcolor red rgb #ff0000 +.defcolor green rgb #00ff00 +.defcolor blue rgb #0000ff +.defcolor yellow rgb #ffff00 +.defcolor magenta rgb #ff00ff +.defcolor cyan rgb #00ffff +.defcolor white rgb #ffffff .cp \n(_C .\" If you want the character definitions in tty-char.tmac to be loaded .\" automatically, remove the `\"' from the next line. |