Add and use TERPRI.
[jscl.git] / src / print.lisp
index 941b97c..66d8b0a 100644 (file)
 ;; You should have received a copy of the GNU General Public License
 ;; along with JSCL.  If not, see <http://www.gnu.org/licenses/>.
 
+(/debug "loading print.lisp!")
+
 ;;; Printer
 
+(defun lisp-escape-string (string)
+  (let ((output "")
+        (index 0)
+        (size (length string)))
+    (while (< index size)
+      (let ((ch (char string index)))
+        (when (or (char= ch #\") (char= ch #\\))
+          (setq output (concat output "\\")))
+        (when (or (char= ch #\newline))
+          (setq output (concat output "\\"))
+          (setq ch #\n))
+        (setq output (concat output (string ch))))
+      (incf index))
+    (concat "\"" output "\"")))
+
 ;;; Return T if the string S contains characters which need to be
 ;;; escaped to print the symbol name, NIL otherwise.
 (defun escape-symbol-name-p (s)
@@ -28,6 +45,7 @@
         (when (or (terminalp ch)
                   (char= ch #\:)
                   (char= ch #\\)
+                  (not (char= ch (char-upcase ch)))
                   (char= ch #\|))
           (return-from escape-symbol-name-p t))))
     dots-only))
   (let ((*print-escape* nil))
     (write-to-string form)))
 
+(defun terpri ()
+  (write-char #\newline)
+  (values))
+
 (defun write-line (x)
   (write-string x)
-  (write-string *newline*)
+  (terpri)
   x)
 
 (defun warn (string)
                ((char= next #\~)
                 (concatf res "~"))
                ((char= next #\%)
-                (concatf res *newline*))
+                (concatf res (string #\newline)))
                ((char= next #\*)
                 (pop arguments))
                (t