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