[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #64212] [PATCH] give troff a string register naming the next trap
From: |
G. Branden Robinson |
Subject: |
[bug #64212] [PATCH] give troff a string register naming the next trap |
Date: |
Thu, 18 May 2023 05:58:28 -0400 (EDT) |
URL:
<https://savannah.gnu.org/bugs/?64212>
Summary: [PATCH] give troff a string register naming the next
trap
Group: GNU roff
Submitter: gbranden
Submitted: Thu 18 May 2023 09:58:26 AM UTC
Category: Core
Severity: 1 - Wish
Item Group: Feature change
Status: Need Info
Privacy: Public
Assigned to: None
Open/Closed: Open
Discussion Lock: Any
Planned Release: None
_______________________________________________________
Follow-up Comments:
-------------------------------------------------------
Date: Thu 18 May 2023 09:58:26 AM UTC By: G. Branden Robinson <gbranden>
This was, uh, "inspired" by the ongoing headache that is bug #57538.
I found it annoying that you can get the _distance_ to the next trap but not
its _name_, when internally, the formatter has ready access to this
information.
So here's a patch adding a new read-only, string-valued register that tells
you the name of the next trap you will spring if you are in the top level.
An empty string is interpolated if you are in a diversion (there is only at
most one trap in a diversion; it has no name) or if, somehow, there is no next
trap at the top level, but that...should be impossible?
Anyway, it worked to tell me what I wanted. It didn't cause a Eureka moment,
though.
diff --git a/src/roff/troff/div.cpp b/src/roff/troff/div.cpp
index f4dc06f33..679575f99 100644
--- a/src/roff/troff/div.cpp
+++ b/src/roff/troff/div.cpp
@@ -250,6 +250,11 @@ vunits macro_diversion::distance_to_next_trap()
return vunits(INT_MAX - vresolution);
}
+const char *macro_diversion::get_next_trap_name()
+{
+ return "";
+}
+
void macro_diversion::transparent_output(unsigned char c)
{
mac->append(c);
@@ -372,6 +377,16 @@ vunits top_level_diversion::distance_to_next_trap()
return d - vertical_position;
}
+const char *top_level_diversion::get_next_trap_name()
+{
+ vunits next_trap_pos;
+ trap *next_trap = find_next_trap(&next_trap_pos);
+ if (0 /* nullptr */ == next_trap)
+ return "";
+ else
+ return next_trap->nm.contents();
+}
+
void top_level_diversion::output(node *nd, int retain_size,
vunits vs, vunits post_vs, hunits width)
{
@@ -1059,6 +1074,16 @@ const char *diversion_name_reg::get_string()
return curdiv->get_diversion_name();
}
+class next_trap_name_reg : public reg {
+public:
+ const char *get_string();
+};
+
+const char *next_trap_name_reg::get_string()
+{
+ return curdiv->get_next_trap_name();
+}
+
class page_number_reg : public general_reg {
public:
page_number_reg();
@@ -1194,6 +1219,7 @@ void init_div_requests()
register_dictionary.define(".pe", new page_ejecting_reg);
register_dictionary.define(".pn", new next_page_number_reg);
register_dictionary.define(".t", new distance_to_next_trap_reg);
+ register_dictionary.define(".trap", new next_trap_name_reg);
register_dictionary.define(".trunc",
new constant_vunits_reg(&truncated_space));
register_dictionary.define(".vpt",
diff --git a/src/roff/troff/div.h b/src/roff/troff/div.h
index 15c7807a5..6180caa0b 100644
--- a/src/roff/troff/div.h
+++ b/src/roff/troff/div.h
@@ -57,6 +57,7 @@ public:
vunits get_vertical_position() { return vertical_position; }
vunits get_high_water_mark() { return high_water_mark; }
virtual vunits distance_to_next_trap() = 0;
+ virtual const char * get_next_trap_name() = 0;
void need(vunits);
const char *get_diversion_name() { return nm.contents(); }
virtual void set_diversion_trap(symbol, vunits) = 0;
@@ -84,6 +85,7 @@ public:
void vjustify(symbol);
#endif /* COLUMN */
vunits distance_to_next_trap();
+ const char *get_next_trap_name();
void set_diversion_trap(symbol, vunits);
void clear_diversion_trap();
void copy_file(const char *filename);
@@ -125,6 +127,7 @@ public:
hunits get_page_offset() { return page_offset; }
vunits get_page_length() { return page_length; }
vunits distance_to_next_trap();
+ const char *get_next_trap_name();
void add_trap(symbol nm, vunits pos);
void change_trap(symbol nm, vunits pos);
void remove_trap(symbol);
Does anybody want this?
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?64212>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
- [bug #64212] [PATCH] give troff a string register naming the next trap,
G. Branden Robinson <=