changeset 11651:64c83b4fa303

argp-version-etc: new module. * lib/argp-version-etc.c: New file. * lib/argp-version-etc.h: New file. * modules/argp-version-etc: New file. * modules/argp-version-etc-tests: New file. * tests/test-argp-version-etc.c: New test. * tests/test-argp-version-etc-1.sh: New test.
author Sergey Poznyakoff <gray@gnu.org.ua>
date Thu, 25 Jun 2009 10:42:21 +0300
parents 7b211eff2192
children 7c297f566e07
files ChangeLog lib/argp-version-etc.c lib/argp-version-etc.h modules/argp-version-etc modules/argp-version-etc-tests tests/test-argp-version-etc-1.sh tests/test-argp-version-etc.c
diffstat 7 files changed, 213 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-06-25  Sergey Poznyakoff  <gray@gnu.org.ua>
+
+	argp-version-etc: new module.
+
+	* lib/argp-version-etc.c: New file.
+	* lib/argp-version-etc.h: New file.
+	* modules/argp-version-etc: New file.
+	* modules/argp-version-etc-tests: New file.
+	* tests/test-argp-version-etc.c: New test.
+	* tests/test-argp-version-etc-1.sh: New test.
+
 2009-06-25  Sergey Poznyakoff  <gray@gnu.org.ua>
 
 	Provide additional interfaces and documentation for version-etc
new file mode 100644
--- /dev/null
+++ b/lib/argp-version-etc.c
@@ -0,0 +1,38 @@
+/* Version hook for Argp.
+   Copyright (C) 2009 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 <version-etc.h>
+#include <argp.h>
+#include <argp-version-etc.h>
+
+static const char *program_canonical_name;
+static const char **program_authors;
+
+static void
+version_etc_hook (FILE *stream, struct argp_state *state)
+{
+  version_etc_ar (stream, program_canonical_name, PACKAGE_NAME, VERSION,
+		  program_authors);
+}
+
+void
+argp_version_setup (const char *name, const char * const *authors)
+{
+  argp_program_version_hook = version_etc_hook;
+  program_canonical_name = name;
+  program_authors = authors;
+}
new file mode 100644
--- /dev/null
+++ b/lib/argp-version-etc.h
@@ -0,0 +1,40 @@
+/* Version hook for Argp.
+   Copyright (C) 2009 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/>.  */
+
+#ifndef _ARGP_VERSION_ETC_H
+#define _ARGP_VERSION_ETC_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Setup standard display of the version information for the `--version'
+   option.  NAME is the canonical program name, and AUTHORS is a NULL-
+   terminated array of author names. At least one author name must be
+   given.
+
+   If NAME is NULL, the package name (as given by the PACKAGE macro)
+   is asumed to be the name of the program.
+
+   This function is intended to be called before argp_parse().
+*/
+extern void argp_version_setup (const char *name, const char * const *authors);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _ARGP_VERSION_ETC_H */
new file mode 100644
--- /dev/null
+++ b/modules/argp-version-etc
@@ -0,0 +1,21 @@
+Description:
+Version-etc hook for Argp.
+
+Files:
+lib/argp-version-etc.c
+lib/argp-version-etc.h
+
+Depends-on:
+argp
+
+Makefile.am:
+lib_SOURCES += argp-version-etc.h argp-version-etc.c
+
+Include:
+"argp-version-etc.h"
+
+License:
+GPL
+
+Maintainer:
+Sergey Poznyakoff
new file mode 100644
--- /dev/null
+++ b/modules/argp-version-etc-tests
@@ -0,0 +1,14 @@
+Files:
+tests/test-argp-version-etc.c
+tests/test-argp-version-etc-1.sh
+
+Depends-on:
+argp
+progname
+version-etc-fsf
+
+Makefile.am:
+TESTS += test-argp-version-etc test-argp-version-etc-1.sh
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@'
+check_PROGRAMS += test-argp-version-etc
+test_argp_version_etc_LDADD = $(LDADD) @LIBINTL@
new file mode 100755
--- /dev/null
+++ b/tests/test-argp-version-etc-1.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Test suite for argp-version-etc.
+# Copyright (C) 2009 Free Software Foundation, Inc.
+# This file is part of the GNUlib Library.
+#
+# 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/>.
+
+TMP=ave-expected.tmp
+LC_ALL=C
+export LC_ALL
+ERR=0
+
+cat > $TMP <<EOT
+test-argp-version-etc (dummy) 0
+COPYRIGHT
+License GPLv3+: GNU GPL version 3 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 Sergey Poznyakoff.
+EOT
+
+./test-argp-version-etc --version |
+ sed '2s/Copyright (C) [0-9]\{4,4\} Free Software Foundation, Inc\./COPYRIGHT/' |
+ diff -c $TMP - || ERR=1
+
+rm $TMP
+
+exit $ERR
+
new file mode 100644
--- /dev/null
+++ b/tests/test-argp-version-etc.c
@@ -0,0 +1,48 @@
+/* Test suite for argp-version-etc.
+   Copyright (C) 2009 Free Software Foundation, Inc.
+   This file is part of the GNUlib Library.
+
+   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 "argp-version-etc.h"
+#include "argp.h"
+#include "progname.h"
+
+static char doc[] = "test for the argp-version-etc module";
+
+struct argp test_argp =
+{
+  NULL,
+  NULL,
+  NULL,
+  doc,
+  NULL,
+  NULL,
+  NULL
+};
+
+const char *authors[] =
+{
+  "Sergey Poznyakoff",
+  NULL
+};
+
+int
+main (int argc, char **argv)
+{
+  set_program_name (argv[0]);
+  argp_version_setup ("test-argp-version-etc", authors);
+  return argp_parse (&test_argp, argc, argv, 0, NULL, NULL);
+}