[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Quilt-dev] Re: remove GNU date dependency [Was: quilt mail broken with
From: |
Gary V. Vaughan |
Subject: |
[Quilt-dev] Re: remove GNU date dependency [Was: quilt mail broken with sed 3.02] |
Date: |
Wed, 01 Feb 2006 10:44:29 +0000 |
User-agent: |
Thunderbird 1.5 (X11/20051201) |
Andreas Gruenbacher wrote:
> Gary,
Morgen!
> I've looked into this a little, and standard date(1) doesn't have the -d
> option, and doesn't support `%s' and `%z'. We could get of the first use of
> -d, but incrementing timestamps is harder, and I'd hate to have to sleep a
> second between each date generated just to get a different timestamp. We
> could put the same timestamp in each message in case we can't increment, but
> then, we still can't generate `%z'. The Perl workaround also relies on
> strftime(3), which probably is the platform's native libc implementation, and
> so probably has the same limitations as date(1).
Apparently, perl doesn't use the native strftime... or at least on darwin %z
works within perl, but isn't used in Apple's date implementation.
> The following snipped computes %z in shell code, but this doesn't solve the
> increment-timestamp problem.
>
> zone_offset=
> while [ "${zone_offset%0}" = "$zone_offset" ]
> do
> zone_offset=$(( 9$(date '+%H%M') - 9$(date -u '+%H%M') ))
> done
> printf '+%04d\n' $zone_offset
>
> So I think I'll go with 0.43 even though this portability issue is not fixed.
Here is a patch for a perl date wrapper (my first perl script!), I hope you
can commit this in time for 0.43... with it, I can `./configure --without-date'
and have the testsuite complete successfully.
Cheers,
Gary.
--
Gary V. Vaughan ())_. address@hidden,gnu.org}
Research Scientist ( '/ http://tkd.kicks-ass.net
GNU Hacker / )= http://www.gnu.org/software/libtool
Technical Author `(_~)_ http://sources.redhat.com/autobook
compat/date.in | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 15 ++++++++++
2 files changed, 93 insertions(+)
Index: quilt-HEAD/compat/date.in
===================================================================
--- /dev/null
+++ quilt-HEAD/compat/date.in
@@ -0,0 +1,78 @@
+#! @PERL@ -w
+
+# This script is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# See the COPYING and AUTHORS files for more details.
+
+use strict;
+use POSIX qw(strftime);
+use Getopt::Long;
+
+my %opt = ();
+my $spec = '%a %b %e %H:%M:%S %Z %Y';
+my $now = time();
+
+sub usage() {
+ print "Usage: date [OPTION]... [+FORMAT]
+Display the current time in the given FORMAT.
+
+ -d, --date=STRING display time described by STRING, not `now'
+ -f, --file=DATEFILE like --date once for each line of DATEFILE
+ -R, --rfc-2822 output RFC-2822 compliant date string
+ -u, --utc, --universal print or set Coordinated Universal Time
+ --help display this help and exit
+";
+ exit;
+}
+
+sub parse_utc_secs() {
+ use Date::Parse;
+
+ my ($now) = @_;
+
+ if ($now =~ / [0-9]+ seconds$/) {
+ # This is an heuristic specifically for quilts mail.in invocation:
+ # date --rfc-822 -d "1970/01/01 UTC nnnnnnnn seconds"
+ $opt{'utc'} = 1 if ($now =~ / (UTC|GMT) /);
+ $now =~ s/^.* ([0-9]+) seconds$/$1/;
+ }
+ else {
+ $now = str2time($now);
+ }
+
+ return $now;
+}
+
+Getopt::Long::Configure ("bundling", "pass_through");
+
+GetOptions (\%opt, 'rfc-822|R', 'utc|universal|u', 'date|d=s', 'help|h');
+
+my $argc = $#ARGV + 1;
+
+&usage if ($argc > 1 || ($argc == 1 && $ARGV[0] !~ /^\+/));
+
+for my $key ( keys %opt ) {
+ if ($key =~ /rfc-822/) { $spec = '%a, %d %b %Y %H:%M:%S %z'; }
+ elsif ($key =~ /utc/) { ; }
+ elsif ($key =~ /date/) { $now = &parse_utc_secs($opt{'date'}); }
+ elsif ($key =~ /help/) { &usage(); }
+ else {
+ die "unknown option `$key'";
+ }
+}
+
+if ($argc == 1) {
+ $spec = substr($ARGV[0], 1);
+}
+
+my @now = ();
+if (exists($opt{'utc'})) {
+ @now = gmtime($now);
+}
+else {
+ @now = localtime($now);
+}
+
+print strftime($spec, @now) . "\n";
Index: quilt-HEAD/configure.ac
===================================================================
--- quilt-HEAD.orig/configure.ac
+++ quilt-HEAD/configure.ac
@@ -82,6 +82,21 @@ duplicates. You can download GNU coreut
fi
QUILT_COMPAT_PROG_PATH(DATE, date, [gdate date])
+
+if test -z "$INTERNAL_DATE"; then
+ AC_MSG_CHECKING([whether $DATE --rfc-822 works])
+ if date --rfc-822 >/dev/null 2>&1; then
+ AC_MSG_RESULT(yes)
+ else
+ AC_MSG_ERROR([no
+
+If you don't have a version of `date' that supports --rfc-822, you
+can specify '--without-date' and $PACKAGE_NAME will use its own
+internal date.
+])
+ fi
+fi
+
QUILT_COMPAT_PROG_PATH(PERL, perl, [perl perl5])
QUILT_COMPAT_PROG_PATH(GREP, grep)
signature.asc
Description: OpenPGP digital signature