X-Git-Url: http://git.kpe.io/?p=xmlutils.git;a=blobdiff_plain;f=pxml3.cl;h=bb835489f05ff5b0f55d64333d5cbdeb9d04ee19;hp=cad55572b5f98046e56569441e81aa378d409439;hb=2e566ae3baa533146fbdb77af653adfda5356b76;hpb=96edd80309cfaea1949768cd4b3a5f7e0dc203d5 diff --git a/pxml3.cl b/pxml3.cl index cad5557..bb83548 100644 --- a/pxml3.cl +++ b/pxml3.cl @@ -27,29 +27,29 @@ (defvar *debug-dtd* nil) (defun parse-dtd (tokenbuf - external external-callback) + external external-callback) (declare (optimize (speed 3) (safety 1))) (let ((guts) - (include-count 0)) + (include-count 0)) (loop (multiple-value-bind (val kind) - (next-dtd-token tokenbuf - external include-count external-callback) - (if* (eq kind :end-dtd) then - (return (nreverse guts)) - elseif (eq kind :include) then - (incf include-count) - elseif (eq kind :ignore) then nil - elseif (eq kind :include-end) then - (if* (> include-count 0) then (decf include-count) - else (xml-error "unexpected ']]>' token")) - else (when (iostruct-do-entity tokenbuf) (push val guts))))))) + (next-dtd-token tokenbuf + external include-count external-callback) + (if* (eq kind :end-dtd) then + (return (nreverse guts)) + elseif (eq kind :include) then + (incf include-count) + elseif (eq kind :ignore) then nil + elseif (eq kind :include-end) then + (if* (> include-count 0) then (decf include-count) + else (xml-error "unexpected ']]>' token")) + else (when (iostruct-do-entity tokenbuf) (push val guts))))))) (defparameter dtd-parser-states ()) (macrolet ((def-dtd-parser-state (var val) - `(progn (eval-when (compile load eval) (defconstant ,var ,val)) - (pushnew '(,val . ,var) dtd-parser-states :key #'car)))) + `(progn (eval-when (compile load eval) (defconstant ,var ,val)) + (pushnew '(,val . ,var) dtd-parser-states :key #'car)))) (def-dtd-parser-state state-dtdstart 0) (def-dtd-parser-state state-tokenstart 1) (def-dtd-parser-state state-dtd-? 2) @@ -146,2369 +146,2369 @@ ) (defun next-dtd-token (tokenbuf - external include-count external-callback) + external include-count external-callback) (declare #+allegro (:fbound parse-default-value) - #+lispworks (optimize (safety 0) (debug 3)) - #-lispworks (optimize (speed 3) (safety 1))) + #+lispworks (optimize (safety 0) (debug 3)) + #-lispworks (optimize (speed 3) (safety 1))) (macrolet ((add-to-entity-buf (entity-symbol p-value) - `(progn - (push (make-tokenbuf :cur 0 :max (length ,p-value) :data ,p-value) - (iostruct-entity-bufs tokenbuf)))) + `(progn + (push (make-tokenbuf :cur 0 :max (length ,p-value) :data ,p-value) + (iostruct-entity-bufs tokenbuf)))) - (un-next-char (ch) - `(push ,ch (iostruct-unget-char tokenbuf))) + (un-next-char (ch) + `(push ,ch (iostruct-unget-char tokenbuf))) - (clear-coll (coll) - `(setf (collector-next ,coll) 0)) + (clear-coll (coll) + `(setf (collector-next ,coll) 0)) - (add-to-coll (coll ch) - `(let ((.next. (collector-next ,coll))) - (if* (>= .next. (collector-max ,coll)) - then (grow-and-add ,coll ,ch) - else (setf (schar (collector-data ,coll) .next.) - ,ch) - (setf (collector-next ,coll) (1+ .next.))))) + (add-to-coll (coll ch) + `(let ((.next. (collector-next ,coll))) + (if* (>= .next. (collector-max ,coll)) + then (grow-and-add ,coll ,ch) + else (setf (schar (collector-data ,coll) .next.) + ,ch) + (setf (collector-next ,coll) (1+ .next.))))) - (to-preferred-case (ch) - ;; should check the case mode - `(char-downcase ,ch)) + (to-preferred-case (ch) + ;; should check the case mode + `(char-downcase ,ch)) - ) + ) (let ((state state-dtdstart) - (coll (get-collector)) - (entity (get-collector)) - (tag-to-return) - (contents-to-return) - (pending (list nil)) - (pending-type) - (value-delim) - (public-string) - (char-code 0) - (check-count 0) - (ignore-count 0) - (reference-save-state) - (prefp) - (entityp) - (pentityp) - (prev-state) - (ch)) + (coll (get-collector)) + (entity (get-collector)) + (tag-to-return) + (contents-to-return) + (pending (list nil)) + (pending-type) + (value-delim) + (public-string) + (char-code 0) + (check-count 0) + (ignore-count 0) + (reference-save-state) + (prefp) + (entityp) + (pentityp) + (prev-state) + (ch)) (loop - (setq ch (get-next-char tokenbuf)) - (when *debug-dtd* - (format t "~@~%" - ch (or (cdr (assoc state dtd-parser-states)) state) - contents-to-return pending pending-type - (iostruct-entity-names tokenbuf))) - (if* (null ch) - then (setf prev-state state) - (setf state :eof) - (return) ;; eof -- exit loop - ) + (setq ch (get-next-char tokenbuf)) + (when *debug-dtd* + (format t "~@~%" + ch (or (cdr (assoc state dtd-parser-states)) state) + contents-to-return pending pending-type + (iostruct-entity-names tokenbuf))) + (if* (null ch) + then (setf prev-state state) + (setf state :eof) + (return) ;; eof -- exit loop + ) - (case state - (#.state-dtdstart - (if* (and (eq #\] ch) - external (> include-count 0)) then - (setf state state-dtd-!-include3) - elseif (and (eq #\] ch) (not external)) then (return) - elseif (eq #\< ch) then (setf state state-tokenstart) - elseif (xml-space-p ch) then nil - elseif (eq #\% ch) then (external-param-reference tokenbuf coll external-callback) - else (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD characters, starting at: '" - (compute-coll-string coll) - "'")) - )) - (#.state-dtd-!-include3 - (if* (eq #\] ch) then (setf state state-dtd-!-include4) - else - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD token, starting at: ']" - (compute-coll-string coll) - "'")))) - (#.state-dtd-!-include4 - (if* (eq #\> ch) then (return) - else - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD token, starting at: ']]" - (compute-coll-string coll) - "'")))) - #+ignore - (#.state-dtd-pref - (if* (xml-name-start-char-p ch) then - (add-to-coll coll ch) - (setf state state-dtd-pref2) - else (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD parameter reference name, starting at: '" - (compute-coll-string coll) - "'")) - )) - (#.state-tokenstart - (if* (eq #\? ch) then (setf state state-dtd-?) - elseif (eq #\! ch) then (setf state state-dtd-!) - else (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD characters, starting at: '<" - (compute-coll-string coll) - "'")) - )) - (#.state-dtd-? - (if* (xml-name-char-p ch) - then - (add-to-coll coll ch) - elseif (and external (eq #\% ch)) then - (external-param-reference tokenbuf coll external-callback) - else - (when (not (xml-space-p ch)) - (xml-error (concatenate 'string - "expecting name following: ' ch) - then - (push (compute-coll-string coll) contents-to-return) - (clear-coll coll) - (return) - else (setf state state-dtd-?-3) - (add-to-coll coll #\?) - (add-to-coll coll ch))) - (#.state-dtd-! - (if* (eq #\- ch) then (setf state state-dtd-comment) - elseif (xml-name-start-char-p ch) then (setf state state-dtd-!-token) - (un-next-char ch) - elseif (and (eq #\[ ch) external) then - (setf state state-dtd-!-cond) - else (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD characters, starting at: ' ch) then (decf ignore-count) - (when (= ignore-count 0) (return)) - else (un-next-char ch) - (setf state state-dtd-!-ignore3))) - (#.state-dtd-!-include - (if* (and (eq check-count 6) (eq ch #\E)) then - (setf state state-dtd-!-include2) - elseif (eq ch (elt "INCLUD" check-count)) then - (incf check-count) - else (xml-error " ch) - then (push (compute-coll-string coll) contents-to-return) - (clear-coll coll) - (return) - else (clear-coll coll) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal token following '--' comment terminator, starting at '--" - (compute-coll-string coll) - "'")) - )) - (#.state-dtd-!-token - (if* (xml-name-char-p ch) then (add-to-coll coll ch) - elseif (and external (eq #\% ch)) then - (external-param-reference tokenbuf coll external-callback) - elseif (xml-space-p ch) then - (setf tag-to-return (compute-tag coll)) - (clear-coll coll) - (if* (eq tag-to-return :ELEMENT) then (setf state state-dtd-!-element) - elseif (eq tag-to-return :ATTLIST) then - (setf state state-dtd-!-attlist) - elseif (eq tag-to-return :ENTITY) then - (setf entityp t) - (setf state state-dtd-!-entity) - elseif (eq tag-to-return :NOTATION) then - (setf state state-dtd-!-notation) - else - (xml-error (concatenate 'string - "illegal DTD characters, starting at: ' ch)) then - (setf state state-!-dtd-system) - (return) - else - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error - (concatenate 'string - "Expected space before: '" - (compute-coll-string coll) "'")) - )) - (#.state-!-dtd-system - (if* (xml-space-p ch) then nil - elseif (and external (eq #\% ch)) then - (external-param-reference tokenbuf coll external-callback) - elseif (or (eq #\" ch) (eq #\' ch)) then - (setf state state-!-dtd-system2) - (setf value-delim ch) - elseif (and (not entityp) - (eq #\> ch)) then (return) - else (xml-error - (concatenate 'string - "expected quote or double-quote got: '" - (string ch) - "' in ch) then (return) - else - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD ch) then (return) - else (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD - elseif (eq #\> ch) then - (push (compute-tag coll) contents-to-return) - (clear-coll coll) - (return) - else (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD (length tmp) 0) - (when (null (first pending)) (setf pending (rest pending))) - (push tmp pending))) - (if* (> (length pending) 1) then - (push (nreverse pending) contents-to-return) - else (push (first pending) contents-to-return)) - (setf pending (list nil)) - (setf state state-dtd-!-entity5) - (clear-coll coll) - (if* pentityp then - (when (not (assoc (third contents-to-return) - (iostruct-parameter-entities tokenbuf))) - (setf (iostruct-parameter-entities tokenbuf) - (acons (third contents-to-return) - (first contents-to-return) - (iostruct-parameter-entities tokenbuf)))) - else - (when (not (assoc (second contents-to-return) - (iostruct-general-entities tokenbuf))) - (setf (iostruct-general-entities tokenbuf) - (acons (second contents-to-return) - (first contents-to-return) - (iostruct-general-entities tokenbuf))))) - elseif (eq #\& ch) then - (setf reference-save-state state-dtd-!-entity-value) - (setf state state-dtd-!-attdef-decl-value3) - elseif (eq #\% ch) then - (setf prefp t) - (setf reference-save-state state-dtd-!-entity-value) - (setf state state-dtd-!-attdef-decl-value3) - elseif (xml-char-p ch) - then (add-to-coll coll ch) - else (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD ch) then (return) - else (clear-coll coll) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD contents following ch) then - (push (compute-tag coll *package*) - contents-to-return) - (clear-coll coll) - (return) - else (push (compute-tag coll) - contents-to-return) - (clear-coll coll) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD ch) then (return) - else (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD )) then - (setf count 6) - else (setf last-ch cch)) - elseif (< count 6) then - (when (and (= count 5) - (xml-space-p cch)) - (setf cch #\space)) - (if* (not (eq cch - (schar string count) - )) then - (loop - (when (= tmp-count count) - (return)) - (add-to-coll coll - (schar string - tmp-count)) - (incf tmp-count)) - (add-to-coll coll cch) - (setf count 10) - else (incf count)) - elseif (= count 6) then - (dotimes (i 6) - (add-to-coll coll (schar string i))) - (setf count 10) - else (add-to-coll coll cch)))) - (setf (iostruct-entity-names tokenbuf) - (rest (iostruct-entity-names tokenbuf))) - (close entity-stream) - (put-back-tokenbuf tmp-buf))))) - ) - (setf state state-dtdstart) - else nil - ))) - (setf state reference-save-state) - else (let ((tmp (compute-coll-string entity))) - (clear-coll coll) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "reference not terminated by ';', starting at: '&" - tmp - (compute-coll-string coll) - "'"))) - )) - (#.state-dtd-!-attdef-decl-value6 - (let ((code (char-code ch))) - (if* (eq #\; ch) - then (add-to-coll coll (code-char char-code)) - (setf char-code 0) - (setq state state-dtd-!-attdef-decl-value) - elseif (<= (char-code #\0) code (char-code #\9)) - then (setf char-code (+ (* char-code 16) (- code (char-code #\0)))) - elseif (<= (char-code #\A) code (char-code #\F)) - then (setf char-code (+ 10 (* char-code 16) (- code (char-code #\A)))) - elseif (<= (char-code #\a) code (char-code #\f)) - then (setf char-code (+ 10 (* char-code 16) (- code (char-code #\a)))) - else (clear-coll coll) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal hexidecimal character reference code, starting at: '" - (compute-coll-string coll) - "', calculated char code: " - (format nil "~s" char-code))) - ))) - (#.state-dtd-!-attdef-decl-value7 - (let ((code (char-code ch))) - (if* (eq #\; ch) - then (add-to-coll coll (code-char char-code)) - (setf char-code 0) - (setq state reference-save-state) - elseif (<= (char-code #\0) code (char-code #\9)) - then (setf char-code (+ (* char-code 10) (- code (char-code #\0)))) - else (clear-coll coll) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal decimal character reference code, starting at: '" - (compute-coll-string coll) - "', calculated char code: " - (format nil "~s" char-code))) - ))) - (#.state-dtd-!-attdef-decl-type - (if* (xml-name-char-p ch) then (add-to-coll coll ch) - elseif (and external (eq #\% ch)) then - (external-param-reference tokenbuf coll external-callback) - elseif (or (xml-space-p ch) (eq #\> ch)) then - (let ((token (compute-tag coll))) - (when (and (not (eq :REQUIRED token)) - (not (eq :IMPLIED token)) - (not (eq :FIXED token))) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD ch) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD ch) then - (setf contents-to-return - (append contents-to-return (list (nreverse pending)))) - (return) - else (setf contents-to-return - (append contents-to-return (list (nreverse pending)))) - (setf pending (list nil)) - (setf state state-dtd-!-attdef))) - (clear-coll coll) - else (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD ch) then - ;; there only one name... - (setf (first contents-to-return) (first (first contents-to-return))) - (return) - elseif (eq #\* ch) then - (setf state state-dtd-!-element-type-paren-pcd5) - (setf (first contents-to-return) (nreverse (first contents-to-return))) - (if* (> (length (first contents-to-return)) 1) then - (setf (first contents-to-return) - (list (append (list :choice) - (first contents-to-return)))) - elseif (listp (first (first contents-to-return))) then - (setf (first contents-to-return) - (first (first contents-to-return)))) - (push :* (first contents-to-return)) - elseif (eq #\? ch) then - (setf state state-dtd-!-element-type-paren-pcd5) - (setf (first contents-to-return) (nreverse (first contents-to-return))) - (if* (> (length (first contents-to-return)) 1) then - (setf (first contents-to-return) - (list (append (list :choice) - (first contents-to-return)))) - elseif (listp (first (first contents-to-return))) then - (setf (first contents-to-return) - (first (first contents-to-return)))) - (push :? (first contents-to-return)) - elseif (eq #\+ ch) then - (setf state state-dtd-!-element-type-paren-pcd5) - (setf (first contents-to-return) (nreverse (first contents-to-return))) - (if* (> (length (first contents-to-return)) 1) then - (setf (first contents-to-return) - (list (append (list :choice) - (first contents-to-return)))) - elseif (listp (first (first contents-to-return))) then - (setf (first contents-to-return) - (first (first contents-to-return)))) - (push :+ (first contents-to-return)) - elseif (and external (eq #\% ch)) then - (external-param-reference tokenbuf coll external-callback) - elseif (xml-space-p ch) then - (setf state state-dtd-!-element-type-paren-pcd5) - (setf (first contents-to-return) (nreverse (first contents-to-return))) - (when (> (length (first contents-to-return)) 1) - (setf (first contents-to-return) - (list (append (list :\choice) - (first contents-to-return))))) - else (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD include-count 0)) then + (setf state state-dtd-!-include3) + elseif (and (eq #\] ch) (not external)) then (return) + elseif (eq #\< ch) then (setf state state-tokenstart) + elseif (xml-space-p ch) then nil + elseif (eq #\% ch) then (external-param-reference tokenbuf coll external-callback) + else (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD characters, starting at: '" + (compute-coll-string coll) + "'")) + )) + (#.state-dtd-!-include3 + (if* (eq #\] ch) then (setf state state-dtd-!-include4) + else + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD token, starting at: ']" + (compute-coll-string coll) + "'")))) + (#.state-dtd-!-include4 + (if* (eq #\> ch) then (return) + else + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD token, starting at: ']]" + (compute-coll-string coll) + "'")))) + #+ignore + (#.state-dtd-pref + (if* (xml-name-start-char-p ch) then + (add-to-coll coll ch) + (setf state state-dtd-pref2) + else (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD parameter reference name, starting at: '" + (compute-coll-string coll) + "'")) + )) + (#.state-tokenstart + (if* (eq #\? ch) then (setf state state-dtd-?) + elseif (eq #\! ch) then (setf state state-dtd-!) + else (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD characters, starting at: '<" + (compute-coll-string coll) + "'")) + )) + (#.state-dtd-? + (if* (xml-name-char-p ch) + then + (add-to-coll coll ch) + elseif (and external (eq #\% ch)) then + (external-param-reference tokenbuf coll external-callback) + else + (when (not (xml-space-p ch)) + (xml-error (concatenate 'string + "expecting name following: ' ch) + then + (push (compute-coll-string coll) contents-to-return) + (clear-coll coll) + (return) + else (setf state state-dtd-?-3) + (add-to-coll coll #\?) + (add-to-coll coll ch))) + (#.state-dtd-! + (if* (eq #\- ch) then (setf state state-dtd-comment) + elseif (xml-name-start-char-p ch) then (setf state state-dtd-!-token) + (un-next-char ch) + elseif (and (eq #\[ ch) external) then + (setf state state-dtd-!-cond) + else (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD characters, starting at: ' ch) then (decf ignore-count) + (when (= ignore-count 0) (return)) + else (un-next-char ch) + (setf state state-dtd-!-ignore3))) + (#.state-dtd-!-include + (if* (and (eq check-count 6) (eq ch #\E)) then + (setf state state-dtd-!-include2) + elseif (eq ch (elt "INCLUD" check-count)) then + (incf check-count) + else (xml-error " ch) + then (push (compute-coll-string coll) contents-to-return) + (clear-coll coll) + (return) + else (clear-coll coll) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal token following '--' comment terminator, starting at '--" + (compute-coll-string coll) + "'")) + )) + (#.state-dtd-!-token + (if* (xml-name-char-p ch) then (add-to-coll coll ch) + elseif (and external (eq #\% ch)) then + (external-param-reference tokenbuf coll external-callback) + elseif (xml-space-p ch) then + (setf tag-to-return (compute-tag coll)) + (clear-coll coll) + (if* (eq tag-to-return :ELEMENT) then (setf state state-dtd-!-element) + elseif (eq tag-to-return :ATTLIST) then + (setf state state-dtd-!-attlist) + elseif (eq tag-to-return :ENTITY) then + (setf entityp t) + (setf state state-dtd-!-entity) + elseif (eq tag-to-return :NOTATION) then + (setf state state-dtd-!-notation) + else + (xml-error (concatenate 'string + "illegal DTD characters, starting at: ' ch)) then + (setf state state-!-dtd-system) + (return) + else + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error + (concatenate 'string + "Expected space before: '" + (compute-coll-string coll) "'")) + )) + (#.state-!-dtd-system + (if* (xml-space-p ch) then nil + elseif (and external (eq #\% ch)) then + (external-param-reference tokenbuf coll external-callback) + elseif (or (eq #\" ch) (eq #\' ch)) then + (setf state state-!-dtd-system2) + (setf value-delim ch) + elseif (and (not entityp) + (eq #\> ch)) then (return) + else (xml-error + (concatenate 'string + "expected quote or double-quote got: '" + (string ch) + "' in ch) then (return) + else + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD ch) then (return) + else (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD + elseif (eq #\> ch) then + (push (compute-tag coll) contents-to-return) + (clear-coll coll) + (return) + else (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD (length tmp) 0) + (when (null (first pending)) (setf pending (rest pending))) + (push tmp pending))) + (if* (> (length pending) 1) then + (push (nreverse pending) contents-to-return) + else (push (first pending) contents-to-return)) + (setf pending (list nil)) + (setf state state-dtd-!-entity5) + (clear-coll coll) + (if* pentityp then + (when (not (assoc (third contents-to-return) + (iostruct-parameter-entities tokenbuf))) + (setf (iostruct-parameter-entities tokenbuf) + (acons (third contents-to-return) + (first contents-to-return) + (iostruct-parameter-entities tokenbuf)))) + else + (when (not (assoc (second contents-to-return) + (iostruct-general-entities tokenbuf))) + (setf (iostruct-general-entities tokenbuf) + (acons (second contents-to-return) + (first contents-to-return) + (iostruct-general-entities tokenbuf))))) + elseif (eq #\& ch) then + (setf reference-save-state state-dtd-!-entity-value) + (setf state state-dtd-!-attdef-decl-value3) + elseif (eq #\% ch) then + (setf prefp t) + (setf reference-save-state state-dtd-!-entity-value) + (setf state state-dtd-!-attdef-decl-value3) + elseif (xml-char-p ch) + then (add-to-coll coll ch) + else (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD ch) then (return) + else (clear-coll coll) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD contents following ch) then + (push (compute-tag coll *package*) + contents-to-return) + (clear-coll coll) + (return) + else (push (compute-tag coll) + contents-to-return) + (clear-coll coll) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD ch) then (return) + else (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD )) then + (setf count 6) + else (setf last-ch cch)) + elseif (< count 6) then + (when (and (= count 5) + (xml-space-p cch)) + (setf cch #\space)) + (if* (not (eq cch + (schar string count) + )) then + (loop + (when (= tmp-count count) + (return)) + (add-to-coll coll + (schar string + tmp-count)) + (incf tmp-count)) + (add-to-coll coll cch) + (setf count 10) + else (incf count)) + elseif (= count 6) then + (dotimes (i 6) + (add-to-coll coll (schar string i))) + (setf count 10) + else (add-to-coll coll cch)))) + (setf (iostruct-entity-names tokenbuf) + (rest (iostruct-entity-names tokenbuf))) + (close entity-stream) + (put-back-tokenbuf tmp-buf))))) + ) + (setf state state-dtdstart) + else nil + ))) + (setf state reference-save-state) + else (let ((tmp (compute-coll-string entity))) + (clear-coll coll) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "reference not terminated by ';', starting at: '&" + tmp + (compute-coll-string coll) + "'"))) + )) + (#.state-dtd-!-attdef-decl-value6 + (let ((code (char-code ch))) + (if* (eq #\; ch) + then (add-to-coll coll (code-char char-code)) + (setf char-code 0) + (setq state state-dtd-!-attdef-decl-value) + elseif (<= (char-code #\0) code (char-code #\9)) + then (setf char-code (+ (* char-code 16) (- code (char-code #\0)))) + elseif (<= (char-code #\A) code (char-code #\F)) + then (setf char-code (+ 10 (* char-code 16) (- code (char-code #\A)))) + elseif (<= (char-code #\a) code (char-code #\f)) + then (setf char-code (+ 10 (* char-code 16) (- code (char-code #\a)))) + else (clear-coll coll) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal hexidecimal character reference code, starting at: '" + (compute-coll-string coll) + "', calculated char code: " + (format nil "~s" char-code))) + ))) + (#.state-dtd-!-attdef-decl-value7 + (let ((code (char-code ch))) + (if* (eq #\; ch) + then (add-to-coll coll (code-char char-code)) + (setf char-code 0) + (setq state reference-save-state) + elseif (<= (char-code #\0) code (char-code #\9)) + then (setf char-code (+ (* char-code 10) (- code (char-code #\0)))) + else (clear-coll coll) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal decimal character reference code, starting at: '" + (compute-coll-string coll) + "', calculated char code: " + (format nil "~s" char-code))) + ))) + (#.state-dtd-!-attdef-decl-type + (if* (xml-name-char-p ch) then (add-to-coll coll ch) + elseif (and external (eq #\% ch)) then + (external-param-reference tokenbuf coll external-callback) + elseif (or (xml-space-p ch) (eq #\> ch)) then + (let ((token (compute-tag coll))) + (when (and (not (eq :REQUIRED token)) + (not (eq :IMPLIED token)) + (not (eq :FIXED token))) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD ch) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD ch) then + (setf contents-to-return + (append contents-to-return (list (nreverse pending)))) + (return) + else (setf contents-to-return + (append contents-to-return (list (nreverse pending)))) + (setf pending (list nil)) + (setf state state-dtd-!-attdef))) + (clear-coll coll) + else (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD ch) then + ;; there only one name... + (setf (first contents-to-return) (first (first contents-to-return))) + (return) + elseif (eq #\* ch) then + (setf state state-dtd-!-element-type-paren-pcd5) + (setf (first contents-to-return) (nreverse (first contents-to-return))) + (if* (> (length (first contents-to-return)) 1) then + (setf (first contents-to-return) + (list (append (list :choice) + (first contents-to-return)))) + elseif (listp (first (first contents-to-return))) then + (setf (first contents-to-return) + (first (first contents-to-return)))) + (push :* (first contents-to-return)) + elseif (eq #\? ch) then + (setf state state-dtd-!-element-type-paren-pcd5) + (setf (first contents-to-return) (nreverse (first contents-to-return))) + (if* (> (length (first contents-to-return)) 1) then + (setf (first contents-to-return) + (list (append (list :choice) + (first contents-to-return)))) + elseif (listp (first (first contents-to-return))) then + (setf (first contents-to-return) + (first (first contents-to-return)))) + (push :? (first contents-to-return)) + elseif (eq #\+ ch) then + (setf state state-dtd-!-element-type-paren-pcd5) + (setf (first contents-to-return) (nreverse (first contents-to-return))) + (if* (> (length (first contents-to-return)) 1) then + (setf (first contents-to-return) + (list (append (list :choice) + (first contents-to-return)))) + elseif (listp (first (first contents-to-return))) then + (setf (first contents-to-return) + (first (first contents-to-return)))) + (push :+ (first contents-to-return)) + elseif (and external (eq #\% ch)) then + (external-param-reference tokenbuf coll external-callback) + elseif (xml-space-p ch) then + (setf state state-dtd-!-element-type-paren-pcd5) + (setf (first contents-to-return) (nreverse (first contents-to-return))) + (when (> (length (first contents-to-return)) 1) + (setf (first contents-to-return) + (list (append (list :\choice) + (first contents-to-return))))) + else (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD (length (first pending)) 1) then - (push (first pending-type) (first pending)) - (setf pending-type (rest pending-type)) - else (setf (first pending) (first (first pending)))) - (push (first pending) contents-to-return) - (setf state state-dtd-!-element-type-paren3) - else (setf (first pending) (nreverse (first pending))) - (if* (> (length (first pending)) 1) then - (push (first pending-type) (first pending)) - (setf pending-type (rest pending-type)) - else (setf (first pending) (first (first pending)))) - (if* (second pending) then - (push (first pending) (second pending)) - else (setf (second pending) (list (first pending)))) - (setf pending (rest pending)) - (setf state state-dtd-!-element-type-paren-choice-name3) - ) - else (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD (length (first pending)) 1) then + (push (first pending-type) (first pending)) + (setf pending-type (rest pending-type)) + else (setf (first pending) (first (first pending)))) + (push (first pending) contents-to-return) + (setf state state-dtd-!-element-type-paren3) + else (setf (first pending) (nreverse (first pending))) + (if* (> (length (first pending)) 1) then + (push (first pending-type) (first pending)) + (setf pending-type (rest pending-type)) + else (setf (first pending) (first (first pending)))) + (if* (second pending) then + (push (first pending) (second pending)) + else (setf (second pending) (list (first pending)))) + (setf pending (rest pending)) + (setf state state-dtd-!-element-type-paren-choice-name3) + ) + else (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD (length (first pending)) 1) then - (push (first pending-type) (first pending)) - (setf pending-type (rest pending-type)) - else (setf (first pending) (first (first pending)))) - (push (first pending) contents-to-return) - (setf state state-dtd-!-element-type-paren3) - else (setf (first pending) (nreverse (first pending))) - (push (first pending-type) (first pending)) - (setf pending-type (rest pending-type)) - (if* (second pending) then - (push (first pending) (second pending)) - else (setf (second pending) - ;; (list (first pending)) ;2001-03-22 - (first pending) ;2001-03-22 - )) - (setf pending (rest pending)) - (setf state state-dtd-!-element-type-paren-choice-name3) - ) - elseif (eq #\, ch) then - (when (and (first pending) (not (eq :seq (first pending-type)))) - (clear-coll coll) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal '|' and ',' mix starting at '" - (compute-coll-string coll) - "'"))) - (push (compute-tag coll) (first pending)) - (clear-coll coll) - (push :seq pending-type) - (setf state state-dtd-!-element-type-paren-choice) - elseif (eq #\| ch) then - (when (and (first pending) (not (eq :choice (first pending-type)))) - (clear-coll coll) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal '|' and ',' mix starting at '" - (compute-coll-string coll) - "'"))) - (push (compute-tag coll) (first pending)) - (clear-coll coll) - (push :choice pending-type) - (setf state state-dtd-!-element-type-paren-choice) - else (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD (length (first pending)) 1) then - (push (first pending-type) (first pending)) - (setf pending-type (rest pending-type)) - else (setf (first pending) (first (first pending)))) - (push (first pending) contents-to-return) - (setf state state-dtd-!-element-type-paren3) - else (setf (first pending) (nreverse (first pending))) - (push (first pending-type) (first pending)) - (setf pending-type (rest pending-type)) - (if* (second pending) then - (push (first pending) (second pending)) - else (setf (second pending) (list (first pending)))) - (setf state state-dtd-!-element-type-paren-choice-name3) - ) - (setf pending (rest pending)) - else (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD (length (first pending)) 1) then - (push (first pending-type) (first pending)) - (setf pending-type (rest pending-type)) - else (setf (first pending) (first (first pending)))) - (push (first pending) contents-to-return) - (setf pending (rest pending)) - (setf state state-dtd-!-element-type-paren3) - else (setf (first pending) (nreverse (first pending))) - (if* (> (length (first pending)) 1) then - (push (first pending-type) (first pending)) - (setf pending-type (rest pending-type)) - else (setf (first pending) (first (first pending)))) - (if* (second pending) then - (push (first pending) (second pending)) - else (setf (second pending) (list (first pending)))) - (setf pending (rest pending)) - (setf state state-dtd-!-element-type-paren-choice) - ) - elseif (eq #\, ch) then - (when (and (rest (first pending)) (not (eq :seq (first pending-type)))) - (clear-coll coll) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal '|' and ',' mix starting at '" - (compute-coll-string coll) - "'"))) - (push :seq pending-type) - (setf state state-dtd-!-element-type-paren-choice) - elseif (eq #\| ch) then - (when (and (rest (first pending)) (not (eq :choice (first pending-type)))) - (clear-coll coll) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal '|' and ',' mix starting at '" - (compute-coll-string coll) - "'"))) - (push :choice pending-type) - (setf state state-dtd-!-element-type-paren-choice) - else (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD ch) then (return) - else (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD ch) then (return) - else (clear-coll coll) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD contents following ch) then (return) - else (clear-coll coll) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD contents following ch) then (return) - else (clear-coll coll) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD contents following (length (first contents-to-return)) 1) - (setf (first contents-to-return) - (list (append (list :choice) - (first contents-to-return))))) - (push :* (first contents-to-return)) - else (clear-coll coll) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "illegal DTD contents in ch) then - (let ((token (compute-tag coll))) - (when (not (or (eq token :EMPTY) (eq token :ANY))) - (xml-error (concatenate 'string - "illegal DTD ch) then (return) - else (xml-error (concatenate 'string - "expected '>', got '" - (string ch) - "' in DTD (length (first pending)) 1) then + (push (first pending-type) (first pending)) + (setf pending-type (rest pending-type)) + else (setf (first pending) (first (first pending)))) + (push (first pending) contents-to-return) + (setf state state-dtd-!-element-type-paren3) + else (setf (first pending) (nreverse (first pending))) + (push (first pending-type) (first pending)) + (setf pending-type (rest pending-type)) + (if* (second pending) then + (push (first pending) (second pending)) + else (setf (second pending) + ;; (list (first pending)) ;2001-03-22 + (first pending) ;2001-03-22 + )) + (setf pending (rest pending)) + (setf state state-dtd-!-element-type-paren-choice-name3) + ) + elseif (eq #\, ch) then + (when (and (first pending) (not (eq :seq (first pending-type)))) + (clear-coll coll) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal '|' and ',' mix starting at '" + (compute-coll-string coll) + "'"))) + (push (compute-tag coll) (first pending)) + (clear-coll coll) + (push :seq pending-type) + (setf state state-dtd-!-element-type-paren-choice) + elseif (eq #\| ch) then + (when (and (first pending) (not (eq :choice (first pending-type)))) + (clear-coll coll) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal '|' and ',' mix starting at '" + (compute-coll-string coll) + "'"))) + (push (compute-tag coll) (first pending)) + (clear-coll coll) + (push :choice pending-type) + (setf state state-dtd-!-element-type-paren-choice) + else (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD (length (first pending)) 1) then + (push (first pending-type) (first pending)) + (setf pending-type (rest pending-type)) + else (setf (first pending) (first (first pending)))) + (push (first pending) contents-to-return) + (setf state state-dtd-!-element-type-paren3) + else (setf (first pending) (nreverse (first pending))) + (push (first pending-type) (first pending)) + (setf pending-type (rest pending-type)) + (if* (second pending) then + (push (first pending) (second pending)) + else (setf (second pending) (list (first pending)))) + (setf state state-dtd-!-element-type-paren-choice-name3) + ) + (setf pending (rest pending)) + else (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD (length (first pending)) 1) then + (push (first pending-type) (first pending)) + (setf pending-type (rest pending-type)) + else (setf (first pending) (first (first pending)))) + (push (first pending) contents-to-return) + (setf pending (rest pending)) + (setf state state-dtd-!-element-type-paren3) + else (setf (first pending) (nreverse (first pending))) + (if* (> (length (first pending)) 1) then + (push (first pending-type) (first pending)) + (setf pending-type (rest pending-type)) + else (setf (first pending) (first (first pending)))) + (if* (second pending) then + (push (first pending) (second pending)) + else (setf (second pending) (list (first pending)))) + (setf pending (rest pending)) + (setf state state-dtd-!-element-type-paren-choice) + ) + elseif (eq #\, ch) then + (when (and (rest (first pending)) (not (eq :seq (first pending-type)))) + (clear-coll coll) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal '|' and ',' mix starting at '" + (compute-coll-string coll) + "'"))) + (push :seq pending-type) + (setf state state-dtd-!-element-type-paren-choice) + elseif (eq #\| ch) then + (when (and (rest (first pending)) (not (eq :choice (first pending-type)))) + (clear-coll coll) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal '|' and ',' mix starting at '" + (compute-coll-string coll) + "'"))) + (push :choice pending-type) + (setf state state-dtd-!-element-type-paren-choice) + else (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD ch) then (return) + else (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD ch) then (return) + else (clear-coll coll) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD contents following ch) then (return) + else (clear-coll coll) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD contents following ch) then (return) + else (clear-coll coll) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD contents following (length (first contents-to-return)) 1) + (setf (first contents-to-return) + (list (append (list :choice) + (first contents-to-return))))) + (push :* (first contents-to-return)) + else (clear-coll coll) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "illegal DTD contents in ch) then + (let ((token (compute-tag coll))) + (when (not (or (eq token :EMPTY) (eq token :ANY))) + (xml-error (concatenate 'string + "illegal DTD ch) then (return) + else (xml-error (concatenate 'string + "expected '>', got '" + (string ch) + "' in DTD include-count 0) (not (eq prev-state state-dtdstart))) then - (xml-error "unexpected end of input while processing external DTD")) - (values nil :end-dtd)) - (t - (print (list tag-to-return contents-to-return)) - (error "need to support dtd state:~s" state))) + (#.state-dtdstart + (when (and (null ch) (not external)) + (xml-error "unexpected end of input while parsing DTD")) + (if* (null tag-to-return) then (values nil :end-dtd) + else (error "process other return state"))) + ((#.state-dtd-!-element-type-end #.state-dtd-!-element-type-token + #.state-dtd-!-element-type-paren-pcd4 #.state-dtd-!-element-type-paren-pcd6 + #.state-dtd-!-element-type-paren-pcd5 #.state-dtd-!-element-type-paren2 + #.state-dtd-!-element-type-paren3) + (values (append (list tag-to-return) (nreverse contents-to-return)) + nil)) + ((#.state-dtd-!-attdef-decl-type #.state-dtd-!-attlist-name + #.state-dtd-!-attdef) + (values (append (list tag-to-return) contents-to-return) + nil)) + ((#.state-dtd-!-entity5 #.state-!-dtd-system3 + #.state-!-dtd-system7 #.state-!-dtd-system4 + #.state-!-dtd-system ;; this is actually a !NOTATION + #.state-dtd-?-4 ;; PI + #.state-dtd-comment4 ;; comment + ) + (let ((ret (append (list tag-to-return) (nreverse contents-to-return)))) + (values ret + nil))) + #+ignore + (#.state-dtd-pref2 + (values (nreverse contents-to-return) nil)) + (#.state-dtd-!-include2 + (values nil :include)) + (#.state-dtd-!-include4 + (values nil :include-end)) + (#.state-dtd-!-ignore7 + (values nil :ignore)) + (:eof + (if* (not external) then + (xml-error "unexpected end of input while processing DTD internal subset") + elseif (or (> include-count 0) (not (eq prev-state state-dtdstart))) then + (xml-error "unexpected end of input while processing external DTD")) + (values nil :end-dtd)) + (t + (print (list tag-to-return contents-to-return)) + (error "need to support dtd state:~s" state))) ) )) (defun external-param-reference (tokenbuf old-coll external-callback) (declare #+allegro (:fbound next-token) - #+lispworks (optimize (safety 0) (debug 3)) - (ignorable old-coll) - #-lispworks (optimize (speed 3) (safety 1))) + #+lispworks (optimize (safety 0) (debug 3)) + (ignorable old-coll) + #-lispworks (optimize (speed 3) (safety 1))) (setf (iostruct-seen-parameter-reference tokenbuf) t) (macrolet ((add-to-entity-buf (entity-symbol p-value) - `(progn - (push (make-tokenbuf :cur 0 :max (length ,p-value) :data ,p-value) - (iostruct-entity-bufs tokenbuf)))) - (clear-coll (coll) - `(setf (collector-next ,coll) 0)) - (un-next-char (ch) - `(push ,ch (iostruct-unget-char tokenbuf))) - (add-to-coll (coll ch) - `(let ((.next. (collector-next ,coll))) - (if* (>= .next. (collector-max ,coll)) - then (grow-and-add ,coll ,ch) - else (setf (schar (collector-data ,coll) .next.) - ,ch) - (setf (collector-next ,coll) (1+ .next.)))))) + `(progn + (push (make-tokenbuf :cur 0 :max (length ,p-value) :data ,p-value) + (iostruct-entity-bufs tokenbuf)))) + (clear-coll (coll) + `(setf (collector-next ,coll) 0)) + (un-next-char (ch) + `(push ,ch (iostruct-unget-char tokenbuf))) + (add-to-coll (coll ch) + `(let ((.next. (collector-next ,coll))) + (if* (>= .next. (collector-max ,coll)) + then (grow-and-add ,coll ,ch) + else (setf (schar (collector-data ,coll) .next.) + ,ch) + (setf (collector-next ,coll) (1+ .next.)))))) (let ((ch (get-next-char tokenbuf)) - (coll (get-collector)) - p-value entity-symbol) + (coll (get-collector)) + p-value entity-symbol) (add-to-coll coll ch) (when (not (xml-name-start-char-p ch)) - (dotimes (i 15) - (add-to-coll coll ch) - (setq ch (get-next-char tokenbuf)) - (if* (null ch) - then (return))) - (xml-error (concatenate 'string - "Illegal DTD parameter entity name starting at: " - (compute-coll-string coll)))) + (dotimes (i 15) + (add-to-coll coll ch) + (setq ch (get-next-char tokenbuf)) + (if* (null ch) + then (return))) + (xml-error (concatenate 'string + "Illegal DTD parameter entity name starting at: " + (compute-coll-string coll)))) (loop - (setf ch (get-next-char tokenbuf)) - (if* (eq #\; ch) then - (setf entity-symbol (compute-tag coll)) - (clear-coll coll) - #+ignore (format t "entity symbol: ~s entities: ~s match: ~s~%" - entity-symbol (iostruct-parameter-entities tokenbuf) - (assoc entity-symbol - (iostruct-parameter-entities tokenbuf))) - (if* (and (iostruct-do-entity tokenbuf) - (setf p-value - (assoc entity-symbol - (iostruct-parameter-entities tokenbuf)))) then - (setf p-value (rest p-value)) - (when (member entity-symbol (iostruct-entity-names tokenbuf)) - (xml-error (concatenate 'string - "entity:" - (string entity-symbol) - " in recursive reference"))) - (push entity-symbol (iostruct-entity-names tokenbuf)) - (if* (stringp p-value) then - (setf p-value (concatenate 'string " " p-value " ")) - (add-to-entity-buf entity-symbol p-value) - elseif (null external-callback) then - (setf (iostruct-do-entity tokenbuf) nil) - elseif p-value then - (let ((entity-stream (apply external-callback p-value))) - (when entity-stream - (let ((entity-buf (get-tokenbuf))) - (setf (tokenbuf-stream entity-buf) entity-stream) - (unicode-check entity-stream tokenbuf) - (add-to-entity-buf entity-symbol " ") - (push entity-buf - (iostruct-entity-bufs tokenbuf)) - (let ((count 0) cch - (string "