auto update
[pspp] / config / mdate-sh
1 #!/bin/sh
2 # Get modification time of a file or directory and pretty-print it.
3
4 scriptversion=2005-02-02.22
5
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
9 #
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.
14 #
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.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software Foundation,
22 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 # As a special exception to the GNU General Public License, if you
25 # distribute this file as part of a program that contains a
26 # configuration script generated by Autoconf, you may include it under
27 # the same distribution terms that you use for the rest of that program.
28
29 # This file is maintained in Automake, please report
30 # bugs to <bug-automake@gnu.org> or send patches to
31 # <automake-patches@gnu.org>.
32
33 case $1 in
34   '')
35      echo "$0: No file.  Try \`$0 --help' for more information." 1>&2
36      exit 1;
37      ;;
38   -h | --h*)
39     cat <<\EOF
40 Usage: mdate-sh [--help] [--version] FILE
41
42 Pretty-print the modification time of FILE.
43
44 Report bugs to <bug-automake@gnu.org>.
45 EOF
46     exit $?
47     ;;
48   -v | --v*)
49     echo "mdate-sh $scriptversion"
50     exit $?
51     ;;
52 esac
53
54 # Prevent date giving response in another language.
55 LANG=C
56 export LANG
57 LC_ALL=C
58 export LC_ALL
59 LC_TIME=C
60 export LC_TIME
61
62 save_arg1="$1"
63
64 # Find out how to get the extended ls output of a file or directory.
65 if ls -L /dev/null 1>/dev/null 2>&1; then
66   ls_command='ls -L -l -d'
67 else
68   ls_command='ls -l -d'
69 fi
70
71 # A `ls -l' line looks as follows on OS/2.
72 #  drwxrwx---        0 Aug 11  2001 foo
73 # This differs from Unix, which adds ownership information.
74 #  drwxrwx---   2 root  root      4096 Aug 11  2001 foo
75 #
76 # To find the date, we split the line on spaces and iterate on words
77 # until we find a month.  This cannot work with files whose owner is a
78 # user named `Jan', or `Feb', etc.  However, it's unlikely that `/'
79 # will be owned by a user whose name is a month.  So we first look at
80 # the extended ls output of the root directory to decide how many
81 # words should be skipped to get the date.
82
83 # On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below.
84 set x`ls -l -d /`
85
86 # Find which argument is the month.
87 month=
88 command=
89 until test $month
90 do
91   shift
92   # Add another shift to the command.
93   command="$command shift;"
94   case $1 in
95     Jan) month=January; nummonth=1;;
96     Feb) month=February; nummonth=2;;
97     Mar) month=March; nummonth=3;;
98     Apr) month=April; nummonth=4;;
99     May) month=May; nummonth=5;;
100     Jun) month=June; nummonth=6;;
101     Jul) month=July; nummonth=7;;
102     Aug) month=August; nummonth=8;;
103     Sep) month=September; nummonth=9;;
104     Oct) month=October; nummonth=10;;
105     Nov) month=November; nummonth=11;;
106     Dec) month=December; nummonth=12;;
107   esac
108 done
109
110 # Get the extended ls output of the file or directory.
111 set x`eval "$ls_command \"\$save_arg1\""`
112
113 # Remove all preceding arguments
114 eval $command
115
116 # Get the month.  Next argument is day, followed by the year or time.
117 case $1 in
118   Jan) month=January; nummonth=1;;
119   Feb) month=February; nummonth=2;;
120   Mar) month=March; nummonth=3;;
121   Apr) month=April; nummonth=4;;
122   May) month=May; nummonth=5;;
123   Jun) month=June; nummonth=6;;
124   Jul) month=July; nummonth=7;;
125   Aug) month=August; nummonth=8;;
126   Sep) month=September; nummonth=9;;
127   Oct) month=October; nummonth=10;;
128   Nov) month=November; nummonth=11;;
129   Dec) month=December; nummonth=12;;
130 esac
131
132 day=$2
133
134 # Here we have to deal with the problem that the ls output gives either
135 # the time of day or the year.
136 case $3 in
137   *:*) set `date`; eval year=\$$#
138        case $2 in
139          Jan) nummonthtod=1;;
140          Feb) nummonthtod=2;;
141          Mar) nummonthtod=3;;
142          Apr) nummonthtod=4;;
143          May) nummonthtod=5;;
144          Jun) nummonthtod=6;;
145          Jul) nummonthtod=7;;
146          Aug) nummonthtod=8;;
147          Sep) nummonthtod=9;;
148          Oct) nummonthtod=10;;
149          Nov) nummonthtod=11;;
150          Dec) nummonthtod=12;;
151        esac
152        # For the first six month of the year the time notation can also
153        # be used for files modified in the last year.
154        if (expr $nummonth \> $nummonthtod) > /dev/null;
155        then
156          year=`expr $year - 1`
157        fi;;
158   *) year=$3;;
159 esac
160
161 # The result.
162 echo $day $month $year
163
164 # Local Variables:
165 # mode: shell-script
166 # sh-indentation: 2
167 # eval: (add-hook 'write-file-hooks 'time-stamp)
168 # time-stamp-start: "scriptversion="
169 # time-stamp-format: "%:y-%02m-%02d.%02H"
170 # time-stamp-end: "$"
171 # End: