automake-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mdate-sh


From: Alexandre Duret-Lutz
Subject: Re: mdate-sh
Date: Tue, 04 Mar 2003 22:22:45 +0100
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i386-pc-linux-gnu)

>>> "adl" == Alexandre Duret-Lutz <address@hidden> writes:

 Andreas> * lib/mdate-sh: Find out which column of the ls -l output contains
 Andreas> the month. Do not assume it is at least the fifth column.

 adl> Thanks a lot.  Would you be willing to assign the copyright of
 adl> this change (and the previous one: lib/am/depend2.am, m4/init.m4)
 adl> to the Free Software Foundation, so that we could install it in 
 adl> Automake?  I'll send you the form.

Hi Andreas,

The FSF clerk just filed your assignement.

I'm installing your patch on HEAD and branch-1-7 as follows.
(I've just added a comment sketching what's going on.)

Thank you.

2003-03-04  Andreas Buening  <address@hidden>

        * 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.

Index: lib/mdate-sh
===================================================================
RCS file: /cvs/automake/automake/lib/mdate-sh,v
retrieving revision 1.10
diff -u -r1.10 mdate-sh
--- lib/mdate-sh        17 Jul 2001 06:00:37 -0000      1.10
+++ lib/mdate-sh        4 Mar 2003 21:18:19 -0000
@@ -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 <address@hidden>, June 1995
 #
 # This program is free software; you can redistribute it and/or modify
@@ -30,24 +30,38 @@
 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;;
@@ -63,6 +77,28 @@
     Dec) month=December; nummonth=12;;
   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
 

-- 
Alexandre Duret-Lutz





reply via email to

[Prev in Thread] Current Thread [Next in Thread]