From 63d35aa5d8506a3b07b1c6180afebf5c0ce80cc3 Mon Sep 17 00:00:00 2001
Message-Id: <63d35aa5d8506a3b07b1c6180afebf5c0ce80cc3.1185041274.git.jay@gnu.org>
In-Reply-To: <53b7790a9677c049de18a1b807d933ba2b7d569c.1185041274.git.jay@gnu.org>
References: <53b7790a9677c049de18a1b807d933ba2b7d569c.1185041274.git.jay@gnu.org>
From: James Youngman <jay@gnu.org>
Date: Sat, 21 Jul 2007 19:07:47 +0100
Subject: [PATCH] Emit version banner in GNU preferred format.
To: findutils-patches@gnu.org
2007-07-21  James Youngman  <jay@gnu.org>

	Version banners now comply with the GNU coding standard.
	* find/parser.c (parse_version): Use display_findutils_version()
	instead of printing the information manually.  Don't include
	gnulib-version.h since we no longer directly use that header.
	* lib/findutils-version.c: Added
	* lib/findutils-version.h: Added
	* import-gnulib.config (modules): Added version-etc and
	version-etc-fsf.
	* lib/Makefile.am (libfind_a_SOURCES): added findutils-version.c.
	* find/version.c: Removed
	* find/Makefile.am: Remove version.c
	* locate/Makefile.am: Don't link ../find/version.o
	* xargs/Makefile.am: Ditto
	* xargs/xargs.c (main): Use display_findutils_version()
	* locate/code.c (main): Ditto
	* locate/frcode.c (main): Ditto
	* locate/locate.c (dolocate): Ditto
	* locate/updatedb.sh (version): Display copyright information in
	the right format.
	* NEWS: Mention the change

Signed-off-by: James Youngman <jay@gnu.org>
---
 NEWS                    |    4 +++
 find/Makefile.am        |    2 +-
 find/parser.c           |    6 +---
 find/version.c          |    3 --
 import-gnulib.config    |    2 +
 lib/Makefile.am         |    4 +-
 lib/findutils-version.c |   65 +++++++++++++++++++++++++++++++++++++++++++++++
 lib/findutils-version.h |   28 ++++++++++++++++++++
 locate/Makefile.am      |    4 +-
 locate/code.c           |    3 +-
 locate/frcode.c         |    3 +-
 locate/locate.c         |    5 +--
 locate/updatedb.sh      |   16 +++++++++++-
 xargs/Makefile.am       |    4 +-
 xargs/xargs.c           |    4 +-
 15 files changed, 130 insertions(+), 23 deletions(-)

diff --git a/NEWS b/NEWS
index e35147b..8bda01e 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,10 @@ example, with the -E option), and stdin is seekable, xargs now
 correctly restores the file position, even on platforms where exit()
 does not follow the POSIX rules of doing likewise.
 
+#20547: The version information printed by find, xargs, locate,
+updatedb, frcode and code now complies with the GNU Project's coding
+standards.
+
 ** Documentation Fixes
 
 Point out more explicitly that the subsecond timestamp support
diff --git a/find/Makefile.am b/find/Makefile.am
index 6cb29ba..b001509 100644
--- a/find/Makefile.am
+++ b/find/Makefile.am
@@ -4,7 +4,7 @@ localedir = $(datadir)/locale
 # regexprops_SOURCES = regexprops.c
 
 noinst_LIBRARIES = libfindtools.a
-libfindtools_a_SOURCES = finddata.c fstype.c parser.c pred.c tree.c util.c version.c
+libfindtools_a_SOURCES = finddata.c fstype.c parser.c pred.c tree.c util.c
 
 
 # We always build two versions of find, one with fts, one without.
diff --git a/find/parser.c b/find/parser.c
index 4ecef66..a5394f2 100644
--- a/find/parser.c
+++ b/find/parser.c
@@ -41,7 +41,7 @@
 #include "fts_.h"
 #include "getdate.h"
 #include "error.h"
-#include "gnulib-version.h"
+#include "findutils-version.h"
 
 #include <fcntl.h>
 
@@ -2356,9 +2356,7 @@ parse_version (const struct parser_table* entry, char **argv, int *arg_ptr)
   (void) arg_ptr;
   (void) entry;
   
-  fflush (stderr);
-  printf (_("GNU find version %s\n"), version_string);
-  printf (_("Built using GNU gnulib version %s\n"), gnulib_version);
+  display_findutils_version("find");
   printf (_("Features enabled: "));
   
 #if CACHE_IDS
