mdate-sh revision 2
70N/A#!/bin/sh
70N/A# Get modification time of a file or directory and pretty-print it.
286N/A
70N/Ascriptversion=2005-06-29.22
70N/A
70N/A# Copyright (C) 1995, 1996, 1997, 2003, 2004, 2005 Free Software
70N/A# Foundation, Inc.
70N/A# written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995
70N/A#
70N/A# This program is free software; you can redistribute it and/or modify
70N/A# it under the terms of the GNU General Public License as published by
70N/A# the Free Software Foundation; either version 2, or (at your option)
70N/A# any later version.
70N/A#
70N/A# This program is distributed in the hope that it will be useful,
70N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of
70N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70N/A# GNU General Public License for more details.
70N/A#
70N/A# You should have received a copy of the GNU General Public License
70N/A# along with this program; if not, write to the Free Software Foundation,
70N/A# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
70N/A
70N/A# As a special exception to the GNU General Public License, if you
70N/A# distribute this file as part of a program that contains a
70N/A# configuration script generated by Autoconf, you may include it under
70N/A# the same distribution terms that you use for the rest of that program.
70N/A
70N/A# This file is maintained in Automake, please report
70N/A# bugs to <bug-automake@gnu.org> or send patches to
649N/A# <automake-patches@gnu.org>.
70N/A
70N/Acase $1 in
70N/A '')
359N/A echo "$0: No file. Try \`$0 --help' for more information." 1>&2
359N/A exit 1;
359N/A ;;
98N/A -h | --h*)
551N/A cat <<\EOF
321N/AUsage: mdate-sh [--help] [--version] FILE
493N/A
321N/APretty-print the modification time of FILE.
550N/A
550N/AReport bugs to <bug-automake@gnu.org>.
213N/AEOF
649N/A exit $?
304N/A ;;
530N/A -v | --v*)
425N/A echo "mdate-sh $scriptversion"
425N/A exit $?
325N/A ;;
493N/Aesac
536N/A
456N/A# Prevent date giving response in another language.
320N/ALANG=C
332N/Aexport LANG
501N/ALC_ALL=C
231N/Aexport LC_ALL
550N/ALC_TIME=C
523N/Aexport LC_TIME
98N/A
347N/A# GNU ls changes its time format in response to the TIME_STYLE
532N/A# variable. Since we cannot assume `unset' works, revert this
525N/A# variable to its documented default.
463N/Aif test "${TIME_STYLE+set}" = set; then
493N/A TIME_STYLE=posix-long-iso
425N/A export TIME_STYLE
493N/Afi
472N/A
324N/Asave_arg1=$1
347N/A
310N/A# Find out how to get the extended ls output of a file or directory.
316N/Aif ls -L /dev/null 1>/dev/null 2>&1; then
474N/A ls_command='ls -L -l -d'
290N/Aelse
332N/A ls_command='ls -l -d'
464N/Afi
332N/A
509N/A# A `ls -l' line looks as follows on OS/2.
332N/A# drwxrwx--- 0 Aug 11 2001 foo
210N/A# This differs from Unix, which adds ownership information.
493N/A# drwxrwx--- 2 root root 4096 Aug 11 2001 foo
128N/A#
414N/A# To find the date, we split the line on spaces and iterate on words
484N/A# until we find a month. This cannot work with files whose owner is a
326N/A# user named `Jan', or `Feb', etc. However, it's unlikely that `/'
493N/A# will be owned by a user whose name is a month. So we first look at
335N/A# the extended ls output of the root directory to decide how many
493N/A# words should be skipped to get the date.
493N/A
425N/A# On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below.
370N/Aset x`ls -l -d /`
70N/A
400N/A# Find which argument is the month.
294N/Amonth=
435N/Acommand=
98N/Auntil test $month
434N/Ado
505N/A shift
277N/A # Add another shift to the command.
433N/A command="$command shift;"
546N/A case $1 in
356N/A Jan) month=January; nummonth=1;;
289N/A Feb) month=February; nummonth=2;;
326N/A Mar) month=March; nummonth=3;;
439N/A Apr) month=April; nummonth=4;;
501N/A May) month=May; nummonth=5;;
469N/A Jun) month=June; nummonth=6;;
290N/A Jul) month=July; nummonth=7;;
542N/A Aug) month=August; nummonth=8;;
424N/A Sep) month=September; nummonth=9;;
286N/A Oct) month=October; nummonth=10;;
543N/A Nov) month=November; nummonth=11;;
90N/A Dec) month=December; nummonth=12;;
475N/A esac
535N/Adone
295N/A
70N/A# Get the extended ls output of the file or directory.
299N/Aset dummy x`eval "$ls_command \"\$save_arg1\""`
262N/A
455N/A# Remove all preceding arguments
539N/Aeval $command
277N/A
332N/A# Because of the dummy argument above, month is in $2.
332N/A#
493N/A# On a POSIX system, we should have
70N/A#
70N/A# $# = 5
319N/A# $1 = file size
280N/A# $2 = month
319N/A# $3 = day
359N/A# $4 = year or time
493N/A# $5 = filename
70N/A#
98N/A# On Darwin 7.7.0 and 7.6.0, we have
98N/A#
414N/A# $# = 4
98N/A# $1 = day
493N/A# $2 = month
493N/A# $3 = year or time
70N/A# $4 = filename
493N/A
493N/A# Get the month.
493N/Acase $2 in
Jan) month=January; nummonth=1;;
Feb) month=February; nummonth=2;;
Mar) month=March; nummonth=3;;
Apr) month=April; nummonth=4;;
May) month=May; nummonth=5;;
Jun) month=June; nummonth=6;;
Jul) month=July; nummonth=7;;
Aug) month=August; nummonth=8;;
Sep) month=September; nummonth=9;;
Oct) month=October; nummonth=10;;
Nov) month=November; nummonth=11;;
Dec) month=December; nummonth=12;;
esac
case $3 in
???*) day=$1;;
*) day=$3; shift;;
esac
# Here we have to deal with the problem that the ls output gives either
# the time of day or the year.
case $3 in
*:*) set `date`; eval year=\$$#
case $2 in
Jan) nummonthtod=1;;
Feb) nummonthtod=2;;
Mar) nummonthtod=3;;
Apr) nummonthtod=4;;
May) nummonthtod=5;;
Jun) nummonthtod=6;;
Jul) nummonthtod=7;;
Aug) nummonthtod=8;;
Sep) nummonthtod=9;;
Oct) nummonthtod=10;;
Nov) nummonthtod=11;;
Dec) nummonthtod=12;;
esac
# For the first six month of the year the time notation can also
# be used for files modified in the last year.
if (expr $nummonth \> $nummonthtod) > /dev/null;
then
year=`expr $year - 1`
fi;;
*) year=$3;;
esac
# The result.
echo $day $month $year
# Local Variables:
# mode: shell-script
# sh-indentation: 2
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End: