groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 03/03: mdate.sh: rewrite in Perl


From: Colin Watson
Subject: [groff] 03/03: mdate.sh: rewrite in Perl
Date: Fri, 9 Mar 2018 07:30:47 -0500 (EST)

cjwatson pushed a commit to branch master
in repository groff.

commit 677274dafc5dd5f79f2a6d16270b21d2f5a16c5b
Author: Colin Watson <address@hidden>
Date:   Fri Mar 9 12:27:37 2018 +0000

    mdate.sh: rewrite in Perl
    
    groff already requires perl to build.  This version is much shorter
    and easier to understand than the shell/awk version: we don't have
    to worry about convincing ls to produce output that we can parse,
    and we don't have to play games with the way that the same field may
    contain either the year or the time depending on how old the file
    is.
    
    While I'm at it, this version also adds `SOURCE_DATE_EPOCH' support
    for reproducible builds: when `SOURCE_DATE_EPOCH' is set, files are
    considered to have been last modified at that time.
    
    * mdate.sh: Rewrite in Perl, moving to ...
    * mdate.pl: ... this new file.
    * Makefile.am (EXTRA_DIST, .man): Update references.
---
 ChangeLog   | 19 +++++++++++++++++++
 Makefile.am |  4 ++--
 mdate.pl    | 32 ++++++++++++++++++++++++++++++++
 mdate.sh    | 59 -----------------------------------------------------------
 4 files changed, 53 insertions(+), 61 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 711f472..da66268 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
 2018-03-09  Colin Watson  <address@hidden>
 
+       mdate.sh: rewrite in Perl
+
+       groff already requires perl to build.  This version is much shorter
+       and easier to understand than the shell/awk version: we don't have
+       to worry about convincing ls to produce output that we can parse,
+       and we don't have to play games with the way that the same field may
+       contain either the year or the time depending on how old the file
+       is.
+
+       While I'm at it, this version also adds `SOURCE_DATE_EPOCH' support
+       for reproducible builds: when `SOURCE_DATE_EPOCH' is set, files are
+       considered to have been last modified at that time.
+
+       * mdate.sh: Rewrite in Perl, moving to ...
+       * mdate.pl: ... this new file.
+       * Makefile.am (EXTRA_DIST, .man): Update references.
+
+2018-03-09  Colin Watson  <address@hidden>
+
        Remove #! lines from non-executable files
 
        These are always invoked by the build system (either in-tree or via
diff --git a/Makefile.am b/Makefile.am
index e19924e..cd86be7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -870,7 +870,7 @@ EXTRA_DIST += \
   INSTALL.extra \
   LICENSES \
   MANIFEST \
-  mdate.sh \
+  mdate.pl \
   MORE.STUFF \
   PROBLEMS \
   PROJECTS \
@@ -913,7 +913,7 @@ SUFFIXES += .man
             -e "s|address@hidden@]|$(man1ext)|g" \
             -e "s|address@hidden@]|$(man5ext)|g" \
             -e "s|address@hidden@]|$(man7ext)|g" \
-            -e "s|address@hidden@]|`$(SHELL) $(top_srcdir)/mdate.sh $<`|g" \
+            -e "s|address@hidden@]|`$(PERL) $(top_srcdir)/mdate.pl $<`|g" \
             -e "s|address@hidden@]|$(oldfontdir)|g" \
             -e "s|address@hidden@]|$(pdfdocdir)|g" \
             -e "s|address@hidden@]|$(systemtmacdir)|g" \
diff --git a/mdate.pl b/mdate.pl
new file mode 100755
index 0000000..94499e7
--- /dev/null
+++ b/mdate.pl
@@ -0,0 +1,32 @@
+#! /usr/bin/env perl
+#
+# Copyright (C) 1991-2017 Free Software Foundation, Inc.
+# 
+# This file is part of groff.
+# 
+# groff 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.
+# 
+# groff 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/>.
+#
+# Print the modification date of $1 `nicely'.
+
+use warnings;
+use strict;
+use POSIX qw(LC_ALL setlocale strftime);
+
+# Don't want localized dates.
+setlocale(LC_ALL, "C");
+
+my @mtime = gmtime($ENV{SOURCE_DATE_EPOCH} || (stat $ARGV[0])[9]);
+my $mdate = strftime("%e %B %Y", @mtime);
+$mdate =~ s/^ //;
+print "$mdate\n";
diff --git a/mdate.sh b/mdate.sh
deleted file mode 100755
index bbbf433..0000000
--- a/mdate.sh
+++ /dev/null
@@ -1,59 +0,0 @@
-#! /bin/sh
-#
-# Copyright (C) 1991-2014 Free Software Foundation, Inc.
-# 
-# This file is part of groff.
-# 
-# groff 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.
-# 
-# groff 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/>.
-#
-# Print the modification date of $1 `nicely'.
-
-# Don't want foreign dates.
-
-LANGUAGE=
-LC_ALL=C; export LC_ALL
-
-
-(date;
-if ls -L /dev/null 1>/dev/null 2>&1; then ls -L -l $1; else ls -l $1; fi
-) | awk '
-BEGIN {
-       full["Jan"] = "January"; number["Jan"] = 1;
-       full["Feb"] = "February"; number["Feb"] = 2;
-       full["Mar"] = "March"; number["Mar"] = 3;
-       full["Apr"] = "April"; number["Apr"] = 4;
-       full["May"] = "May"; number["May"] = 5;
-       full["Jun"] = "June"; number["Jun"] = 6;
-       full["Jul"] = "July"; number["Jul"] = 7;
-       full["Aug"] = "August"; number["Aug"] = 8;
-       full["Sep"] = "September"; number["Sep"] = 9;
-       full["Oct"] = "October"; number["Oct"] = 10;
-       full["Nov"] = "November"; number["Nov"] = 11;
-       full["Dec"] = "December"; number["Dec"] = 12;
-}
-
-NR == 1 {
-       month = $2;
-       year = $NF;
-}
-
-NR == 2 {
-       if ($(NF-1) ~ /:/) {
-               if (number[$(NF-3)] > number[month])
-                       year--;
-       }
-       else
-               year = $(NF-1);
-       print $(NF-2), full[$(NF-3)], year
-}'



reply via email to

[Prev in Thread] Current Thread [Next in Thread]