diff options
author | wlemb <wlemb> | 2002-05-11 07:20:03 +0000 |
---|---|---|
committer | wlemb <wlemb> | 2002-05-11 07:20:03 +0000 |
commit | 93144cf203cf3eb2bd572648c039b9149c1aebe4 (patch) | |
tree | ba7f77af5d3931fe40175220f00846dab921762b | |
parent | bbf2e3c1ebf9ee6a8a0bde2aa812f29fe0f3029e (diff) | |
download | groff-93144cf203cf3eb2bd572648c039b9149c1aebe4.tar.gz |
Adding `warnscale' and `spreadwarn' requests, based on a patch from
Jeffrey Friedl <jfriedl@yahoo.com>.
* src/roff/troff/input.cc (spread_limit, warn_scale,
warn_scaling_indicator): New global variables.
(warnscale_request, spreadwarn_requests): New functions.
(main): Initialize `warn_scale' and `warn_scaling_indicator'.
(init_input_requests): Updated.
(error_type): Add `OUTPUT_WARNING'.
(do_error): Handle it.
(output_warning): New warning function which shows output location.
* src/roff/troff/env.h (spread_limit): New external variable.
* src/roff/troff/env.cc (environment::choose_breakpoint): Use
`output_warning'.
(distribute_space): Emit warning if added space is larger than
`spread_limit'.
(environment::possibly_break_line): Emit warning if a line can't
be adjusted on both sides.
* doc/groff.texinfo, man/groff_diff.man, man/groff.man: Document it.
-rw-r--r-- | ChangeLog | 23 | ||||
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | doc/groff.texinfo | 39 | ||||
-rw-r--r-- | man/groff.man | 49 | ||||
-rw-r--r-- | man/groff_diff.man | 50 | ||||
-rw-r--r-- | src/roff/troff/env.cc | 13 | ||||
-rw-r--r-- | src/roff/troff/env.h | 2 | ||||
-rw-r--r-- | src/roff/troff/input.cc | 78 | ||||
-rw-r--r-- | src/roff/troff/troff.h | 6 |
9 files changed, 244 insertions, 22 deletions
@@ -1,3 +1,26 @@ +2002-05-11 Werner LEMBERG <wl@gnu.org> + + Adding `warnscale' and `spreadwarn' requests, based on a patch from + Jeffrey Friedl <jfriedl@yahoo.com>. + + * src/roff/troff/input.cc (spread_limit, warn_scale, + warn_scaling_indicator): New global variables. + (warnscale_request, spreadwarn_requests): New functions. + (main): Initialize `warn_scale' and `warn_scaling_indicator'. + (init_input_requests): Updated. + (error_type): Add `OUTPUT_WARNING'. + (do_error): Handle it. + (output_warning): New warning function which shows output location. + * src/roff/troff/env.h (spread_limit): New external variable. + * src/roff/troff/env.cc (environment::choose_breakpoint): Use + `output_warning'. + (distribute_space): Emit warning if added space is larger than + `spread_limit'. + (environment::possibly_break_line): Emit warning if a line can't + be adjusted on both sides. + + * doc/groff.texinfo, man/groff_diff.man, man/groff.man: Document it. + 2002-05-08 Werner LEMBERG <wl@gnu.org> * src/roff/troff/node.cc (special_node::special_node): Use @@ -547,6 +547,12 @@ o Two new requests `tm1' and `tmc' have been added to improve writing messages to the terminal. `tm1' is similar to `tm' but allows leading whitespace. `tmc' is similar to `tm1' but doesn't emit a final newline. +o The new `spreadwarn' request will make troff warn if spaces in an output + line are widened by a given limit or more. + +o Use `warnscale' to change the scaling indicator troff will use for + warning messages. + o A new request `dei' (define indirect) has been added. The first and second parameter of `dei' are taken from string registers rather than directly; this very special request is needed to make `trace.tmac' diff --git a/doc/groff.texinfo b/doc/groff.texinfo index b28ef4b5..e2b4fbf0 100644 --- a/doc/groff.texinfo +++ b/doc/groff.texinfo @@ -5926,6 +5926,15 @@ The @code{\:} escape inserts a zero-width break point @Example ... check the /var/log/\:httpd/\:access_log file ... @endExample + +@cindex @code{\X}, followed by @code{\%} +@cindex @code{\Y}, followed by @code{\%} +@cindex @code{\%}, following @code{\X} or @code{\Y} +Note that @code{\X} and @code{\Y} start a word, that is, the @code{\%} +escape in (say) @w{@samp{ \X'...'\%foobar}} and +@w{@samp{ \Y'...'\%foobar}} no longer prevents hyphenation but inserts +a hyphenation point at the beginning of @samp{foobar}; most likely +this isn't what you want to do. @endDefesc @Defreq {hc, [@Var{char}]} @@ -11985,8 +11994,38 @@ to set the maximum number of objects on the input stack. If @code{slimit} is less than or equal to@w{ }0, there is no limit set. With no limit, a buggy recursive macro can exhaust virtual memory. + +The default value is 1000; this is a compile-time constant. @endDefreg +@Defreq {warnscale, si} +Set the scaling indicator used in warnings to @var{si}. Valid values for +@var{si} are @samp{u}, @samp{i}, @samp{c}, @samp{p}, and @samp{P}. At +startup, it is set to @samp{i}. +@endDefreq + +@Defreq {spreadwarn, [@Var{limit}]} +Make @code{gtroff} emit a warning if the additional space inserted for +each space between words in an output line is larger or equal to +@var{limit}. A negative value is changed to zero; no argument toggles the +warning on and off without changing @var{limit}. The default scaling +indicator is @samp{m}. At startup, @code{spreadwarn} is deactivated, and +@var{limit} is set to 3@dmn{m}. + +For example, + +@Example +.spreadwarn 0.2m +@endExample + +@noindent +will cause a warning if @code{gtroff} must add 0.2@dmn{m} or more for each +interword space in a line. + +This request is active only if text is justified to both margins (using +@w{@samp{.ad b}}). +@endDefreq + @cindex warnings @code{gtroff} has command line options for printing out more warnings (@option{-w}) and for printing backtraces (@option{-b}) when a warning diff --git a/man/groff.man b/man/groff.man index 133a39c4..bfa0420e 100644 --- a/man/groff.man +++ b/man/groff.man @@ -2,7 +2,7 @@ .ig groff.man -Last update: 21 Apr 2002 +Last update: 11 May 2002 This file is part of groff, the GNU roff type-setting system. @@ -746,21 +746,21 @@ There is a sophisticated interface for handling tab positions. A .B numerical value is a signed or unsigned integer or float with or without an appended -scale indicator. +scaling indicator. . A -.B scale indicator +.B scaling indicator is a one-character abbreviation for a unit of measurement. . -A number followed by a scale indicator signifies a size value. +A number followed by a scaling indicator signifies a size value. . -By default, numerical values do not have a scale indicator, i.e., they +By default, numerical values do not have a scaling indicator, i.e., they are normal numbers. . .P The .I roff -language defines the following scale indicators. +language defines the following scaling indicators. . . .P @@ -1385,7 +1385,7 @@ or .BR grey . .I component can be single components specified as fractions in the range 0 to 1 -(default scale indicator\~\c +(default scaling indicator\~\c .scaleindicator f ), as a string of two-digit hexadecimal color components with a leading .BR # , @@ -1436,7 +1436,7 @@ but with compatibility mode switched off during string expansion. .REQ .dt N trap Set diversion trap to position .I N -(default scale indicator\~\c +(default scaling indicator\~\c .scaleindicator v ). . .REQ .ec @@ -1610,7 +1610,7 @@ Switch to hyphenation mode .REQ .hym n Set the hyphenation margin to .I n -(default scale indicator\~\c +(default scaling indicator\~\c .scaleindicator m ). . .REQ .hys n @@ -1647,7 +1647,7 @@ Change to previous indent value. .REQ .in \[+-]N Change indent according to .I \[+-]N -(default scale indicator\~\c +(default scaling indicator\~\c .scaleindicator m ). . .REQ .it N trap @@ -1710,7 +1710,7 @@ Set line length according to .I \[+-]N (default size .scalednumber 6.5 i , -default scale indicator\~\c +default scaling indicator\~\c .scaleindicator m ). . .REQ .ls @@ -1724,7 +1724,7 @@ i.e., blank lines are inserted after each text output line. . .REQ .lt \[+-]N -Length of title (default scale indicator\~\c +Length of title (default scaling indicator\~\c .scaleindicator m ). . .REQ .mc @@ -1740,7 +1740,7 @@ Set margin character to .I c and distance to .I N -from right margin (default scale indicator\~\c +from right margin (default scaling indicator\~\c .scaleindicator m ). . .REQ .mk register @@ -1761,7 +1761,7 @@ Need a one-line vertical space. .REQ .ne N Need .I N -vertical space (default scale indicator\~\c +vertical space (default scaling indicator\~\c .scaleindicator v ). . .REQ .nf @@ -1850,7 +1850,7 @@ The current page length is stored in .REQ .pl \[+-]N Change page length to .I \[+-]N -(default scale indicator\~\c +(default scaling indicator\~\c .scaleindicator v ). . .REQ .pm @@ -1903,7 +1903,7 @@ Change to previous post-vertical line spacing. .REQ .pvs \[+-]N Change post-vertical line spacing according to .I \[+-]N -(default scale indicator\~\c +(default scaling indicator\~\c .scaleindicator p ). . .REQ .rchar c1 c2 .\|.\|.\& @@ -1949,7 +1949,7 @@ Restore spacing; turn no-space mode off. .REQ .rt \[+-]N Return .I (upward only) -to marked vertical place (default scale indicator\~\c +to marked vertical place (default scaling indicator\~\c .scaleindicator v ). . .REQ .shc @@ -1993,6 +1993,15 @@ Fonts etc.\& are special and will be searched for characters not in the current font. . +.REQ .spreadwarn +Toggle the spread warning on and off without changing its value. +. +.REQ .spreadwarn limit +Emit a warning if each space in an output line is widened by +.I limit +or more (default scaling indicator\~\c +.scaleindicator m ). +. .REQ .ss N Space-character size set to .IR N /12 @@ -2162,7 +2171,7 @@ Change to previous vertical base line spacing. .REQ .vs \[+-]N Set vertical base line spacing according to .I \[+-]N -(default scale indicator\~\c +(default scaling indicator\~\c .scaleindicator p ). Default value is .scalednumber 12 p . @@ -2171,6 +2180,10 @@ Default value is Set warnings code to .IR n . . +.REQ .warnscale si +Set scaling indicator used in warnings to +.IR si . +. .REQ .wh N Remove (first) trap at position .IR N . diff --git a/man/groff_diff.man b/man/groff_diff.man index ca8168e2..c1e22e2f 100644 --- a/man/groff_diff.man +++ b/man/groff_diff.man @@ -3,7 +3,7 @@ .ig groff_diff.man -Last update : 15 Apr 2002 +Last update : 11 May 2002 This file is part of groff, the GNU roff type-setting system. It is the source of the man-page groff_diff(7). @@ -1913,6 +1913,36 @@ are special and will be searched for characters not in the current font. . .TP +.BI .spreadwarn\ limit +Make +.B troff +emit a warning if the additional space inserted for each space between +words in an output line is larger or equal to +.IR limit . +. +A negative value is changed to zero; no argument toggles the warning on +and off without changing +.IR limit . +. +The default scaling indicator is\~\c +.BR m . +. +At startup, +.B spreadwarn +is deactivated, and +.I limit +is set to 3m. +. +For example, +.B .spreadwarn\ 0.2m +will cause a warning if +.B troff +must add 0.2m or more for each interword space in a line. +. +This request is active only if text is justified to both margins (using +.BR .ad\ b ). +. +.TP .BI .sty\ n\ f Associate style\~\c .I f @@ -2208,6 +2238,24 @@ If is not given, all warnings will be enabled. . .TP +.BI .warnscale\ si +Set the scaling indicator used in warnings to +.IR si . +. +Valid values for +.I si +are +.BR u , +.BR i , +.BR c , +.BR p , +and +.BR P . +. +At startup, it is set to\~\c +.BR i . +. +.TP .BI .while \ c\ anything While condition\~\c .I c diff --git a/src/roff/troff/env.cc b/src/roff/troff/env.cc index ede6b78c..2d677745 100644 --- a/src/roff/troff/env.cc +++ b/src/roff/troff/env.cc @@ -1884,7 +1884,7 @@ breakpoint *environment::choose_breakpoint() } if (best_bp) { if (!best_bp_fits) - warning(WARN_BREAK, "can't break line"); + output_warning(WARN_BREAK, "can't break line"); return best_bp; } return 0; @@ -1970,6 +1970,14 @@ static void distribute_space(node *n, int nspaces, hunits desired_space, static int reverse = 0; if (force_reverse || reverse) n = node_list_reverse(n); + if (!force_reverse && nspaces > 0 && spread_limit >= 0 + && desired_space.to_units() > 0) { + hunits em = curenv->get_size(); + double Ems = (double)desired_space.to_units() / nspaces + / (em.is_zero() ? hresolution : em.to_units()); + if (Ems > spread_limit) + output_warning(WARN_BREAK, "spreading %1m per space", Ems); + } for (node *tem = n; tem; tem = tem->next) tem->spread_space(&nspaces, &desired_space); if (force_reverse || reverse) @@ -2004,6 +2012,9 @@ void environment::possibly_break_line(int start_here, int forced) case ADJUST_BOTH: if (bp->nspaces != 0) extra_space_width = target_text_length - bp->width; + else if (bp->width > 0 && target_text_length > 0 + && target_text_length > bp->width) + output_warning(WARN_BREAK, "cannot adjust line"); break; case ADJUST_CENTER: saved_indent += (target_text_length - bp->width)/2; diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h index c8aede6c..1c694916 100644 --- a/src/roff/troff/env.h +++ b/src/roff/troff/env.h @@ -356,6 +356,8 @@ void init_environments(); void read_hyphen_file(const char *name); void title(); +extern double spread_limit; + extern int break_flag; extern symbol default_family; extern int translate_space_to_dummy; diff --git a/src/roff/troff/input.cc b/src/roff/troff/input.cc index 6902de82..d3ff2ea3 100644 --- a/src/roff/troff/input.cc +++ b/src/roff/troff/input.cc @@ -122,6 +122,11 @@ int have_input = 0; // whether \f, \H, \R, \s, or \S has int tcommand_flag = 0; int safer_flag = 1; // safer by default +double spread_limit = -3.0 - 1.0; // negative means deactivated + +double warn_scale; +char warn_scaling_indicator; + search_path *mac_path = &safer_macro_path; static int get_copy(node**, int = 0); @@ -5604,6 +5609,47 @@ void write_macro_request() skip_line(); } +void warnscale_request() +{ + if (has_arg()) { + char c = tok.ch(); + if (c == 'u') + warn_scale = 1.0; + else if (c == 'i') + warn_scale = (double)units_per_inch; + else if (c == 'c') + warn_scale = (double)units_per_inch / 2.54; + else if (c == 'p') + warn_scale = (double)units_per_inch / 72.0; + else if (c == 'P') + warn_scale = (double)units_per_inch / 6.0; + else { + warning(WARN_SCALE, + "invalid scaling indicator `%1', using `i' instead", c); + c = 'i'; + } + warn_scaling_indicator = c; + } + skip_line(); +} + +void spreadwarn_request() +{ + hunits n; + if (has_arg() && get_hunits(&n, 'm')) { + if (n < 0) + n = 0; + hunits em = curenv->get_size(); + spread_limit = (double)n.to_units() + / (em.is_zero() ? hresolution : em.to_units()); + } + else + spread_limit = -spread_limit - 1; // no arg toggles on/off without + // changing value; we mirror at + // -0.5 to make zero a valid value + skip_line(); +} + static void init_charset_table() { char buf[16]; @@ -6659,6 +6705,8 @@ int main(int argc, char **argv) vresolution = font::vert; sizescale = font::sizescale; tcommand_flag = font::tcommand; + warn_scale = (double)units_per_inch; + warn_scaling_indicator = 'i'; if (!fflag && font::family != 0 && *font::family != '\0') default_family = symbol(font::family); font_size::init_size_table(font::sizes); @@ -6877,6 +6925,8 @@ void init_input_requests() #endif /* not POPEN_MISSING */ init_request("psbb", ps_bbox_request); init_request("defcolor", define_color); + init_request("warnscale", warnscale_request); + init_request("spreadwarn", spreadwarn_request); number_reg_dictionary.define("systat", new variable_reg(&system_status)); number_reg_dictionary.define("slimit", new variable_reg(&input_stack::limit)); @@ -7151,7 +7201,7 @@ static void copy_mode_error(const char *format, error(format, arg1, arg2, arg3); } -enum error_type { WARNING, ERROR, FATAL }; +enum error_type { WARNING, OUTPUT_WARNING, ERROR, FATAL }; static void do_error(error_type type, const char *format, @@ -7180,6 +7230,18 @@ static void do_error(error_type type, case WARNING: fputs("warning: ", stderr); break; + case OUTPUT_WARNING: + double fromtop = topdiv->get_vertical_position().to_units() / warn_scale; + fprintf(stderr, "warning [p %d, %.1f%c", + topdiv->get_page_number(), fromtop, warn_scaling_indicator); + if (topdiv != curdiv) { + double fromtop1 = curdiv->get_vertical_position().to_units() + / warn_scale; + fprintf(stderr, ", div `%s', %.1f%c", + curdiv->get_diversion_name(), fromtop1, warn_scaling_indicator); + } + fprintf(stderr, "]: "); + break; } errprint(format, arg1, arg2, arg3); fputc('\n', stderr); @@ -7202,6 +7264,20 @@ int warning(warning_type t, return 0; } +int output_warning(warning_type t, + const char *format, + const errarg &arg1, + const errarg &arg2, + const errarg &arg3) +{ + if ((t & warning_mask) != 0) { + do_error(OUTPUT_WARNING, format, arg1, arg2, arg3); + return 1; + } + else + return 0; +} + void error(const char *format, const errarg &arg1, const errarg &arg2, diff --git a/src/roff/troff/troff.h b/src/roff/troff/troff.h index 48e72a6e..e37137e0 100644 --- a/src/roff/troff/troff.h +++ b/src/roff/troff/troff.h @@ -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) @@ -88,3 +88,7 @@ int warning(warning_type, const char *, const errarg & = empty_errarg, const errarg & = empty_errarg, const errarg & = empty_errarg); +int output_warning(warning_type, const char *, + const errarg & = empty_errarg, + const errarg & = empty_errarg, + const errarg & = empty_errarg); |