17c478bd9Sstevel@tonic-gate#!/bin/sh 27c478bd9Sstevel@tonic-gate# Get modification time of a file or directory and pretty-print it. 37c478bd9Sstevel@tonic-gate 4*1b8adde7SWilliam Kucharskiscriptversion=2004-12-08.12 57c478bd9Sstevel@tonic-gate 6*1b8adde7SWilliam Kucharski# Copyright (C) 1995, 1996, 1997, 2003, 2004 Free Software Foundation, Inc. 77c478bd9Sstevel@tonic-gate# written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995 87c478bd9Sstevel@tonic-gate# 97c478bd9Sstevel@tonic-gate# This program is free software; you can redistribute it and/or modify 107c478bd9Sstevel@tonic-gate# it under the terms of the GNU General Public License as published by 117c478bd9Sstevel@tonic-gate# the Free Software Foundation; either version 2, or (at your option) 127c478bd9Sstevel@tonic-gate# any later version. 137c478bd9Sstevel@tonic-gate# 147c478bd9Sstevel@tonic-gate# This program is distributed in the hope that it will be useful, 157c478bd9Sstevel@tonic-gate# but WITHOUT ANY WARRANTY; without even the implied warranty of 167c478bd9Sstevel@tonic-gate# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 177c478bd9Sstevel@tonic-gate# GNU General Public License for more details. 187c478bd9Sstevel@tonic-gate# 197c478bd9Sstevel@tonic-gate# You should have received a copy of the GNU General Public License 207c478bd9Sstevel@tonic-gate# along with this program; if not, write to the Free Software Foundation, 217c478bd9Sstevel@tonic-gate# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 227c478bd9Sstevel@tonic-gate 237c478bd9Sstevel@tonic-gate# As a special exception to the GNU General Public License, if you 247c478bd9Sstevel@tonic-gate# distribute this file as part of a program that contains a 257c478bd9Sstevel@tonic-gate# configuration script generated by Autoconf, you may include it under 267c478bd9Sstevel@tonic-gate# the same distribution terms that you use for the rest of that program. 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate# This file is maintained in Automake, please report 297c478bd9Sstevel@tonic-gate# bugs to <bug-automake@gnu.org> or send patches to 307c478bd9Sstevel@tonic-gate# <automake-patches@gnu.org>. 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gatecase $1 in 337c478bd9Sstevel@tonic-gate '') 347c478bd9Sstevel@tonic-gate echo "$0: No file. Try \`$0 --help' for more information." 1>&2 357c478bd9Sstevel@tonic-gate exit 1; 367c478bd9Sstevel@tonic-gate ;; 377c478bd9Sstevel@tonic-gate -h | --h*) 387c478bd9Sstevel@tonic-gate cat <<\EOF 397c478bd9Sstevel@tonic-gateUsage: mdate-sh [--help] [--version] FILE 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gatePretty-print the modification time of FILE. 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gateReport bugs to <bug-automake@gnu.org>. 447c478bd9Sstevel@tonic-gateEOF 457c478bd9Sstevel@tonic-gate exit 0 467c478bd9Sstevel@tonic-gate ;; 477c478bd9Sstevel@tonic-gate -v | --v*) 487c478bd9Sstevel@tonic-gate echo "mdate-sh $scriptversion" 497c478bd9Sstevel@tonic-gate exit 0 507c478bd9Sstevel@tonic-gate ;; 517c478bd9Sstevel@tonic-gateesac 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate# Prevent date giving response in another language. 547c478bd9Sstevel@tonic-gateLANG=C 557c478bd9Sstevel@tonic-gateexport LANG 567c478bd9Sstevel@tonic-gateLC_ALL=C 577c478bd9Sstevel@tonic-gateexport LC_ALL 587c478bd9Sstevel@tonic-gateLC_TIME=C 597c478bd9Sstevel@tonic-gateexport LC_TIME 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gatesave_arg1="$1" 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate# Find out how to get the extended ls output of a file or directory. 647c478bd9Sstevel@tonic-gateif ls -L /dev/null 1>/dev/null 2>&1; then 657c478bd9Sstevel@tonic-gate ls_command='ls -L -l -d' 667c478bd9Sstevel@tonic-gateelse 677c478bd9Sstevel@tonic-gate ls_command='ls -l -d' 687c478bd9Sstevel@tonic-gatefi 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate# A `ls -l' line looks as follows on OS/2. 717c478bd9Sstevel@tonic-gate# drwxrwx--- 0 Aug 11 2001 foo 727c478bd9Sstevel@tonic-gate# This differs from Unix, which adds ownership information. 737c478bd9Sstevel@tonic-gate# drwxrwx--- 2 root root 4096 Aug 11 2001 foo 747c478bd9Sstevel@tonic-gate# 757c478bd9Sstevel@tonic-gate# To find the date, we split the line on spaces and iterate on words 767c478bd9Sstevel@tonic-gate# until we find a month. This cannot work with files whose owner is a 777c478bd9Sstevel@tonic-gate# user named `Jan', or `Feb', etc. However, it's unlikely that `/' 787c478bd9Sstevel@tonic-gate# will be owned by a user whose name is a month. So we first look at 797c478bd9Sstevel@tonic-gate# the extended ls output of the root directory to decide how many 807c478bd9Sstevel@tonic-gate# words should be skipped to get the date. 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate# On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below. 83*1b8adde7SWilliam Kucharskiset x`ls -l -d /` 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate# Find which argument is the month. 867c478bd9Sstevel@tonic-gatemonth= 877c478bd9Sstevel@tonic-gatecommand= 887c478bd9Sstevel@tonic-gateuntil test $month 897c478bd9Sstevel@tonic-gatedo 907c478bd9Sstevel@tonic-gate shift 917c478bd9Sstevel@tonic-gate # Add another shift to the command. 927c478bd9Sstevel@tonic-gate command="$command shift;" 937c478bd9Sstevel@tonic-gate case $1 in 947c478bd9Sstevel@tonic-gate Jan) month=January; nummonth=1;; 957c478bd9Sstevel@tonic-gate Feb) month=February; nummonth=2;; 967c478bd9Sstevel@tonic-gate Mar) month=March; nummonth=3;; 977c478bd9Sstevel@tonic-gate Apr) month=April; nummonth=4;; 987c478bd9Sstevel@tonic-gate May) month=May; nummonth=5;; 997c478bd9Sstevel@tonic-gate Jun) month=June; nummonth=6;; 1007c478bd9Sstevel@tonic-gate Jul) month=July; nummonth=7;; 1017c478bd9Sstevel@tonic-gate Aug) month=August; nummonth=8;; 1027c478bd9Sstevel@tonic-gate Sep) month=September; nummonth=9;; 1037c478bd9Sstevel@tonic-gate Oct) month=October; nummonth=10;; 1047c478bd9Sstevel@tonic-gate Nov) month=November; nummonth=11;; 1057c478bd9Sstevel@tonic-gate Dec) month=December; nummonth=12;; 1067c478bd9Sstevel@tonic-gate esac 1077c478bd9Sstevel@tonic-gatedone 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate# Get the extended ls output of the file or directory. 110*1b8adde7SWilliam Kucharskiset x`eval "$ls_command \"\$save_arg1\""` 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate# Remove all preceding arguments 1137c478bd9Sstevel@tonic-gateeval $command 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate# Get the month. Next argument is day, followed by the year or time. 1167c478bd9Sstevel@tonic-gatecase $1 in 1177c478bd9Sstevel@tonic-gate Jan) month=January; nummonth=1;; 1187c478bd9Sstevel@tonic-gate Feb) month=February; nummonth=2;; 1197c478bd9Sstevel@tonic-gate Mar) month=March; nummonth=3;; 1207c478bd9Sstevel@tonic-gate Apr) month=April; nummonth=4;; 1217c478bd9Sstevel@tonic-gate May) month=May; nummonth=5;; 1227c478bd9Sstevel@tonic-gate Jun) month=June; nummonth=6;; 1237c478bd9Sstevel@tonic-gate Jul) month=July; nummonth=7;; 1247c478bd9Sstevel@tonic-gate Aug) month=August; nummonth=8;; 1257c478bd9Sstevel@tonic-gate Sep) month=September; nummonth=9;; 1267c478bd9Sstevel@tonic-gate Oct) month=October; nummonth=10;; 1277c478bd9Sstevel@tonic-gate Nov) month=November; nummonth=11;; 1287c478bd9Sstevel@tonic-gate Dec) month=December; nummonth=12;; 1297c478bd9Sstevel@tonic-gateesac 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gateday=$2 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate# Here we have to deal with the problem that the ls output gives either 1347c478bd9Sstevel@tonic-gate# the time of day or the year. 1357c478bd9Sstevel@tonic-gatecase $3 in 1367c478bd9Sstevel@tonic-gate *:*) set `date`; eval year=\$$# 1377c478bd9Sstevel@tonic-gate case $2 in 1387c478bd9Sstevel@tonic-gate Jan) nummonthtod=1;; 1397c478bd9Sstevel@tonic-gate Feb) nummonthtod=2;; 1407c478bd9Sstevel@tonic-gate Mar) nummonthtod=3;; 1417c478bd9Sstevel@tonic-gate Apr) nummonthtod=4;; 1427c478bd9Sstevel@tonic-gate May) nummonthtod=5;; 1437c478bd9Sstevel@tonic-gate Jun) nummonthtod=6;; 1447c478bd9Sstevel@tonic-gate Jul) nummonthtod=7;; 1457c478bd9Sstevel@tonic-gate Aug) nummonthtod=8;; 1467c478bd9Sstevel@tonic-gate Sep) nummonthtod=9;; 1477c478bd9Sstevel@tonic-gate Oct) nummonthtod=10;; 1487c478bd9Sstevel@tonic-gate Nov) nummonthtod=11;; 1497c478bd9Sstevel@tonic-gate Dec) nummonthtod=12;; 1507c478bd9Sstevel@tonic-gate esac 1517c478bd9Sstevel@tonic-gate # For the first six month of the year the time notation can also 1527c478bd9Sstevel@tonic-gate # be used for files modified in the last year. 1537c478bd9Sstevel@tonic-gate if (expr $nummonth \> $nummonthtod) > /dev/null; 1547c478bd9Sstevel@tonic-gate then 1557c478bd9Sstevel@tonic-gate year=`expr $year - 1` 1567c478bd9Sstevel@tonic-gate fi;; 1577c478bd9Sstevel@tonic-gate *) year=$3;; 1587c478bd9Sstevel@tonic-gateesac 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate# The result. 1617c478bd9Sstevel@tonic-gateecho $day $month $year 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate# Local Variables: 1647c478bd9Sstevel@tonic-gate# mode: shell-script 1657c478bd9Sstevel@tonic-gate# sh-indentation: 2 1667c478bd9Sstevel@tonic-gate# eval: (add-hook 'write-file-hooks 'time-stamp) 1677c478bd9Sstevel@tonic-gate# time-stamp-start: "scriptversion=" 1687c478bd9Sstevel@tonic-gate# time-stamp-format: "%:y-%02m-%02d.%02H" 1697c478bd9Sstevel@tonic-gate# time-stamp-end: "$" 1707c478bd9Sstevel@tonic-gate# End: 171