[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 33/33: [eqn]: Clear line number when it becomes nonsense.
From: |
G. Branden Robinson |
Subject: |
[groff] 33/33: [eqn]: Clear line number when it becomes nonsense. |
Date: |
Sun, 16 Oct 2022 15:52:21 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit c2e894cf5b42cfdaae48f03476fee24a6103f9c9
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Oct 16 14:23:26 2022 -0500
[eqn]: Clear line number when it becomes nonsense.
* src/preproc/eqn/lex.cpp (get_delimited_text): Clear line number when
hitting EOF.
* src/preproc/eqn/main.cpp: Revise end-of-file handling. Clear line
number upon reaching EOF so that we don't report a nonsense value one
greater than the number of lines in the input file.
(read_line): Boolify. Make static (local linkage only), since it has
no external callers. Introduce new Boolean variable `is_end_of_file`.
Clear `current_lineno` if EOF, and increment it otherwise.
(do_file, main): Clarify diagnostic messages.
---
ChangeLog | 13 +++++++++++++
src/preproc/eqn/lex.cpp | 2 ++
src/preproc/eqn/main.cpp | 16 ++++++++++------
3 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 97061669f..b57357021 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2022-10-15 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ * src/preproc/eqn/lex.cpp (get_delimited_text): Clear line
+ number when hitting EOF.
+ * src/preproc/eqn/main.cpp: Revise end-of-file handling. Clear
+ line number upon reaching EOF so that we don't report a nonsense
+ value one greater than the number of lines in the input file.
+ (read_line): Boolify. Make static (local linkage only), since
+ it has no external callers. Introduce new Boolean variable
+ `is_end_of_file`. Clear `current_lineno` if EOF, and increment
+ it otherwise.
+ (do_file, main): Clarify diagnostic messages.
+
2022-10-15 G. Branden Robinson <g.branden.robinson@gmail.com>
[eqn]: Improve diagnostics involving unprintable characters.
diff --git a/src/preproc/eqn/lex.cpp b/src/preproc/eqn/lex.cpp
index 2770b69e0..afca8e6f8 100644
--- a/src/preproc/eqn/lex.cpp
+++ b/src/preproc/eqn/lex.cpp
@@ -710,6 +710,7 @@ void get_delimited_text()
start = get_char();
token_buffer.clear();
if (start == EOF) {
+ current_lineno = 0;
if (got_location)
error_with_file_and_line(filename, lineno,
"end of input while defining macro");
@@ -720,6 +721,7 @@ void get_delimited_text()
for (;;) {
int c = get_char();
if (c == EOF) {
+ current_lineno = 0;
if (got_location)
error_with_file_and_line(filename, lineno,
"end of input while defining macro");
diff --git a/src/preproc/eqn/main.cpp b/src/preproc/eqn/main.cpp
index 536f256a9..eee83d435 100644
--- a/src/preproc/eqn/main.cpp
+++ b/src/preproc/eqn/main.cpp
@@ -76,7 +76,7 @@ static const char *input_char_description(int c)
return buf;
}
-int read_line(FILE *fp, string *p)
+static bool read_line(FILE *fp, string *p)
{
p->clear();
int c = -1;
@@ -88,8 +88,12 @@ int read_line(FILE *fp, string *p)
if (c == '\n')
break;
}
- current_lineno++;
- return p->length() > 0;
+ bool is_end_of_file = (p->length() > 0);
+ if (is_end_of_file)
+ current_lineno++;
+ else
+ current_lineno = 0;
+ return is_end_of_file;
}
void do_file(FILE *fp, const char *filename)
@@ -132,7 +136,7 @@ void do_file(FILE *fp, const char *filename)
else if (linebuf[2] == 'Q' && linebuf.length() > 3
&& (linebuf[3] == ' ' || linebuf[3] == '\n'
|| compatible_flag))
- fatal("nested .EQ");
+ fatal("equations cannot be nested (.EQ within .EQ)");
}
str += linebuf;
}
@@ -451,7 +455,7 @@ int main(int argc, char **argv)
errno = 0;
FILE *fp = fopen(argv[i], "r");
if (!fp)
- fatal("can't open '%1': %2", argv[i], strerror(errno));
+ fatal("unable to open '%1': %2", argv[i], strerror(errno));
else {
do_file(fp, argv[i]);
if (fclose(fp) < 0)
@@ -459,7 +463,7 @@ int main(int argc, char **argv)
}
}
if (ferror(stdout))
- fatal("error status on standard output stream");
+ fatal("standard output stream is in an error state");
if (fflush(stdout) < 0)
fatal("unable to flush standard output stream: %1",
strerror(errno));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 33/33: [eqn]: Clear line number when it becomes nonsense.,
G. Branden Robinson <=