;;; -*- Mode:Lisp; Readtable:ZL; Package:USER; Base:10; Patch-File:T -*-
;;; Patch file for System version 124.62
;;; Reason:
;;;  QSEND now prompts user more legibly.  PARSE-SINGLE-DEST now parses
;;;  unspecified and unfound hosts (i.e., from menu when user moves off
;;;  without clicking) into the host "<undetermined-host>".
;;; Written 15-Jun-88 17:41:53 by saz (David M.J. Saslav) at site Gigamos Cambridge
;;; while running on Brahms' First from band 3
;;; with Experimental System 124.59, Experimental Local-File 74.2, Experimental File-Server 23.1, Experimental Unix-Interface 12.0, Experimental ZMail 72.0, Experimental Tape 23.6, Experimental Lambda-Diag 16.1, microcode 1759, SDU Boot Tape 3.14, SDU ROM 103.



; From modified file DJ: L.IO1; CONVER.LISP#157 at 15-Jun-88 17:42:00
#10R ZWEI#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "ZWEI")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: IO1; CONVER  "


(DEFUN QSEND (&OPTIONAL DESTINATION MESSAGE (MAIL-P NIL) (WAIT-P *CONVERSE-WAIT-P*)
	      &AUX SWITCH-TO-CONVERSE DESTINATION-LIST)
  "Send an interactive message, MESSAGE, to the people in DESTINATION.
If MESSAGE is empty, you will be prompted for it.
If DESTINATION is empty, Converse will be selected.
If MAIL-P is NIL (the default), the message will be sent interactively, 
   otherwise the message will be mailed.
If WAIT-P is NIL, then queue up to message to be soon, but return NIL.
If WAIT-P is T, then wait until we determine the status of the messages sent, 
and return a list of the successful recipients.  The default value of the variable
is contained in the init variable ZWEI:*CONVERSE-WAIT-P*.

This function is expected to be called by a user.
Programs which call it are guaranteed to do something useful only if MESSAGE and
DESTINATION are non-NIL."
  (SETQ DESTINATION-LIST (PARSE-COMMAS-INTO-LIST DESTINATION))
  (COND ((NULL DESTINATION)  ;; Person wants to select Converse.
	 (SEND (FIND-CONVERSE-WINDOW) :SELECT)) ;;do your thing
	((NULL MESSAGE)
	 (FORMAT T
		 "~%Please enter a message for ~{~A~^, ~}:~%
  To terminate the message ~40Ttype ~:@C
  To quit ~40Ttype ~:@C
  To switch to a Converse Frame ~40Ttype ~:@C~@%"
		 DESTINATION-LIST
		 #/END #/ABORT #/C-M-E)
	 (SETF (VALUES MESSAGE SWITCH-TO-CONVERSE)
	       (QSEND-GET-MESSAGE *STANDARD-INPUT*))
	 (COND (SWITCH-TO-CONVERSE
		(SETQ *AWAITING-EXPOSURE* T) ;in case of converse-problem  ;;???? -hdt
		(SEND (FIND-CONVERSE-WINDOW) :ENTER-REQUEST
		      'CONVERSE-EDIT-AND-SEND-MSG DESTINATION MESSAGE)
		(PROCESS-WAIT "Expose Converse"
			      (FIND-CONVERSE-WINDOW) :EXPOSED-P)
		(TV:AWAIT-WINDOW-EXPOSURE)
		(SETQ *AWAITING-EXPOSURE* NIL))
	       (T  ;;didn't select converse, just send it.
		(QSEND-FORCE-MESSAGE DESTINATION MESSAGE MAIL-P WAIT-P))))
	(T  ;;we got the message without querying user, now just send it
	 (QSEND-FORCE-MESSAGE DESTINATION MESSAGE MAIL-P WAIT-P))))

))

; From modified file DJ: L.IO1; CONVER.LISP#157 at 15-Jun-88 17:42:03
#10R ZWEI#: 
(COMPILER-LET ((*PACKAGE* (PKG-FIND-PACKAGE "ZWEI")))
  (COMPILER::PATCH-SOURCE-FILE "SYS: IO1; CONVER  "


(DEFUN PARSE-SINGLE-DEST (DEST &OPTIONAL JUST-VERIFY &AUX HOST)
  "Parse the string DEST as a single destination for a QSEND message.
First value is a string of the form USERNAME@HOSTNAME,
where hostname is the official name of a host,
or NIL if DEST did not specify a host and the person cannot be found.
Also returns just the username as the second value
and just the host as a third value.

If JUST-VERIFY is non-NIL, we do only enough to get an error
if the host specified is nonexistent."
  ;;this code is slightly gross, most parsing has already been done.
  (LET ((@-POS (STRING-SEARCH-CHAR #/@ DEST)))
    (COND ((NULL @-POS)
	   (UNLESS JUST-VERIFY
	     (SETQ DEST (STRING-TRIM " " DEST))
	     (SETQ HOST (DECIDE-HOST
			  (CHAOS:FIND-HOSTS-OR-LISPMS-LOGGED-IN-AS-USER
			    DEST *CONVERSE-EXTRA-HOSTS-TO-CHECK*)
			  DEST))))
	  (T  (SETQ HOST (SI:PARSE-HOST (STRING-TRIM " " (SUBSTRING DEST (1+ @-POS))))
		    DEST (STRING-TRIM " " (SUBSTRING DEST 0 @-POS)))))
    (VALUES (STRING-APPEND DEST #/@ (if host (STRING HOST) "<undetermined-host>"))
	    DEST
	    (IF (NUMBERP HOST) NIL HOST))))

))
