;;; -*- Mode:Lisp; Readtable:ZL; Package:USER; Base:8; Patch-File:T -*-
;;; Patch file for Kermit version 35.3
;;; Reason:
;;;  Various changes to clean up handling of SDU serial ports.
;;;  
;;;  There's a new serial-port OPEN form, SDU-SERIAL-OPEN.  This function
;;;  knows about global Kermit parameters for specifying 1) Ascii conversion
;;;  and/or 2) Xon-Xoff flow control.  These are set under Review Parameters,
;;;  and work for <new> connections.  We create new serial port streams of
;;;  the appropriate flavor.  Other options are set as before.
;;;  
;;;  Don't let user specify *image* mode with Ascii! Menu puts up error
;;;  message.
;;; Written 18-Jul-88 23:34:31 by keith (Keith Corbett) at site Gigamos Cambridge
;;; while running on Breaking Glass from band 3
;;; with System 125.6, ZWEI 125.2, ZMail 73.0, Local-File 75.0, File-Server 24.0, Unix-Interface 13.0, Tape 24.0, Lambda-Diag 17.0, Experimental Kermit 35.1, microcode 1761, SDU Boot Tape 3.14, SDU ROM 103.



; From file DJ: L.NETWORK.KERMIT; CALLS.LISP#63 at 18-Jul-88 23:34:31
#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
		 *sdu-serial-xon-xoff-p* *sdu-serial-ascii-p*
		 *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
			*sdu-serial-xon-xoff-p* *sdu-serial-ascii-p*
			*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 A" (open "SDU-SERIAL-A:"))
		 ;; ("Serial Port B" (open "SDU-SERIAL-B:"))
		 ;;Ok, this computes the serial devices on a Lambda:
		 #+lambda
		 ,@(gather-sdu-serial-devices)
		 ,@(IF (FIND-PACKAGE "TCP") '(("TCP TELNET" (OPEN-TCP-TELNET-SERIAL-STREAM))))
		 ;;Does this work anymore???
		 ("CHAOS TELNET" (OPEN-CHAOS-TELNET-STREAM))
		 ;; SUPDUP doesnt work because we are not sending the right negotiations.
		 ;; ("CHAOS SUPDUP" (OPEN-CHAOS-TELNET-STREAM "SUPDUP"))
		 ;;This was pace's own hack, and doesn't work anywhere anymore:
		 ;("REMOTE SERIAL STREAM" (OPEN-REMOTE-SERIAL-STREAM))
		 ;("REMOTE UNIX SERIAL" (OPEN-REMOTE-UNIX-SERIAL-STREAM))
		 ("Prompt User" (prompt-and-read :eval-read "~&Form to Eval and return a 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.")

	      (*sdu-serial-ascii-p*
		:documentation "For serial ports, Yes to perform ASCII//LISPM character conversion."
		:boolean)
	      (*sdu-serial-xon-xoff-p*
		:documentation "For serial ports, Yes to use software Xon//Xoff flow control."
		:boolean)

	      (*image* :documentation
		         "Yes, if you want 8-bit, binary mode (no character translation)."
		       :boolean)
	      (*debug* :documentation
		         "Yes, if you want verbose debugging information during transfer."
		       :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 features//problems."

	      (*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)))
	    :function #'(lambda(window var old new)
			  (if (and (member var '(*sdu-serial-ascii-p* *image*))
				   new
				   *sdu-serial-ascii-p* *image*)
			      (progn
				(beep)
				(send window :clear-window)
				(send window :fat-string-out *invalid-image-opt-msg*)
				(send window :tyi)
				(send window :refresh)
				(set var old))
			    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)))

))
