2c24a0094bdc74d057925626e470493d93149934
[platform/upstream/groff.git] / mdate.sh
1 #! /bin/sh
2 #
3 # Copyright (C) 1991-2014 Free Software Foundation, Inc.
4
5 # This file is part of groff.
6
7 # groff is free software; you can redistribute it and/or modify it under
8 # the terms of the GNU General Public License as published by the Free
9 # Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11
12 # groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 # for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #
20 # Print the modification date of $1 `nicely'.
21
22 # Don't want foreign dates.
23
24 LANGUAGE=
25 LC_ALL=C; export LC_ALL
26
27
28 (date;
29 if ls -L /dev/null 1>/dev/null 2>&1; then ls -L -l $1; else ls -l $1; fi
30 ) | awk '
31 BEGIN {
32         full["Jan"] = "January"; number["Jan"] = 1;
33         full["Feb"] = "February"; number["Feb"] = 2;
34         full["Mar"] = "March"; number["Mar"] = 3;
35         full["Apr"] = "April"; number["Apr"] = 4;
36         full["May"] = "May"; number["May"] = 5;
37         full["Jun"] = "June"; number["Jun"] = 6;
38         full["Jul"] = "July"; number["Jul"] = 7;
39         full["Aug"] = "August"; number["Aug"] = 8;
40         full["Sep"] = "September"; number["Sep"] = 9;
41         full["Oct"] = "October"; number["Oct"] = 10;
42         full["Nov"] = "November"; number["Nov"] = 11;
43         full["Dec"] = "December"; number["Dec"] = 12;
44 }
45
46 NR == 1 {
47         month = $2;
48         year = $NF;
49 }
50
51 NR == 2 {
52         if ($(NF-1) ~ /:/) {
53                 if (number[$(NF-3)] > number[month])
54                         year--;
55         }
56         else
57                 year = $(NF-1);
58         print $(NF-2), full[$(NF-3)], year
59 }'