This time I come with a patch.

I propose to implement the following new read-only registers.

.it     Interpolates the number of lines remaining in the input trap.
.itc    Interpolates 1 if the input trap respects \c, 0 otherwise.
.itm    Interpolates the name of the macro bound to the input trap.

The above data are reported in `pev` output but there is no way to
expose this information to a *roff document.  The foregoing new
registers would do so.

Any objections to this extension?

Regards,
Branden
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index ea3f0d9cf..2dfe5e1ab 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -427,6 +427,21 @@ int environment::get_no_number_count()
   return no_number_count;
 }
 
+int environment::get_input_trap_line_count()
+{
+  return input_trap_count;
+}
+
+int environment::get_input_trap_respects_continuation()
+{
+  return continued_input_trap;
+}
+
+const char *environment::get_input_trap_macro()
+{
+  return input_trap.contents();
+}
+
 void environment::add_italic_correction()
 {
   if (current_tab) {
@@ -691,7 +706,7 @@ environment::environment(symbol nm)
   have_temporary_indent(0),
   underline_lines(0),
   underline_spaces(0),
-  input_trap_count(0),
+  input_trap_count(-1),
   continued_input_trap(false),
   line(0),
   prev_text_length(0),
@@ -784,7 +799,7 @@ environment::environment(const environment *e)
   have_temporary_indent(0),
   underline_lines(0),
   underline_spaces(0),
-  input_trap_count(0),
+  input_trap_count(-1),
   continued_input_trap(false),
   line(0),
   prev_text_length(e->prev_text_length),
@@ -865,7 +880,7 @@ void environment::copy(const environment *e)
   temporary_indent = 0;
   underline_lines = 0;
   underline_spaces = 0;
-  input_trap_count = 0;
+  input_trap_count = -1;
   continued_input_trap = false;
   prev_text_length = e->prev_text_length;
   width_total = 0;
@@ -2589,7 +2604,8 @@ void no_adjust()
 
 void do_input_trap(bool respect_continuation)
 {
-  curenv->input_trap_count = 0;
+  curenv->input_trap_count = -1;
+  curenv->input_trap = 0 /* nullptr */;
   if (respect_continuation)
     curenv->continued_input_trap = true;
   else
@@ -2598,7 +2614,7 @@ void do_input_trap(bool respect_continuation)
   if (has_arg() && get_integer(&n)) {
     if (n <= 0)
       warning(WARN_RANGE,
-	      "number of lines for input trap must be greater than zero");
+	      "input trap line count must be greater than zero");
     else {
       symbol s = get_name(true /* required */);
       if (!s.is_null()) {
@@ -3520,6 +3536,9 @@ void init_env_requests()
   init_hunits_env_reg(".i", get_indent);
   init_hunits_env_reg(".in", get_saved_indent);
   init_int_env_reg(".int", get_prev_line_interrupted);
+  init_int_env_reg(".it", get_input_trap_line_count);
+  init_int_env_reg(".itc", get_input_trap_respects_continuation);
+  init_string_env_reg(".itm", get_input_trap_macro);
   init_int_env_reg(".linetabs", get_line_tabs);
   init_hunits_env_reg(".lt", get_title_length);
   init_int_env_reg(".j", get_adjust_mode);
diff --git a/src/roff/troff/env.h b/src/roff/troff/env.h
index 65b9f0103..0777a3c6b 100644
--- a/src/roff/troff/env.h
+++ b/src/roff/troff/env.h
@@ -314,6 +314,9 @@ public:
   hunits get_hyphenation_space();
   hunits get_hyphenation_margin();
   int get_center_lines();
+  int get_input_trap_line_count();
+  int get_input_trap_respects_continuation();
+  const char *get_input_trap_macro();
   int get_right_justify_lines();
   int get_no_number_count();
   int get_prev_line_interrupted() { return prev_line_interrupted; }

Attachment: signature.asc
Description: PGP signature

Reply via email to