155682Smarkm#!/bin/sh
255682Smarkm# Get modification time of a file or directory and pretty-print it.
355682Smarkm# Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
455682Smarkm# written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995
555682Smarkm#
655682Smarkm# This program is free software; you can redistribute it and/or modify
755682Smarkm# it under the terms of the GNU General Public License as published by
855682Smarkm# the Free Software Foundation; either version 2, or (at your option)
955682Smarkm# any later version.
1055682Smarkm#
1155682Smarkm# This program is distributed in the hope that it will be useful,
1255682Smarkm# but WITHOUT ANY WARRANTY; without even the implied warranty of
1355682Smarkm# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1455682Smarkm# GNU General Public License for more details.
1555682Smarkm#
1655682Smarkm# You should have received a copy of the GNU General Public License
1755682Smarkm# along with this program; if not, write to the Free Software Foundation,
1855682Smarkm# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1955682Smarkm
2055682Smarkm# Prevent date giving response in another language.
2155682SmarkmLANG=C
2255682Smarkmexport LANG
2355682SmarkmLC_ALL=C
2455682Smarkmexport LC_ALL
2555682SmarkmLC_TIME=C
2655682Smarkmexport LC_TIME
2755682Smarkm
2855682Smarkm# Get the extended ls output of the file or directory.
2955682Smarkm# On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below.
3055682Smarkmif ls -L /dev/null 1>/dev/null 2>&1; then
3155682Smarkm  set - x`ls -L -l -d $1`
3255682Smarkmelse
3355682Smarkm  set - x`ls -l -d $1`
3455682Smarkmfi
3555682Smarkm# The month is at least the fourth argument
3655682Smarkm# (3 shifts here, the next inside the loop).
3755682Smarkmshift
3855682Smarkmshift
3955682Smarkmshift
4055682Smarkm
4155682Smarkm# Find the month.  Next argument is day, followed by the year or time.
4255682Smarkmmonth=
4355682Smarkmuntil test $month
4455682Smarkmdo
4555682Smarkm  shift
4655682Smarkm  case $1 in
4755682Smarkm    Jan) month=January; nummonth=1;;
4855682Smarkm    Feb) month=February; nummonth=2;;
4955682Smarkm    Mar) month=March; nummonth=3;;
5055682Smarkm    Apr) month=April; nummonth=4;;
5155682Smarkm    May) month=May; nummonth=5;;
5255682Smarkm    Jun) month=June; nummonth=6;;
5355682Smarkm    Jul) month=July; nummonth=7;;
5455682Smarkm    Aug) month=August; nummonth=8;;
5555682Smarkm    Sep) month=September; nummonth=9;;
5655682Smarkm    Oct) month=October; nummonth=10;;
5755682Smarkm    Nov) month=November; nummonth=11;;
5855682Smarkm    Dec) month=December; nummonth=12;;
5955682Smarkm  esac
6055682Smarkmdone
6155682Smarkm
6255682Smarkmday=$2
6355682Smarkm
6455682Smarkm# Here we have to deal with the problem that the ls output gives either
6555682Smarkm# the time of day or the year.
6655682Smarkmcase $3 in
6755682Smarkm  *:*) set `date`; eval year=\$$#
6855682Smarkm       case $2 in
6955682Smarkm	 Jan) nummonthtod=1;;
7055682Smarkm	 Feb) nummonthtod=2;;
7155682Smarkm	 Mar) nummonthtod=3;;
7255682Smarkm	 Apr) nummonthtod=4;;
7355682Smarkm	 May) nummonthtod=5;;
7455682Smarkm	 Jun) nummonthtod=6;;
7555682Smarkm	 Jul) nummonthtod=7;;
7655682Smarkm	 Aug) nummonthtod=8;;
7755682Smarkm	 Sep) nummonthtod=9;;
7855682Smarkm	 Oct) nummonthtod=10;;
7955682Smarkm	 Nov) nummonthtod=11;;
8055682Smarkm	 Dec) nummonthtod=12;;
8155682Smarkm       esac
8255682Smarkm       # For the first six month of the year the time notation can also
8355682Smarkm       # be used for files modified in the last year.
8455682Smarkm       if (expr $nummonth \> $nummonthtod) > /dev/null;
8555682Smarkm       then
8655682Smarkm	 year=`expr $year - 1`
8755682Smarkm       fi;;
8855682Smarkm  *) year=$3;;
8955682Smarkmesac
9055682Smarkm
9155682Smarkm# The result.
9255682Smarkmecho $day $month $year
93