1#!/bin/sh 2# Get modification time of a file or directory and pretty-print it. 3 4scriptversion=2005-06-29.22 5 6# Copyright (C) 1995, 1996, 1997, 2003, 2004, 2005 Free Software 7# Foundation, Inc. 8# written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995 9# 10# This program is free software; you can redistribute it and/or modify 11# it under the terms of the GNU General Public License as published by 12# the Free Software Foundation; either version 2, or (at your option) 13# any later version. 14# 15# This program is distributed in the hope that it will be useful, 16# but WITHOUT ANY WARRANTY; without even the implied warranty of 17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18# GNU General Public License for more details. 19# 20# You should have received a copy of the GNU General Public License 21# along with this program. If not, see <http://www.gnu.org/licenses/>. 22 23# As a special exception to the GNU General Public License, if you 24# distribute this file as part of a program that contains a 25# configuration script generated by Autoconf, you may include it under 26# the same distribution terms that you use for the rest of that program. 27 28# This file is maintained in Automake, please report 29# bugs to <bug-automake@gnu.org> or send patches to 30# <automake-patches@gnu.org>. 31 32case $1 in 33 '') 34 echo "$0: No file. Try \`$0 --help' for more information." 1>&2 35 exit 1; 36 ;; 37 -h | --h*) 38 cat <<\EOF 39Usage: mdate-sh [--help] [--version] FILE 40 41Pretty-print the modification time of FILE. 42 43Report bugs to <bug-automake@gnu.org>. 44EOF 45 exit $? 46 ;; 47 -v | --v*) 48 echo "mdate-sh $scriptversion" 49 exit $? 50 ;; 51esac 52 53# Prevent date giving response in another language. 54LANG=C 55export LANG 56LC_ALL=C 57export LC_ALL 58LC_TIME=C 59export LC_TIME 60 61# GNU ls changes its time format in response to the TIME_STYLE 62# variable. Since we cannot assume `unset' works, revert this 63# variable to its documented default. 64if test "${TIME_STYLE+set}" = set; then 65 TIME_STYLE=posix-long-iso 66 export TIME_STYLE 67fi 68 69save_arg1=$1 70 71# Find out how to get the extended ls output of a file or directory. 72if ls -L /dev/null 1>/dev/null 2>&1; then 73 ls_command='ls -L -l -d' 74else 75 ls_command='ls -l -d' 76fi 77 78# A `ls -l' line looks as follows on OS/2. 79# drwxrwx--- 0 Aug 11 2001 foo 80# This differs from Unix, which adds ownership information. 81# drwxrwx--- 2 root root 4096 Aug 11 2001 foo 82# 83# To find the date, we split the line on spaces and iterate on words 84# until we find a month. This cannot work with files whose owner is a 85# user named `Jan', or `Feb', etc. However, it's unlikely that `/' 86# will be owned by a user whose name is a month. So we first look at 87# the extended ls output of the root directory to decide how many 88# words should be skipped to get the date. 89 90# On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below. 91set x`ls -l -d /` 92 93# Find which argument is the month. 94month= 95command= 96until test $month 97do 98 shift 99 # Add another shift to the command. 100 command="$command shift;" 101 case $1 in 102 Jan) month=January; nummonth=1;; 103 Feb) month=February; nummonth=2;; 104 Mar) month=March; nummonth=3;; 105 Apr) month=April; nummonth=4;; 106 May) month=May; nummonth=5;; 107 Jun) month=June; nummonth=6;; 108 Jul) month=July; nummonth=7;; 109 Aug) month=August; nummonth=8;; 110 Sep) month=September; nummonth=9;; 111 Oct) month=October; nummonth=10;; 112 Nov) month=November; nummonth=11;; 113 Dec) month=December; nummonth=12;; 114 esac 115done 116 117# Get the extended ls output of the file or directory. 118set dummy x`eval "$ls_command \"\$save_arg1\""` 119 120# Remove all preceding arguments 121eval $command 122 123# Because of the dummy argument above, month is in $2. 124# 125# On a POSIX system, we should have 126# 127# $# = 5 128# $1 = file size 129# $2 = month 130# $3 = day 131# $4 = year or time 132# $5 = filename 133# 134# On Darwin 7.7.0 and 7.6.0, we have 135# 136# $# = 4 137# $1 = day 138# $2 = month 139# $3 = year or time 140# $4 = filename 141 142# Get the month. 143case $2 in 144 Jan) month=January; nummonth=1;; 145 Feb) month=February; nummonth=2;; 146 Mar) month=March; nummonth=3;; 147 Apr) month=April; nummonth=4;; 148 May) month=May; nummonth=5;; 149 Jun) month=June; nummonth=6;; 150 Jul) month=July; nummonth=7;; 151 Aug) month=August; nummonth=8;; 152 Sep) month=September; nummonth=9;; 153 Oct) month=October; nummonth=10;; 154 Nov) month=November; nummonth=11;; 155 Dec) month=December; nummonth=12;; 156esac 157 158case $3 in 159 ???*) day=$1;; 160 *) day=$3; shift;; 161esac 162 163# Here we have to deal with the problem that the ls output gives either 164# the time of day or the year. 165case $3 in 166 *:*) set `date`; eval year=\$$# 167 case $2 in 168 Jan) nummonthtod=1;; 169 Feb) nummonthtod=2;; 170 Mar) nummonthtod=3;; 171 Apr) nummonthtod=4;; 172 May) nummonthtod=5;; 173 Jun) nummonthtod=6;; 174 Jul) nummonthtod=7;; 175 Aug) nummonthtod=8;; 176 Sep) nummonthtod=9;; 177 Oct) nummonthtod=10;; 178 Nov) nummonthtod=11;; 179 Dec) nummonthtod=12;; 180 esac 181 # For the first six month of the year the time notation can also 182 # be used for files modified in the last year. 183 if (expr $nummonth \> $nummonthtod) > /dev/null; 184 then 185 year=`expr $year - 1` 186 fi;; 187 *) year=$3;; 188esac 189 190# The result. 191echo $day $month $year 192 193# Local Variables: 194# mode: shell-script 195# sh-indentation: 2 196# eval: (add-hook 'write-file-hooks 'time-stamp) 197# time-stamp-start: "scriptversion=" 198# time-stamp-format: "%:y-%02m-%02d.%02H" 199# time-stamp-end: "$" 200# End: 201