;*******************************************************************************************
;* Here is a simple lisp routine to convert a lisp file to html in Visual Lisp format * ;******************************************************************************************* (defun html-format (str) (vl-string-subst "<" "<" (vl-string-subst "&" "&" str)))
(defun c:lisp2html (/ file rf wf t1 str char i f argument) (setq file (getfiled "Select Lisp File" (getvar "dwgprefix") "lsp" 0) rf (open file "r") wf (open (strcat (vl-filename-directory file) "/" (vl-filename-base file) ".html") "w") );s (write-line "<pre><font face=Arial color=black size=2>" wf) (while (setq t1 (read-line rf)) (setq str "" i 1) (while (<= i (strlen t1)) (setq word "") (while (not (member (setq char (substr t1 i 1)) '("" " " ";" "(" ")" """))) (setq word (strcat word char) i (1+ i)) );w (if (= word "") (setq word char i (+ i (strlen char)))) (if (= word ";") (setq str (strcat str "<font color=purple><span style="background-color:white">" (html-format (substr t1 (1- i))) "</span></font>") i (1+ (strlen t1)) );s (cond ((member word '("(" ")")) (setq str (strcat str "<font color=red>") i (1- i)) (while (member (setq char (substr t1 i 1)) '("(" ")")) (setq str (strcat str char) i (1+ i)) );w (setq str (strcat str "</font>") f (= (substr t1 (1- i) 1) "(")) ) ((= word """) (setq str (strcat str "<font color=#FF00FF>" word)) (while (and (/= (setq char (substr t1 i 1)) "") (or (/= char """) (and (> i 1) (= (substr t1 (1- i) 1) "\") (or (= i 2) (/= (substr t1 (- i 2) 1) "\"))))) (setq str (strcat str (html-format char)) i (1+ i)) );w (setq str (strcat str char "</font>") i (1+ i)) ) ((= word "'") (setq str (strcat str "<font color=#800000>'</font>"))) ((= word "/") (setq str (strcat str "<font color=blue>/</font>") argument nil f nil)) ((= word ".") (setq str (strcat str word))) ((numberp (read word)) (setq str (strcat str "<font color=green>" word "</font>") f nil)) (f (if argument (setq str (strcat str (html-format word)) argument nil f nil) (setq str (strcat str "<font color=blue>" (html-format word) "</font>") argument (= (strcase word) "DEFUN") f nil) ));f (T (setq str (strcat str (html-format word)))) );c );i );w (write-line str wf) );f (write-line "</font></pre>" wf) (close rf) (close wf) (princ) );d (prompt "nType "lsp2html" at the command prompt to run routine.") (princ) |