diff --git a/find/version.c b/find/version.c
deleted file mode 100644
index c833c5b..0000000
--- a/find/version.c
+++ /dev/null
@@ -1,3 +0,0 @@
-#include <config.h>
-char *version_string = VERSION;
-
diff --git a/import-gnulib.config b/import-gnulib.config
index 6703d44..4f54380 100644
--- a/import-gnulib.config
+++ b/import-gnulib.config
@@ -79,6 +79,8 @@ strtoumax
 sys_stat
 timespec
 verify
+version-etc
+version-etc-fsf
 wcwidth
 xalloc
 xalloc-die
diff --git a/lib/Makefile.am b/lib/Makefile.am
index e900bf3..56b8b49 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -13,9 +13,9 @@ noinst_PROGRAMS = regexprops
 regexprops_SOURCES = regexprops.c regextype.c
 endif
 
-libfind_a_SOURCES = gnulib-version.c
+libfind_a_SOURCES = gnulib-version.c findutils-version.c
 EXTRA_DIST = modetype.h wait.h extendbuf.h savedirinfo.h buildcmd.h \
-	gnulib-version.h gnulib-version.c
+	gnulib-version.h gnulib-version.c findutils-version.h
 BUILT_SOURCES = gnulib-version.c
 SUFFIXES =
 MOSTLYCLEANFILES = 
diff --git a/lib/findutils-version.c b/lib/findutils-version.c
new file mode 100644
index 0000000..643a407
--- /dev/null
+++ b/lib/findutils-version.c
@@ -0,0 +1,65 @@
+/* findutils-version.c -- show version information for findutils
+   Copyright (C) 2007 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License 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-safer.h"
+#include "version-etc.h"
+#include "gnulib-version.h"
+
+
+
+#if ENABLE_NLS
+# include <libintl.h>
+# define _(Text) gettext (Text)
+#else
+# define _(Text) Text
+#endif
+#ifdef gettext_noop
+# define N_(String) gettext_noop (String)
+#else
+/* See locate.c for explanation as to why not use (String) */
+# define N_(String) String
+#endif
+
+
+
+#ifdef _LIBC
+/* In the GNU C library, there is a predefined variable for this.  */
+# define program_name program_invocation_name
+#endif
+
+
+extern char *program_name;
+char *version_string = VERSION;
+
+
+void
+display_findutils_version(const char *official_name)
+{
+  /* We use official_name rather than program name in the version 
+   * information.  This is deliberate, it is specified by the 
+   * GNU coding standard.
+   */
+  fflush (stderr);
+  version_etc(stdout,
+	      official_name, "GNU findutils", version_string,
+	      "Eric B. Decker",
+	      "James Youngman",
+	      "Kevin Dalley",
+	      (const char*) NULL);
+  printf (_("Built using GNU gnulib version %s\n"), gnulib_version);
+}
diff --git a/lib/findutils-version.h b/lib/findutils-version.h
new file mode 100644
index 0000000..ebb7ba9
--- /dev/null
+++ b/lib/findutils-version.h
@@ -0,0 +1,28 @@
+/* findutils-version.h -- show version information for findutils
+   Copyright (C) 2007 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License 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/>.
+*/
+
+/*
+ * display_findutils_version displays GNU coding standard compliant 
+ * version information.   
+ *
+ * official_name   Official name of the program, for example
+ *                 "find" or "xargs" (as opposed to "/bin/find"
+ *                 or gfind).
+ *                       
+ */
+void display_findutils_version(const char *official_name);
+
diff --git a/locate/Makefile.am b/locate/Makefile.am
index 027f279..76f88f2 100644
--- a/locate/Makefile.am
+++ b/locate/Makefile.am
@@ -19,9 +19,9 @@ code_SOURCES = code.c word_io.c
 
 INCLUDES = -I$(top_srcdir)/lib -I../gnulib/lib -I$(top_srcdir)/gnulib/lib -I../intl -DLOCATE_DB=\"$(LOCATE_DB)\" -DLOCALEDIR=\"$(localedir)\"
 
-LDADD = ../find/version.o ../lib/libfind.a ../gnulib/lib/libgnulib.a @INTLLIBS@
+LDADD = ../lib/libfind.a ../gnulib/lib/libgnulib.a @INTLLIBS@
 
-$(PROGRAMS) $(LIBPROGRAMS): ../find/version.o ../lib/libfind.a ../gnulib/lib/libgnulib.a
+$(PROGRAMS) $(LIBPROGRAMS): ../lib/libfind.a ../gnulib/lib/libgnulib.a
 
 updatedb: updatedb.sh
 	rm -f $@
diff --git a/locate/code.c b/locate/code.c
index 800e5e9..90a473f 100644
--- a/locate/code.c
+++ b/locate/code.c
@@ -185,8 +185,7 @@ main (int argc, char **argv)
     }
   else if (0 == strcmp(argv[1], "--version"))
     {
-      printf (_("GNU findutils version %s\n"), version_string);
-      printf (_("Built using GNU gnulib version %s\n"), gnulib_version);
+      display_findutils_version("code");
       return 0;
     }
   
