Back to the Main Page. | normpath |
Download the M4 Source. |
adl_NORMALIZE_PATH(VARNAME, [REFERENCE_STRING])
1.1 (2001/07/26) 0.5.65 : Miscellaneous
Alexandre Duret-Lutz <duret_g@epita.fr>
(which might indicate a networked disk on some OS).
filename='A:\FOO\\BAR\'
old_filename="$filename"
# Switch to the unix notation
adl_NORMALIZE_PATH([filename], ["/"])
# now we have $filename = 'A:/FOO/BAR' and we can process it as if
# it was a Unix path. For instance let's say that you want
# to append '/subpath':
filename="$filename/subpath"
# finally switch back to the original notation
adl_NORMALIZE_PATH([filename], ["$old_filename"])
# now $filename equals to 'A:\FOO\BAR\subpath'
expr 'A:\FOO' : 'A:\Foo'
expr 'A:\Foo' : 'A:\\Foo'
firstdir='/usr/local//share'
seconddir='C:\Program Files\\'
thirddir='C:\home/usr/'
adl_NORMALIZE_PATH([firstdir])
adl_NORMALIZE_PATH([seconddir])
adl_NORMALIZE_PATH([thirddir])
# $firstdir = '/usr/local/share'
# $seconddir = 'C:\Program Files'
# $thirddir = 'C:\home\usr'
AC_DEFUN([adl_NORMALIZE_PATH], [case ":[$]$1:" in # change empty paths to '.' ::) $1='.' ;; # strip trailing slashes :*[[\\/]]:) $1=`echo "[$]$1" | sed 's,[[\\/]]*[$],,'` ;; :*:) ;; esac # squeze repeated slashes case ifelse($2,,"[$]$1",$2) in # if the path contains any backslashes, turn slashes into backslashes *\\*) $1=`echo "[$]$1" | sed 's,\(.\)[[\\/]][[\\/]]*,\1\\\\,g'` ;; # if the path contains slashes, also turn backslashes into slashes *) $1=`echo "[$]$1" | sed 's,\(.\)[[\\/]][[\\/]]*,\1/,g'` ;; esac])