From e3876f16eb237bdeb9f79aca2e7db5e9e2d86686 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Wed, 16 Nov 2016 12:02:03 +0100 Subject: gpgscm: Improve library functions. * tests/gpgscm/tests.scm (absolute-path?): New function. (canonical-path): Use the new function. * tests/gpgscm/lib.scm (string-split-pln): New function. (string-indexp, string-splitp): Likewise. (string-splitn): Express using the above function. (string-ltrim, string-rtrim): Fix corner case. (list->string-reversed): New function. (read-line): Fix performance. Signed-off-by: Justus Winter --- tests/gpgscm/tests.scm | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'tests/gpgscm/tests.scm') diff --git a/tests/gpgscm/tests.scm b/tests/gpgscm/tests.scm index bec19223d..d360272fd 100644 --- a/tests/gpgscm/tests.scm +++ b/tests/gpgscm/tests.scm @@ -186,16 +186,19 @@ (assert (string=? (path-join "foo" "bar" "baz") "foo/bar/baz")) (assert (string=? (path-join "" "bar" "baz") "bar/baz")) +;; Is PATH an absolute path? +(define (absolute-path? path) + (or (char=? #\/ (string-ref path 0)) + (and *win32* (char=? #\\ (string-ref path 0))) + (and *win32* + (char-alphabetic? (string-ref path 0)) + (char=? #\: (string-ref path 1)) + (or (char=? #\/ (string-ref path 2)) + (char=? #\\ (string-ref path 2)))))) + +;; Make PATH absolute. (define (canonical-path path) - (if (or (char=? #\/ (string-ref path 0)) - (and *win32* (char=? #\\ (string-ref path 0))) - (and *win32* - (char-alphabetic? (string-ref path 0)) - (char=? #\: (string-ref path 1)) - (or (char=? #\/ (string-ref path 2)) - (char=? #\\ (string-ref path 2))))) - path - (path-join (getcwd) path))) + (if (absolute-path? path) path (path-join (getcwd) path))) (define (in-srcdir . names) (canonical-path (apply path-join (cons (getenv "srcdir") names)))) -- cgit v1.2.3