1*d874e919Schristos#!/bin/sh 2*d874e919Schristos# Get modification time of a file or directory and pretty-print it. 3*d874e919Schristos 4*d874e919Schristosscriptversion=2010-08-21.06; # UTC 5*d874e919Schristos 6*d874e919Schristos# Copyright (C) 1995-2012 Free Software Foundation, Inc. 7*d874e919Schristos# written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995 8*d874e919Schristos# 9*d874e919Schristos# This program is free software; you can redistribute it and/or modify 10*d874e919Schristos# it under the terms of the GNU General Public License as published by 11*d874e919Schristos# the Free Software Foundation; either version 2, or (at your option) 12*d874e919Schristos# any later version. 13*d874e919Schristos# 14*d874e919Schristos# This program is distributed in the hope that it will be useful, 15*d874e919Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of 16*d874e919Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*d874e919Schristos# GNU General Public License for more details. 18*d874e919Schristos# 19*d874e919Schristos# You should have received a copy of the GNU General Public License 20*d874e919Schristos# along with this program. If not, see <http://www.gnu.org/licenses/>. 21*d874e919Schristos 22*d874e919Schristos# As a special exception to the GNU General Public License, if you 23*d874e919Schristos# distribute this file as part of a program that contains a 24*d874e919Schristos# configuration script generated by Autoconf, you may include it under 25*d874e919Schristos# the same distribution terms that you use for the rest of that program. 26*d874e919Schristos 27*d874e919Schristos# This file is maintained in Automake, please report 28*d874e919Schristos# bugs to <bug-automake@gnu.org> or send patches to 29*d874e919Schristos# <automake-patches@gnu.org>. 30*d874e919Schristos 31*d874e919Schristosif test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then 32*d874e919Schristos emulate sh 33*d874e919Schristos NULLCMD=: 34*d874e919Schristos # Pre-4.2 versions of Zsh do word splitting on ${1+"$@"}, which 35*d874e919Schristos # is contrary to our usage. Disable this feature. 36*d874e919Schristos alias -g '${1+"$@"}'='"$@"' 37*d874e919Schristos setopt NO_GLOB_SUBST 38*d874e919Schristosfi 39*d874e919Schristos 40*d874e919Schristoscase $1 in 41*d874e919Schristos '') 42*d874e919Schristos echo "$0: No file. Try '$0 --help' for more information." 1>&2 43*d874e919Schristos exit 1; 44*d874e919Schristos ;; 45*d874e919Schristos -h | --h*) 46*d874e919Schristos cat <<\EOF 47*d874e919SchristosUsage: mdate-sh [--help] [--version] FILE 48*d874e919Schristos 49*d874e919SchristosPretty-print the modification day of FILE, in the format: 50*d874e919Schristos1 January 1970 51*d874e919Schristos 52*d874e919SchristosReport bugs to <bug-automake@gnu.org>. 53*d874e919SchristosEOF 54*d874e919Schristos exit $? 55*d874e919Schristos ;; 56*d874e919Schristos -v | --v*) 57*d874e919Schristos echo "mdate-sh $scriptversion" 58*d874e919Schristos exit $? 59*d874e919Schristos ;; 60*d874e919Schristosesac 61*d874e919Schristos 62*d874e919Schristoserror () 63*d874e919Schristos{ 64*d874e919Schristos echo "$0: $1" >&2 65*d874e919Schristos exit 1 66*d874e919Schristos} 67*d874e919Schristos 68*d874e919Schristos 69*d874e919Schristos# Prevent date giving response in another language. 70*d874e919SchristosLANG=C 71*d874e919Schristosexport LANG 72*d874e919SchristosLC_ALL=C 73*d874e919Schristosexport LC_ALL 74*d874e919SchristosLC_TIME=C 75*d874e919Schristosexport LC_TIME 76*d874e919Schristos 77*d874e919Schristos# GNU ls changes its time format in response to the TIME_STYLE 78*d874e919Schristos# variable. Since we cannot assume 'unset' works, revert this 79*d874e919Schristos# variable to its documented default. 80*d874e919Schristosif test "${TIME_STYLE+set}" = set; then 81*d874e919Schristos TIME_STYLE=posix-long-iso 82*d874e919Schristos export TIME_STYLE 83*d874e919Schristosfi 84*d874e919Schristos 85*d874e919Schristossave_arg1=$1 86*d874e919Schristos 87*d874e919Schristos# Find out how to get the extended ls output of a file or directory. 88*d874e919Schristosif ls -L /dev/null 1>/dev/null 2>&1; then 89*d874e919Schristos ls_command='ls -L -l -d' 90*d874e919Schristoselse 91*d874e919Schristos ls_command='ls -l -d' 92*d874e919Schristosfi 93*d874e919Schristos# Avoid user/group names that might have spaces, when possible. 94*d874e919Schristosif ls -n /dev/null 1>/dev/null 2>&1; then 95*d874e919Schristos ls_command="$ls_command -n" 96*d874e919Schristosfi 97*d874e919Schristos 98*d874e919Schristos# A 'ls -l' line looks as follows on OS/2. 99*d874e919Schristos# drwxrwx--- 0 Aug 11 2001 foo 100*d874e919Schristos# This differs from Unix, which adds ownership information. 101*d874e919Schristos# drwxrwx--- 2 root root 4096 Aug 11 2001 foo 102*d874e919Schristos# 103*d874e919Schristos# To find the date, we split the line on spaces and iterate on words 104*d874e919Schristos# until we find a month. This cannot work with files whose owner is a 105*d874e919Schristos# user named "Jan", or "Feb", etc. However, it's unlikely that '/' 106*d874e919Schristos# will be owned by a user whose name is a month. So we first look at 107*d874e919Schristos# the extended ls output of the root directory to decide how many 108*d874e919Schristos# words should be skipped to get the date. 109*d874e919Schristos 110*d874e919Schristos# On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below. 111*d874e919Schristosset x`$ls_command /` 112*d874e919Schristos 113*d874e919Schristos# Find which argument is the month. 114*d874e919Schristosmonth= 115*d874e919Schristoscommand= 116*d874e919Schristosuntil test $month 117*d874e919Schristosdo 118*d874e919Schristos test $# -gt 0 || error "failed parsing '$ls_command /' output" 119*d874e919Schristos shift 120*d874e919Schristos # Add another shift to the command. 121*d874e919Schristos command="$command shift;" 122*d874e919Schristos case $1 in 123*d874e919Schristos Jan) month=January; nummonth=1;; 124*d874e919Schristos Feb) month=February; nummonth=2;; 125*d874e919Schristos Mar) month=March; nummonth=3;; 126*d874e919Schristos Apr) month=April; nummonth=4;; 127*d874e919Schristos May) month=May; nummonth=5;; 128*d874e919Schristos Jun) month=June; nummonth=6;; 129*d874e919Schristos Jul) month=July; nummonth=7;; 130*d874e919Schristos Aug) month=August; nummonth=8;; 131*d874e919Schristos Sep) month=September; nummonth=9;; 132*d874e919Schristos Oct) month=October; nummonth=10;; 133*d874e919Schristos Nov) month=November; nummonth=11;; 134*d874e919Schristos Dec) month=December; nummonth=12;; 135*d874e919Schristos esac 136*d874e919Schristosdone 137*d874e919Schristos 138*d874e919Schristostest -n "$month" || error "failed parsing '$ls_command /' output" 139*d874e919Schristos 140*d874e919Schristos# Get the extended ls output of the file or directory. 141*d874e919Schristosset dummy x`eval "$ls_command \"\\\$save_arg1\""` 142*d874e919Schristos 143*d874e919Schristos# Remove all preceding arguments 144*d874e919Schristoseval $command 145*d874e919Schristos 146*d874e919Schristos# Because of the dummy argument above, month is in $2. 147*d874e919Schristos# 148*d874e919Schristos# On a POSIX system, we should have 149*d874e919Schristos# 150*d874e919Schristos# $# = 5 151*d874e919Schristos# $1 = file size 152*d874e919Schristos# $2 = month 153*d874e919Schristos# $3 = day 154*d874e919Schristos# $4 = year or time 155*d874e919Schristos# $5 = filename 156*d874e919Schristos# 157*d874e919Schristos# On Darwin 7.7.0 and 7.6.0, we have 158*d874e919Schristos# 159*d874e919Schristos# $# = 4 160*d874e919Schristos# $1 = day 161*d874e919Schristos# $2 = month 162*d874e919Schristos# $3 = year or time 163*d874e919Schristos# $4 = filename 164*d874e919Schristos 165*d874e919Schristos# Get the month. 166*d874e919Schristoscase $2 in 167*d874e919Schristos Jan) month=January; nummonth=1;; 168*d874e919Schristos Feb) month=February; nummonth=2;; 169*d874e919Schristos Mar) month=March; nummonth=3;; 170*d874e919Schristos Apr) month=April; nummonth=4;; 171*d874e919Schristos May) month=May; nummonth=5;; 172*d874e919Schristos Jun) month=June; nummonth=6;; 173*d874e919Schristos Jul) month=July; nummonth=7;; 174*d874e919Schristos Aug) month=August; nummonth=8;; 175*d874e919Schristos Sep) month=September; nummonth=9;; 176*d874e919Schristos Oct) month=October; nummonth=10;; 177*d874e919Schristos Nov) month=November; nummonth=11;; 178*d874e919Schristos Dec) month=December; nummonth=12;; 179*d874e919Schristosesac 180*d874e919Schristos 181*d874e919Schristoscase $3 in 182*d874e919Schristos ???*) day=$1;; 183*d874e919Schristos *) day=$3; shift;; 184*d874e919Schristosesac 185*d874e919Schristos 186*d874e919Schristos# Here we have to deal with the problem that the ls output gives either 187*d874e919Schristos# the time of day or the year. 188*d874e919Schristoscase $3 in 189*d874e919Schristos *:*) set `date`; eval year=\$$# 190*d874e919Schristos case $2 in 191*d874e919Schristos Jan) nummonthtod=1;; 192*d874e919Schristos Feb) nummonthtod=2;; 193*d874e919Schristos Mar) nummonthtod=3;; 194*d874e919Schristos Apr) nummonthtod=4;; 195*d874e919Schristos May) nummonthtod=5;; 196*d874e919Schristos Jun) nummonthtod=6;; 197*d874e919Schristos Jul) nummonthtod=7;; 198*d874e919Schristos Aug) nummonthtod=8;; 199*d874e919Schristos Sep) nummonthtod=9;; 200*d874e919Schristos Oct) nummonthtod=10;; 201*d874e919Schristos Nov) nummonthtod=11;; 202*d874e919Schristos Dec) nummonthtod=12;; 203*d874e919Schristos esac 204*d874e919Schristos # For the first six month of the year the time notation can also 205*d874e919Schristos # be used for files modified in the last year. 206*d874e919Schristos if (expr $nummonth \> $nummonthtod) > /dev/null; 207*d874e919Schristos then 208*d874e919Schristos year=`expr $year - 1` 209*d874e919Schristos fi;; 210*d874e919Schristos *) year=$3;; 211*d874e919Schristosesac 212*d874e919Schristos 213*d874e919Schristos# The result. 214*d874e919Schristosecho $day $month $year 215*d874e919Schristos 216*d874e919Schristos# Local Variables: 217*d874e919Schristos# mode: shell-script 218*d874e919Schristos# sh-indentation: 2 219*d874e919Schristos# eval: (add-hook 'write-file-hooks 'time-stamp) 220*d874e919Schristos# time-stamp-start: "scriptversion=" 221*d874e919Schristos# time-stamp-format: "%:y-%02m-%02d.%02H" 222*d874e919Schristos# time-stamp-time-zone: "UTC" 223*d874e919Schristos# time-stamp-end: "; # UTC" 224*d874e919Schristos# End: 225