gbranden pushed a commit to branch master
in repository groff.
commit 2e16600dcfcdc52976ec446a3ce9e73559f5035e
Author: G. Branden Robinson <[email protected]>
AuthorDate: Fri Sep 13 03:14:34 2024 -0500
[troff]: Refactor *roff stream handling (2/2).
* src/roff/troff/input.cpp (close_request): Move stream-closing
logic (as opposed to request argument validation) into...
(close_stream): ...its own new function.
---
ChangeLog | 6 ++++++
src/roff/troff/input.cpp | 33 ++++++++++++++++++++-------------
2 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index dcdf74d00..addfc34ee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-09-13 G. Branden Robinson <[email protected]>
+
+ * src/roff/troff/input.cpp (close_request): Move stream-closing
+ logic (as opposed to request argument validation) into...
+ (close_stream): ...its own new function.
+
2024-09-13 G. Branden Robinson <[email protected]>
* src/roff/troff/input.cpp: Declare global `stream_dictionary`
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 57a2032d0..afe1718db 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -7275,6 +7275,24 @@ static void opena_request() // .opena
skip_line();
}
+static void close_stream(symbol &stream)
+{
+ assert(!stream.is_null());
+ FILE *fp = (FILE *)stream_dictionary.lookup(stream);
+ if (0 /* nullptr */ == fp) {
+ error("cannot close nonexistent stream '%1'", stream.contents());
+ return;
+ }
+ else {
+ if (fclose(fp) != 0) {
+ error("cannot close stream '%1': %2", stream.contents(),
+ strerror(errno));
+ return;
+ }
+ }
+ stream_dictionary.remove(stream);
+}
+
static void close_request() // .close
{
if (!has_arg(true /* peek */)) {
@@ -7285,19 +7303,8 @@ static void close_request() // .close
symbol stream = get_name();
// Testing has_arg() should have ensured this.
assert(stream != 0 /* nullptr */);
- FILE *fp = (FILE *)stream_dictionary.lookup(stream);
- if (0 /* nullptr */ == fp) {
- error("cannot close nonexistent stream '%1'", stream.contents());
- skip_line();
- return;
- }
- if (fclose(fp) != 0) {
- error("cannot close stream '%1': %2", stream.contents(),
- strerror(errno));
- skip_line();
- return;
- }
- stream_dictionary.remove(stream);
+ if (!stream.is_null())
+ close_stream(stream);
skip_line();
}
_______________________________________________
Groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit