argp-version-etc: new module.
authorSergey Poznyakoff <gray@gnu.org.ua>
Thu, 25 Jun 2009 07:42:21 +0000 (10:42 +0300)
committerSergey Poznyakoff <gray@gnu.org.ua>
Thu, 25 Jun 2009 07:42:21 +0000 (10:42 +0300)
* 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.

ChangeLog
lib/argp-version-etc.c [new file with mode: 0644]
lib/argp-version-etc.h [new file with mode: 0644]
modules/argp-version-etc [new file with mode: 0644]
modules/argp-version-etc-tests [new file with mode: 0644]
tests/test-argp-version-etc-1.sh [new file with mode: 0755]
tests/test-argp-version-etc.c [new file with mode: 0644]

index 740548255c9a7e7174d3c3693b5b72c46233ec5d..11684a386f4c870f5db944350d64b8a300083270 100644 (file)
--- 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
diff --git a/lib/argp-version-etc.c b/lib/argp-version-etc.c
new file mode 100644 (file)
index 0000000..e681196
--- /dev/null
@@ -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;
+}
diff --git a/lib/argp-version-etc.h b/lib/argp-version-etc.h
new file mode 100644 (file)
index 0000000..2cd4331
--- /dev/null
@@ -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 */
diff --git a/modules/argp-version-etc b/modules/argp-version-etc
new file mode 100644 (file)
index 0000000..464fc95
--- /dev/null
@@ -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
diff --git a/modules/argp-version-etc-tests b/modules/argp-version-etc-tests
new file mode 100644 (file)
index 0000000..eeed143
--- /dev/null
@@ -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@
diff --git a/tests/test-argp-version-etc-1.sh b/tests/test-argp-version-etc-1.sh
new file mode 100755 (executable)
index 0000000..e0a9575
--- /dev/null
@@ -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
+
diff --git a/tests/test-argp-version-etc.c b/tests/test-argp-version-etc.c
new file mode 100644 (file)
index 0000000..485a4bd
--- /dev/null
@@ -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);
+}