groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 04/10: [libgroff,grops]: Slightly refactor.


From: G. Branden Robinson
Subject: [groff] 04/10: [libgroff,grops]: Slightly refactor.
Date: Wed, 10 Nov 2021 09:23:43 -0500 (EST)

gbranden pushed a commit to branch master
in repository groff.

commit d184e4bdb8bd9e4ef6fd985b1c6808b02d7c97fd
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Tue Nov 9 23:18:16 2021 +1100

    [libgroff,grops]: Slightly refactor.
    
    * src/devices/grops/ps.cpp: Explicitly preprocessor-include "lib.h"
      since we use the `PI` symbol it defines.
    
    * src/include/lib.h: Add inclusion guard.  Wrap only `extern "C" and its
      braces in preprocessor conditionals, so that prototypes are present in
      the header even for C language code that #includes this header.  Add
      `static` storage class to `PI` symbol to avoid redefinition errors
      from the linker.  Give `path_name_max` a proper prototype, taking a
      `void` parameter list.
    
    * src/libs/libgroff/iftoa.c (if_to_a):
    * src/libs/libgroff/itoa.c (i_to_a, ui_to_a): Add `const` type qualifier
      to function definitions for agreement with prototypes in "lib.h".
      Drop local copies of prototypes.
---
 ChangeLog                 | 18 ++++++++++++
 src/devices/grops/ps.cpp  |  1 +
 src/include/lib.h         | 70 +++++++++++++++++++++++++----------------------
 src/libs/libgroff/iftoa.c |  9 ++----
 src/libs/libgroff/itoa.c  |  8 ++----
 5 files changed, 61 insertions(+), 45 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7f65e86..c7c0592 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
 2021-11-09  G. Branden Robinson <g.branden.robinson@gmail.com>
 
+       [libgroff,grops]: Slightly refactor.
+
+       * src/devices/grops/ps.cpp: Explicitly preprocessor-include
+       "lib.h" since we use the `PI` symbol it defines.
+
+       * src/include/lib.h: Add inclusion guard.  Wrap only `extern "C"
+       and its braces in preprocessor conditionals, so that prototypes
+       are present in the header even for C language code that
+       #includes this header.  Add `static` storage class to `PI`
+       symbol to avoid redefinition errors from the linker.
+
+       * src/libs/libgroff/iftoa.c (if_to_a):
+       * src/libs/libgroff/itoa.c (i_to_a, ui_to_a): Add `const` type
+       qualifier to function definitions for agreement with prototypes
+       in "lib.h".  Drop local copies of prototypes.
+
+2021-11-09  G. Branden Robinson <g.branden.robinson@gmail.com>
+
        [libgroff]: Centralize definitions of {U,}INT_DIGITS.
 
        * src/libs/libgroff/iftoa.c:
diff --git a/src/devices/grops/ps.cpp b/src/devices/grops/ps.cpp
index 37ac546..83acb11 100644
--- a/src/devices/grops/ps.cpp
+++ b/src/devices/grops/ps.cpp
@@ -22,6 +22,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
  *   http://partners.adobe.com/public/developer/en/ps/5001.DSC_Spec.pdf
  */
 
+#include "lib.h" // PI
 #include "driver.h"
 #include "stringclass.h"
 #include "cset.h"
diff --git a/src/include/lib.h b/src/include/lib.h
index 639b9e0..a9ca8b4 100644
--- a/src/include/lib.h
+++ b/src/include/lib.h
@@ -16,6 +16,9 @@ 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/>. */
 
+#ifndef GROFF_LIB_H
+#define GROFF_LIB_H
+
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -26,14 +29,16 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 
 #ifdef __cplusplus
 extern "C" {
+#endif
 #ifndef HAVE_STRERROR
   char *strerror(int);
 #endif
   const char *i_to_a(int);
   const char *ui_to_a(unsigned int);
   const char *if_to_a(int, int);
+#ifdef __cplusplus
 }
-#endif /* __cplusplus */
+#endif
 
 #define __GETOPT_PREFIX groff_
 #include <getopt.h>
@@ -60,12 +65,14 @@ double groff_hypot(double, double);
 
 #include <stdarg.h>
 
-/* LynxOS 4.0.0 doesn't declare vfprintf() */
 #ifdef __cplusplus
