xref: /freebsd-src/crypto/heimdal/doc/mdate-sh (revision b528cefc6b8f9670b31a865051741d946cb37085)
1*b528cefcSMark Murray#!/bin/sh
2*b528cefcSMark Murray# Get modification time of a file or directory and pretty-print it.
3*b528cefcSMark Murray# Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
4*b528cefcSMark Murray# written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995
5*b528cefcSMark Murray#
6*b528cefcSMark Murray# This program is free software; you can redistribute it and/or modify
7*b528cefcSMark Murray# it under the terms of the GNU General Public License as published by
8*b528cefcSMark Murray# the Free Software Foundation; either version 2, or (at your option)
9*b528cefcSMark Murray# any later version.
10*b528cefcSMark Murray#
11*b528cefcSMark Murray# This program is distributed in the hope that it will be useful,
12*b528cefcSMark Murray# but WITHOUT ANY WARRANTY; without even the implied warranty of
13*b528cefcSMark Murray# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*b528cefcSMark Murray# GNU General Public License for more details.
15*b528cefcSMark Murray#
16*b528cefcSMark Murray# You should have received a copy of the GNU General Public License
17*b528cefcSMark Murray# along with this program; if not, write to the Free Software Foundation,
18*b528cefcSMark Murray# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19*b528cefcSMark Murray
20*b528cefcSMark Murray# Prevent date giving response in another language.
21*b528cefcSMark MurrayLANG=C
22*b528cefcSMark Murrayexport LANG
23*b528cefcSMark MurrayLC_ALL=C
24*b528cefcSMark Murrayexport LC_ALL
25*b528cefcSMark MurrayLC_TIME=C
26*b528cefcSMark Murrayexport LC_TIME
27*b528cefcSMark Murray
28*b528cefcSMark Murray# Get the extended ls output of the file or directory.
29*b528cefcSMark Murray# On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below.
30*b528cefcSMark Murrayif ls -L /dev/null 1>/dev/null 2>&1; then
31*b528cefcSMark Murray  set - x`ls -L -l -d $1`
32*b528cefcSMark Murrayelse
33*b528cefcSMark Murray  set - x`ls -l -d $1`
34*b528cefcSMark Murrayfi
35*b528cefcSMark Murray# The month is at least the fourth argument
36*b528cefcSMark Murray# (3 shifts here, the next inside the loop).
37*b528cefcSMark Murrayshift
38*b528cefcSMark Murrayshift
39*b528cefcSMark Murrayshift
40*b528cefcSMark Murray
41*b528cefcSMark Murray# Find the month.  Next argument is day, followed by the year or time.
42*b528cefcSMark Murraymonth=
43*b528cefcSMark Murrayuntil test $month
44*b528cefcSMark Murraydo
45*b528cefcSMark Murray  shift
46*b528cefcSMark Murray  case $1 in
47*b528cefcSMark Murray    Jan) month=January; nummonth=1;;
48*b528cefcSMark Murray    Feb) month=February; nummonth=2;;
49*b528cefcSMark Murray    Mar) month=March; nummonth=3;;
50*b528cefcSMark Murray    Apr) month=April; nummonth=4;;
51*b528cefcSMark Murray    May) month=May; nummonth=5;;
52*b528cefcSMark Murray    Jun) month=June; nummonth=6;;
53*b528cefcSMark Murray    Jul) month=July; nummonth=7;;
54*b528cefcSMark Murray    Aug) month=August; nummonth=8;;
55*b528cefcSMark Murray    Sep) month=September; nummonth=9;;
56*b528cefcSMark Murray    Oct) month=October; nummonth=10;;
57*b528cefcSMark Murray    Nov) month=November; nummonth=11;;
58*b528cefcSMark Murray    Dec) month=December; nummonth=12;;
59*b528cefcSMark Murray  esac
60*b528cefcSMark Murraydone
61*b528cefcSMark Murray
62*b528cefcSMark Murrayday=$2
63*b528cefcSMark Murray
64*b528cefcSMark Murray# Here we have to deal with the problem that the ls output gives either
65*b528cefcSMark Murray# the time of day or the year.
66*b528cefcSMark Murraycase $3 in
67*b528cefcSMark Murray  *:*) set `date`; eval year=\$$#
68*b528cefcSMark Murray       case $2 in
69*b528cefcSMark Murray	 Jan) nummonthtod=1;;
70*b528cefcSMark Murray	 Feb) nummonthtod=2;;
71*b528cefcSMark Murray	 Mar) nummonthtod=3;;
72*b528cefcSMark Murray	 Apr) nummonthtod=4;;
73*b528cefcSMark Murray	 May) nummonthtod=5;;
74*b528cefcSMark Murray	 Jun) nummonthtod=6;;
75*b528cefcSMark Murray	 Jul) nummonthtod=7;;
76*b528cefcSMark Murray	 Aug) nummonthtod=8;;
77*b528cefcSMark Murray	 Sep) nummonthtod=9;;
78*b528cefcSMark Murray	 Oct) nummonthtod=10;;
79*b528cefcSMark Murray	 Nov) nummonthtod=11;;
80*b528cefcSMark Murray	 Dec) nummonthtod=12;;
81*b528cefcSMark Murray       esac
82*b528cefcSMark Murray       # For the first six month of the year the time notation can also
83*b528cefcSMark Murray       # be used for files modified in the last year.
84*b528cefcSMark Murray       if (expr $nummonth \> $nummonthtod) > /dev/null;
85*b528cefcSMark Murray       then
86*b528cefcSMark Murray	 year=`expr $year - 1`
87*b528cefcSMark Murray       fi;;
88*b528cefcSMark Murray  *) year=$3;;
89*b528cefcSMark Murrayesac
90*b528cefcSMark Murray
91*b528cefcSMark Murray# The result.
92*b528cefcSMark Murrayecho $day $month $year
93