| 1 |
#!/bin/sh |
| 2 |
# Get modification time of a file or directory and pretty-print it. |
| 3 |
# Copyright (C) 1995, 1996, 1997, 2003 Free Software Foundation, Inc. |
| 4 |
# written by Ulrich Drepper <[email protected]>, June 1995 |
| 5 |
# |
| 6 |
# This program is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation; either version 2, or (at your option) |
| 9 |
# any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program; if not, write to the Free Software Foundation, |
| 18 |
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 |
|
| 20 |
# As a special exception to the GNU General Public License, if you |
| 21 |
# distribute this file as part of a program that contains a |
| 22 |
# configuration script generated by Autoconf, you may include it under |
| 23 |
# the same distribution terms that you use for the rest of that program. |
| 24 |
|
| 25 |
# Prevent date giving response in another language. |
| 26 |
LANG=C |
| 27 |
export LANG |
| 28 |
LC_ALL=C |
| 29 |
export LC_ALL |
| 30 |
LC_TIME=C |
| 31 |
export LC_TIME |
| 32 |
|
| 33 |
save_arg1="$1" |
| 34 |
|
| 35 |
# Find out how to get the extended ls output of a file or directory. |
| 36 |
if ls -L /dev/null 1>/dev/null 2>&1; then |
| 37 |
ls_command='ls -L -l -d' |
| 38 |
else |
| 39 |
ls_command='ls -l -d' |
| 40 |
fi |
| 41 |
|
| 42 |
# A `ls -l' line looks as follows on OS/2. |
| 43 |
# drwxrwx--- 0 Aug 11 2001 foo |
| 44 |
# This differs from Unix, which adds ownership information. |
| 45 |
# drwxrwx--- 2 root root 4096 Aug 11 2001 foo |
| 46 |
# |
| 47 |
# To find the date, we split the line on spaces and iterate on words |
| 48 |
# until we find a month. This cannot work with files whose owner is a |
| 49 |
# user named `Jan', or `Feb', etc. However, it's unlikely that `/' |
| 50 |
# will be owned by a user whose name is a month. So we first look at |
| 51 |
# the extended ls output of the root directory to decide how many |
| 52 |
# words should be skipped to get the date. |
| 53 |
|
| 54 |
# On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below. |
| 55 |
set - x`$ls_command /` |
| 56 |
|
| 57 |
# Find which argument is the month. |
| 58 |
month= |
| 59 |
command= |
| 60 |
until test $month |
| 61 |
do |
| 62 |
shift |
| 63 |
# Add another shift to the command. |
| 64 |
command="$command shift;" |
| 65 |
case $1 in |
| 66 |
Jan) month=January; nummonth=1;; |
| 67 |
Feb) month=February; nummonth=2;; |
| 68 |
Mar) month=March; nummonth=3;; |
| 69 |
Apr) month=April; nummonth=4;; |
| 70 |
May) month=May; nummonth=5;; |
| 71 |
Jun) month=June; nummonth=6;; |
| 72 |
Jul) month=July; nummonth=7;; |
| 73 |
Aug) month=August; nummonth=8;; |
| 74 |
Sep) month=September; nummonth=9;; |
| 75 |
Oct) month=October; nummonth=10;; |
| 76 |
Nov) month=November; nummonth=11;; |
| 77 |
Dec) month=December; nummonth=12;; |
| 78 |
esac |
| 79 |
done |
| 80 |
|
| 81 |
# Get the extended ls output of the file or directory. |
| 82 |
set - x`eval "$ls_command \"\$save_arg1\""` |
| 83 |
|
| 84 |
# Remove all preceding arguments |
| 85 |
eval $command |
| 86 |
|
| 87 |
# Get the month. Next argument is day, followed by the year or time. |
| 88 |
case $1 in |
| 89 |
Jan) month=January; nummonth=1;; |
| 90 |
Feb) month=February; nummonth=2;; |
| 91 |
Mar) month=March; nummonth=3;; |
| 92 |
Apr) month=April; nummonth=4;; |
| 93 |
May) month=May; nummonth=5;; |
| 94 |
Jun) month=June; nummonth=6;; |
| 95 |
Jul) month=July; nummonth=7;; |
| 96 |
Aug) month=August; nummonth=8;; |
| 97 |
Sep) month=September; nummonth=9;; |
| 98 |
Oct) month=October; nummonth=10;; |
| 99 |
Nov) month=November; nummonth=11;; |
| 100 |
Dec) month=December; nummonth=12;; |
| 101 |
esac |
| 102 |
|
| 103 |
day=$2 |
| 104 |
|
| 105 |
# Here we have to deal with the problem that the ls output gives either |
| 106 |
# the time of day or the year. |
| 107 |
case $3 in |
| 108 |
*:*) set `date`; eval year=\$$# |
| 109 |
case $2 in |
| 110 |
Jan) nummonthtod=1;; |
| 111 |
Feb) nummonthtod=2;; |
| 112 |
Mar) nummonthtod=3;; |
| 113 |
Apr) nummonthtod=4;; |
| 114 |
May) nummonthtod=5;; |
| 115 |
Jun) nummonthtod=6;; |
| 116 |
Jul) nummonthtod=7;; |
| 117 |
Aug) nummonthtod=8;; |
| 118 |
Sep) nummonthtod=9;; |
| 119 |
Oct) nummonthtod=10;; |
| 120 |
Nov) nummonthtod=11;; |
| 121 |
Dec) nummonthtod=12;; |
| 122 |
esac |
| 123 |
# For the first six month of the year the time notation can also |
| 124 |
# be used for files modified in the last year. |
| 125 |
if (expr $nummonth \> $nummonthtod) > /dev/null; |
| 126 |
then |
| 127 |
year=`expr $year - 1` |
| 128 |
fi;; |
| 129 |
*) year=$3;; |
| 130 |
esac |
| 131 |
|
| 132 |
# The result. |
| 133 |
echo $day $month $year |