Blame build-aux/mdate-sh

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