;;; common --- some -*-scheme-*- useful for testing

;; Copyright (C) 2012, 2013, 2014 Thien-Thi Nguyen
;;
;; This file is part of Guile-WWW.
;;
;; Guile-WWW is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 3, or
;; (at your option) any later version.
;;
;; Guile-WWW is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Guile-WWW.  If not, see <https://www.gnu.org/licenses/>.

(define verbose? (equal? "1" (getenv "VERBOSE")))

(and verbose? (set! %load-verbosely #t))

(define vfso (if verbose?
                 (lambda (s . args)
                   (apply simple-format #t s args))
                 (lambda ignored
                   #f)))

(define (fse s . args)
  (apply simple-format (current-error-port) s args))

(define (srcdir/ filename)
  (in-vicinity (getenv "srcdir") filename))

;;;---------------------------------------------------------------------------
;;; A test xNNN keeps its extra data in directory xNNN.d.
;;; Protocol: Call ‘use-dot-d-files!’ first, then ‘dot-d/’ afterwards.

(define dot-d/ #f)

(define (use-dot-d-files!)
  (let ((d (string-append (basename (port-filename (current-load-port)))
                          ".d")))
    (set! dot-d/ (lambda (filename)
                   (srcdir/ (in-vicinity d filename))))))

;;; common ends here
