X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=config%2Fmdate-sh;h=881782eb55e450d170a16422ca9d50fb09afbe7a;hb=442f1f7d711e447a912fb2bc5c38ca3d8cfe936e;hp=37171f21fbd9fa5e825543aa766970281a9c5988;hpb=7cb622b42c51aa1cd522aa6f37d148993906cb80;p=gnulib.git diff --git a/config/mdate-sh b/config/mdate-sh index 37171f21f..881782eb5 100755 --- a/config/mdate-sh +++ b/config/mdate-sh @@ -1,6 +1,9 @@ #!/bin/sh # Get modification time of a file or directory and pretty-print it. -# Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc. + +scriptversion=2004-12-08.12 + +# Copyright (C) 1995, 1996, 1997, 2003, 2004 Free Software Foundation, Inc. # written by Ulrich Drepper , June 1995 # # This program is free software; you can redistribute it and/or modify @@ -17,6 +20,36 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# This file is maintained in Automake, please report +# bugs to or send patches to +# . + +case $1 in + '') + echo "$0: No file. Try \`$0 --help' for more information." 1>&2 + exit 1; + ;; + -h | --h*) + cat <<\EOF +Usage: mdate-sh [--help] [--version] FILE + +Pretty-print the modification time of FILE. + +Report bugs to . +EOF + exit 0 + ;; + -v | --v*) + echo "mdate-sh $scriptversion" + exit 0 + ;; +esac + # Prevent date giving response in another language. LANG=C export LANG @@ -25,24 +58,38 @@ export LC_ALL LC_TIME=C export LC_TIME -# Get the extended ls output of the file or directory. -# On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below. +save_arg1="$1" + +# Find out how to get the extended ls output of a file or directory. if ls -L /dev/null 1>/dev/null 2>&1; then - set - x`ls -L -l -d $1` + ls_command='ls -L -l -d' else - set - x`ls -l -d $1` + ls_command='ls -l -d' fi -# The month is at least the fourth argument -# (3 shifts here, the next inside the loop). -shift -shift -shift -# Find the month. Next argument is day, followed by the year or time. +# A `ls -l' line looks as follows on OS/2. +# drwxrwx--- 0 Aug 11 2001 foo +# This differs from Unix, which adds ownership information. +# drwxrwx--- 2 root root 4096 Aug 11 2001 foo +# +# To find the date, we split the line on spaces and iterate on words +# until we find a month. This cannot work with files whose owner is a +# user named `Jan', or `Feb', etc. However, it's unlikely that `/' +# will be owned by a user whose name is a month. So we first look at +# the extended ls output of the root directory to decide how many +# words should be skipped to get the date. + +# On HPUX /bin/sh, "set" interprets "-rw-r--r--" as options, so the "x" below. +set x`ls -l -d /` + +# Find which argument is the month. month= +command= until test $month do shift + # Add another shift to the command. + command="$command shift;" case $1 in Jan) month=January; nummonth=1;; Feb) month=February; nummonth=2;; @@ -59,6 +106,28 @@ do esac done +# Get the extended ls output of the file or directory. +set x`eval "$ls_command \"\$save_arg1\""` + +# Remove all preceding arguments +eval $command + +# Get the month. Next argument is day, followed by the year or time. +case $1 in + Jan) month=January; nummonth=1;; + Feb) month=February; nummonth=2;; + Mar) month=March; nummonth=3;; + Apr) month=April; nummonth=4;; + May) month=May; nummonth=5;; + Jun) month=June; nummonth=6;; + Jul) month=July; nummonth=7;; + Aug) month=August; nummonth=8;; + Sep) month=September; nummonth=9;; + Oct) month=October; nummonth=10;; + Nov) month=November; nummonth=11;; + Dec) month=December; nummonth=12;; +esac + day=$2 # Here we have to deal with the problem that the ls output gives either @@ -90,3 +159,12 @@ esac # The result. echo $day $month $year + +# Local Variables: +# mode: shell-script +# sh-indentation: 2 +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-end: "$" +# End: