From d4276760ab12d7e8873cdeb1eb18164b08ebd64a Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 9 Oct 2021 00:38:54 -0700
Subject: [PATCH] [gnulib]: Include <config.h> first

Gnulib requires that files that might use Gnulib features
(which pretty much means every C or C++ source file)
must include <config.h> first.  Arrange for that.
This will be needed once Groff updates to the latest Gnulib;
see Bjarni Ingi Gislason's problem report in:
https://lists.gnu.org/r/bug-gnulib/2021-10/msg00008.html

The only exception I can see is src/utils/addftinfo/guess.cpp,
which does not include any standard include file either directly
or indirectly, and so need not include <config.h>.
---
 src/devices/xditview/Dvi.c      | 2 ++
 src/devices/xditview/font.c     | 2 ++
 src/devices/xditview/lex.c      | 2 ++
 src/devices/xditview/page.c     | 2 ++
 src/devices/xditview/parse.c    | 2 ++
 src/libs/libbib/map.c           | 6 ++----
 src/libs/libgroff/change_lf.cpp | 1 +
 src/libs/libgroff/cmap.cpp      | 1 +
 src/libs/libgroff/cset.cpp      | 1 +
 src/libs/libgroff/fmod.c        | 2 +-
 src/libs/libgroff/getcwd.c      | 1 +
 src/libs/libgroff/lf.cpp        | 4 ++--
 src/libs/libgroff/ptable.cpp    | 2 ++
 src/libs/libgroff/quotearg.c    | 2 ++
 src/libs/libxutil/DviChar.c     | 2 ++
 src/libs/libxutil/XFontName.c   | 2 ++
 src/libs/libxutil/xmalloc.c     | 2 ++
 src/utils/indxbib/signal.c      | 5 +----
 18 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/src/devices/xditview/Dvi.c b/src/devices/xditview/Dvi.c
index 28512ae4..3520676f 100644
--- a/src/devices/xditview/Dvi.c
+++ b/src/devices/xditview/Dvi.c
@@ -1,3 +1,5 @@
+#include <config.h>
+
 #ifndef SABER
 #ifndef lint
 static char Xrcsid[] = "$XConsortium: Dvi.c,v 1.9 89/12/10 16:12:25 rws Exp $";
diff --git a/src/devices/xditview/font.c b/src/devices/xditview/font.c
index 97eb46e7..84626082 100644
--- a/src/devices/xditview/font.c
+++ b/src/devices/xditview/font.c
@@ -4,6 +4,8 @@
  * map dvi fonts to X fonts
  */
 
+#include <config.h>
+
 #include <X11/Xos.h>
 #include <X11/IntrinsicP.h>
 #include <X11/StringDefs.h>
diff --git a/src/devices/xditview/lex.c b/src/devices/xditview/lex.c
index 75711016..19cf2920 100644
--- a/src/devices/xditview/lex.c
+++ b/src/devices/xditview/lex.c
@@ -1,3 +1,5 @@
+#include <config.h>
+
 #include <X11/Xos.h>
 #include <X11/IntrinsicP.h>
 #include <X11/StringDefs.h>
diff --git a/src/devices/xditview/page.c b/src/devices/xditview/page.c
index dcc655a4..352d8712 100644
--- a/src/devices/xditview/page.c
+++ b/src/devices/xditview/page.c
@@ -4,6 +4,8 @@
  * map page numbers to file position
  */
 
+#include <config.h>
+
 #include <X11/Xos.h>
 #include <X11/IntrinsicP.h>
 #include <X11/StringDefs.h>
diff --git a/src/devices/xditview/parse.c b/src/devices/xditview/parse.c
index 2584a8c9..456c7dab 100644
--- a/src/devices/xditview/parse.c
+++ b/src/devices/xditview/parse.c
@@ -4,6 +4,8 @@
  * parse dvi input
  */
 
+#include <config.h>
+
 #include <X11/Xos.h>
 #include <X11/IntrinsicP.h>
 #include <X11/StringDefs.h>
diff --git a/src/libs/libbib/map.c b/src/libs/libbib/map.c
index 5710d314..9eae72b8 100644
--- a/src/libs/libbib/map.c
+++ b/src/libs/libbib/map.c
@@ -16,11 +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/>. */
 
-#include <stdlib.h>
-
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
+
+#include <stdlib.h>
 
 #ifdef HAVE_MMAP
 
diff --git a/src/libs/libgroff/change_lf.cpp b/src/libs/libgroff/change_lf.cpp
index 5a183754..eb98766d 100644
--- a/src/libs/libgroff/change_lf.cpp
+++ b/src/libs/libgroff/change_lf.cpp
@@ -16,6 +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/>. */
 
+#include <config.h>
 #include <string.h>
 
 extern char *strsave(const char *);
diff --git a/src/libs/libgroff/cmap.cpp b/src/libs/libgroff/cmap.cpp
index 4a80a6db..3f2c0c32 100644
--- a/src/libs/libgroff/cmap.cpp
+++ b/src/libs/libgroff/cmap.cpp
@@ -17,6 +17,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/>. */
 
