[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 03/27: src/preproc/html/pre-html.cpp: Refactor (2/11).
From: |
G. Branden Robinson |
Subject: |
[groff] 03/27: src/preproc/html/pre-html.cpp: Refactor (2/11). |
Date: |
Sat, 2 Jul 2022 00:43:11 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit 9a97cca3737d168c2e6aee16d2e03a6f69055f86
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Jun 27 11:16:09 2022 -0500
src/preproc/html/pre-html.cpp: Refactor (2/11).
* src/preproc/html/pre-html.cpp (do_file): Drop conditional with empty
consequent.
(char_buffer::read_file): Demote return type from `int` to `void`.
Stop returning after calling functions that don't return. Call
`sys_fatal()` if `fread()` returns an error, similarly to other calls
into the standard C library that this file makes. Improve check for
error from `fread()` by not regarding a return value of zero when the
end-of-file indicator is set as an error condition.
---
ChangeLog | 8 ++++++++
src/preproc/html/pre-html.cpp | 22 ++++++++--------------
2 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 181073e0..55680f77 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,14 @@
* src/preproc/html/pre-html.cpp: Refactor. Drop unnecessary
prototype for static function.
+ (char_buffer::read_file): Demote return type from `int` to
+ `void`. Stop returning after calling functions that don't
+ return. Call `sys_fatal()` if `fread()` returns an error,
+ similarly to other calls into the standard C library that this
+ file makes. Improve check for error from `fread()` by not
+ regarding a return value of zero when the end-of-file indicator
+ is set as an error condition.
+ (do_file): Drop conditional with empty consequent.
2022-06-27 G. Branden Robinson <g.branden.robinson@gmail.com>
diff --git a/src/preproc/html/pre-html.cpp b/src/preproc/html/pre-html.cpp
index e3fde226..51713b64 100644
--- a/src/preproc/html/pre-html.cpp
+++ b/src/preproc/html/pre-html.cpp
@@ -448,7 +448,7 @@ class char_buffer {
public:
char_buffer();
~char_buffer();
- int read_file(FILE *fp);
+ void read_file(FILE *fp);
int do_html(int argc, char *argv[]);
int do_image(int argc, char *argv[]);
void emit_troff_output(int device_format_selector);
@@ -489,7 +489,7 @@ char_buffer::~char_buffer()
* char_blocks.
*/
-int char_buffer::read_file(FILE *fp)
+void char_buffer::read_file(FILE *fp)
{
int n;
while (!feof(fp)) {
@@ -505,14 +505,12 @@ int char_buffer::read_file(FILE *fp)
}
// at this point we have a tail which is ready for the next SIZE
// bytes of the file
- n = fread(tail->buffer, sizeof(char), char_block::SIZE-tail->used, fp);
- if (n <= 0)
- // error
- return 0;
- else
- tail->used += n * sizeof(char);
+ n = fread(tail->buffer, sizeof(char), char_block::SIZE-tail->used,
+ fp);
+ if ((n < 0) || ((0 == n) && !feof(fp)))
+ sys_fatal("fread");
+ tail->used += n * sizeof(char);
}
- return 1;
}
/*
@@ -1819,11 +1817,7 @@ static int do_file(const char *filename)
return 0;
}
}
-
- if (inputFile.read_file(fp)) {
- // XXX
- }
-
+ inputFile.read_file(fp);
if (fp != stdin)
fclose(fp);
current_filename = NULL;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 03/27: src/preproc/html/pre-html.cpp: Refactor (2/11).,
G. Branden Robinson <=