summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--doc/user/bib.skb20
-rw-r--r--src/guile/skribilo/biblio.scm103
-rw-r--r--src/guile/skribilo/package/base.scm8
-rw-r--r--src/guile/skribilo/utils/compat.scm13
4 files changed, 67 insertions, 77 deletions
diff --git a/doc/user/bib.skb b/doc/user/bib.skb
index 5b26417..e7b5b77 100644
--- a/doc/user/bib.skb
+++ b/doc/user/bib.skb
@@ -52,32 +52,36 @@ tables.])
    
    (p [The predicate ,(code "bib-table?") returns ,(code "#t") if and only
 if its argument is a bibliography table as returned by 
-,(markup-ref "make-bib-table") or ,(markup-ref "default-bib-table"). Otherwise
+,(markup-ref "make-bib-table") or ,(markup-ref "*bib-table*"). Otherwise
 ,(code "bib-table?") returns ,(code "#f").])
    
    (doc-markup 'bib-table?
 	       '((obj [The value to be tested]))
-	       :see-also '(make-bib-table default-bib-table bibliography the-bibliography)
+	       :see-also '(make-bib-table *bib-table* bibliography the-bibliography)
 	       :force-engines *api-engines*
 	       :common-args '()
 	       :source #f ;;"skribilo/biblio.scm"
                :def '(define-markup (bib-table? obj) ...))
    
-   (p [The function ,(code "default-bib-table") returns a global, pre-existing
+   (p [The function ,(code "*bib-table*") returns a global, pre-existing
 bibliography-table:])
-   (doc-markup 'default-bib-table
+   (doc-markup '*bib-table*
 	       '()
 	       :see-also '(bib-table? make-bib-table bibliography the-bibliography)
 	       :force-engines *api-engines*
 	       :common-args '()
                :source #f
-               :def '(define-markup (default-bib-table) ...))
+               :def '(define-markup (*bib-table*) ...))
+   (p [Technically, ,(code "*bib-table*") is actually an ,(ref :text
+[SRFI-39] :url "http://srfi.schemers.org/srfi-39/srfi-39.html")
+parameter object, so it can be queried and modified like any other
+parameter object.])
    
    (p [The function ,(code "make-bib-table") constructs a new 
 bibliography-table:])
    (doc-markup 'make-bib-table
 	       '((ident [The name of the bibliography table.]))
-	       :see-also '(bib-table? default-bib-table bibliography the-bibliography)
+	       :see-also '(bib-table? *bib-table* bibliography the-bibliography)
 	       :force-engines *api-engines*
 	       :common-args '()
 	       :source #f
@@ -109,7 +113,7 @@ the ,(code "bibliography") Skribe function call before the call to the
               :text "bibliograph path")). Otherwise, it is a list described
               by the ,(ref :subsection "Bibliography syntax" :text "syntax") 
               below.]))
-	    :see-also '(bib-table? make-bib-table default-bib-table the-bibliography)
+	    :see-also '(bib-table? make-bib-table *bib-table* the-bibliography)
 	    :force-engines *api-engines*
 	    :common-args '())
 
@@ -161,7 +165,7 @@ Here is an example of a simple Skribe database.])
                filtered in by ,(param :pred). The value ,(code "full")
                tells Skribe to count all entries, event those filtered out
                by ,(param :pred).]))
-	    :see-also '(bib-table? make-bib-table default-bib-table bibliography)
+	    :see-also '(bib-table? make-bib-table *bib-table* bibliography)
 	    :force-engines *api-engines*
 	    :common-args '())
 
diff --git a/src/guile/skribilo/biblio.scm b/src/guile/skribilo/biblio.scm
index 1fb4b78..55f2ea9 100644
--- a/src/guile/skribilo/biblio.scm
+++ b/src/guile/skribilo/biblio.scm
@@ -1,5 +1,6 @@
 ;;; biblio.scm  --  Bibliography functions.
 ;;;
+;;; Copyright 2001, 2002, 2003, 2004  Manuel Serrano
 ;;; Copyright 2003, 2004  Erick Gallesio - I3S-CNRS/ESSI <eg@essi.fr>
 ;;; Copyright 2005, 2006  Ludovic Courtès <ludovic.courtes@laas.fr>
 ;;;
@@ -24,9 +25,10 @@
   :use-module (skribilo utils strings)
   :use-module (skribilo utils syntax) ;; `when', `unless'
 
