Blame build-aux/mdate-sh

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