1
; libctl: flexible Guile-based control files for scientific software
2
; Copyright (C) 1998, 1999, 2000, 2001, 2002, Steven G. Johnson
4
; This library is free software; you can redistribute it and/or
5
; modify it under the terms of the GNU Lesser General Public
6
; License as published by the Free Software Foundation; either
7
; version 2 of the License, or (at your option) any later version.
9
; This library is distributed in the hope that it will be useful,
10
; but WITHOUT ANY WARRANTY; without even the implied warranty of
11
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
; Lesser General Public License for more details.
14
; You should have received a copy of the GNU Lesser General Public
15
; License along with this library; if not, write to the
16
; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
; Boston, MA 02111-1307, USA.
19
; Steven G. Johnson can be contacted at stevenj@alum.mit.edu.
21
; ****************************************************************
24
; Here, we supply an (include "<filename>") utility that is similar to
25
; C's #include "<filename>". We need this because Guile's load
26
; function is broken--it doesn't allow you to use relative paths. If
27
; you use (load "<filename>"), the filename is interpreted relative to
28
; the path of the top-level Guile invocation, which may not be the
29
; same as the path of the current Scheme file. Our include function
30
; remembers the path of the current file and loads relative to this.
32
(define (string-suffix? suff s)
33
(if (> (string-length suff) (string-length s))
35
(string=? suff (substring s (- (string-length s)
39
(define (string-find-previous-char s c)
40
(if (= (string-length s) 0)
42
(let ((last-index (- (string-length s) 1)))
43
(if (eq? (string-ref s last-index) c)
45
(string-find-previous-char (substring s 0 last-index) c)))))
47
(define (strip-trailing-slashes s)
48
(if (string-suffix? "/" s)
49
(strip-trailing-slashes (substring s 0 (- (string-length s) 1)))
52
(define (pathname-absolute? s)
53
(and (> (string-length s) 0) (eq? (string-ref s 0) #\/)))
55
(define (split-pathname s)
56
(let ((s2 (strip-trailing-slashes s)))
57
(let ((last-slash (string-find-previous-char s2 #\/)))
60
(cons (substring s2 0 (+ 1 last-slash))
61
(substring s2 (+ 1 last-slash) (string-length s2)))))))
63
(define include-dir "")
65
(define (include pathname)
66
(let ((save-include-dir include-dir)
67
(pathpair (split-pathname pathname)))
68
(if (pathname-absolute? (car pathpair))
70
(set! include-dir (car pathpair))
73
(set! include-dir (string-append include-dir (car pathpair)))
74
(load (string-append include-dir (cdr pathpair)))))
75
(set! include-dir save-include-dir)))
77
(define (fix-path pathname)
78
(if (pathname-absolute? pathname)
80
(string-append include-dir pathname)))
82
; ****************************************************************