;;; -*- Mode:Lisp; Readtable:ZL; Package:USER; Base:8; Patch-File:T -*-
;;; Patch file for KERMIT version 31.1
;;; Reason:
;;;  CHAOS TELNET now an option in review parameters.
;;; Written 1-Feb-86 09:27:45 by GJC (George Carrette) at site LMI Cambridge
;;; while running on Djinn from band 2
;;; with Experimental System 110.12, Experimental Local-File 66.0, Experimental FILE-Server 18.1, Experimental MagTape 4.0, Experimental ZMail 65.1, Experimental Unix-Interface 9.0, Experimental KERMIT 31.0, microcode 1363.



; From file DJ: L.NETWORK.KERMIT; CALLS.LISP#51 at 1-Feb-86 09:27:47
#8R KERMIT#:
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "KERMIT")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERMIT; CALLS  "

(defmethod (kstate :set-params) ()
  (declare (special kermit-frame serial-stream-open-form))
  (let ((oldx tv:mouse-x) (oldy tv:mouse-y)
	(menux (tv:sheet-inside-right kermit-frame))
	(menuy (tv:sheet-inside-bottom kermit-frame))

	;; append new symbols to these two lists:
	(vars '(kermit-default-pathname serial-stream-open-form
		 *file-closing-disposition* *filnamcnv* *8-bit-lispm* *image*
		 ascii-extra-safe-filter?
		 *soh* *mytime* *myquote* *mypad* *mypchar* *image* *debug*
		 *checksum-type*
		  ))
	(old-vals (list kermit-default-pathname serial-stream-open-form
			*file-closing-disposition* *filnamcnv* *8-bit-lispm* *image*
			ascii-extra-safe-filter?
			*soh* *mytime* *myquote* *mypad* *mypchar* *image* *debug*
			*checksum-type*
			)))

    (tv:mouse-warp (- menux 50.) (- menuy 50.))	;try to put the mouse around the ctr of menu
    (multiple-value-bind (nil abort-p)
	(*catch 'legal-abortion
	  (tv:choose-variable-values
	    `("     MODIFY PARAMETERS used by KERMIT by clicking with the mouse     "
	      "     over the appropriate value, typing a new value, and hitting the     "
	      "     return key. When all values are satisfactory, click the box      "
	      "     labelled /"EXECUTE:/" in the lower left corner.     "
	      
	      "================================================================================"
	      
	      (kermit-default-pathname
		:documentation "Where to write to or read from by default"
		:pathname kermit-default-pathname)

	      (serial-stream-open-form
		:documentation "The serial stream//device for connections."
		:menu-alist
		;; one could map over fs:*pathname-host-list* to get these devices...
		(("Serial Port B" (open "SDU-SERIAL-B:"))
		 ,@(IF (FIND-PACKAGE "TCP") '(("TCP TELNET" (OPEN-TCP-TELNET-SERIAL-STREAM))))
		 ("CHAOS TELNET" (OPEN-CHAOS-TELNET-STREAM))
		 ;; SUPDUP doesnt work because we are not sending the right negotiations.
		 ;; ("CHAOS SUPDUP" (OPEN-CHAOS-TELNET-STREAM "SUPDUP"))
		 ("Prompt User" (prompt-and-read :eval-read "~&Serial stream: "))
		 ;; one should make sure the pathname exists; otherwise, you'll
		 ;; open an 'i//o stream' to some random file probably.
		 . ,(loop for share-tty in (and (boundp 'unix:*share-ttys*)
						unix:*share-ttys*)
			  as port-number from 0
			  collect
			   (list
			     (format nil "Unix Port ~D (//dev//ttyl~D)"
				     port-number port-number)
			     `(open
				,(format nil "UNIX-STREAM-~D:"
					 port-number))))))

	      "--------------------------------------------------------------------------------"
	      
	      
	      (*filnamcnv* :documentation "Specify your OS for filename conversion purposes."
			   :menu-alist ,(cons '("Raw - no conversion" :raw)
					      (cons '("Unknown - generic" :generic)
						    (mapcar #'(lambda (x)
								(list (car x) (car x)))
							    (get (locf fs:canonical-types)
								 ':lisp)))))
	      (*8-bit-lispm* :documentation
	       "Yes if you can send 8-bit characters, want lispm//ascii chars translated right."
	       :boolean)

	      (ascii-extra-safe-filter?
		:documentation
		"Either nil, or a lisp function that filters wierd ctrl characters.")

	      (*image* :documentation
		         "Yes if you want 8-bit, binary mode. (no character translation)"
		       :boolean)
	      (*debug* :documentation
		         "Yes, if you want verbose debugging information during xfer"
		       :boolean)
	      (*terminal-debug-mode* :documentation "Yes for debugging the terminal emulator"
				     :boolean)
	      (*file-closing-disposition*
		:documentation
		  "Decide whether files only partially written due to interrupt should be saved."
		:menu-alist (("delete-if-abort" :abort)
			     ("dont-delete" nil)))
	      "--------------------------------------------------------------------------------"
	      "Some less commonly changed, packet level parameters requiring a more advanced"
              "knowledge of the Kermit Protocol and//or the specific operating system"
              "being dealt with and their (mis)features."

	      (*soh* :documentation
		       "mark for start of packet (a non-printing character)"
		     :number)
	      (*mytime* :documentation
			  "max time to wait for packet"
			:number)
	      (*myquote* :documentation "Character to use to quote non-printing chars."
			 :number)
	      (*myeol* :documentation "mark for end of packet"
		       :number)
	      (*mypad* :documentation
		         "Number of padding characters to use in packet (usually 0)"
		       :number)
	      (*mypchar* :documentation
			   "Padding character to use in packet (usually NUL (0))" 
			 :number)
	      (*checksum-type* :documentation
			       "[Only one character checksums are supported at this time]"
			       :menu-alist (("Normal-one-character" 1)))
	      "      ")
	    
	    ':near-mode `(:point ,menux ,menuy)
	    ':superior kermit-frame
	    ':margin-choices '("EXECUTE:" ("abort:" (*throw 'legal-abortion nil)))))
      (and abort-p
	   (loop for var in vars and old-val in old-vals doing (set var old-val)))
      nil)
    
    (tv:mouse-warp oldx oldy)))

))

; From file DJ: L.NETWORK.KERMIT; CALLS.LISP#51 at 1-Feb-86 09:28:03
#8R KERMIT#:
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "KERMIT")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERMIT; CALLS  "

(defun open-chaos-telnet-stream (&OPTIONAL (CONTACT "TELNET"))
  (enable-telnet-iac)
  (let (host)
    (do-forever
      (setq host (prompt-and-read :string-or-nil "~&Telnet to host: "))
      (when host (return nil)))
    (format t "~&Connecting to ~S" host)
    (make-input-force-output-stream (chaos:open-stream host CONTACT))))

))

; From file DJ: L.NETWORK.KERMIT; CALLS.LISP#51 at 1-Feb-86 09:28:08
#8R KERMIT#:
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "KERMIT")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: NETWORK; KERMIT; CALLS  "

(defun make-input-force-output-stream (substream &aux stream need-forcep)
  (setq stream #'(lambda (op &optional arg1 &rest args)
		   (si:selectq-with-which-operations op
		     ((:tyi :listen)
		       (when need-forcep
			 (send substream :force-output)
			 (setq need-forcep nil))
		       (send substream op))
		     (:tyo
		       (setq need-forcep t)
		       (send substream :tyo arg1))
		     (:close
		       (send substream :close))
		     (t
		       (stream-default-handler stream op arg1 args))))))

))
