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