From 64ebefbe296c90dbeefba5074774dbe56f81e85a Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Wed, 26 Feb 2003 06:12:24 +0000 Subject: [PATCH] Add relative-to to calculate relative paths between dirs. [SVN r17653] --- new/path.jam | 24 ++++++++++++++++++++++++ v2/util/path.jam | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/new/path.jam b/new/path.jam index 6d29e2e84..48ac7563c 100644 --- a/new/path.jam +++ b/new/path.jam @@ -327,6 +327,30 @@ rule relative ( child parent ) } } +# Returns the minimal path to path2 that is relative path1. +# +rule relative-to ( path1 path2 ) +{ + local root_1 = [ regex.split [ reverse $(path1) ] / ] ; + local split1 = [ regex.split $(path1) / ] ; + local split2 = [ regex.split $(path2) / ] ; + + while $(split1) && $(root_1) + { + if $(split1[1]) = $(split2[1]) + { + root_1 = $(root_1[2-]) ; + split1 = $(split1[2-]) ; + split2 = $(split2[2-]) ; + } + else + { + split1 = ; + } + } + return [ join . $(root_1) $(split2) ] ; +} + rule make-NT ( native ) diff --git a/v2/util/path.jam b/v2/util/path.jam index 6d29e2e84..48ac7563c 100644 --- a/v2/util/path.jam +++ b/v2/util/path.jam @@ -327,6 +327,30 @@ rule relative ( child parent ) } } +# Returns the minimal path to path2 that is relative path1. +# +rule relative-to ( path1 path2 ) +{ + local root_1 = [ regex.split [ reverse $(path1) ] / ] ; + local split1 = [ regex.split $(path1) / ] ; + local split2 = [ regex.split $(path2) / ] ; + + while $(split1) && $(root_1) + { + if $(split1[1]) = $(split2[1]) + { + root_1 = $(root_1[2-]) ; + split1 = $(split1[2-]) ; + split2 = $(split2[2-]) ; + } + else + { + split1 = ; + } + } + return [ join . $(root_1) $(split2) ] ; +} + rule make-NT ( native )