From ffb0da8f73d65580025dfd9bc0705cffe0281d74 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Thu, 25 Jun 2009 10:42:21 +0300 Subject: [PATCH] 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. --- ChangeLog | 11 ++++++++ lib/argp-version-etc.c | 38 +++++++++++++++++++++++++ lib/argp-version-etc.h | 40 ++++++++++++++++++++++++++ modules/argp-version-etc | 21 ++++++++++++++ modules/argp-version-etc-tests | 14 ++++++++++ tests/test-argp-version-etc-1.sh | 41 +++++++++++++++++++++++++++ tests/test-argp-version-etc.c | 48 ++++++++++++++++++++++++++++++++ 7 files changed, 213 insertions(+) create mode 100644 lib/argp-version-etc.c create mode 100644 lib/argp-version-etc.h create mode 100644 modules/argp-version-etc create mode 100644 modules/argp-version-etc-tests create mode 100755 tests/test-argp-version-etc-1.sh create mode 100644 tests/test-argp-version-etc.c diff --git a/ChangeLog b/ChangeLog index 740548255c..11684a386f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2009-06-25 Sergey Poznyakoff + + 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 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 index 0000000000..e681196f67 --- /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 . */ + +#include +#include +#include +#include + +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 index 0000000000..2cd43319f2 --- /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 . */ + +#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 index 0000000000..464fc95754 --- /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 diff --git a/modules/argp-version-etc-tests b/modules/argp-version-etc-tests new file mode 100644 index 0000000000..eeed14361a --- /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@ diff --git a/tests/test-argp-version-etc-1.sh b/tests/test-argp-version-etc-1.sh new file mode 100755 index 0000000000..e0a95757f4 --- /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 . + +TMP=ave-expected.tmp +LC_ALL=C +export LC_ALL +ERR=0 + +cat > $TMP <. +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 index 0000000000..485a4bdd0f --- /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 . */ + +#include +#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); +} -- 2.30.2