[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 06/27: src/preproc/html/pre-html.cpp: Refactor (5/11).
From: |
G. Branden Robinson |
Subject: |
[groff] 06/27: src/preproc/html/pre-html.cpp: Refactor (5/11). |
Date: |
Sat, 2 Jul 2022 00:43:11 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit ed392d6e66d59bdfed63d8ebc3139ba2aec3254a
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Jun 27 19:49:21 2022 -0500
src/preproc/html/pre-html.cpp: Refactor (5/11).
* src/preproc/html/pre-html.cpp (main): Boolify. Use idiomatic C++98
null pointer constant. Annotate it as null pointer to ease any future
migration to ISO C++11. Declare local variables closer to the points
of use. Stop trying to be a register allocator: stop reusing loop
index variable `i` as integer storage for another (albeit related)
purpose; introduce `operand_index` instead. Clarify logic by
splitting combined initialization and comparison operations, and by
testing function return value directly instead of storing it in a
pointless temporary. Use `EXIT_SUCCESS` and `EXIT_FAILURE` constants
from C library instead of integer literals for exit status.
---
ChangeLog | 16 +++++++++++++---
src/preproc/html/pre-html.cpp | 40 +++++++++++++++++-----------------------
2 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 54610ec9..bb7c0da2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -10,12 +10,22 @@
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.
- (makeTempFiles, do_file): Boolify. Use idiomatic C++98 null
- pointer constant. Annotate it as null pointer to ease any
- future migration to ISO C++11. Reorder null pointer equality
+ (makeTempFiles, do_file, main): Boolify. Use idiomatic C++98
+ null pointer constant. Annotate it as null pointer to ease any
+ future migration to ISO C++11.
+ (makeTempFiles, do_file): Reorder null pointer equality
comparisons to avoid inadvertent lvalue assignment.
(do_file): Demote return type from `int` to `bool`. Return
Boolean literals. Drop conditional with empty consequent.
+ (main): Declare local variables closer to the points of use.
+ Stop trying to be a register allocator: stop reusing loop index
+ variable `i` as integer storage for another (albeit related)
+ purpose; introduce `operand_index` instead. Clarify logic by
+ splitting combined initialization and comparison operations, and
+ by testing function return value directly instead of storing it
+ in a pointless temporary. Use `EXIT_SUCCESS` and `EXIT_FAILURE`
+ constants from C library instead of integer literals for exit
+ status.
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 3e3f13b6..21cc3603 100644
--- a/src/preproc/html/pre-html.cpp
+++ b/src/preproc/html/pre-html.cpp
@@ -1811,25 +1811,20 @@ static bool do_file(const char *filename)
int main(int argc, char **argv)
{
- program_name = argv[0];
- int i;
- int found = 0;
- int ok = 1;
-
#ifdef CAPTURE_MODE
- FILE *dump;
fprintf(stderr, "%s: invoked with %d arguments ...\n", argv[0], argc);
- for (i = 0; i < argc; i++)
+ for (int i = 0; i < argc; i++)
fprintf(stderr, "%2d: %s\n", i, argv[i]);
- if ((dump = fopen(DEBUG_FILE("pre-html-data"), "wb")) != NULL) {
- while((i = fgetc(stdin)) >= 0)
- fputc(i, dump);
+ FILE *dump = fopen(DEBUG_FILE("pre-html-data"), "wb");
+ if (dump != 0 /* nullptr */) {
+ while((int ch = fgetc(stdin)) >= 0)
+ fputc(ch, dump);
fclose(dump);
}
- exit(1);
+ exit(EXIT_FAILURE);
#endif /* CAPTURE_MODE */
- device = "html";
- i = scanArguments(argc, argv);
+ program_name = argv[0];
+ int operand_index = scanArguments(argc, argv);
image_gen = strsave(get_image_generator());
if (0 == image_gen)
fatal("'image_generator' directive not found in file '%1'",
@@ -1841,18 +1836,17 @@ int main(int argc, char **argv)
setupAntiAlias();
checkImageDir();
makeFileName();
- while (i < argc) {
- if (argv[i][0] != '-') {
- /* found source file */
- ok = do_file(argv[i]);
- if (!ok)
- return 0;
- found = 1;
+ bool have_file_operand = false;
+ while (operand_index < argc) {
+ if (argv[operand_index][0] != '-') {
+ if(!do_file(argv[operand_index]))
+ exit(EXIT_FAILURE);
+ have_file_operand = true;
}
- i++;
+ operand_index++;
}
- if (!found)
+ if (!have_file_operand)
do_file("-");
makeTempFiles();
int wstatus = inputFile.do_image(argc, argv);
@@ -1865,7 +1859,7 @@ int main(int argc, char **argv)
fatal("'%1' exited with status %2; re-run '%1' with a different"
" output driver to see diagnostic messages", argv[0],
WEXITSTATUS(wstatus));
- return 0;
+ exit(EXIT_SUCCESS);
}
// Local Variables:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 06/27: src/preproc/html/pre-html.cpp: Refactor (5/11).,
G. Branden Robinson <=