From 91b267562d94064d00c709fcdcef29f225a80c5b Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Tue, 4 Dec 2018 19:28:54 +1100 Subject: * lib/utils.exp (relative_filename): New proc. * runtest.exp: Use it. * doc/dejagnu.texi (relative_filename procedure): Document it. * testsuite/runtest.all/utils.test: Add tests for relative_filename. Signed-off-by: Ben Elliston --- runtest.exp | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) (limited to 'runtest.exp') diff --git a/runtest.exp b/runtest.exp index b0ddfed..327131a 100644 --- a/runtest.exp +++ b/runtest.exp @@ -1771,15 +1771,8 @@ foreach current_target $target_list { # set subdir to the tail of the dirname after $srcdir, # for the driver files that want it. XXX this is silly. # drivers should get a single var, not "$srcdir/$subdir" - set subdir [file dirname $test_name] - set p [expr {[string length $srcdir] - 1}] - while {0 < $p && [string index $srcdir $p] == "/"} { - incr p -1 - } - if {[string range $subdir 0 $p] == $srcdir} { - set subdir [string range $subdir [expr {$p + 1}] end] - regsub "^/" $subdir "" subdir - } + set subdir [relative_filename $srcdir \ + [file dirname $test_name]] # XXX not the right thing to do. set runtests [list [file tail $test_name] ""] @@ -1860,20 +1853,8 @@ foreach current_target $target_list { # Get the path after the $srcdir so we know # the subdir we're in. - set subdir [file dirname $test_name] - # We used to do - # regsub $srcdir [file dirname $test_name] "" subdir - # but what if [file dirname $test_name] contains regexp - # characters? We lose. Instead... - set first [string first $srcdir $subdir] - if { $first >= 0 } { - set first [expr {$first + [string length $srcdir]}] - set subdir [string range $subdir $first end] - regsub "^/" "$subdir" "" subdir - } - if { "$srcdir" == "$subdir" || "$srcdir" == "$subdir/" } { - set subdir "" - } + set subdir [relative_filename $srcdir \ + [file dirname $test_name]] # Check to see if the range of tests is limited, # set `runtests' to a list of two elements: the script name # and any arguments ("" if none). -- cgit v1.1