+#include <config.h>
 #include <ctype.h>
 #include "cmap.h"
 
diff --git a/src/libs/libgroff/cset.cpp b/src/libs/libgroff/cset.cpp
index 97905507..67022372 100644
--- a/src/libs/libgroff/cset.cpp
+++ b/src/libs/libgroff/cset.cpp
@@ -17,6 +17,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/>. */
 
+#include <config.h>
 #include <ctype.h>
 
 #include "lib.h"
diff --git a/src/libs/libgroff/fmod.c b/src/libs/libgroff/fmod.c
index 8b0b25aa..45278f96 100644
--- a/src/libs/libgroff/fmod.c
+++ b/src/libs/libgroff/fmod.c
@@ -16,6 +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/>. */
 
+#include <config.h>
 #include <math.h>
 
 double fmod(x, y)
@@ -24,4 +25,3 @@ double fmod(x, y)
   double quot = x/y;
   return x - (quot < 0.0 ? ceil(quot) : floor(quot)) * y;
 }
-
diff --git a/src/libs/libgroff/getcwd.c b/src/libs/libgroff/getcwd.c
index d0cfc8f7..dd8b5788 100644
--- a/src/libs/libgroff/getcwd.c
+++ b/src/libs/libgroff/getcwd.c
@@ -18,6 +18,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 /* Partial emulation of getcwd in terms of getwd. */
 
+#include <config.h>
 #include <sys/param.h>
 #include <string.h>
 #include <errno.h>
diff --git a/src/libs/libgroff/lf.cpp b/src/libs/libgroff/lf.cpp
index 135fd794..9c255fbc 100644
--- a/src/libs/libgroff/lf.cpp
+++ b/src/libs/libgroff/lf.cpp
@@ -17,13 +17,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 <ctype.h>
-
 #include "lib.h"
 #include "cset.h"
 #include "stringclass.h"
 #include "lf.h"
 
+#include <ctype.h>
+
 extern void change_filename(const char *);
 extern void change_lineno(int);
 
diff --git a/src/libs/libgroff/ptable.cpp b/src/libs/libgroff/ptable.cpp
index eff0e04c..52d09f8b 100644
--- a/src/libs/libgroff/ptable.cpp
+++ b/src/libs/libgroff/ptable.cpp
@@ -16,6 +16,8 @@ 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 <config.h>
+
 #include "ptable.h"
 #include "errarg.h"
 #include "error.h"
diff --git a/src/libs/libgroff/quotearg.c b/src/libs/libgroff/quotearg.c
index 8d217073..75eaca8f 100644
--- a/src/libs/libgroff/quotearg.c
+++ b/src/libs/libgroff/quotearg.c
@@ -17,6 +17,8 @@ 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 <config.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/src/libs/libxutil/DviChar.c b/src/libs/libxutil/DviChar.c
index ef9262db..d44e27c3 100644
--- a/src/libs/libxutil/DviChar.c
+++ b/src/libs/libxutil/DviChar.c
@@ -22,6 +22,8 @@ internet at <http://www.gnu.org/licenses/gpl-2.0.txt>. */
  * font indexes and back
  */
 
+#include <config.h>
+
 #include <stdlib.h>
 #include <string.h>
 #include "DviChar.h"
diff --git a/src/libs/libxutil/XFontName.c b/src/libs/libxutil/XFontName.c
index d366ada5..81ccdaab 100644
--- a/src/libs/libxutil/XFontName.c
+++ b/src/libs/libxutil/XFontName.c
@@ -21,6 +21,8 @@ internet at <http://www.gnu.org/licenses/gpl-2.0.txt>. */
  * build/parse X Font name strings
  */
 
+#include <config.h>
+
 #include <X11/Xlib.h>
 #include <X11/Xos.h>
 #include "XFontName.h"
diff --git a/src/libs/libxutil/xmalloc.c b/src/libs/libxutil/xmalloc.c
index 9eb7564d..0852c626 100644
--- a/src/libs/libxutil/xmalloc.c
+++ b/src/libs/libxutil/xmalloc.c
@@ -15,6 +15,8 @@ for more details.
 The GNU General Public License version 2 (GPL2) is available in the
 internet at <http://www.gnu.org/licenses/gpl-2.0.txt>. */
 
+#include <config.h>
+
 #include <X11/Xlib.h>
 #include <X11/Intrinsic.h>
 
diff --git a/src/utils/indxbib/signal.c b/src/utils/indxbib/signal.c
index a1f30cef..2231b646 100644
--- a/src/utils/indxbib/signal.c
+++ b/src/utils/indxbib/signal.c
@@ -19,12 +19,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 /* Unfortunately vendors seem to have problems writing a <signal.h>
 that is correct for C++, so we implement all signal handling in C. */
 
-#include <stdlib.h>
-
-#ifdef HAVE_CONFIG_H
 #include <config.h>
-#endif
 
+#include <stdlib.h>
 #include <sys/types.h>
 #include <signal.h>
 #ifdef HAVE_UNISTD_H
-- 
2.31.1

