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