diff --git a/locate/frcode.c b/locate/frcode.c
index 0f1f35e..44f2595 100644
--- a/locate/frcode.c
+++ b/locate/frcode.c
@@ -109,6 +109,7 @@
 #include <getopt.h>
 #include "error.h"
 #include "closeout.h"
+#include "findutils-version.h"
 
 char *xmalloc PARAMS((size_t));
 
@@ -265,7 +266,7 @@ main (int argc, char **argv)
 	return 0;
 
       case 'v':
-	printf (_("GNU locate version %s\n"), version_string);
+	display_findutils_version("frcode");
 	return 0;
 
       default:
diff --git a/locate/locate.c b/locate/locate.c
index 71e0265..b02f227 100644
--- a/locate/locate.c
+++ b/locate/locate.c
@@ -130,7 +130,7 @@
 #include "quotearg.h"
 #include "printquoted.h"
 #include "regextype.h"
-#include "gnulib-version.h"
+#include "findutils-version.h"
 
 /* Note that this evaluates Ch many times.  */
 #ifdef _LIBC
@@ -1659,8 +1659,7 @@ dolocate (int argc, char **argv, int secure_db_fd)
 	break;
 
       case 'v':
-	printf (_("GNU locate version %s\n"), version_string);
-	printf (_("Built using GNU gnulib version %s\n"), gnulib_version);
+	display_findutils_version("locate");
 	return 0;
 
       case 'w':
diff --git a/locate/updatedb.sh b/locate/updatedb.sh
index 909af00..0241bc3 100644
--- a/locate/updatedb.sh
+++ b/locate/updatedb.sh
@@ -21,6 +21,20 @@
 #exec 2> /tmp/updatedb-trace.txt 
 #set -x
 
+version() {
+cat <<EOF
+updatedb (GNU findutils) @VERSION@
+Copyright (C) 2007 Free Software Foundation, Inc.
+License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl.html>
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
+
+Written by Eric B. Decker, James Youngman, and Kevin Dalley.
+Built using GNU gnulib version 2007-07-07
+EOF
+}
+
+
 usage="\
 Usage: $0 [--findoptions='-option1 -option2...']
        [--localpaths='dir1 dir2...'] [--netpaths='dir1 dir2...']
@@ -51,7 +65,7 @@ do
     --old-format) old=yes ;;
     --changecwd)  changeto="$val" ;;
     --dbformat)   dbformat="$val" ;;
-    --version) echo "GNU updatedb version @VERSION@"; exit 0 ;;
+    --version) version; exit 0 ;;
     --help) echo "$usage"; exit 0 ;;
     *) echo "updatedb: invalid option $opt
 $usage" >&2
diff --git a/xargs/Makefile.am b/xargs/Makefile.am
index e0bf599..20b4c29 100644
--- a/xargs/Makefile.am
+++ b/xargs/Makefile.am
@@ -3,11 +3,11 @@ localedir = $(datadir)/locale
 bin_PROGRAMS = xargs
 man_MANS = xargs.1
 INCLUDES = -I.. -I../gnulib/lib -I$(top_srcdir)/gnulib/lib -I$(top_srcdir)/lib -I../intl -DLOCALEDIR=\"$(localedir)\"
-LDADD = ../find/version.o ../lib/libfind.a ../gnulib/lib/libgnulib.a @INTLLIBS@
+LDADD = ../lib/libfind.a ../gnulib/lib/libgnulib.a @INTLLIBS@
 EXTRA_DIST = $(man_MANS)
 SUBDIRS = . testsuite
 
-$(PROGRAMS): ../find/version.o ../lib/libfind.a ../gnulib/lib/libgnulib.a
+$(PROGRAMS): ../lib/libfind.a ../gnulib/lib/libgnulib.a
 
 dist-hook: findutils-check-manpages
 
diff --git a/xargs/xargs.c b/xargs/xargs.c
index 7caca6e..1394fa3 100644
--- a/xargs/xargs.c
+++ b/xargs/xargs.c
@@ -97,6 +97,7 @@
 #include "verify.h"
 #include "wait.h"
 #include "quotearg.h"
+#include "findutils-version.h"
 
 
 #ifdef STDC_HEADERS
@@ -618,8 +619,7 @@ main (int argc, char **argv)
           break;
 
 	case 'v':
-	  printf (_("GNU xargs version %s\n"), version_string);
-	  printf (_("Built using GNU gnulib version %s\n"), gnulib_version);
+	  display_findutils_version("xargs");
 	  return 0;
 
 	default:
-- 
1.5.2.1

