;;; common -*- scheme -*-

;; Copyright (C) 2003, 2009, 2011, 2013 Thien-Thi Nguyen
;;
;; This program 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 of
;; the License, or (at your option) any later version.
;;
;; This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

(use-modules ((guile-baux common) #:select (fs fso fse)))

(define (env-1? x)
  (string=? "1" (or (getenv x) "")))

(define *have-ttf*    (env-1? "HAVE_TTF"))
(define *have-mixer*  (env-1? "HAVE_MIXER"))
(define *interactive* (env-1? "INTERACTIVE"))

(define (exit-77 msg)
  (fso "INFO: ~A: ~A~%"
       (basename (car (command-line)))
       (string-upcase msg))
  (exit 77))

(define datafile
  (let ((srcdir (or (getenv "srcdir") ".")))
    (lambda (name)
      (in-vicinity srcdir name))))

(define (half n)
  (ash n -1))

(define verbose? (env-1? "VERBOSE"))

(define info (if verbose?
                 (lambda (s . args)
                   (apply fso s args)
                   (newline))
                 (lambda ignored #t)))

(and (env-1? "DEBUG")
     (debug-enable 'debug 'backtrace))

(define (hex n)
  (number->string n 16))

;;; common ends here