+extern "C" {
+#endif
+
+/* LynxOS 4.0.0 doesn't declare vfprintf() */
 #ifdef NEED_DECLARATION_VFPRINTF
-extern "C" { int vfprintf(FILE *, const char *, va_list); }
+  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
@@ -76,58 +83,55 @@ 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,
-              int do_unlink = 1);
-char *xtmptemplate(const char *postfix_long, const char *postfix_short);
+  FILE *xtmpfile(char **namep = 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 *); }
+  FILE *popen(const char *, const char *);
 #endif /* NEED_DECLARATION_POPEN */
-#endif /* __cplusplus */
 
-#ifdef __cplusplus
 #ifdef NEED_DECLARATION_PCLOSE
-extern "C" { int pclose (FILE *); }
+  int pclose (FILE *);
 #endif /* NEED_DECLARATION_PCLOSE */
-#endif /* __cplusplus */
 
-size_t file_name_max(const char *fname);
-size_t path_name_max();
+  size_t file_name_max(const char *fname);
+  size_t path_name_max(void);
 
-extern char invalid_char_table[];
+  extern char invalid_char_table[];
 
-inline int invalid_input_char(int c)
-{
-  return c >= 0 && invalid_char_table[c];
-}
+  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.
-extern "C" { int strcasecmp(const char *, const char *); }
+  int strcasecmp(const char *, const char *); }
 #endif /* NEED_DECLARATION_STRCASECMP */
 #else /* !HAVE_STRCASECMP */
-extern "C" { int strcasecmp(const char *, const char *); }
+  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
 // SunOS's string.h fails to declare this.
-extern "C" { int strncasecmp(const char *, const char *, int); }
+  int strncasecmp(const char *, const char *, int);
 #endif /* NEED_DECLARATION_STRNCASECMP */
 #else /* !HAVE_STRNCASECMP */
-extern "C" { int strncasecmp(const char *, const char *, size_t); }
+  int strncasecmp(const char *, const char *, size_t);
 #endif /* HAVE_STRNCASECMP */
 #endif /* !_AIX && !sinix && !__sinix__ */
-#endif /* __cplusplus */
+
+#ifdef __cplusplus
+}
+#endif
 
 #ifdef HAVE_CC_LIMITS_H
 #include <limits.h>
@@ -144,9 +148,9 @@ extern "C" { int strncasecmp(const char *, const char *, 
size_t); }
 #undef PI
 #endif
 
-#ifdef __cplusplus
-const double PI = 3.14159265358979323846;
-#endif
+static const double PI = 3.14159265358979323846;
+
+#endif /* GROFF_LIB_H */
 
 // Local Variables:
 // fill-column: 72
diff --git a/src/libs/libgroff/iftoa.c b/src/libs/libgroff/iftoa.c
index c0cf154..87aec58 100644
--- a/src/libs/libgroff/iftoa.c
+++ b/src/libs/libgroff/iftoa.c
@@ -16,16 +16,13 @@ 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/>. */
 
+#include "lib.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include "lib.h"
-
-/* Prototype */
-char *if_to_a(int, int);
-
-char *if_to_a(int i, int decimal_point)
+const char *if_to_a(int i, int decimal_point)
 {
   static char buf[INT_DIGITS + 3]; // INT_DIGITS + '-', '.', '\0'
   char *p = buf + INT_DIGITS + 2;
diff --git a/src/libs/libgroff/itoa.c b/src/libs/libgroff/itoa.c
index 2fad3a9..a573b2c 100644
--- a/src/libs/libgroff/itoa.c
+++ b/src/libs/libgroff/itoa.c
@@ -22,11 +22,7 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>. */
 extern "C" {
 #endif
 
-/* Prototypes */
-char *i_to_a(int);
-char *ui_to_a(unsigned int);
-
-char *i_to_a(int i)
+const char *i_to_a(int i)
 {
   /* Room for INT_DIGITS digits, - and '\0' */
   static char buf[INT_DIGITS + 2];
@@ -48,7 +44,7 @@ char *i_to_a(int i)
   return p;
 }
 
-char *ui_to_a(unsigned int i)
+const char *ui_to_a(unsigned int i)
 {
   /* Room for UINT_DIGITS digits and '\0' */
   static char buf[UINT_DIGITS + 1];



reply via email to

[Prev in Thread] Current Thread [Next in Thread]