summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwl <wl>2006-04-04 20:20:03 +0000
committerwl <wl>2006-04-04 20:20:03 +0000
commitdbc2938995b9724fb06930dcd7f4b4af833793bf (patch)
treee0b0a8988ac64baf2a07d2e8451293596e3e604c
parent8de88e49f386e53ed293ee62a48d66fd8c67ccbe (diff)
downloadgroff-dbc2938995b9724fb06930dcd7f4b4af833793bf.tar.gz
Implement new number register `.br' which is set to 1 if a macro has
been called as .foo and to 0 if called as 'bar. This is useful for -mtrace so that requests can be reliably traced too. * src/roff/troff/input.cpp (input_iterator): Add virtual function `get_break_flag'. (macro_iterator): Add `with_break' member and `get_break_flag' function. Update constructors. (input_stack): Add function `get_break_flag'. (break_flag_reg): New number register class. (input_init_requests): Register `.br'. * src/roff/troff/TODO: Updated. * tmac/trace.tmac: s/!!sp/!!!sp/. Modify definitions of `de', `de1', `am', and `am1' to use \n[.br]. * docs/groff.texinfo, man/groff.man, man/groff_diff.man, NEWS: Document it.
-rw-r--r--ChangeLog23
-rw-r--r--NEWS14
-rw-r--r--doc/groff.texinfo25
-rw-r--r--man/groff.man6
-rw-r--r--man/groff_diff.man27
-rw-r--r--src/roff/troff/TODO3
-rw-r--r--src/roff/troff/input.cpp32
-rw-r--r--tmac/trace.tmac82
8 files changed, 170 insertions, 42 deletions
diff --git a/ChangeLog b/ChangeLog
index 6d224d10..b1de2e45 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2006-04-04 Werner LEMBERG <wl@gnu.org>
+
+ Implement new number register `.br' which is set to 1 if a macro has
+ been called as .foo and to 0 if called as 'bar. This is useful for
+ -mtrace so that requests can be reliably traced too.
+
+ * src/roff/troff/input.cpp (input_iterator): Add virtual function
+ `get_break_flag'.
+ (macro_iterator): Add `with_break' member and `get_break_flag'
+ function.
+ Update constructors.
+ (input_stack): Add function `get_break_flag'.
+ (break_flag_reg): New number register class.
+ (input_init_requests): Register `.br'.
+
+ * src/roff/troff/TODO: Updated.
+
+ * tmac/trace.tmac: s/!!sp/!!!sp/.
+ Modify definitions of `de', `de1', `am', and `am1' to use \n[.br].
+
+ * docs/groff.texinfo, man/groff.man, man/groff_diff.man, NEWS:
+ Document it.
+
2006-03-29 Werner LEMBERG <wl@gnu.org>
* src/devices/grops/ps.cpp: s/must not/should not/ in warning
diff --git a/NEWS b/NEWS
index a680c095..763f2ccb 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,18 @@ o Swedish macro localization has been added also.
o Two new requests `device' and `devicem' have been added which are
equivalents to the \X and \Y escapes, respectively.
+o A new read-only number register `.br' is available which is set to 1
+ if a macro is called as .foo and to 0 if called as 'foo. This allows to
+ reliably modify requests.
+
+ .als bp@orig bp
+ .de bp
+ . tm before bp
+ . ie \\n[.br] .bp@orig
+ . el 'bp@orig
+ . tm after bp
+ ..
+
Pic
---
@@ -34,6 +46,8 @@ Macro Packages
o A new macro `Dx' has been added which identifies the DragonFly OS.
+o -mtrace now shows whether a macro has been called as .foo or as 'foo.
+
VERSION 1.19.2
==============
diff --git a/doc/groff.texinfo b/doc/groff.texinfo
index 907c9a59..d1f7ee79 100644
--- a/doc/groff.texinfo
+++ b/doc/groff.texinfo
@@ -5438,6 +5438,29 @@ In most cases the period is used as a control character. Several
requests cause a break implicitly; using the single quote control
character prevents this.
+@Defreg {.br}
+A read-only number register which is set to@tie{}1 if a macro is called
+with the normal control character (as defined with the @code{cc}
+request), and set to@tie{}0 otherwise.
+
+@cindex modifying requests
+@cindex requests, modifying
+This allows to reliably modify requests.
+
+@Example
+.als bp*orig bp
+.de bp
+. tm before bp
+. ie \\n[.br] .bp*orig
+. el 'bp*orig
+. tm after bp
+..
+@endExample
+
+Using this register outside of a macro makes no sense (it always returns
+zero in such cases).
+@endDefreg
+
@menu
* Request and Macro Arguments::
@end menu
@@ -7620,6 +7643,8 @@ no-break control character is associated with the current environment
(@pxref{Environments}).
@endDefreq
+@xref{Requests}.
+
@Defreq {eo, }
@cindex disabling @code{\} (@code{eo})
@cindex @code{\}, disabling (@code{eo})
diff --git a/man/groff.man b/man/groff.man
index afc3a9d1..90e9d33b 100644
--- a/man/groff.man
+++ b/man/groff.man
@@ -2,7 +2,7 @@
.ig
groff.man
-Last update: 27 Mar 2006
+Last update: 04 Apr 2006
This file is part of groff, the GNU roff type-setting system.
@@ -3076,6 +3076,10 @@ if option
is used; always\~1 in
.BR nroff .
.
+.REG .br
+Within a macro, set to\~1 if macro called with the `normal' control
+character, and to\~0 otherwise.
+.
.REG .c
Current input line number.
.
diff --git a/man/groff_diff.man b/man/groff_diff.man
index e160a860..a33710fe 100644
--- a/man/groff_diff.man
+++ b/man/groff_diff.man
@@ -3,7 +3,7 @@
.ig
groff_diff.man
-Last update : 27 Mar 2006
+Last update : 04 Apr 2006
This file is part of groff, the GNU roff type-setting system.
It is the source of the man-page groff_diff(7).
@@ -2607,6 +2607,31 @@ sets tabs every half an inch.
The following read-only registers are available:
.
.TP
+.B \[rs]n[.br]
+Within a macro call, it is set to\~1 if the macro is called with the
+`normal' control character (`.' by default), and set to\~0 otherwise.
+This allows to reliably modify requests.
+.
+.RS
+.IP
+.ne 6v+\n(.Vu
+.ft CB
+.nf
+.Text .als bp*orig bp
+.Text .de bp
+.Text .tm before bp
+.Text .ie \[rs]\[rs]n[.br] .bp*orig
+.Text .el 'bp*orig
+.Text .tm after bp
+.Text ..
+.fi
+.RE
+.
+.IP
+Using this register outside of a macro makes no sense (it always returns
+zero in such cases).
+.
+.TP
.B \[rs]n[.C]
1\~if compatibility mode is in effect, 0\~otherwise.
.
diff --git a/src/roff/troff/TODO b/src/roff/troff/TODO
index 49aa0eb2..a1b531e5 100644
--- a/src/roff/troff/TODO
+++ b/src/roff/troff/TODO
@@ -106,9 +106,6 @@ Better string-processing support (search).
Generalized ligatures.
-Provide some way for a macro to tell whether it was called with `'' or
-`.'. This would be useful for implementing a tracing macro package.
-
Request to remove an environment. (Maintain a count of the references
to the environment from the environment table, environment dictionary
or environment stack.)
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index b750a1e2..55fd5db3 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -217,6 +217,7 @@ private:
virtual int has_args() { return 0; }
virtual int nargs() { return 0; }
virtual input_iterator *get_arg(int) { return 0; }
+ virtual int get_break_flag() { return 0; }
virtual int get_location(int, const char **, int *) { return 0; }
virtual void backtrace() {}
virtual int set_location(const char *, int) { return 0; }
@@ -416,6 +417,7 @@ public:
static int peek();
static void push(input_iterator *);
static input_iterator *get_arg(int);
+ static int get_break_flag();
static int nargs();
static int get_location(int, const char **, int *);
static int set_location(const char *, int);
@@ -497,10 +499,10 @@ int input_stack::finish_get(node **np)
input_iterator *tem = top;
check_end_diversion(tem);
#if defined(DEBUGGING)
- if (debug_state)
- if (tem->is_diversion)
- fprintf(stderr,
- "in diversion level = %d\n", input_stack::get_div_level());
+ if (debug_state)
+ if (tem->is_diversion)
+ fprintf(stderr,
+ "in diversion level = %d\n", input_stack::get_div_level());
#endif
top = top->next;
level--;
@@ -622,6 +624,11 @@ input_iterator *input_stack::get_arg(int i)
return 0;
}
+int input_stack::get_break_flag()
+{
+ return top->get_break_flag();
+}
+
void input_stack::shift(int n)
{
for (input_iterator *p = top; p; p = p->next)
@@ -3584,12 +3591,14 @@ arg_list::~arg_list()
class macro_iterator : public string_iterator {
arg_list *args;
int argc;
+ int with_break; // whether called as .foo or 'foo
public:
macro_iterator(symbol, macro &, const char *how_invoked = "macro");
macro_iterator();
~macro_iterator();
int has_args() { return 1; }
input_iterator *get_arg(int i);
+ int get_break_flag() { return with_break; }
int nargs() { return argc; }
void add_arg(const macro &m);
void shift(int n);
@@ -3823,11 +3832,11 @@ int macro::empty()
}
macro_iterator::macro_iterator(symbol s, macro &m, const char *how_called)
-: string_iterator(m, how_called, s), args(0), argc(0)
+: string_iterator(m, how_called, s), args(0), argc(0), with_break(break_flag)
{
}
-macro_iterator::macro_iterator() : args(0), argc(0)
+macro_iterator::macro_iterator() : args(0), argc(0), with_break(break_flag)
{
}
@@ -6806,6 +6815,16 @@ const char *filename_reg::get_string()
return 0;
}
+class break_flag_reg : public reg {
+public:
+ const char *get_string();
+};
+
+const char *break_flag_reg::get_string()
+{
+ return i_to_a(input_stack::get_break_flag());
+}
+
class constant_reg : public reg {
const char *s;
public:
@@ -7669,6 +7688,7 @@ void init_input_requests()
init_request("writec", write_request_continue);
init_request("writem", write_macro_request);
number_reg_dictionary.define(".$", new nargs_reg);
+ number_reg_dictionary.define(".br", new break_flag_reg);
number_reg_dictionary.define(".C", new constant_int_reg(&compatible_flag));
number_reg_dictionary.define(".c", new lineno_reg);
number_reg_dictionary.define(".color", new constant_int_reg(&color_flag));
diff --git a/tmac/trace.tmac b/tmac/trace.tmac
index 286c605b..fbe295fd 100644
--- a/tmac/trace.tmac
+++ b/tmac/trace.tmac
@@ -5,7 +5,7 @@
.nr _C \n(.C
.cp 0
.
-.do ds !!sp " \"
+.do ds !!!sp " \"
.
.eo
.
@@ -17,13 +17,18 @@
. do ecs
. ec
. do !!de \$1
-. ie "\$1"\\$0" .do tm1 "\\*[!!sp]*** de trace enter: \\$0 \\$@
-. el .do tm1 "\\*[!!sp]*** de trace enter \$1: \\$0 \\$@
-. do as !!sp " \"
-. do nop \\*[!!\$1]\\
-. do substring !!sp 1
-. ie "\$1"\\$0" .do tm1 "\\*[!!sp]*** trace exit: \\$0 \\$@
-. el .do tm1 "\\*[!!sp]*** trace exit \$1: \\$0 \\$@
+. do ie \\n[.br] .ds !!!br .\"
+. el .do ds !!!br '\"
+. ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** de trace enter: \\*[!!!br]\\$0 \\$@
+. el .do tm1 "\\*[!!!sp]*** de trace enter \$1: \\*[!!!br]\\$0 \\$@
+. do as !!!sp " \"
+. do ie \\n[.br] .do !!\$1 \\$@
+. el 'do !!\$1 \\$@
+. do substring !!!sp 1
+. do ie \\n[.br] .ds !!!br .\"
+. el .do ds !!!br '\"
+. ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** trace exit: \\*[!!!br]\\$0 \\$@
+. el .do tm1 "\\*[!!!sp]*** trace exit \$1: \\*[!!!br]\\$0 \\$@
\..
.
. do ds !!d1 !!\$1
@@ -37,13 +42,18 @@
. do ecs
. ec
. do !!de \$1
-. ie "\$1"\\$0" .do tm1 "\\*[!!sp]*** de1 trace enter: \\$0 \\$@
-. el .do tm1 "\\*[!!sp]*** de1 trace enter \$1: \\$0 \\$@
-. do as !!sp " \"
-. do nop \\*[!!\$1]\\
-. do substring !!sp 1
-. ie "\$1"\\$0" .do tm1 "\\*[!!sp]*** trace exit: \\$0 \\$@
-. el .do tm1 "\\*[!!sp]*** trace exit \$1: \\$0 \\$@
+. do ie \\n[.br] .ds !!!br .\"
+. el .do ds !!!br '\"
+. ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** de1 trace enter: \\*[!!!br]\\$0 \\$@
+. el .do tm1 "\\*[!!!sp]*** de1 trace enter \$1: \\*[!!!br]\\$0 \\$@
+. do as !!!sp " \"
+. do ie \\n[.br] .di !!\$1 \\$@
+. el 'do !!\$1 \\$@
+. do substring !!!sp 1
+. do ie \\n[.br] .ds !!!br .\"
+. el .do ds !!!br '\"
+. ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** trace exit: \\$0 \\$@
+. el .do tm1 "\\*[!!!sp]*** trace exit \$1: \\$0 \\$@
\..
.
. do ds !!d1 !!\$1
@@ -60,13 +70,18 @@
. do ecs
. ec
. do !!de \$1
-. ie "\$1"\\$0" .do tm1 "\\*[!!sp]*** am trace enter: \\$0 \\$@
-. el .do tm1 "\\*[!!sp]*** am trace enter \$1: \\$0 \\$@
-. do as !!sp " \"
-. do nop \\*[!!\$1]\\
-. do substring !!sp 1
-. ie "\$1"\\$0" .do tm1 "\\*[!!sp]*** trace exit: \\$0 \\$@
-. el .do tm1 "\\*[!!sp]*** trace exit \$1: \\$0 \\$@
+. do ie \\n[.br] .ds !!!br .\"
+. el .do ds !!!br '\"
+. ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** am trace enter: \\*[!!!br]\\$0 \\$@
+. el .do tm1 "\\*[!!!sp]*** am trace enter \$1: \\*[!!!br]\\$0 \\$@
+. do as !!!sp " \"
+. do ie \\n[.br] .do !!\$1 \\$@
+. el 'do !!\$1 \\$@
+. do substring !!!sp 1
+. do ie \\n[.br] .ds !!!br .\"
+. el .do ds !!!br '\"
+. ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** trace exit: \\*[!!!br]\\$0 \\$@
+. el .do tm1 "\\*[!!!sp]*** trace exit \$1: \\*[!!!br]\\$0 \\$@
\..
.
. do ds !!a1 !!\$1
@@ -80,13 +95,18 @@
. do ecs
. ec
. do !!de \$1
-. ie "\$1"\\$0" .do tm1 "\\*[!!sp]*** am1 trace enter: \\$0 \\$@
-. el .do tm1 "\\*[!!sp]*** am1 trace enter \$1: \\$0 \\$@
-. do as !!sp " \"
-. do nop \\*[!!\$1]\\
-. do substring !!sp 1
-. ie "\$1"\\$0" .do tm1 "\\*[!!sp]*** trace exit: \\$0 \\$@
-. el .do tm1 "\\*[!!sp]*** trace exit \$1: \\$0 \\$@
+. do ie \\n[.br] .ds !!!br .\"
+. el .do ds !!!br '\"
+. ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** am1 trace enter: \\*[!!!br]\\$0 \\$@
+. el .do tm1 "\\*[!!!sp]*** am1 trace enter \$1: \\*[!!!br]\\$0 \\$@
+. do as !!!sp " \"
+. do ie \\n[.br] .do !!\$1 \\$@
+. el 'do !!\$1 \\$@
+. do substring !!!sp 1
+. do ie \\n[.br] .ds !!!br .\"
+. el .do ds !!!br '\"
+. ie "\$1"\\$0" .do tm1 "\\*[!!!sp]*** trace exit: \\*[!!!br]\\$0 \\$@
+. el .do tm1 "\\*[!!!sp]*** trace exit \$1: \\*[!!!br]\\$0 \\$@
\..
.
. do ds !!a1 !!\$1
@@ -99,8 +119,8 @@
.rn return !!return
.
.!!de1 return
-. substring !!sp 1
-. tm1 "\*[!!sp]*** return
+. substring !!!sp 1
+. tm1 "\*[!!!sp]*** return
. !!return twice
..
.