+  :use-module (srfi srfi-1)
   :autoload   (srfi srfi-34)         (raise)
   :use-module (srfi srfi-35)
-  :use-module (srfi srfi-1)
+  :use-module (srfi srfi-39)
   :autoload   (skribilo condition)   (&file-search-error)
 
   :autoload   (skribilo reader)      (%default-reader)
@@ -36,9 +38,9 @@
   :use-module (ice-9 optargs)
   :use-module (oop goops)
 
-  :export (bib-table? make-bib-table default-bib-table
+  :export (bib-table? make-bib-table *bib-table*
 	   bib-add! bib-duplicate bib-for-each bib-map
-	   skribe-open-bib-file parse-bib
+	   open-bib-file parse-bib
 
            bib-load! resolve-bib resolve-the-bib make-bib-entry
 
@@ -52,27 +54,15 @@
 ;;; Provides the bibliography data type and basic bibliography handling,
 ;;; including simple procedures to sort bibliography entries.
 ;;;
-;;; FIXME: This module need cleanup!
-;;;
 ;;; Code:
 
 (fluid-set! current-reader %skribilo-module-reader)
 
-
-;; FIXME: Should be a fluid?
-(define *bib-table*	     #f)
-
-;; Forward declarations
-(define skribe-open-bib-file #f)
-(define parse-bib	     #f)
-
 
 
-;;; ======================================================================
 ;;;
-;;;				Utilities
+;;; Accessors.
 ;;;
-;;; ======================================================================
 
 (define (make-bib-table ident)
    (make-hash-table))
@@ -80,10 +70,9 @@
 (define (bib-table? obj)
   (hash-table? obj))
 
-(define (default-bib-table)
-  (unless *bib-table*
-    (set! *bib-table* (make-bib-table "default-bib-table")))
-  *bib-table*)
+;; The current bib table.
+(define *bib-table*
+  (make-parameter (make-bib-table "default-bib-table")))
 
 (define (%bib-error who entry)
   (let ((msg "bibliography syntax error on entry"))
@@ -91,22 +80,34 @@
 	(skribe-line-error (%epair-file entry) (%epair-line entry) who msg entry)
 	(skribe-error who msg entry))))
 
-(define* (bib-for-each proc :optional (table (default-bib-table)))
+(define (bib-add! table . entries)
+  (if (not (bib-table? table))
+      (skribe-error 'bib-add! "Illegal bibliography table" table)
+      (for-each (lambda (entry)
+		  (cond
+		    ((and (list? entry) (> (length entry) 2))
+		     (let* ((kind   (car entry))
+			    (key    (format #f "~A" (cadr entry)))
+			    (fields (cddr entry))
+			    (old    (hash-ref table key)))
+		       (if old
+			   (bib-duplicate key #f old)
+			   (hash-set! table key
+				      (make-bib-entry kind key fields #f)))))
+		    (else
+		     (%bib-error 'bib-add! entry))))
+		entries)))
+
+(define* (bib-for-each proc :optional (table (*bib-table*)))
   (hash-for-each (lambda (ident entry)
 		   (proc ident entry))
 		 table))
 
-(define* (bib-map proc :optional (table (default-bib-table)))
+(define* (bib-map proc :optional (table (*bib-table*)))
   (hash-map->list (lambda (ident entry)
 		    (proc ident entry))
 		  table))
 
-
-;;; ======================================================================
-;;;
-;;;				BIB-DUPLICATE
-;;;
-;;; ======================================================================
 (define (bib-duplicate ident from old)
   (let ((ofrom (markup-option old 'from)))
     (skribe-warning 2
@@ -120,11 +121,11 @@
 			" ignoring redefinition."))))
 
 
-;;; ======================================================================
+
 ;;;
-;;;				PARSE-BIB
+;;; Parsing.
 ;;;
-;;; ======================================================================
+
 (define (parse-bib table port)
   (let ((read %default-reader)) ;; FIXME: We should use a fluid
     (if (not (bib-table? table))
@@ -146,43 +147,15 @@
 	       (else
 		(%bib-error 'bib-parse entry)))))))))
 
-
-;;; ======================================================================
-;;;
-;;;				   BIB-ADD!
-;;;
-;;; ======================================================================
-(define (bib-add! table . entries)
-  (if (not (bib-table? table))
-      (skribe-error 'bib-add! "Illegal bibliography table" table)
-      (for-each (lambda (entry)
-		  (cond
-		    ((and (list? entry) (> (length entry) 2))
-		     (let* ((kind   (car entry))
-			    (key    (format #f "~A" (cadr entry)))
-			    (fields (cddr entry))
-			    (old    (hash-ref table key)))
-		       (if old
-			   (bib-duplicate key #f old)
-			   (hash-set! table key
-				      (make-bib-entry kind key fields #f)))))
-		    (else
-		     (%bib-error 'bib-add! entry))))
-		entries)))
-
-
-;;; ======================================================================
-;;;
-;;;				SKRIBE-OPEN-BIB-FILE
-;;;
-;;; ======================================================================
-;; FIXME: Factoriser
-(define (skribe-open-bib-file file command)
+(define* (open-bib-file file :optional (command #f))
  (let ((path (search-path (*bib-path*) file)))
    (if (string? path)
        (begin
 	 (when (> (*verbose*) 0)
-	   (format (current-error-port) "  [loading bibliography: ~S]\n" path))
+	   (format (current-error-port)
+                   "  [loading bibliography: ~S]\n" path))
+         ;; FIXME: The following `open-input-file' won't work with actual
+         ;; commands.  We need to use `(ice-9 popen)'.
 	 (open-input-file (if (string? command)
 			      (string-append "| "
 					     (format #f command path))
@@ -209,7 +182,7 @@
    (if (not (bib-table? table))
        (skribe-error 'bib-load "Illegal bibliography table" table)
        ;; read the file
-       (let ((p (skribe-open-bib-file filename command)))
+       (let ((p (open-bib-file filename command)))
 	  (if (not (input-port? p))
 	      (skribe-error 'bib-load "Can't open data base" filename)
 	      (unwind-protect
diff --git a/src/guile/skribilo/package/base.scm b/src/guile/skribilo/package/base.scm
index 4c9e84c..01e8667 100644
--- a/src/guile/skribilo/package/base.scm
+++ b/src/guile/skribilo/package/base.scm
@@ -33,7 +33,7 @@
   :autoload   (skribilo engine)    (engine?)
 
   ;; optional ``sub-packages''
-  :autoload   (skribilo biblio)    (default-bib-table resolve-bib
+  :autoload   (skribilo biblio)    (*bib-table* resolve-bib
                                     bib-load! bib-add!)
   :autoload   (skribilo color)     (skribe-use-color!)
   :autoload   (skribilo source)    (language? source-read-lines source-fontify)
@@ -1015,7 +1015,7 @@
 		    (subsection #f)
 		    (subsubsection #f)
 		    (bib #f)
-		    (bib-table (default-bib-table))
+		    (bib-table (*bib-table*))
 		    (url #f)
 		    (figure #f)
 		    (mark #f)
@@ -1245,7 +1245,7 @@
 ;*---------------------------------------------------------------------*/
 (define-markup (bibliography #!rest files
 			     #!key
-			     (command #f) (bib-table (default-bib-table)))
+			     (command #f) (bib-table (*bib-table*)))
    (for-each (lambda (f)
 		(cond
 		   ((string? f)
@@ -1267,7 +1267,7 @@
 (define-markup (the-bibliography #!rest opts
 				 #!key
 				 pred
-				 (bib-table (default-bib-table))
+				 (bib-table (*bib-table*))
 				 (sort bib-sort/authors)
 				 (count 'partial))
    (if (not (memq count '(partial full)))
diff --git a/src/guile/skribilo/utils/compat.scm b/src/guile/skribilo/utils/compat.scm
index 118f294..4905cef 100644
--- a/src/guile/skribilo/utils/compat.scm
+++ b/src/guile/skribilo/utils/compat.scm
@@ -35,6 +35,7 @@
   :autoload   (skribilo lib)       (type-name)
   :autoload   (skribilo resolve)   (*document-being-resolved*)
   :autoload   (skribilo output)    (*document-being-output*)
+  :autoload   (skribilo biblio)    (*bib-table* open-bib-file)
   :use-module (skribilo debug)
 
   :re-export (file-size)  ;; re-exported from `(skribilo utils files)'
@@ -209,6 +210,18 @@
 
 
 ;;;
+;;; Bibliography.
+;;;
+
+(define-public (default-bib-table)
+  (*bib-table*))
+
+(define-public (skribe-open-bib-file file command)
+  (open-bib-file file command))
+
+
+
+;;;
 ;;; Debugging facilities.
 ;;;