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