gbranden pushed a commit to branch master
in repository groff.
commit ff11d1a9a61e648c88c150fd6b0e8de4e89887a1
Author: G. Branden Robinson <[email protected]>
AuthorDate: Mon Nov 2 11:02:11 2026 -0600
[soelim]: Fix Savannah #68719 (1/2).
* src/preproc/soelim/soelim.cpp (do_file): In raw mode, don't add a
newline to the end of file lacking one.
Begins fixing Savannah #68719.
NEWS: Add item.
ANNOUNCE: Acknowledge Ralph (who reported the issue in August 2018).
---
ANNOUNCE | 1 +
ChangeLog | 7 +++++++
NEWS | 3 +++
src/preproc/soelim/soelim.cpp | 22 ++++++++++++++--------
4 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/ANNOUNCE b/ANNOUNCE
index 4e1136a72..194489349 100644
--- a/ANNOUNCE
+++ b/ANNOUNCE
@@ -236,4 +236,5 @@ Doug McIlroy
Larry Kollar
Morten Bo Johansen
Peter Schaffter
+Ralph Corderoy
Stefan Möding
diff --git a/ChangeLog b/ChangeLog
index f8d1db197..0cf109d02 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2026-11-02 G. Branden Robinson <[email protected]>
+
+ * src/preproc/soelim/soelim.cpp (do_file): In raw mode, don't
+ add a newline to the end of file lacking one.
+
+ Begins fixing Savannah #68719.
+
2026-11-02 G. Branden Robinson <[email protected]>
[soelim]: Regression-test Savannah #68719.
diff --git a/NEWS b/NEWS
index 7a9e37e6f..84134e2e7 100644
--- a/NEWS
+++ b/NEWS
@@ -49,6 +49,9 @@ troff
soelim
------
+* soelim now appends a trailing newline to files it reads that are
+ lacking them, unless the `-r` ("raw") option is specified.
+
* soelim now recognizes an option `-x` that promotes failure to open
any included file to a fatal error.
diff --git a/src/preproc/soelim/soelim.cpp b/src/preproc/soelim/soelim.cpp
index 01f6ce027..63f97fa9a 100644
--- a/src/preproc/soelim/soelim.cpp
+++ b/src/preproc/soelim/soelim.cpp
@@ -233,10 +233,15 @@ static bool do_file(const char *filename)
SEEN_DOT_lf,
OTHER } state
= START;
+ bool file_ends_with_newline = false;
+ int prevc = 0;
for (;;) {
int c = getc(fp);
- if (c == EOF)
+ if (c == EOF) {
+ if ('\n' == prevc)
+ file_ends_with_newline = true;
break;
+ }
switch (state) {
case START:
if (c == '.')
@@ -342,32 +347,33 @@ static bool do_file(const char *filename)
default:
assert(0 == "unhandled state in file parser");
}
+ prevc = c;
}
// We've reached the end of input.
switch (state) {
case SEEN_DOT:
- fputs(".\n", stdout);
+ putc('.', stdout);
break;
case SEEN_DOT_l:
- fputs(".l\n", stdout);
+ fputs(".l", stdout);
break;
case SEEN_DOT_s:
- fputs(".s\n", stdout);
+ fputs(".s", stdout);
break;
case SEEN_DOT_lf:
- fputs(".lf\n", stdout);
+ fputs(".lf", stdout);
break;
case SEEN_DOT_so:
- fputs(".so\n", stdout);
+ fputs(".so", stdout);
break;
case OTHER:
- putc('\n', stdout);
- break;
case START:
break;
default:
assert(0 == "unhandled state in file parser at EOF");
}
+ if (!want_raw_output && !file_ends_with_newline)
+ putc('\n', stdout);
if (fp != stdin)
if (fclose(fp) < 0)
fatal("cannot close '%1': %2", whole_filename.contents(),
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit