Blame build-aux/mdate-sh

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