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