From a387e5177100130ee62326bcdff1858b7c575a94 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Thu, 2 May 2002 16:30:38 +0000 Subject: [PATCH] Major bug fix (gotta fix that Jam lexer!) Some coding convention fixes [SVN r13612] --- new/os.path.jam | 54 ++++++++++++++++++++++++++++++++----------------- v2/os.path.jam | 54 ++++++++++++++++++++++++++++++++----------------- 2 files changed, 72 insertions(+), 36 deletions(-) diff --git a/new/os.path.jam b/new/os.path.jam index 8ecbca725..f6a5ce15b 100644 --- a/new/os.path.jam +++ b/new/os.path.jam @@ -93,14 +93,17 @@ rule parent ( path ) } # -# Returns path2 such that "[ join path path 2 ] = .". +# Returns path2 such that "[ join path path2 ] = .". # The path may not contain ".." element or be rooted. # rule reverse ( path ) { - if $(path) = . { + if $(path) = . + { return $(path) ; - } else { + } + else + { local tokens = [ regex.split $(path) "/" ] ; local tokens2 ; for local i in $(tokens) { @@ -115,27 +118,37 @@ rule reverse ( path ) # rule join ( path1 path2 ) { - if $(path1) = . { + if $(path1) = . + { return $(path2) ; - } else if $(path1) = / { + } + else if $(path1) = / + { return /$(path2) ; - } else { - + } + else + { local parts = [ regex.match "((\.\./)*)(.*)" : $(path2) : 1 3 ] ; - if $(parts[1]) { - + if $(parts[1]) + { local up_tokens = [ regex.split $(parts[1]) "/" ] ; - for local i in $(up_tokens[1--2]) { + for local i in $(up_tokens[1--2]) + { path1 = [ parent $(path1) ] ; } } - if $(path1) = . { + if $(path1) = . + { return $(parts[2]) ; - } else if $(path1) = / { + } + else if $(path1) = / + { return /$(parts[2]) ; - } else { + } + else + { return $(path1)/$(parts[2]) ; } } @@ -200,13 +213,17 @@ rule make-NT ( native ) { local tokens = [ regex.split $(native) "[/\\]" ] ; local result ; + # Handle paths ending with slashes - if $(tokens[-1) { - result = [ sequence.join $(tokens) : "/" ] ; - } else { - result = [ sequence.join $(tokens[--2]) : "/" ] ; + if $(tokens[-1]) = "" + { + tokens = $(tokens[1--2]) ; # discard the empty element } - if [ regex.match "(^.:)" : $(native) ] { + + result = [ sequence.join $(tokens) : "/" ] ; + + if [ regex.match "(^.:)" : $(native) ] + { result = /$(result) ; } return $(result) ; @@ -283,6 +300,7 @@ rule __test__ ( ) { assert.result "foo/bar/giz" : make "foo/bar/giz" ; assert.result "foo/bar/giz" : make "foo\\bar\\giz" ; assert.result "/D:/My Documents" : make "D:\\My Documents" ; + assert.result "/c:/boost/tools/build/test/../new/project.jam" : make "c:\\boost\\tools\\build\\test\\..\\new\\project.jam" ; assert.result "foo\\bar\\giz" : native "foo/bar/giz" ; assert.result "foo" : native "foo" ; diff --git a/v2/os.path.jam b/v2/os.path.jam index 8ecbca725..f6a5ce15b 100644 --- a/v2/os.path.jam +++ b/v2/os.path.jam @@ -93,14 +93,17 @@ rule parent ( path ) } # -# Returns path2 such that "[ join path path 2 ] = .". +# Returns path2 such that "[ join path path2 ] = .". # The path may not contain ".." element or be rooted. # rule reverse ( path ) { - if $(path) = . { + if $(path) = . + { return $(path) ; - } else { + } + else + { local tokens = [ regex.split $(path) "/" ] ; local tokens2 ; for local i in $(tokens) { @@ -115,27 +118,37 @@ rule reverse ( path ) # rule join ( path1 path2 ) { - if $(path1) = . { + if $(path1) = . + { return $(path2) ; - } else if $(path1) = / { + } + else if $(path1) = / + { return /$(path2) ; - } else { - + } + else + { local parts = [ regex.match "((\.\./)*)(.*)" : $(path2) : 1 3 ] ; - if $(parts[1]) { - + if $(parts[1]) + { local up_tokens = [ regex.split $(parts[1]) "/" ] ; - for local i in $(up_tokens[1--2]) { + for local i in $(up_tokens[1--2]) + { path1 = [ parent $(path1) ] ; } } - if $(path1) = . { + if $(path1) = . + { return $(parts[2]) ; - } else if $(path1) = / { + } + else if $(path1) = / + { return /$(parts[2]) ; - } else { + } + else + { return $(path1)/$(parts[2]) ; } } @@ -200,13 +213,17 @@ rule make-NT ( native ) { local tokens = [ regex.split $(native) "[/\\]" ] ; local result ; + # Handle paths ending with slashes - if $(tokens[-1) { - result = [ sequence.join $(tokens) : "/" ] ; - } else { - result = [ sequence.join $(tokens[--2]) : "/" ] ; + if $(tokens[-1]) = "" + { + tokens = $(tokens[1--2]) ; # discard the empty element } - if [ regex.match "(^.:)" : $(native) ] { + + result = [ sequence.join $(tokens) : "/" ] ; + + if [ regex.match "(^.:)" : $(native) ] + { result = /$(result) ; } return $(result) ; @@ -283,6 +300,7 @@ rule __test__ ( ) { assert.result "foo/bar/giz" : make "foo/bar/giz" ; assert.result "foo/bar/giz" : make "foo\\bar\\giz" ; assert.result "/D:/My Documents" : make "D:\\My Documents" ; + assert.result "/c:/boost/tools/build/test/../new/project.jam" : make "c:\\boost\\tools\\build\\test\\..\\new\\project.jam" ; assert.result "foo\\bar\\giz" : native "foo/bar/giz" ; assert.result "foo" : native "foo" ;