mdate-sh revision 1
45e9809aff7304721fddb95654901b32195c9c7avboxsync#!/bin/sh
45e9809aff7304721fddb95654901b32195c9c7avboxsync# Get modification time of a file or directory and pretty-print it.
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncscriptversion=2004-12-08.12
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync# Copyright (C) 1995, 1996, 1997, 2003, 2004 Free Software Foundation, Inc.
45e9809aff7304721fddb95654901b32195c9c7avboxsync# written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995
45e9809aff7304721fddb95654901b32195c9c7avboxsync#
45e9809aff7304721fddb95654901b32195c9c7avboxsync# This program is free software; you can redistribute it and/or modify
45e9809aff7304721fddb95654901b32195c9c7avboxsync# it under the terms of the GNU General Public License as published by
45e9809aff7304721fddb95654901b32195c9c7avboxsync# the Free Software Foundation; either version 2, or (at your option)
45e9809aff7304721fddb95654901b32195c9c7avboxsync# any later version.
45e9809aff7304721fddb95654901b32195c9c7avboxsync#
45e9809aff7304721fddb95654901b32195c9c7avboxsync# This program is distributed in the hope that it will be useful,
45e9809aff7304721fddb95654901b32195c9c7avboxsync# but WITHOUT ANY WARRANTY; without even the implied warranty of
45e9809aff7304721fddb95654901b32195c9c7avboxsync# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45e9809aff7304721fddb95654901b32195c9c7avboxsync# GNU General Public License for more details.
45e9809aff7304721fddb95654901b32195c9c7avboxsync#
45e9809aff7304721fddb95654901b32195c9c7avboxsync# You should have received a copy of the GNU General Public License
45e9809aff7304721fddb95654901b32195c9c7avboxsync# along with this program; if not, write to the Free Software Foundation,
45e9809aff7304721fddb95654901b32195c9c7avboxsync# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync# As a special exception to the GNU General Public License, if you
45e9809aff7304721fddb95654901b32195c9c7avboxsync# distribute this file as part of a program that contains a
45e9809aff7304721fddb95654901b32195c9c7avboxsync# configuration script generated by Autoconf, you may include it under
45e9809aff7304721fddb95654901b32195c9c7avboxsync# the same distribution terms that you use for the rest of that program.
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync# This file is maintained in Automake, please report
45e9809aff7304721fddb95654901b32195c9c7avboxsync# bugs to <bug-automake@gnu.org> or send patches to
45e9809aff7304721fddb95654901b32195c9c7avboxsync# <automake-patches@gnu.org>.
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsynccase $1 in
45e9809aff7304721fddb95654901b32195c9c7avboxsync '')
45e9809aff7304721fddb95654901b32195c9c7avboxsync echo "$0: No file. Try \`$0 --help' for more information." 1>&2
45e9809aff7304721fddb95654901b32195c9c7avboxsync exit 1;
45e9809aff7304721fddb95654901b32195c9c7avboxsync ;;
45e9809aff7304721fddb95654901b32195c9c7avboxsync -h | --h*)
45e9809aff7304721fddb95654901b32195c9c7avboxsync cat <<\EOF
45e9809aff7304721fddb95654901b32195c9c7avboxsyncUsage: mdate-sh [--help] [--version] FILE
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncPretty-print the modification time of FILE.
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncReport bugs to <bug-automake@gnu.org>.
45e9809aff7304721fddb95654901b32195c9c7avboxsyncEOF
45e9809aff7304721fddb95654901b32195c9c7avboxsync exit 0
45e9809aff7304721fddb95654901b32195c9c7avboxsync ;;
45e9809aff7304721fddb95654901b32195c9c7avboxsync -v | --v*)
45e9809aff7304721fddb95654901b32195c9c7avboxsync echo "mdate-sh $scriptversion"
45e9809aff7304721fddb95654901b32195c9c7avboxsync exit 0
45e9809aff7304721fddb95654901b32195c9c7avboxsync ;;
45e9809aff7304721fddb95654901b32195c9c7avboxsyncesac
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync# Prevent date giving response in another language.
45e9809aff7304721fddb95654901b32195c9c7avboxsyncLANG=C
45e9809aff7304721fddb95654901b32195c9c7avboxsyncexport LANG
45e9809aff7304721fddb95654901b32195c9c7avboxsyncLC_ALL=C
45e9809aff7304721fddb95654901b32195c9c7avboxsyncexport LC_ALL
45e9809aff7304721fddb95654901b32195c9c7avboxsyncLC_TIME=C
45e9809aff7304721fddb95654901b32195c9c7avboxsyncexport LC_TIME
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsyncsave_arg1="$1"
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync# Find out how to get the extended ls output of a file or directory.
45e9809aff7304721fddb95654901b32195c9c7avboxsyncif ls -L /dev/null 1>/dev/null 2>&1; then
45e9809aff7304721fddb95654901b32195c9c7avboxsync ls_command='ls -L -l -d'
45e9809aff7304721fddb95654901b32195c9c7avboxsyncelse
45e9809aff7304721fddb95654901b32195c9c7avboxsync ls_command='ls -l -d'
45e9809aff7304721fddb95654901b32195c9c7avboxsyncfi
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync# A `ls -l' line looks as follows on OS/2.
45e9809aff7304721fddb95654901b32195c9c7avboxsync# drwxrwx--- 0 Aug 11 2001 foo
45e9809aff7304721fddb95654901b32195c9c7avboxsync# This differs from Unix, which adds ownership information.
45e9809aff7304721fddb95654901b32195c9c7avboxsync# drwxrwx--- 2 root root 4096 Aug 11 2001 foo
45e9809aff7304721fddb95654901b32195c9c7avboxsync#
45e9809aff7304721fddb95654901b32195c9c7avboxsync# To find the date, we split the line on spaces and iterate on words
45e9809aff7304721fddb95654901b32195c9c7avboxsync# until we find a month. This cannot work with files whose owner is a
45e9809aff7304721fddb95654901b32195c9c7avboxsync# user named `Jan', or `Feb', etc. However, it's unlikely that `/'
45e9809aff7304721fddb95654901b32195c9c7avboxsync# will be owned by a user whose name is a month. So we first look at
45e9809aff7304721fddb95654901b32195c9c7avboxsync# the extended ls output of the root directory to decide how many
45e9809aff7304721fddb95654901b32195c9c7avboxsync# words should be skipped to get the date.
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync# On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below.
45e9809aff7304721fddb95654901b32195c9c7avboxsyncset x`ls -l -d /`
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync# Find which argument is the month.
45e9809aff7304721fddb95654901b32195c9c7avboxsyncmonth=
45e9809aff7304721fddb95654901b32195c9c7avboxsynccommand=
45e9809aff7304721fddb95654901b32195c9c7avboxsyncuntil test $month
45e9809aff7304721fddb95654901b32195c9c7avboxsyncdo
45e9809aff7304721fddb95654901b32195c9c7avboxsync shift
45e9809aff7304721fddb95654901b32195c9c7avboxsync # Add another shift to the command.
45e9809aff7304721fddb95654901b32195c9c7avboxsync command="$command shift;"
45e9809aff7304721fddb95654901b32195c9c7avboxsync case $1 in
45e9809aff7304721fddb95654901b32195c9c7avboxsync Jan) month=January; nummonth=1;;
45e9809aff7304721fddb95654901b32195c9c7avboxsync Feb) month=February; nummonth=2;;
45e9809aff7304721fddb95654901b32195c9c7avboxsync Mar) month=March; nummonth=3;;
45e9809aff7304721fddb95654901b32195c9c7avboxsync Apr) month=April; nummonth=4;;
45e9809aff7304721fddb95654901b32195c9c7avboxsync May) month=May; nummonth=5;;
45e9809aff7304721fddb95654901b32195c9c7avboxsync Jun) month=June; nummonth=6;;
45e9809aff7304721fddb95654901b32195c9c7avboxsync 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
done
# Get the extended ls output of the file or directory.
set x`eval "$ls_command \"\$save_arg1\""`
# Remove all preceding arguments
eval $command
# Get the month. Next argument is day, followed by the year or time.
case $1 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
day=$2
# 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: