Fixed EOF detection for encrypted packets.
[gnupg.git] / scripts / mdate-sh
blob9a6d216e325fa80f0affe6f5213fb6b0845becaf
1 #!/bin/sh
2 # Get modification time of a file or directory and pretty-print it.
4 scriptversion=2005-06-29.22
6 # Copyright (C) 1995, 1996, 1997, 2003, 2004, 2005 Free Software
7 # Foundation, Inc.
8 # written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2, or (at your option)
13 # any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, see <http://www.gnu.org/licenses/>.
22 # As a special exception to the GNU General Public License, if you
23 # distribute this file as part of a program that contains a
24 # configuration script generated by Autoconf, you may include it under
25 # the same distribution terms that you use for the rest of that program.
27 # This file is maintained in Automake, please report
28 # bugs to <bug-automake@gnu.org> or send patches to
29 # <automake-patches@gnu.org>.
31 case $1 in
32 '')
33 echo "$0: No file. Try \`$0 --help' for more information." 1>&2
34 exit 1;
36 -h | --h*)
37 cat <<\EOF
38 Usage: mdate-sh [--help] [--version] FILE
40 Pretty-print the modification time of FILE.
42 Report bugs to <bug-automake@gnu.org>.
43 EOF
44 exit $?
46 -v | --v*)
47 echo "mdate-sh $scriptversion"
48 exit $?
50 esac
52 # Prevent date giving response in another language.
53 LANG=C
54 export LANG
55 LC_ALL=C
56 export LC_ALL
57 LC_TIME=C
58 export LC_TIME
60 # GNU ls changes its time format in response to the TIME_STYLE
61 # variable. Since we cannot assume `unset' works, revert this
62 # variable to its documented default.
63 if test "${TIME_STYLE+set}" = set; then
64 TIME_STYLE=posix-long-iso
65 export TIME_STYLE
68 save_arg1=$1
70 # Find out how to get the extended ls output of a file or directory.
71 if ls -L /dev/null 1>/dev/null 2>&1; then
72 ls_command='ls -L -l -d'
73 else
74 ls_command='ls -l -d'
77 # A `ls -l' line looks as follows on OS/2.
78 # drwxrwx--- 0 Aug 11 2001 foo
79 # This differs from Unix, which adds ownership information.
80 # drwxrwx--- 2 root root 4096 Aug 11 2001 foo
82 # To find the date, we split the line on spaces and iterate on words
83 # until we find a month. This cannot work with files whose owner is a
84 # user named `Jan', or `Feb', etc. However, it's unlikely that `/'
85 # will be owned by a user whose name is a month. So we first look at
86 # the extended ls output of the root directory to decide how many
87 # words should be skipped to get the date.
89 # On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below.
90 set x`ls -l -d /`
92 # Find which argument is the month.
93 month=
94 command=
95 until test $month
97 shift
98 # Add another shift to the command.
99 command="$command shift;"
100 case $1 in
101 Jan) month=January; nummonth=1;;
102 Feb) month=February; nummonth=2;;
103 Mar) month=March; nummonth=3;;
104 Apr) month=April; nummonth=4;;
105 May) month=May; nummonth=5;;
106 Jun) month=June; nummonth=6;;
107 Jul) month=July; nummonth=7;;
108 Aug) month=August; nummonth=8;;
109 Sep) month=September; nummonth=9;;
110 Oct) month=October; nummonth=10;;
111 Nov) month=November; nummonth=11;;
112 Dec) month=December; nummonth=12;;
113 esac
114 done
116 # Get the extended ls output of the file or directory.
117 set dummy x`eval "$ls_command \"\$save_arg1\""`
119 # Remove all preceding arguments
120 eval $command
122 # Because of the dummy argument above, month is in $2.
124 # On a POSIX system, we should have
126 # $# = 5
127 # $1 = file size
128 # $2 = month
129 # $3 = day
130 # $4 = year or time
131 # $5 = filename
133 # On Darwin 7.7.0 and 7.6.0, we have
135 # $# = 4
136 # $1 = day
137 # $2 = month
138 # $3 = year or time
139 # $4 = filename
141 # Get the month.
142 case $2 in
143 Jan) month=January; nummonth=1;;
144 Feb) month=February; nummonth=2;;
145 Mar) month=March; nummonth=3;;
146 Apr) month=April; nummonth=4;;
147 May) month=May; nummonth=5;;
148 Jun) month=June; nummonth=6;;
149 Jul) month=July; nummonth=7;;
150 Aug) month=August; nummonth=8;;
151 Sep) month=September; nummonth=9;;
152 Oct) month=October; nummonth=10;;
153 Nov) month=November; nummonth=11;;
154 Dec) month=December; nummonth=12;;
155 esac
157 case $3 in
158 ???*) day=$1;;
159 *) day=$3; shift;;
160 esac
162 # Here we have to deal with the problem that the ls output gives either
163 # the time of day or the year.
164 case $3 in
165 *:*) set `date`; eval year=\$$#
166 case $2 in
167 Jan) nummonthtod=1;;
168 Feb) nummonthtod=2;;
169 Mar) nummonthtod=3;;
170 Apr) nummonthtod=4;;
171 May) nummonthtod=5;;
172 Jun) nummonthtod=6;;
173 Jul) nummonthtod=7;;
174 Aug) nummonthtod=8;;
175 Sep) nummonthtod=9;;
176 Oct) nummonthtod=10;;
177 Nov) nummonthtod=11;;
178 Dec) nummonthtod=12;;
179 esac
180 # For the first six month of the year the time notation can also
181 # be used for files modified in the last year.
182 if (expr $nummonth \> $nummonthtod) > /dev/null;
183 then
184 year=`expr $year - 1`
185 fi;;
186 *) year=$3;;
187 esac
189 # The result.
190 echo $day $month $year
192 # Local Variables:
193 # mode: shell-script
194 # sh-indentation: 2
195 # eval: (add-hook 'write-file-hooks 'time-stamp)
196 # time-stamp-start: "scriptversion="
197 # time-stamp-format: "%:y-%02m-%02d.%02H"
198 # time-stamp-end: "$"
199 # End: