[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 26/80: [troff]: Align with modern groff conventions.
From: |
G. Branden Robinson |
Subject: |
[groff] 26/80: [troff]: Align with modern groff conventions. |
Date: |
Sat, 30 Nov 2024 04:02:16 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit 5269992fb8a36756f7e8b63db6991ec568c132d1
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Wed Nov 27 16:12:06 2024 -0600
[troff]: Align with modern groff conventions.
* src/roff/troff/div.cpp:
* src/roff/troff/input.cpp: Add Autoconf "<config.h>"-inclusion
boilerplate to these translation units. Include system library
headers before local ones.
* src/roff/troff/input.cpp: Fix code style nits. Include "<string.h>"
header, since this file calls `strdup()`. Declare and use a constant
object to store a magic number. Use C++ `static_cast` operator
instead of C-style type cast.
---
ChangeLog | 14 ++++++++++++++
src/roff/troff/div.cpp | 7 ++++++-
src/roff/troff/input.cpp | 8 ++++++++
src/roff/troff/node.cpp | 12 ++++++++----
4 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 8fef8e97b..75c812db8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2024-11-27 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ [troff]: Align with modern groff conventions.
+
+ * src/roff/troff/div.cpp:
+ * src/roff/troff/input.cpp: Add Autoconf "<config.h>"-inclusion
+ boilerplate to these translation units. Include system library
+ headers before local ones.
+
+ * src/roff/troff/input.cpp: Fix code style nits. Include
+ "<string.h>" header, since this file calls `strdup()`. Declare
+ a and use a constant object to store a magic number. Use C++
+ `static_cast` operator instead of C-style type cast.
+
2024-11-27 G. Branden Robinson <g.branden.robinson@gmail.com>
* src/roff/troff/node.cpp: Fix inclusion wart. Include local
diff --git a/src/roff/troff/div.cpp b/src/roff/troff/div.cpp
index 94f28efcd..8b6fce33a 100644
--- a/src/roff/troff/div.cpp
+++ b/src/roff/troff/div.cpp
@@ -16,9 +16,14 @@ for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
// diversions
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h> // exit(), EXIT_SUCCESS
+
#include "troff.h"
#include "dictionary.h"
#include "hvunits.h"
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 474260a10..57e97d470 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -16,6 +16,14 @@ for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h> // atoi(), exit(), EXIT_FAILURE, EXIT_SUCCESS,
+ // free(), getenv(), putenv(), strtol(), system()
+#include <string.h> // strdup()
+
#include "troff.h"
#include "dictionary.h"
#include "hvunits.h"
diff --git a/src/roff/troff/node.cpp b/src/roff/troff/node.cpp
index ca5faa45b..1af9639de 100644
--- a/src/roff/troff/node.cpp
+++ b/src/roff/troff/node.cpp
@@ -22,7 +22,8 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
#include <config.h>
#endif
-#include <errno.h> // errno
+#include <errno.h>
+#include <stdlib.h> // free(), malloc()
#include "dictionary.h"
#include "hvunits.h"
@@ -4184,12 +4185,15 @@ void suppress_node::tprint(troff_output_file *out)
subimage_counter++;
assert(sizeof subimage_counter <= 8);
// A 64-bit signed int produces up to 19 decimal digits.
- char *subimage_number = (char *)malloc(20); // 19 digits + \0
+ const size_t ndigits = 19;
+ // Reserve enough for that plus null terminator.
+ char *subimage_number
+ = static_cast<char *>(malloc(ndigits + 1));
if (0 == subimage_number)
fatal("memory allocation failure");
// Replace the %d in the filename with this number.
- size_t enough = image_filename_len + 19 - format_len;
- char *new_name = (char *)malloc(enough);
+ size_t enough = image_filename_len + ndigits - format_len;
+ char *new_name = static_cast<char *>(malloc(enough));
if (0 == new_name)
fatal("memory allocation failure");
ptrdiff_t prefix_length = percent_position - image_filename;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 26/80: [troff]: Align with modern groff conventions.,
G. Branden Robinson <=