1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
6 ;;;; Purpose: File and directory functions for LML
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Aug 2002
10 ;;;; This file, part of LML2, is Copyright (c) 2000-2003 by Kevin Rosenberg.
11 ;;;; Rights of modification and redistribution are in the LICENSE file.
13 ;;;; *************************************************************************
17 (eval-when (:compile-toplevel :load-toplevel :execute)
18 (defvar *output-dir* nil)
19 (defvar *sources-dir* nil)
22 (defmacro lml-file-name (file &optional (type :source))
24 (when (and (consp f) (eql (car f) 'cl:quote))
27 (setq f (string-downcase (symbol-name f))))
29 (unless (position #\. f)
30 (setq f (concatenate 'string f ".html"))))
32 (make-pathname :defaults (ecase type
33 (:source *sources-dir*)
34 (:output *output-dir*))
35 :name `,(pathname-name f)
36 :type `,(pathname-type f))
41 (defmacro with-dir ((output &key sources) &body body)
42 (let ((output-dir (gensym))
43 (sources-dir (gensym)))
44 `(let ((,output-dir ,output)
45 (,sources-dir ,sources))
46 (when (stringp ,output-dir)
47 (setq ,output-dir (parse-namestring ,output-dir)))
48 (when (stringp ,sources-dir)
49 (setq ,sources-dir (parse-namestring ,sources-dir)))
51 (setq ,sources-dir ,output-dir))
52 (let ((*output-dir* ,output-dir)
53 (*sources-dir* ,sources-dir))
56 (defun lml-load-path (file)
58 (with-open-file (in file :direction :input)
59 (do ((form (read in nil 'eof) (read in nil 'eof)))
62 (format *trace-output* "Warning: unable to load LML file ~S" file)))
64 (defun process-dir (dir &key sources)
65 (with-dir (dir :sources sources)
66 (let ((lml-files (directory
67 (make-pathname :defaults *sources-dir*
70 (dolist (file lml-files)
71 (format *trace-output* "~&; Processing ~A~%" file)
72 (lml-load-path file)))))
74 (defun lml-load (file)
75 (lml-load-path (eval `(lml-file-name ,file :source))))
77 (defun include-file (file)
78 (print-file-contents file *html-stream*))