From 429dbdf1be538a324d5176927eb8b978cf589482 Mon Sep 17 00:00:00 2001
From: James Youngman
Date: Wed, 9 Jan 2008 23:57:40 +0000
Subject: [PATCH] New module releasedate for determining the package release date.
2008-01-09 James Youngman
* modules/releasedate: New module for determining the release date
of a package, and its age.
* lib/releasedate.c, lib/releasedate.h, m4/releasedate.m4: New files.
Signed-off-by: James Youngman
---
lib/releasedate.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++
lib/releasedate.h | 28 +++++++++++++++++++++
m4/releasedate.m4 | 38 ++++++++++++++++++++++++++++
modules/releasedate | 26 +++++++++++++++++++
4 files changed, 160 insertions(+), 0 deletions(-)
create mode 100644 lib/releasedate.c
create mode 100644 lib/releasedate.h
create mode 100644 m4/releasedate.m4
create mode 100644 modules/releasedate
diff --git a/lib/releasedate.c b/lib/releasedate.c
new file mode 100644
index 0000000..3816e19
--- /dev/null
+++ b/lib/releasedate.c
@@ -0,0 +1,68 @@
+/* releasedate.c --- Fetch the release date for the package.
+ Copyright (C) 2008 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 .
+
+ Written by James Youngman. */
+
+#include
+
+#include
+#include
+
+#include "timespec.h"
+#include "getdate.h"
+#include "releasedate.h"
+
+
+static bool
+now (struct timespec *result)
+{
+ time_t t = time (NULL);
+ if ((time_t)-1 != t)
+ {
+ result->tv_sec = t;
+ result->tv_nsec = 0;
+ return true;
+ }
+ else
+ {
+ /* We can't tell the time. */
+ return false;
+ }
+}
+
+extern bool
+release_date (struct timespec * when)
+{
+ struct timespec current;
+
+ return now (¤t) && get_date(when, PACKAGE_RELEASE_DATE, ¤t);
+}
+
+extern bool
+release_age (double *age)
+{
+ struct timespec rd, current;
+
+ if (now (¤t) && release_date (&rd))
+ {
+ *age = difftime (current.tv_sec, rd.tv_sec);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
diff --git a/lib/releasedate.h b/lib/releasedate.h
new file mode 100644
index 0000000..4105509
--- /dev/null
+++ b/lib/releasedate.h
@@ -0,0 +1,28 @@
+/* releasedate.h --- Fetch the release date for the package.
+ Copyright (C) 2008 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 .
+
+ Written by James Youngman. */
+
+#ifndef RELEASEDATE_H
+# define RELEASEDATE_H
+
+#include
+#include
+
+extern bool release_date (struct timespec *);
+extern bool release_age (double*);
+
+#endif /* RELEASEDATE_H */
diff --git a/m4/releasedate.m4 b/m4/releasedate.m4
new file mode 100644
index 0000000..355fc76
--- /dev/null
+++ b/m4/releasedate.m4
@@ -0,0 +1,38 @@
+# releasedate.m4 serial 1
+dnl Copyright (C) 2008 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_RELEASE_DATE],
+[
+ AC_MSG_CHECKING(for a release date in the NEWS file)
+ if test -r $srcdir/NEWS; then
+ if test -n "$PACKAGE_VERSION"; then
+ # Look for a release date field for this package in the NEWS file.
+ # Assume that the release date is separated from the version number
+ # by a comma. Also assume that the package version matches itself
+ # as a glob.
+ ac_release_date=`
+ sed 15q < $srcdir/NEWS |
+ while read line; do
+ case "$line" in
+ *$PACKAGE_VERSION*[,]*)
+ echo "$line" | sed 's/.*[,] *//' | sed 's/ *$//';;
+ esac
+ done | sed 1q`
+ if test -z "$ac_release_date" ; then
+ AC_MSG_RESULT(release $PACKAGE_VERSION has no release date)
+ unset ac_release_date
+ else
+ AC_MSG_RESULT($ac_release_date)
+ AC_DEFINE_UNQUOTED(PACKAGE_RELEASE_DATE, ["$ac_release_date"],
+ [Define with the release date of the package, YYYY-MM-DD])
+ fi
+ else
+ AC_MSG_RESULT(package version is unknown)
+ fi
+ else
+ AC_MSG_RESULT(NEWS file is absent)
+ fi
+])
diff --git a/modules/releasedate b/modules/releasedate
new file mode 100644
index 0000000..7b8afad
--- /dev/null
+++ b/modules/releasedate
@@ -0,0 +1,26 @@
+Description:
+Extract the release date of this version of the package.
+
+Files:
+lib/releasedate.h
+lib/releasedate.c
+m4/releasedate.m4
+
+Depends-on:
+getdate
+
+
+configure.ac:
+gl_RELEASE_DATE
+
+Makefile.am:
+lib_SOURCES += releasedate.h releasedate.c
+
+Include:
+"releasedate.h"
+
+License:
+GPL
+
+Maintainer:
+James Youngman
--
1.5.3.7