Blame doc/mdate-sh

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