[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 03/10: [libgroff]: Centralize defs of {U,}INT_DIGITS.
From: |
G. Branden Robinson |
Subject: |
[groff] 03/10: [libgroff]: Centralize defs of {U,}INT_DIGITS. |
Date: |
Wed, 10 Nov 2021 09:23:43 -0500 (EST) |
gbranden pushed a commit to branch master
in repository groff.
commit f208a2271c89b3f295e3d77b61d0a2c002b167ee
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Tue Nov 9 21:38:56 2021 +1100
[libgroff]: Centralize defs of {U,}INT_DIGITS.
* src/libs/libgroff/iftoa.c:
* src/libs/libgroff/itoa.c: Move definitions of `INT_DIGITS` and
`UINT_DIGITS` from here...
* src/include/lib.h: ...to here.
* src/libs/libgroff/iftoa.c:
* src/libs/libgroff/itoa.c: Preprocessor-include "lib.h". This
revealed missing guards around `extern "C"` declarations, so...
* src/include/lib.h: Add them where necessary.
Also wrap long lines.
Also update editor aids where missing; drop old style Emacs file-local
variable settings.
---
ChangeLog | 15 +++++++++++++++
src/include/lib.h | 34 ++++++++++++++++++++++++++++------
src/libs/libgroff/iftoa.c | 13 +++++++++----
src/libs/libgroff/itoa.c | 9 +++++++--
4 files changed, 59 insertions(+), 12 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 34a51d3..7f65e86 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
2021-11-09 G. Branden Robinson <g.branden.robinson@gmail.com>
+ [libgroff]: Centralize definitions of {U,}INT_DIGITS.
+
+ * src/libs/libgroff/iftoa.c:
+ * src/libs/libgroff/itoa.c: Move definitions of `INT_DIGITS` and
+ `UINT_DIGITS` from here...
+ * src/include/lib.h: ...to here.
+
+ * src/libs/libgroff/iftoa.c:
+ * src/libs/libgroff/itoa.c: Preprocessor-include "lib.h". This
+ revealed missing guards around `extern "C"` declarations, so...
+
+ * src/include/lib.h: Add them where necessary.
+
+2021-11-09 G. Branden Robinson <g.branden.robinson@gmail.com>
+
* tmac/an.tmac (OP): Fix code style nits. Don't quote macro
arguments unnecessarily. Use consistent backslashing. Use
groff font escape sequence syntax. Use adjustable non-breaking
diff --git a/src/include/lib.h b/src/include/lib.h
index be95b9b..639b9e0 100644
--- a/src/include/lib.h
+++ b/src/include/lib.h
@@ -1,4 +1,3 @@
-// -*- C++ -*-
/* Copyright (C) 1989-2020 Free Software Foundation, Inc.
Written by James Clark (jjc@jclark.com)
@@ -25,6 +24,7 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
#define _ALL_SOURCE
#endif
+#ifdef __cplusplus
extern "C" {
#ifndef HAVE_STRERROR
char *strerror(int);
@@ -33,6 +33,7 @@ extern "C" {
const char *ui_to_a(unsigned int);
const char *if_to_a(int, int);
}
+#endif /* __cplusplus */
#define __GETOPT_PREFIX groff_
#include <getopt.h>
@@ -60,9 +61,11 @@ double groff_hypot(double, double);
#include <stdarg.h>
/* LynxOS 4.0.0 doesn't declare vfprintf() */
+#ifdef __cplusplus
#ifdef NEED_DECLARATION_VFPRINTF
extern "C" { int vfprintf(FILE *, const char *, va_list); }
#endif
+#endif /* __cplusplus */
#ifndef HAVE_MKSTEMP
/* since mkstemp() is defined as a real C++ function if taken from
@@ -72,18 +75,25 @@ int mkstemp(char *tmpl);
int mksdir(char *tmpl);
+#ifdef __cplusplus
FILE *xtmpfile(char **namep = 0,
- const char *postfix_long = 0, const char *postfix_short = 0,
+ const char *postfix_long = 0,
+ const char *postfix_short = 0,
int do_unlink = 1);
char *xtmptemplate(const char *postfix_long, const char *postfix_short);
+#endif
+#ifdef __cplusplus
#ifdef NEED_DECLARATION_POPEN
extern "C" { FILE *popen(const char *, const char *); }
#endif /* NEED_DECLARATION_POPEN */
+#endif /* __cplusplus */
+#ifdef __cplusplus
#ifdef NEED_DECLARATION_PCLOSE
extern "C" { int pclose (FILE *); }
#endif /* NEED_DECLARATION_PCLOSE */
+#endif /* __cplusplus */
size_t file_name_max(const char *fname);
size_t path_name_max();
@@ -95,6 +105,7 @@ inline int invalid_input_char(int c)
return c >= 0 && invalid_char_table[c];
}
+#ifdef __cplusplus
#ifdef HAVE_STRCASECMP
#ifdef NEED_DECLARATION_STRCASECMP
// Ultrix4.3's string.h fails to declare this.
@@ -103,7 +114,9 @@ extern "C" { int strcasecmp(const char *, const char *); }
#else /* !HAVE_STRCASECMP */
extern "C" { int strcasecmp(const char *, const char *); }
#endif /* HAVE_STRCASECMP */
+#endif /* __cplusplus */
+#ifdef __cplusplus
#if !defined(_AIX) && !defined(sinix) && !defined(__sinix__)
#ifdef HAVE_STRNCASECMP
#ifdef NEED_DECLARATION_STRNCASECMP
@@ -114,6 +127,7 @@ extern "C" { int strncasecmp(const char *, const char *,
int); }
extern "C" { int strncasecmp(const char *, const char *, size_t); }
#endif /* HAVE_STRNCASECMP */
#endif /* !_AIX && !sinix && !__sinix__ */
+#endif /* __cplusplus */
#ifdef HAVE_CC_LIMITS_H
#include <limits.h>
@@ -121,13 +135,21 @@ extern "C" { int strncasecmp(const char *, const char *,
size_t); }
#define INT_MAX 2147483647
#endif /* !HAVE_CC_LIMITS_H */
-/* Maximum number of digits in the decimal representation of an int
- (not including the -). */
-
-#define INT_DIGITS 10
+/* Maximum number of digits in decimal representations of `int` types
+ not including a leading minus sign. */
+#define INT_DIGITS 19 /* enough for 64 bit integer */
+#define UINT_DIGITS 20
#ifdef PI
#undef PI
#endif
+#ifdef __cplusplus
const double PI = 3.14159265358979323846;
+#endif
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/libs/libgroff/iftoa.c b/src/libs/libgroff/iftoa.c
index 57d72b6..c0cf154 100644
--- a/src/libs/libgroff/iftoa.c
+++ b/src/libs/libgroff/iftoa.c
@@ -16,19 +16,18 @@ 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/>. */
-#define INT_DIGITS 19 /* enough for 64-bit integer */
-
#ifdef __cplusplus
extern "C" {
#endif
+#include "lib.h"
+
/* Prototype */
char *if_to_a(int, int);
char *if_to_a(int i, int decimal_point)
{
- /* room for a -, INT_DIGITS digits, a decimal point, and a terminating '\0'
*/
- static char buf[INT_DIGITS + 3];
+ static char buf[INT_DIGITS + 3]; // INT_DIGITS + '-', '.', '\0'
char *p = buf + INT_DIGITS + 2;
int point = 0;
buf[INT_DIGITS + 2] = '\0';
@@ -72,3 +71,9 @@ char *if_to_a(int i, int decimal_point)
#ifdef __cplusplus
}
#endif
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
diff --git a/src/libs/libgroff/itoa.c b/src/libs/libgroff/itoa.c
index 2a5897e..2fad3a9 100644
--- a/src/libs/libgroff/itoa.c
+++ b/src/libs/libgroff/itoa.c
@@ -16,8 +16,7 @@ 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/>. */
-#define INT_DIGITS 19 /* enough for 64 bit integer */
-#define UINT_DIGITS 20
+#include "lib.h"
#ifdef __cplusplus
extern "C" {
@@ -64,3 +63,9 @@ char *ui_to_a(unsigned int i)
#ifdef __cplusplus
}
#endif
+
+// Local Variables:
+// fill-column: 72
+// mode: C++
+// End:
+// vim: set cindent noexpandtab shiftwidth=2 textwidth=72:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 03/10: [libgroff]: Centralize defs of {U,}INT_DIGITS.,
G. Branden Robinson <=