bug-gnulib
[Top][All Lists]
Advanced

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

Re: gnulib-tool nits


From: Bruno Haible
Subject: Re: gnulib-tool nits
Date: Sun, 1 Jul 2007 15:05:39 +0200
User-agent: KMail/1.5.4

Ralf Wildenhues wrote:
> 2007-07-01  Bruno Haible <address@hidden>
>           Eric Blake  <address@hidden>
>           Ralf Wildenhues  <address@hidden>
> 
>       * gnulib-tool (self_abspathname): Fix algorithm to cope with
>       empty components in $PATH, denoting '.'.

Thanks. I untabified the tabs that you entered, added comments and added
handling of those Windows shells for which the PATH separator is ';' rather
than ':'.

2007-07-01  Bruno Haible <address@hidden>

        * gnulib-tool (self_abspathname): Determine PATH_SEPARATOR and handle
        Windows PATH as well. Conservative double-quoting. Comments.

*** gnulib-tool 1 Jul 2007 12:17:22 -0000       1.244
--- gnulib-tool 1 Jul 2007 12:57:31 -0000
***************
*** 887,910 ****
    /*) self_abspathname="$0" ;;
    */*) self_abspathname=`pwd`/"$0" ;;
    *)
      self_abspathname=
!     pathx=$PATH
!     case :$PATH: in
!       *::*)
!         pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 
's/:\$//'`
!         ;;
!     esac
!     save_IFS=$IFS
!     IFS=:
      for d in $pathx; do
!       IFS=$save_IFS
        test -z "$d" && d=.
        if test -x "$d/$0" && test ! -d "$d/$0"; then
!         self_abspathname=$d/$0
          break
        fi
      done
!     IFS=$save_IFS
      if test -z "$self_abspathname"; then
        func_fatal_error "could not locate the gnulib-tool program - how did 
you invoke it?"
      fi
--- 887,943 ----
    /*) self_abspathname="$0" ;;
    */*) self_abspathname=`pwd`/"$0" ;;
    *)
+     # Look in $PATH.
+     # Iterate through the elements of $PATH.
+     # We use IFS=: instead of
+     #   for d in `echo ":$PATH:" | sed -e 's/:::*/:.:/g' | sed -e 's/:/ /g'`
+     # because the latter does not work when some PATH element contains spaces.
+     # We use a canonicalized $pathx instead of $PATH, because empty PATH
+     # elements are by definition equivalent to '.', however field splitting
+     # according to IFS=: loses empty fields in many shells:
+     #   - /bin/sh on OSF/1 and Solaris loses all empty fields (at the
+     #     beginning, at the end, and in the middle),
+     #   - /bin/sh on IRIX and /bin/ksh on IRIX and OSF/1 lose empty fields
+     #     at the beginning and at the end,
+     #   - GNU bash, /bin/sh on AIX and HP-UX, and /bin/ksh on AIX, HP-UX,
+     #     Solaris lose empty fields at the end.
+     # The 'case' statement is an optimization, to avoid evaluating the
+     # explicit canonicalization command when $PATH contains no empty fields.
      self_abspathname=
!     if test "${PATH_SEPARATOR+set}" != set; then
!       func_tmpdir
!       { echo "#! /bin/sh"; echo "exit 0"; } > "$tmp"/conf.sh
!       chmod +x "$tmp"/conf.sh
!       if (PATH="/nonexistent;$tmp"; conf.sh) >/dev/null 2>&1; then
!         PATH_SEPARATOR=';'
!       else
!         PATH_SEPARATOR=:
!       fi
!       rm -rf "$tmp"
!     fi
!     if test "$PATH_SEPARATOR" = ";"; then
!       # On Windows, programs are searched in "." before $PATH.
!       pathx=".;$PATH"
!     else
!       # On Unix, we have to convert empty PATH elements to ".".
!       pathx="$PATH"
!       case :$PATH: in
!         *::*)
!           pathx=`echo ":$PATH:" | sed -e 's/:::*/:.:/g' -e 's/^://' -e 
's/:\$//'`
!           ;;
!       esac
!     fi
!     save_IFS="$IFS"
!     IFS="$PATH_SEPARATOR"
      for d in $pathx; do
!       IFS="$save_IFS"
        test -z "$d" && d=.
        if test -x "$d/$0" && test ! -d "$d/$0"; then
!         self_abspathname="$d/$0"
          break
        fi
      done
!     IFS="$save_IFS"
      if test -z "$self_abspathname"; then
        func_fatal_error "could not locate the gnulib-tool program - how did 
you invoke it?"
      fi





reply via email to

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