X-Git-Url: http://git.kpe.io/?p=lml2.git;a=blobdiff_plain;f=files.lisp;h=068347c9f83ecd7d38ca14f7eec213fe5b735077;hp=9045cb4fc5a87728f124b0149680bae8c3899309;hb=90a1a084ef0d15eccc7c433d1a3787c9408b3f82;hpb=a5621a5bf235313916f437a55d9998418ee26f5a diff --git a/files.lisp b/files.lisp index 9045cb4..068347c 100644 --- a/files.lisp +++ b/files.lisp @@ -2,16 +2,14 @@ ;;;; ************************************************************************* ;;;; FILE IDENTIFICATION ;;;; -;;;; Name: files.cl +;;;; Name: files.lisp ;;;; Purpose: File and directory functions for LML ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Aug 2002 ;;;; -;;;; This file, part of LML2, is Copyright (c) 2002 by Kevin M. Rosenberg +;;;; This file, part of LML2, is Copyright (c) 2000-2003 by Kevin Rosenberg. +;;;; Rights of modification and redistribution are in the LICENSE file. ;;;; -;;;; LML2 users are granted the rights to distribute and use this software -;;;; as governed by the terms of the GNU General Public License v2 -;;;; (http://www.gnu.org/licenses/gpl.html) ;;;; ************************************************************************* (in-package #:lml2) @@ -21,30 +19,32 @@ (defvar *sources-dir* nil) ) -(defmacro lml-file-name (file &optional (type :source)) - (let ((f file)) - (when (and (consp f) (eql (car f) 'cl:quote)) - (setq f (cadr f))) - (when (symbolp f) - (setq f (string-downcase (symbol-name f)))) - (when (stringp f) - (unless (position #\. f) - (setq f (concatenate 'string f ".html")))) - (if *sources-dir* - (make-pathname :defaults (ecase type - (:source *sources-dir*) - (:output *output-dir*)) - :name `,(pathname-name f) - :type `,(pathname-type f)) +(defun lml-file-name (f &optional (type :source)) + (when (and (consp f) (eql (car f) 'cl:quote)) + (setq f (cadr f))) + (when (symbolp f) + (setq f (string-downcase (symbol-name f)))) + (when (stringp f) + (unless (position #\. f) + (setq f (concatenate 'string f ".html")))) + (if (or (and (eq type :source) *sources-dir*) + (and (eq type :output) *output-dir*)) + (merge-pathnames + (make-pathname :name (pathname-name f) + :type (pathname-type f) + :directory (pathname-directory f)) + (ecase type + (:source *sources-dir*) + (:output *output-dir*))) (if (stringp f) - (parse-namestring f) - f)))) + (parse-namestring f) + f))) (defmacro with-dir ((output &key sources) &body body) (let ((output-dir (gensym)) - (sources-dir (gensym))) + (sources-dir (gensym))) `(let ((,output-dir ,output) - (,sources-dir ,sources)) + (,sources-dir ,sources)) (when (stringp ,output-dir) (setq ,output-dir (parse-namestring ,output-dir))) (when (stringp ,sources-dir) @@ -52,29 +52,30 @@ (unless ,sources-dir (setq ,sources-dir ,output-dir)) (let ((*output-dir* ,output-dir) - (*sources-dir* ,sources-dir)) + (*sources-dir* ,sources-dir)) ,@body)))) -(defun lml-load-path (file) +(defun lml-load-path (file &key optional) (if (probe-file file) (with-open-file (in file :direction :input) (do ((form (read in nil 'eof) (read in nil 'eof))) - ((eq form 'eof)) - (eval form))) - (format *trace-output* "Warning: unable to load LML file ~S" file))) + ((eq form 'eof)) + (eval form))) + (unless optional + (format *trace-output* "Warning: unable to load LML file ~S" file)))) (defun process-dir (dir &key sources) (with-dir (dir :sources sources) (let ((lml-files (directory - (make-pathname :defaults *sources-dir* - :name :wild - :type "lml")))) + (make-pathname :defaults *sources-dir* + :name :wild + :type "lml")))) (dolist (file lml-files) - (format *trace-output* "~&; Processing ~A~%" file) - (lml-load-path file))))) + (format *trace-output* "~&; Processing ~A~%" file) + (lml-load-path file))))) -(defun lml-load (file) - (lml-load-path (eval `(lml-file-name ,file :source)))) +(defun lml-load (file &key optional) + (lml-load-path (eval `(lml-file-name ,file :source)) :optional optional)) -(defun include-file (file) +(defun insert-file (file) (print-file-contents file *html-stream*))