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