[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 16/16: [eqn]: Fix Savannah #63299.
From: |
G. Branden Robinson |
Subject: |
[groff] 16/16: [eqn]: Fix Savannah #63299. |
Date: |
Mon, 31 Oct 2022 21:33:29 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit dc98a8b09e7f3dcfe968b978eb210f468db78cc9
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Oct 31 20:01:34 2022 -0500
[eqn]: Fix Savannah #63299.
* src/preproc/eqn/main.cpp: Revise input file line number handling.
(read_line): Stop dealing with `current_lineno` here; it's now up to
its caller (`do_file()`) to manipulate the line number.
(do_file): When reading new file, initialize `current_lineno` to
1 instead of 0. Reset it to zero when encountering EOF (so that
diagnostics will not include a line number at all). When performing
nested call to `read_line()` to gather '.EN' from input, increment
the line number. Write correct line number in output groff `lf`
requests; in groff, its first argument assigns the number of the
_next_ input line. Increment line number at end of outer
`read_line()` loop.
Fixes <https://savannah.gnu.org/bugs/index.php?63299>. Thanks to Alex
Colomar for the report.
Also wrap long input lines and add explanatory comments.
---
ChangeLog | 20 ++++++++++++++++++++
src/preproc/eqn/main.cpp | 33 ++++++++++++++++++++-------------
2 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c87a94305..9bff3b0d9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2022-10-31 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ [eqn]: Fix Savannah #63299.
+
+ * src/preproc/eqn/main.cpp: Revise input file line number
+ handling.
+ (read_line): Stop dealing with `current_lineno` here; it's now
+ up to its caller (`do_file()`) to manipulate the line number.
+ (do_file): When reading new file, initialize `current_lineno` to
+ 1 instead of 0. Reset it to zero when encountering EOF (so that
+ diagnostics will not include a line number at all). When
+ performing nested call to `read_line()` to gather '.EN' from
+ input, increment the line number. Write correct line number in
+ output groff `lf` requests; in groff, its first argument assigns
+ the number of the _next_ input line. Increment line number at
+ end of outer `read_line()` loop.
+
+ Fixes <https://savannah.gnu.org/bugs/index.php?63299>. Thanks
+ to Alex Colomar for the report.
+
2022-10-31 G. Branden Robinson <g.branden.robinson@gmail.com>
[eqn]: Regression-test Savannah #63299.
diff --git a/src/preproc/eqn/main.cpp b/src/preproc/eqn/main.cpp
index 897a291dd..81d518443 100644
--- a/src/preproc/eqn/main.cpp
+++ b/src/preproc/eqn/main.cpp
@@ -88,12 +88,7 @@ static bool read_line(FILE *fp, string *p)
if (c == '\n')
break;
}
- bool is_end_of_file = (p->length() > 0);
- if (is_end_of_file)
- current_lineno = 0;
- else
- current_lineno++;
- return is_end_of_file;
+ return (p->length() > 0);
}
void do_file(FILE *fp, const char *filename)
@@ -106,13 +101,15 @@ void do_file(FILE *fp, const char *filename)
current_filename = fn.contents();
if (output_format == troff)
printf(".lf 1 %s\n", current_filename);
- current_lineno = 0;
+ current_lineno = 1;
while (read_line(fp, &linebuf)) {
if (linebuf.length() >= 4
&& linebuf[0] == '.' && linebuf[1] == 'l' && linebuf[2] == 'f'
- && (linebuf[3] == ' ' || linebuf[3] == '\n' || compatible_flag)) {
+ && (linebuf[3] == ' ' || linebuf[3] == '\n' || compatible_flag))
+ {
put_string(linebuf, stdout);
linebuf += '\0';
+ // In GNU roff, `lf` assigns the number of the _next_ line.
if (interpret_lf_args(linebuf.contents() + 3))
current_lineno--;
}
@@ -126,17 +123,23 @@ void do_file(FILE *fp, const char *filename)
int start_lineno = current_lineno + 1;
str.clear();
for (;;) {
- if (!read_line(fp, &linebuf))
+ if (!read_line(fp, &linebuf)) {
+ current_lineno = 0; // suppress report of line number
fatal("end of file before .EN");
- if (linebuf.length() >= 3 && linebuf[0] == '.' && linebuf[1] == 'E') {
+ }
+ if (linebuf.length() >= 3
+ && linebuf[0] == '.'
+ && linebuf[1] == 'E') {
if (linebuf[2] == 'N'
&& (linebuf.length() == 3 || linebuf[3] == ' '
|| linebuf[3] == '\n' || compatible_flag))
break;
else if (linebuf[2] == 'Q' && linebuf.length() > 3
&& (linebuf[3] == ' ' || linebuf[3] == '\n'
- || compatible_flag))
+ || compatible_flag)) {
+ current_lineno++; // We just read another line.
fatal("equations cannot be nested (.EQ within .EQ)");
+ }
}
str += linebuf;
}
@@ -151,12 +154,15 @@ void do_file(FILE *fp, const char *filename)
if (output_format == mathml)
putchar('\n');
else {
- printf(".lf %d\n", current_lineno - 1);
+ current_lineno++;
+ printf(".lf %d\n", current_lineno);
output_string();
}
}
- if (output_format == troff)
+ if (output_format == troff) {
+ current_lineno++;
printf(".lf %d\n", current_lineno);
+ }
put_string(linebuf, stdout);
}
else if (start_delim != '\0' && linebuf.search(start_delim) >= 0
@@ -164,6 +170,7 @@ void do_file(FILE *fp, const char *filename)
;
else
put_string(linebuf, stdout);
+ current_lineno++;
}
current_filename = 0;
current_lineno = 0;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 16/16: [eqn]: Fix Savannah #63299.,
G. Branden Robinson <=