Blame doc/mdate-sh

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