1*1b8adde7SWilliam Kucharski#!/bin/sh 2*1b8adde7SWilliam Kucharski# Get modification time of a file or directory and pretty-print it. 3*1b8adde7SWilliam Kucharski 4*1b8adde7SWilliam Kucharskiscriptversion=2004-12-08.12 5*1b8adde7SWilliam Kucharski 6*1b8adde7SWilliam Kucharski# Copyright (C) 1995, 1996, 1997, 2003, 2004 Free Software Foundation, Inc. 7*1b8adde7SWilliam Kucharski# written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995 8*1b8adde7SWilliam Kucharski# 9*1b8adde7SWilliam Kucharski# This program is free software; you can redistribute it and/or modify 10*1b8adde7SWilliam Kucharski# it under the terms of the GNU General Public License as published by 11*1b8adde7SWilliam Kucharski# the Free Software Foundation; either version 2, or (at your option) 12*1b8adde7SWilliam Kucharski# any later version. 13*1b8adde7SWilliam Kucharski# 14*1b8adde7SWilliam Kucharski# This program is distributed in the hope that it will be useful, 15*1b8adde7SWilliam Kucharski# but WITHOUT ANY WARRANTY; without even the implied warranty of 16*1b8adde7SWilliam Kucharski# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17*1b8adde7SWilliam Kucharski# GNU General Public License for more details. 18*1b8adde7SWilliam Kucharski# 19*1b8adde7SWilliam Kucharski# You should have received a copy of the GNU General Public License 20*1b8adde7SWilliam Kucharski# along with this program; if not, write to the Free Software Foundation, 21*1b8adde7SWilliam Kucharski# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 22*1b8adde7SWilliam Kucharski 23*1b8adde7SWilliam Kucharski# As a special exception to the GNU General Public License, if you 24*1b8adde7SWilliam Kucharski# distribute this file as part of a program that contains a 25*1b8adde7SWilliam Kucharski# configuration script generated by Autoconf, you may include it under 26*1b8adde7SWilliam Kucharski# the same distribution terms that you use for the rest of that program. 27*1b8adde7SWilliam Kucharski 28*1b8adde7SWilliam Kucharski# This file is maintained in Automake, please report 29*1b8adde7SWilliam Kucharski# bugs to <bug-automake@gnu.org> or send patches to 30*1b8adde7SWilliam Kucharski# <automake-patches@gnu.org>. 31*1b8adde7SWilliam Kucharski 32*1b8adde7SWilliam Kucharskicase $1 in 33*1b8adde7SWilliam Kucharski '') 34*1b8adde7SWilliam Kucharski echo "$0: No file. Try \`$0 --help' for more information." 1>&2 35*1b8adde7SWilliam Kucharski exit 1; 36*1b8adde7SWilliam Kucharski ;; 37*1b8adde7SWilliam Kucharski -h | --h*) 38*1b8adde7SWilliam Kucharski cat <<\EOF 39*1b8adde7SWilliam KucharskiUsage: mdate-sh [--help] [--version] FILE 40*1b8adde7SWilliam Kucharski 41*1b8adde7SWilliam KucharskiPretty-print the modification time of FILE. 42*1b8adde7SWilliam Kucharski 43*1b8adde7SWilliam KucharskiReport bugs to <bug-automake@gnu.org>. 44*1b8adde7SWilliam KucharskiEOF 45*1b8adde7SWilliam Kucharski exit 0 46*1b8adde7SWilliam Kucharski ;; 47*1b8adde7SWilliam Kucharski -v | --v*) 48*1b8adde7SWilliam Kucharski echo "mdate-sh $scriptversion" 49*1b8adde7SWilliam Kucharski exit 0 50*1b8adde7SWilliam Kucharski ;; 51*1b8adde7SWilliam Kucharskiesac 52*1b8adde7SWilliam Kucharski 53*1b8adde7SWilliam Kucharski# Prevent date giving response in another language. 54*1b8adde7SWilliam KucharskiLANG=C 55*1b8adde7SWilliam Kucharskiexport LANG 56*1b8adde7SWilliam KucharskiLC_ALL=C 57*1b8adde7SWilliam Kucharskiexport LC_ALL 58*1b8adde7SWilliam KucharskiLC_TIME=C 59*1b8adde7SWilliam Kucharskiexport LC_TIME 60*1b8adde7SWilliam Kucharski 61*1b8adde7SWilliam Kucharskisave_arg1="$1" 62*1b8adde7SWilliam Kucharski 63*1b8adde7SWilliam Kucharski# Find out how to get the extended ls output of a file or directory. 64*1b8adde7SWilliam Kucharskiif ls -L /dev/null 1>/dev/null 2>&1; then 65*1b8adde7SWilliam Kucharski ls_command='ls -L -l -d' 66*1b8adde7SWilliam Kucharskielse 67*1b8adde7SWilliam Kucharski ls_command='ls -l -d' 68*1b8adde7SWilliam Kucharskifi 69*1b8adde7SWilliam Kucharski 70*1b8adde7SWilliam Kucharski# A `ls -l' line looks as follows on OS/2. 71*1b8adde7SWilliam Kucharski# drwxrwx--- 0 Aug 11 2001 foo 72*1b8adde7SWilliam Kucharski# This differs from Unix, which adds ownership information. 73*1b8adde7SWilliam Kucharski# drwxrwx--- 2 root root 4096 Aug 11 2001 foo 74*1b8adde7SWilliam Kucharski# 75*1b8adde7SWilliam Kucharski# To find the date, we split the line on spaces and iterate on words 76*1b8adde7SWilliam Kucharski# until we find a month. This cannot work with files whose owner is a 77*1b8adde7SWilliam Kucharski# user named `Jan', or `Feb', etc. However, it's unlikely that `/' 78*1b8adde7SWilliam Kucharski# will be owned by a user whose name is a month. So we first look at 79*1b8adde7SWilliam Kucharski# the extended ls output of the root directory to decide how many 80*1b8adde7SWilliam Kucharski# words should be skipped to get the date. 81*1b8adde7SWilliam Kucharski 82*1b8adde7SWilliam Kucharski# On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below. 83*1b8adde7SWilliam Kucharskiset x`ls -l -d /` 84*1b8adde7SWilliam Kucharski 85*1b8adde7SWilliam Kucharski# Find which argument is the month. 86*1b8adde7SWilliam Kucharskimonth= 87*1b8adde7SWilliam Kucharskicommand= 88*1b8adde7SWilliam Kucharskiuntil test $month 89*1b8adde7SWilliam Kucharskido 90*1b8adde7SWilliam Kucharski shift 91*1b8adde7SWilliam Kucharski # Add another shift to the command. 92*1b8adde7SWilliam Kucharski command="$command shift;" 93*1b8adde7SWilliam Kucharski case $1 in 94*1b8adde7SWilliam Kucharski Jan) month=January; nummonth=1;; 95*1b8adde7SWilliam Kucharski Feb) month=February; nummonth=2;; 96*1b8adde7SWilliam Kucharski Mar) month=March; nummonth=3;; 97*1b8adde7SWilliam Kucharski Apr) month=April; nummonth=4;; 98*1b8adde7SWilliam Kucharski May) month=May; nummonth=5;; 99*1b8adde7SWilliam Kucharski Jun) month=June; nummonth=6;; 100*1b8adde7SWilliam Kucharski Jul) month=July; nummonth=7;; 101*1b8adde7SWilliam Kucharski Aug) month=August; nummonth=8;; 102*1b8adde7SWilliam Kucharski Sep) month=September; nummonth=9;; 103*1b8adde7SWilliam Kucharski Oct) month=October; nummonth=10;; 104*1b8adde7SWilliam Kucharski Nov) month=November; nummonth=11;; 105*1b8adde7SWilliam Kucharski Dec) month=December; nummonth=12;; 106*1b8adde7SWilliam Kucharski esac 107*1b8adde7SWilliam Kucharskidone 108*1b8adde7SWilliam Kucharski 109*1b8adde7SWilliam Kucharski# Get the extended ls output of the file or directory. 110*1b8adde7SWilliam Kucharskiset x`eval "$ls_command \"\$save_arg1\""` 111*1b8adde7SWilliam Kucharski 112*1b8adde7SWilliam Kucharski# Remove all preceding arguments 113*1b8adde7SWilliam Kucharskieval $command 114*1b8adde7SWilliam Kucharski 115*1b8adde7SWilliam Kucharski# Get the month. Next argument is day, followed by the year or time. 116*1b8adde7SWilliam Kucharskicase $1 in 117*1b8adde7SWilliam Kucharski Jan) month=January; nummonth=1;; 118*1b8adde7SWilliam Kucharski Feb) month=February; nummonth=2;; 119*1b8adde7SWilliam Kucharski Mar) month=March; nummonth=3;; 120*1b8adde7SWilliam Kucharski Apr) month=April; nummonth=4;; 121*1b8adde7SWilliam Kucharski May) month=May; nummonth=5;; 122*1b8adde7SWilliam Kucharski Jun) month=June; nummonth=6;; 123*1b8adde7SWilliam Kucharski Jul) month=July; nummonth=7;; 124*1b8adde7SWilliam Kucharski Aug) month=August; nummonth=8;; 125*1b8adde7SWilliam Kucharski Sep) month=September; nummonth=9;; 126*1b8adde7SWilliam Kucharski Oct) month=October; nummonth=10;; 127*1b8adde7SWilliam Kucharski Nov) month=November; nummonth=11;; 128*1b8adde7SWilliam Kucharski Dec) month=December; nummonth=12;; 129*1b8adde7SWilliam Kucharskiesac 130*1b8adde7SWilliam Kucharski 131*1b8adde7SWilliam Kucharskiday=$2 132*1b8adde7SWilliam Kucharski 133*1b8adde7SWilliam Kucharski# Here we have to deal with the problem that the ls output gives either 134*1b8adde7SWilliam Kucharski# the time of day or the year. 135*1b8adde7SWilliam Kucharskicase $3 in 136*1b8adde7SWilliam Kucharski *:*) set `date`; eval year=\$$# 137*1b8adde7SWilliam Kucharski case $2 in 138*1b8adde7SWilliam Kucharski Jan) nummonthtod=1;; 139*1b8adde7SWilliam Kucharski Feb) nummonthtod=2;; 140*1b8adde7SWilliam Kucharski Mar) nummonthtod=3;; 141*1b8adde7SWilliam Kucharski Apr) nummonthtod=4;; 142*1b8adde7SWilliam Kucharski May) nummonthtod=5;; 143*1b8adde7SWilliam Kucharski Jun) nummonthtod=6;; 144*1b8adde7SWilliam Kucharski Jul) nummonthtod=7;; 145*1b8adde7SWilliam Kucharski Aug) nummonthtod=8;; 146*1b8adde7SWilliam Kucharski Sep) nummonthtod=9;; 147*1b8adde7SWilliam Kucharski Oct) nummonthtod=10;; 148*1b8adde7SWilliam Kucharski Nov) nummonthtod=11;; 149*1b8adde7SWilliam Kucharski Dec) nummonthtod=12;; 150*1b8adde7SWilliam Kucharski esac 151*1b8adde7SWilliam Kucharski # For the first six month of the year the time notation can also 152*1b8adde7SWilliam Kucharski # be used for files modified in the last year. 153*1b8adde7SWilliam Kucharski if (expr $nummonth \> $nummonthtod) > /dev/null; 154*1b8adde7SWilliam Kucharski then 155*1b8adde7SWilliam Kucharski year=`expr $year - 1` 156*1b8adde7SWilliam Kucharski fi;; 157*1b8adde7SWilliam Kucharski *) year=$3;; 158*1b8adde7SWilliam Kucharskiesac 159*1b8adde7SWilliam Kucharski 160*1b8adde7SWilliam Kucharski# The result. 161*1b8adde7SWilliam Kucharskiecho $day $month $year 162*1b8adde7SWilliam Kucharski 163*1b8adde7SWilliam Kucharski# Local Variables: 164*1b8adde7SWilliam Kucharski# mode: shell-script 165*1b8adde7SWilliam Kucharski# sh-indentation: 2 166*1b8adde7SWilliam Kucharski# eval: (add-hook 'write-file-hooks 'time-stamp) 167*1b8adde7SWilliam Kucharski# time-stamp-start: "scriptversion=" 168*1b8adde7SWilliam Kucharski# time-stamp-format: "%:y-%02m-%02d.%02H" 169*1b8adde7SWilliam Kucharski# time-stamp-end: "$" 170*1b8adde7SWilliam Kucharski# End: 171