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