;;; -*- Mode:Lisp; Readtable:ZL; Package:USER; Base:8; Patch-File:T -*-
;;; Patch file for Unix-Interface version 6.1
;;; Reason:
;;;  Fix unix-stream sharetty so backspace works again.
;;; Written 19-Dec-85 21:34:19 by bobp of LMI Cambridge
;;; while running on BobP from band 1
;;; with Experimental System 109.35, Experimental Local-File 64.1, Experimental FILE-Server 17.1, Experimental MagTape 3.4, Experimental Unix-Interface 6.0, Experimental ZMail 64.1, microcode 1326.


;; *** Note: ***
;;   You may lose because the buffer has no readtable attribute.
;; *************

; From modified file DJ: L.UNIX; LAMTTY.LISP#53 at 19-Dec-85 21:34:20
#8R UNIX#:
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "UNIX")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: UNIX; LAMTTY  "

(defmethod (simple-unix-window-mixin :typeout-top-level) ()
  (multiple-value-bind (array starting ending)
      (send unix-stream :read-input-buffer)
    (do* ((search-start starting)
	  (first-hard (string-search-set '(10 11 12 15 33 #\space) array search-start ending)
		      (string-search-set '(10 11 12 15 33 #\space) array search-start ending))
	  )
	 ((null first-hard)
	  (send self :clear-then-string-out array starting ending)
	  (send unix-stream :advance-input-buffer ending))

      ;;; Hook so that other users can get at the characters as they are received from unix
      (send self :raw-unix-character-in first-hard)

      (selectq (aref array first-hard)
;temporary fix so backspace works,
;maybe it should be fixed in the tyo instead -- bobp
;	(10 (aset #\overstrike array first-hard)
;	    (setq search-start (1+ first-hard)))
	(10 (send self :clear-then-string-out array starting first-hard)
	    (setq starting (1+ first-hard))
	    (setq search-start starting)
	    (send self :tyo #\overstrike))
	(11 (aset #\tab array first-hard)
	    (setq search-start (1+ first-hard)))
	(12 (aset #\return array first-hard)
	    (setq search-start (1+ first-hard)))
	(15 (send self :clear-then-string-out array starting first-hard)
	    (setq starting (1+ first-hard))
	    (setq search-start starting))
	(#\space (send self :clear-then-string-out array starting first-hard)
		 (do ((n (1+ first-hard) (1+ n)))
		     ((or (= n ending)
			  (not (= (aref array n) #\space)))
		      (dotimes (x (- n first-hard))
			(send self :clear-char)
			(send self :forward-char))
		      (setq starting n)
		      (setq search-start n))))
	(33 (send self :clear-then-string-out array starting first-hard)
	    (send unix-stream :advance-input-buffer first-hard)
	    (send self :handle-escape)
	    (return nil))
	(t (ferror nil "internal bug: hard case not handled"))
	))))

))
