* lib/mdate-sh: Find out which column of the ls -l output contains
authorAlexandre Duret-Lutz <adl@gnu.org>
Tue, 4 Mar 2003 21:26:06 +0000 (21:26 +0000)
committerAlexandre Duret-Lutz <adl@gnu.org>
Tue, 4 Mar 2003 21:26:06 +0000 (21:26 +0000)
the month. Do not assume it is at least the fifth column.

ChangeLog
lib/mdate-sh

index 4f22d29..6eb69cb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2003-03-04  Andreas Buening  <andreas.buening@nexgo.de>
+
+       * lib/mdate-sh: Find out which column of the ls -l output contains
+       the month. Do not assume it is at least the fifth column.
+
 2003-02-26  Alexandre Duret-Lutz  <adl@gnu.org>
 
        * automake.texi (Emacs Lisp): Mention that `dist_' can be used.
index c079aed..b610b47 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Get modification time of a file or directory and pretty-print it.
-# Copyright 1995, 1996, 1997 Free Software Foundation, Inc.
+# Copyright (C) 1995, 1996, 1997, 2003  Free Software Foundation, Inc.
 # written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, June 1995
 #
 # This program is free software; you can redistribute it and/or modify
@@ -30,24 +30,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_command /`
+
+# 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;;
@@ -64,6 +78,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