diff options
author | wlemb <wlemb> | 2000-02-11 22:17:10 +0000 |
---|---|---|
committer | wlemb <wlemb> | 2000-02-11 22:17:10 +0000 |
commit | fb0d74aff2c3f5f3a4e771123f118c4b763eb648 (patch) | |
tree | cda22c6547a8750af32cc354643c02fdeab5083e | |
parent | 2f271d75ec362d861cff1f30d3106ec4f5eb1f7e (diff) | |
download | groff-fb0d74aff2c3f5f3a4e771123f118c4b763eb648.tar.gz |
A new request `length' is available which returns the length of a
string in a number register:
* src/roff/troff/input.cc (length_macro): Implement it.
* src/roff/troff/input.cc (init_input_requests): Register it.
* src/roff/troff/troff.man, doc/groff.texinfo: Document `length'
request.
-rw-r--r-- | ChangeLog | 12 | ||||
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | doc/groff.texinfo | 9 | ||||
-rw-r--r-- | src/roff/troff/TODO | 2 | ||||
-rw-r--r-- | src/roff/troff/input.cc | 39 | ||||
-rw-r--r-- | src/roff/troff/troff.man | 7 |
6 files changed, 70 insertions, 2 deletions
@@ -1,7 +1,19 @@ +2000-02-11 Abramo Bagnara <abramo@alsa-project.org> + + A new request `length' is available which returns the length of a + string in a number register: + + * src/roff/troff/input.cc (length_macro): Implement it. + * src/roff/troff/input.cc (init_input_requests): Register it. + 2000-02-11 Werner LEMBERG <wl@gnu.org> * doc/groff.texinfo, src/roff/troff/troff.man: Add documentation of the `substring' request. + + * src/roff/troff/troff.man, doc/groff.texinfo: Document `length' + request. + * src/roff/troff/TODO, NEWS: Updated. 2000-02-09 Werner LEMBERG <wl@gnu.org> @@ -57,6 +57,9 @@ Previously, the text after \fP appeared as bold. The `substring' request is not new, but hasn't been documented before. +A new request `length' computes the length of a string and returns it in +a number register. + The macro files `tmac.a4' (for specifying A4 paper format) and `tmac.trace' (a debugging aid) are now installed also. diff --git a/doc/groff.texinfo b/doc/groff.texinfo index d02126f0..902ce9a2 100644 --- a/doc/groff.texinfo +++ b/doc/groff.texinfo @@ -3660,6 +3660,13 @@ the index value n1 or n2 is negative or zero, it will be counted from the end of the string, going backwards: The last character has index@w{ }0, the character before the last character has index@w{ }-1, etc. +@findex length +@cindex length of a string +@cindex string, length of +@code{.length xx string} +Compute the length of string and return it in the number register@w{ }xx +(which is not necessarily defined before). + @findex rn @code{rn} @@ -3962,7 +3969,7 @@ request can make a macro have more than one name. This would be called as @example -.vl $Id: groff.texinfo,v 1.2 2000/02/11 16:26:45 wlemb Exp $ +.vl $Id: groff.texinfo,v 1.3 2000/02/11 22:17:10 wlemb Exp $ @end example diff --git a/src/roff/troff/TODO b/src/roff/troff/TODO index 2f2ecbf3..1852aafc 100644 --- a/src/roff/troff/TODO +++ b/src/roff/troff/TODO @@ -105,7 +105,7 @@ optionally print the contents of a macro. Provide some way to round numbers to multiples of the current horizontal or vertical resolution. -Better string-processing support (length, search). +Better string-processing support (search). Generalized ligatures. diff --git a/src/roff/troff/input.cc b/src/roff/troff/input.cc index a4565904..7647bc62 100644 --- a/src/roff/troff/input.cc +++ b/src/roff/troff/input.cc @@ -3512,6 +3512,44 @@ void substring_macro() skip_line(); } +void length_macro() +{ + symbol ret; + ret = get_name(1); + if (ret.is_null()) { + skip_line(); + return; + } + int c; + node *n; + if (tok.newline()) + c = '\n'; + else if (tok.tab()) + c = '\t'; + else if (!tok.space()) { + error("bad string definition"); + skip_line(); + return; + } + else + c = get_copy(&n); + while (c == ' ') + c = get_copy(&n); + if (c == '"') + c = get_copy(&n); + int len = 0; + while (c != '\n' && c != EOF) { + ++len; + c = get_copy(&n); + } + tok.next(); + reg *r = (reg*)number_reg_dictionary.lookup(ret); + if (r) + r->set_value(len); + else + set_number_reg(ret, len); +} + void asciify_macro() { symbol s = get_name(1); @@ -5832,6 +5870,7 @@ void init_input_requests() init_request("backtrace", backtrace_request); init_request("chop", chop_macro); init_request("substring", substring_macro); + init_request("length", length_macro); init_request("asciify", asciify_macro); init_request("warn", warn_request); init_request("open", open_request); diff --git a/src/roff/troff/troff.man b/src/roff/troff/troff.man index 25053376..0dc4e306 100644 --- a/src/roff/troff/troff.man +++ b/src/roff/troff/troff.man @@ -1047,6 +1047,13 @@ If .I n is non-zero or missing, enable pairwise kerning, otherwise disable it. .TP +.BI .length\ xx\ string +Compute the length of +.I string +and return it in the number register +.I xx +(which is not necessarily defined before). +.TP .BI .mso\ file The same as the .B so |