1 ;; -*- mode: common-lisp; package: lml2 -*-
3 ;; $Id: htmlgen.lisp,v 1.14 2003/07/15 16:52:23 kevin Exp $
5 ;; copyright (c) 1986-2000 Franz Inc, Berkeley, CA
6 ;; copyright (c) 2003 Kevin Rosenberg
8 ;; Main changes from Allegro version:
9 ;; - Support XHTML end tags
10 ;; - lowercase symbol names for attributes
11 ;; - Add custom tags such as :jscript, :insert-file, :load-file, :nbsp
12 ;; - removal of if* macro -- partially complete
14 ;; This code is free software; you can redistribute it and/or
15 ;; modify it under the terms of the version 2.1 of
16 ;; the GNU Lesser General Public License as published by
17 ;; the Free Software Foundation, as clarified by the LLGPL
23 (defstruct (html-process (:type list) (:constructor
24 make-html-process (key has-inverse
29 key ; keyword naming this tag
30 has-inverse ; t if the / form is used
31 macro ; the macro to define this
32 special ; if true then call this to process the keyword and return
34 print ; function used to handle this in html-print
35 name-attr ; attribute symbols which can name this object for subst purposes
39 (defparameter *html-process-table*
40 (make-hash-table :test #'equal) ; #'eq is accurate but want to avoid rehashes
43 (defmacro html (&rest forms &environment env)
44 ;; just emit html to the current stream
45 (process-html-forms forms env))
47 (defmacro html-out-stream-check (stream)
48 ;; ensure that a real stream is passed to this function
52 (error "html-stream must be passed a stream object, not ~s" ,s))
56 (defmacro html-stream (stream &rest forms)
57 ;; set output stream and emit html
58 `(let ((*html-stream* (html-out-stream-check ,stream))) (html ,@forms)))
61 (defun process-html-forms (forms env)
63 (flet ((do-ent (ent args argsp body)
64 ;; ent is an html-process object associated with the
65 ;; html tag we're processing
66 ;; args is the list of values after the tag in the form
67 ;; ((:tag &rest args) ....)
68 ;; argsp is true if this isn't a singleton tag (i.e. it has
69 ;; a body) .. (:tag ...) or ((:tag ...) ...)
70 ;; body is the body if any of the form
73 (if* (setq spec (html-process-special ent))
74 then ; do something different
75 (push (funcall spec ent args argsp body) res)
77 then ; singleton tag, just do the set
78 (push `(,(html-process-macro ent) :set) res)
80 else (if* (equal args '(:unset))
81 then ; ((:tag :unset)) is a special case.
82 ; that allows us to close off singleton tags
84 (push `(,(html-process-macro ent) :unset) res)
87 (push `(,(html-process-macro ent)
89 ,(process-html-forms body env))
95 (do* ((xforms forms (cdr xforms))
96 (form (car xforms) (car xforms)))
99 (setq form (macroexpand form env))
102 then (if* (keywordp form)
103 then (let ((ent (gethash form *html-process-table*)))
105 (error "unknown html keyword ~s" form)
106 (do-ent ent nil nil nil)))
107 elseif (stringp form)
108 then ; turn into a print of it
109 (push `(write-string ,form *html-stream*) res)
110 else (push form res))
111 else (let ((first (car form)))
112 (if* (keywordp first)
113 then ; (:xxx . body) form
114 (let ((ent (gethash first
115 *html-process-table*)))
117 (error "unknown html keyword ~s" form)
118 (do-ent ent nil t (cdr form))))
119 elseif (and (consp first) (keywordp (car first)))
120 then ; ((:xxx args ) . body)
121 (let ((ent (gethash (car first)
122 *html-process-table*)))
124 (error "unknown html keyword ~s" form)
125 (do-ent ent (cdr first) t (cdr form))))
126 else (push form res))))))
127 `(progn ,@(nreverse res))))
130 (defun html-atom-check (args open close body)
131 (when (and args (atom args))
132 (let ((ans (case args
133 (:set `(write-string ,open *html-stream*))
134 (:unset `(write-string ,close *html-stream*))
135 (t (error "illegal arg ~s to ~s" args open)))))
137 (error "can't have a body form with this arg: ~s" args)
140 (defun html-body-form (open close body)
141 ;; used when args don't matter
142 `(progn (write-string ,open *html-stream*)
144 (write-string ,close *html-stream*)))
147 (defun process-attributes (args)
148 (do* ((xx args (cddr xx))
150 (name (first xx) (first xx))
151 (value (second xx) (second xx)))
157 then (write-string ,(format nil " ~(~a~)" (third xx))
159 (prin1-safe-http-string ,(fourth xx)))
163 (unless (and (listp value)
164 (>= (length value) 2))
165 (error ":fformat must be given a list at least 2 elements"))
167 ,(format nil " ~(~a~)=\"" (first value))
170 `(fformat *html-stream* ,(second value) ,@(cddr value)) res)
171 (push `(write-char #\" *html-stream*) res))
173 (unless (and (listp value) (>= (length value) 2))
174 (error ":format must be given a list at least 2 elements"))
175 (push `(write-string ,(format nil " ~(~a~)" (first value))
177 (push `(prin1-safe-http-string
178 (fformat nil ,(second value) ,@(cddr value)))
181 (push `(when ,(second value)
183 ,(format nil " ~(~a~)" (first value))
185 (prin1-safe-http-string ,(second value)))
188 (unless (and (listp value)
189 (>= (length value) 3)
190 (<= (length value) 4))
191 (error ":if must be given a list with 3 and 4 elements"))
192 (let ((eval-if (gensym "EVAL-IF-")))
193 (push `(let ((,eval-if ,(second value)))
194 (write-string ,(format nil " ~(~a~)" (first value)) *html-stream*)
195 (prin1-safe-http-string
201 (push `(write-string ,(format nil " ~(~a~)" name) *html-stream*)
203 (push `(prin1-safe-http-string ,value) res)))))
205 (defun html-body-key-form (string-code has-inv args body)
206 ;; do what's needed to handle given keywords in the args
208 (when (and args (atom args))
210 (return-from html-body-key-form
213 `(write-string ,(format nil "<~a>" string-code)
215 `(write-string ,(format nil "<~a />" string-code)
217 (:unset (when has-inv
218 `(write-string ,(format nil "</~a>" string-code)
220 (t (error "illegal arg ~s to ~s" args string-code)))))
222 (unless (evenp (length args))
223 (warn "arg list ~s isn't even" args))
227 `(progn (write-string ,(format nil "<~a" string-code)
229 ,@(process-attributes args)
231 ,(unless has-inv `(write-string " /" *html-stream*))
232 (write-string ">" *html-stream*)
234 ,(when (and body has-inv)
235 `(write-string ,(format nil "</~a>" string-code)
238 `(progn (write-string ,(format nil "<~a>" string-code)
242 `(write-string ,(format nil "</~a>" string-code)
244 `(progn (write-string ,(format nil "<~a />" string-code)
249 (defun princ-http (val)
250 ;; print the given value to the http stream using ~a
251 (format *html-stream* "~a" val))
253 (defun prin1-http (val)
254 ;; print the given value to the http stream using ~s
255 (format *html-stream* "~s" val))
258 (defun princ-safe-http (val)
259 (emit-safe *html-stream* (format nil "~a" val)))
261 (defun prin1-safe-http (val)
262 (emit-safe *html-stream* (format nil "~s" val)))
265 (defun prin1-safe-http-string (val)
266 ;; used only in a parameter value situation
268 ;; if the parameter value is the symbol with the empty print name
269 ;; then turn this into a singleton object. Thus || is differnent
272 ;; print the contents inside a string double quotes (which should
273 ;; not be turned into "'s
274 ;; symbols are turned into their name
275 (unless (and (symbolp val)
276 (equal "" (symbol-name val)))
277 (write-char #\= *html-stream*)
278 (if (or (stringp val)
280 (setq val (string-downcase
281 (symbol-name val)))))
283 (write-char #\" *html-stream*)
284 (emit-safe *html-stream* val)
285 (write-char #\" *html-stream*))
286 (prin1-safe-http val))))
289 (defun emit-safe (stream string)
290 ;; send the string to the http response stream watching out for
291 ;; special html characters and encoding them appropriately
294 (end (length string)))
297 (write-sequence string stream :start start :end i)))
299 (let ((ch (schar string i))
302 then (setq cvt "<")
304 then (setq cvt ">")
306 then (setq cvt "&")
308 then (setq cvt """))
310 ;; must do a conversion, emit previous chars first
313 (write-sequence string stream :start start :end i))
314 (write-string cvt stream)
316 (setq start (1+ i))))))
320 (defun html-print-list (list-of-forms stream &key unknown)
321 ;; html print a list of forms
322 (dolist (x list-of-forms)
323 (html-print-subst x nil stream unknown)))
326 (defun html-print-list-subst (list-of-forms subst stream &key unknown)
327 ;; html print a list of forms
328 (dolist (x list-of-forms)
329 (html-print-subst x subst stream unknown)))
332 (defun html-print (form stream &key unknown)
333 (html-print-subst form nil stream unknown))
336 (defun html-print-subst (form subst stream unknown)
337 ;; Print the given lhtml form to the given stream
338 (assert (streamp stream))
344 (possible-kwd (if* (atom form)
346 elseif (consp (car form))
347 then (setq attrs (cdar form))
352 (if* (keywordp possible-kwd)
353 then (if* (null (setq ent (gethash possible-kwd *html-process-table*)))
355 (return-from html-print-subst
356 (funcall unknown form stream))
357 (error "unknown html tag: ~s" possible-kwd))
358 else ; see if we should subst
361 (setq attr-name (html-process-name-attr ent))
362 (setq name (getf attrs attr-name))
363 (setq attrs (html-find-value name subst)))
365 (return-from html-print-subst
366 (if* (functionp (cdr attrs))
368 (funcall (cdr attrs) stream)
369 else (html-print-subst
376 (html-process-print ent)))
378 then (if* (keywordp form)
379 then (funcall print-handler ent :set nil nil nil nil stream)
380 elseif (stringp form)
381 then (write-string form stream)
382 else (princ form stream))
384 then (funcall print-handler
387 (when (consp (car form)) (cdr (car form)))
392 else (error "Illegal form: ~s" form))))
395 (defun html-find-value (key subst)
396 ; find the (key . value) object in the subst list.
397 ; A subst list is an assoc list ((key . value) ....)
398 ; but instead of a (key . value) cons you may have an assoc list
400 (let ((to-process nil)
403 (do* ((entlist alist (cdr entlist))
404 (ent (car entlist) (car entlist)))
405 ((null entlist) (setq alist nil))
406 (if* (consp (car ent))
407 then ; this is another alist
409 (push (cdr entlist) to-process))
412 elseif (equal key (car ent))
413 then (return-from html-find-value ent)))
416 then ; we need to find a new alist to process
419 (setq alist (pop to-process))
422 (defun html-standard-print (ent cmd args form subst unknown stream)
423 ;; the print handler for the normal html operators
425 (:set ; just turn it on
426 (format stream "<~a>" (html-process-key ent)))
427 (:full ; set, do body and then unset
430 then (if* (and (setq iter (getf args :iter))
431 (setq iter (html-find-value iter subst)))
432 then ; remove the iter and pre
433 (setq args (copy-list args))
436 (cons (cons (caar form)
441 (return-from html-standard-print)
443 (format stream "<~a" (html-process-key ent))
444 (do ((xx args (cddr xx)))
446 ; assume that the arg is already escaped
449 (format stream " ~a=\"~a\"" (car xx) (cadr xx)))
451 else (format stream "<~a>" (html-process-key ent)))
452 (dolist (ff (cdr form))
453 (html-print-subst ff subst stream unknown)))
454 (when (html-process-has-inverse ent)
456 (format stream "</~a>" (html-process-key ent))))))
465 ;; -- defining how html tags are handled. --
467 ;; most tags are handled in a standard way and the def-std-html
468 ;; macro is used to define such tags
470 ;; Some tags need special treatment and def-special-html defines
471 ;; how these are handled. The tags requiring special treatment
472 ;; are the pseudo tags we added to control operations
473 ;; in the html generator.
476 ;; tags can be found in three ways:
477 ;; :br - singleton, no attributes, no body
478 ;; (:b "foo") - no attributes but with a body
479 ;; ((:a href="foo") "balh") - attributes and body
484 (defmacro def-special-html (kwd fcn print-fcn)
485 ;; kwd - the tag we're defining behavior for.
486 ;; fcn - function to compute the macroexpansion of a use of this
487 ;; tag. args to fcn are:
488 ;; ent - html-process object holding info on this tag
489 ;; args - list of attribute-values following tag
490 ;; argsp - true if there is a body in this use of the tag
491 ;; body - list of body forms.
492 ;; print-fcn - function to print an lhtml form with this tag
494 ;; ent - html-process object holding info on this tag
495 ;; cmd - one of :set, :unset, :full
496 ;; args - list of attribute-value pairs
497 ;; subst - subsitution list
498 ;; unknown - function to call for unknown tags
499 ;; stream - stream to write to
501 `(setf (gethash ,kwd *html-process-table*)
502 (make-html-process ,kwd nil nil ,fcn ,print-fcn nil)))
505 (defmacro named-function (name &body body)
506 (declare (ignore name))
510 (def-special-html :newline
511 (named-function html-newline-function
512 (lambda (ent args argsp body)
513 (declare (ignore ent args argsp))
515 (error "can't have a body with :newline -- body is ~s" body))
516 `(terpri *html-stream*)))
518 (named-function html-newline-print-function
519 (lambda (ent cmd args form subst unknown stream)
520 (declare (ignore args ent unknown subst))
523 (error ":newline in an illegal place: ~s" form)))))
525 (def-special-html :princ
526 (named-function html-princ-function
527 (lambda (ent args argsp body)
528 (declare (ignore ent args argsp))
529 `(progn ,@(mapcar #'(lambda (bod)
533 (named-function html-princ-print-function
534 (lambda (ent cmd args form subst unknown stream)
535 (declare (ignore args ent unknown subst))
536 (assert (eql 2 (length form)))
538 (format stream "~a" (cadr form))
539 (error ":princ must be given an argument")))))
541 (def-special-html :princ-safe
542 (named-function html-princ-safe-function
543 (lambda (ent args argsp body)
544 (declare (ignore ent args argsp))
545 `(progn ,@(mapcar #'(lambda (bod)
546 `(princ-safe-http ,bod))
548 (named-function html-princ-safe-print-function
549 (lambda (ent cmd args form subst unknown stream)
550 (declare (ignore args ent unknown subst))
551 (assert (eql 2 (length form)))
553 (emit-safe stream (format nil "~a" (cadr form)))
554 (error ":princ-safe must be given an argument")))))
556 (def-special-html :prin1
557 (named-function html-prin1-function
558 (lambda (ent args argsp body)
559 (declare (ignore ent args argsp))
560 `(progn ,@(mapcar #'(lambda (bod)
563 (named-function html-prin1-print-function
564 (lambda (ent cmd args form subst unknown stream)
565 (declare (ignore ent args unknown subst))
566 (assert (eql 2 (length form)))
568 (format stream "~s" (cadr form))
569 (error ":prin1 must be given an argument")))))
571 (def-special-html :prin1-safe
572 (named-function html-prin1-safe-function
573 (lambda (ent args argsp body)
574 (declare (ignore ent args argsp))
575 `(progn ,@(mapcar #'(lambda (bod)
576 `(prin1-safe-http ,bod))
578 (named-function html-prin1-safe-print-function
579 (lambda (ent cmd args form subst unknown stream)
580 (declare (ignore args ent subst unknown))
581 (assert (eql 2 (length form)))
583 (emit-safe stream (format nil "~s" (cadr form)))
584 (error ":prin1-safe must be given an argument")))))
586 (def-special-html :comment
587 (named-function html-comment-function
588 (lambda (ent args argsp body)
589 ;; must use <!-- --> syntax
590 (declare (ignore ent args argsp))
591 `(progn (write-string "<!--" *html-stream*)
593 (write-string "-->" *html-stream*))))
594 (named-function html-comment-print-function
595 (lambda (ent cmd args form subst unknown stream)
596 (declare (ignore ent cmd args subst unknown))
597 (format stream "<!--~a-->" (cadr form)))))
601 (defmacro def-std-html (kwd has-inverse name-attrs)
602 (let ((mac-name (intern (format nil "~a-~a" :with-html kwd)))
603 (string-code (string-downcase (string kwd))))
604 `(progn (setf (gethash ,kwd *html-process-table*)
605 (make-html-process ,kwd ,has-inverse
608 #'html-standard-print
610 (defmacro ,mac-name (args &rest body)
611 (html-body-key-form ,string-code ,has-inverse args body)))))
615 (def-std-html :a t nil)
616 (def-std-html :abbr t nil)
617 (def-std-html :acronym t nil)
618 (def-std-html :address t nil)
619 (def-std-html :applet t nil)
620 (def-std-html :area nil nil)
622 (def-std-html :b t nil)
623 (def-std-html :base nil nil)
624 (def-std-html :basefont nil nil)
625 (def-std-html :bdo t nil)
626 (def-std-html :bgsound nil nil)
627 (def-std-html :big t nil)
628 (def-std-html :blink t nil)
629 (def-std-html :blockquote t nil)
630 (def-std-html :body t nil)
631 (def-std-html :br nil nil)
632 (def-std-html :button nil nil)
634 (def-std-html :caption t nil)
635 (def-std-html :center t nil)
636 (def-std-html :cite t nil)
637 (def-std-html :code t nil)
638 (def-std-html :col nil nil)
639 (def-std-html :colgroup nil nil)
641 (def-std-html :dd t nil)
642 (def-std-html :del t nil)
643 (def-std-html :dfn t nil)
644 (def-std-html :dir t nil)
645 (def-std-html :div t nil)
646 (def-std-html :dl t nil)
647 (def-std-html :dt t nil)
649 (def-std-html :em t nil)
650 (def-std-html :embed t nil)
652 (def-std-html :fieldset t nil)
653 (def-std-html :font t nil)
654 (def-std-html :form t :name)
655 (def-std-html :frame t nil)
656 (def-std-html :frameset t nil)
658 (def-std-html :h1 t nil)
659 (def-std-html :h2 t nil)
660 (def-std-html :h3 t nil)
661 (def-std-html :h4 t nil)
662 (def-std-html :h5 t nil)
663 (def-std-html :h6 t nil)
664 (def-std-html :head t nil)
665 (def-std-html :hr nil nil)
666 (def-std-html :html t nil)
668 (def-std-html :i t nil)
669 (def-std-html :iframe t nil)
670 (def-std-html :ilayer t nil)
671 (def-std-html :img nil :id)
672 (def-std-html :input nil nil)
673 (def-std-html :ins t nil)
674 (def-std-html :isindex nil nil)
676 (def-std-html :kbd t nil)
677 (def-std-html :keygen nil nil)
679 (def-std-html :label t nil)
680 (def-std-html :layer t nil)
681 (def-std-html :legend t nil)
682 (def-std-html :li t nil)
683 (def-std-html :link nil nil)
684 (def-std-html :listing t nil)
686 (def-std-html :map t nil)
687 (def-std-html :marquee t nil)
688 (def-std-html :menu t nil)
689 (def-std-html :meta nil nil)
690 (def-std-html :multicol t nil)
692 (def-std-html :nobr t nil)
693 (def-std-html :noembed t nil)
694 (def-std-html :noframes t nil)
695 (def-std-html :noscript t nil)
697 (def-std-html :object t nil)
698 (def-std-html :ol t nil)
699 (def-std-html :optgroup t nil)
700 (def-std-html :option t nil)
702 (def-std-html :p t nil)
703 (def-std-html :param t nil)
704 (def-std-html :plaintext nil nil)
705 (def-std-html :pre t nil)
707 (def-std-html :q t nil)
709 (def-std-html :s t nil)
710 (def-std-html :samp t nil)
711 (def-std-html :script t nil)
712 (def-std-html :select t nil)
713 (def-std-html :server t nil)
714 (def-std-html :small t nil)
715 (def-std-html :spacer nil nil)
716 (def-std-html :span t :id)
717 (def-std-html :strike t nil)
718 (def-std-html :strong t nil)
719 (def-std-html :style t nil)
720 (def-std-html :sub t nil)
721 (def-std-html :sup t nil)
723 (def-std-html :table t :name)
724 (def-std-html :tbody t nil)
725 (def-std-html :td t nil)
726 (def-std-html :textarea t nil)
727 (def-std-html :tfoot t nil)
728 (def-std-html :th t nil)
729 (def-std-html :thead t nil)
730 (def-std-html :title t nil)
731 (def-std-html :tr t nil)
732 (def-std-html :tt t nil)
734 (def-std-html :u t nil)
735 (def-std-html :ul t nil)
737 (def-std-html :var t nil)
739 (def-std-html :wbr nil nil)
741 (def-std-html :xmp t nil)
746 ;;; KMR Local Additions
748 (def-special-html :jscript
749 (named-function html-comment-function
750 (lambda (ent args argsp body)
751 ;; must use <!-- --> syntax
752 (declare (ignore ent args argsp))
754 (write-string "<script language=\"JavaScript\" type=\"text/javascript\">" *html-stream*)
755 (write-char #\newline *html-stream*)
756 (write-string "//![CDATA[" *html-stream*)
757 (write-char #\newline *html-stream*)
759 (write-char #\newline *html-stream*)
760 (write-string "//]]>" *html-stream*)
761 (write-char #\newline *html-stream*)
762 (write-string "</script>" *html-stream*))))
763 (named-function html-comment-print-function
764 (lambda (ent cmd args form subst unknown stream)
765 (declare (ignore ent cmd args subst unknown))
766 (format stream "<script language=\"JavaScript\" type=\"text/javascript\">~%//![CDATA[~%~A~%//]]>~%</script>"
769 (def-special-html :nbsp
770 (named-function html-nbsp-function
771 (lambda (ent args argsp body)
772 (declare (ignore ent args argsp))
774 (error "can't have a body with :nbsp -- body is ~s" body))
775 `(write-string " " *html-stream*)))
777 (named-function html-nbsp-print-function
778 (lambda (ent cmd args form subst unknown stream)
779 (declare (ignore args ent unknown subst))
781 (write-string " " stream)
782 (error ":nbsp in an illegal place: ~s" form)))))
785 (def-special-html :load-file
786 (named-function html-nbsp-function
787 (lambda (ent args argsp body)
788 (declare (ignore ent args argsp))
790 (error "must have a body with :load-file"))
791 `(progn ,@(mapcar #'(lambda (bod)
795 (named-function html-nbsp-print-function
796 (lambda (ent cmd args form subst unknown stream)
797 (declare (ignore ent unknown subst stream args))
798 (assert (eql 2 (length form)))
800 (lml-load (cadr form))
801 (error ":load-file must be given an argument")))))
803 (def-special-html :insert-file
804 (named-function html-nbsp-function
805 (lambda (ent args argsp body)
806 (declare (ignore ent args argsp))
808 (error "must have a body with :insert-file"))
809 `(progn ,@(mapcar #'(lambda (bod)
813 (named-function html-nbsp-print-function
814 (lambda (ent cmd args form subst unknown stream)
815 (declare (ignore ent unknown subst stream args))
816 (assert (eql 2 (length form)))
818 (insert-file (cadr form))
819 (error ":insert-file must be given an argument")))))
821 (def-special-html :write-string
822 (named-function html-write-string-function
823 (lambda (ent args argsp body)
824 (declare (ignore ent args argsp))
825 `(progn ,@(mapcar #'(lambda (bod)
826 `(write-string ,bod *html-stream*))
829 (named-function html-write-string-print-function
830 (lambda (ent cmd args form subst unknown stream)
831 (declare (ignore args ent unknown subst))
832 (assert (eql 2 (length form)))
834 (write-string (cadr form) stream)
835 (error ":write-string must be given an argument")))))
837 (def-special-html :write-char
838 (named-function html-write-char-function
839 (lambda (ent args argsp body)
840 (declare (ignore ent args argsp))
841 `(progn ,@(mapcar #'(lambda (bod)
842 `(write-char ,bod *html-stream*))
845 (named-function html-write-char-print-function
846 (lambda (ent cmd args form subst unknown stream)
847 (declare (ignore args ent unknown subst))
848 (assert (eql 2 (length form)))
850 (write-char (cadr form) stream)
851 (error ":write-char must be given an argument")))))
854 (def-special-html :fformat
855 (named-function html-write-char-function
856 (lambda (ent args argsp body)
857 (declare (ignore ent args argsp))
858 `(progn ,@(mapcar #'(lambda (bod)
860 (format *html-stream* " ~(~A~)=\"" (car ,bod))
861 (apply #'format *html-stream* (cdr ,bod))
862 (write-char #\" *html-stream*)))
865 (named-function html-write-char-print-function
866 (lambda (ent cmd args form subst unknown stream)
867 (declare (ignore args ent unknown subst))
868 (assert (eql 2 (length form)))
871 (format stream " ~(~A~)=\"" (car form))
872 (apply #'format stream (cdr form))
873 (write-char #\" stream))
874 (error ":fformat must be given an argument")))))