(FILECREATED " 4-Sep-84 22:00:06" {ERIS}<LISPCORE>SOURCES>PASSWORDS.;32 27014  

      changes to:  (FNS PROMPTFORWORD)

      previous date: "15-Aug-84 16:08:12" {ERIS}<LISPCORE>SOURCES>PASSWORDS.;31)


(* Copyright (c) 1982, 1983, 1984 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT PASSWORDSCOMS)

(RPAQQ PASSWORDSCOMS ((COMS (FNS LOGIN SETPASSWORD \INTERNAL/GETPASSWORD \LOGIN.READ 
				 PROVIDE.PROMPTING.WINDOW \ADJUST.USERNAME \ENCRYPT.PWD \DECRYPT.PWD)
			    (INITVARS (LOGINPASSWORDS (HASHARRAY 8))
				      (\GETPASSWORD.LOCK (CREATE.MONITORLOCK "GetPassword"))
				      (DEFAULTREGISTRY)
				      (\AFTERLOGINFNS)
				      (UNSCHEDULEDPROMPTREGION (QUOTE (262 466 500 100))))
			    (GLOBALVARS LOGINPASSWORDS USERNAME \GETPASSWORD.LOCK DEFAULTREGISTRY 
					\AFTERLOGINFNS UNSCHEDULEDPROMPTREGION)
			    (DECLARE: EVAL@COMPILE DONTCOPY (PROP DMACRO EMPASSWORDLOC)
				      (EXPORT (MACROS \DECRYPT.PWD.CHAR)))
			    (P (MOVD? (QUOTE NILL)
				      (QUOTE CLBUFS))))
		      (COMS (* PROMPTFORWORD)
			    (FNS PROMPTFORWORD \PROMPTFORWORDBIN \PROMPTFORWORDERASE \PROMPTFORWORDBS 
				 \PROMPTFORWORDRETYPE)
			    (INITVARS (\PROMPTFORWORDTTBL NIL))
			    (GLOBALVARS \PROMPTFORWORDTTBL))
		      (LOCALVARS . T)))
(DEFINEQ

(LOGIN
  [LAMBDA (HOST FLG DIRECTORY MSG)                           (* bvm: "24-Jul-84 18:11")

          (* Forces a login at HOST optionally connecting to DIRECTORY, and returns the name logged in.
	  MSG is optional message string to print before asking)


    (PROG ((NSFLG (STRPOS ":" HOST)))
          (RETURN (CAR (\INTERNAL/GETPASSWORD (SELECTQ HOST
						       ((NIL NS:: GV)
							 HOST)
						       (OR (COND
							     (NSFLG (\CANONICAL.NSHOSTNAME HOST))
							     (T (\CANONICAL.HOSTNAME HOST)))
							   (ERROR "Host not found" HOST)))
					      (NEQ FLG (QUOTE QUIET))
					      DIRECTORY MSG NIL (AND NSFLG (QUOTE NS])

(SETPASSWORD
  [LAMBDA (HOST USER PASSWORD DIRECTORY)                     (* bvm: " 3-NOV-83 22:14")
    (PROG [(INFO (GETHASH HOST LOGINPASSWORDS))
	   (ENCRYPTED (\ENCRYPT.PWD (CONCAT PASSWORD]
          (SETQ USER (\DTEST USER (QUOTE LITATOM)))
          [COND
	    [DIRECTORY (SETQ DIRECTORY (\DTEST DIRECTORY (QUOTE LITATOM)))
		       (RPLACD (OR INFO (SETQ INFO (PUTHASH HOST (CONS)
							    LOGINPASSWORDS)))
			       (CONS (CONS DIRECTORY ENCRYPTED)
				     (CDR INFO]
	    (T (FRPLACA (OR INFO (PUTHASH HOST (CONS)
					  LOGINPASSWORDS))
			(CONS USER ENCRYPTED]
          (RETURN HOST])

(\INTERNAL/GETPASSWORD
  [LAMBDA (HOST ALWAYSASK DIRECTORY MSG DEFAULTNAME OSTYPE)
                                                             (* bvm: "24-Jul-84 19:58")

          (* returns (name . password) with which to login (or connect if DIRECTORY given) at HOST, performing an alto-style
	  login if necessary, or if ALWAYSASK is true. MSG is optional message string to print before asking)


    [COND
      ((AND HOST (NOT OSTYPE)
	    (STRPOS ":" HOST))
	(SETQ OSTYPE (QUOTE NS]
    (PROG ((INFO (GETHASH HOST LOGINPASSWORDS))
	   INFOCHANGED PWD PASSWORDADDR NAME/PASS NEWNAME/PASS DISKNAME RESULT)
          (COND
	    ([AND (NOT ALWAYSASK)
		  (SETQ NAME/PASS (COND
		      (DIRECTORY (ASSOC DIRECTORY (CDR INFO)))
		      (T (CAR INFO]                          (* We already have login info)
	      (RETURN NAME/PASS)))
          [SETQ RESULT
	    (WITH.MONITOR
	      \GETPASSWORD.LOCK                              (* Don't grab the monitor til now, since we don't really
							     care if what we fetched above was about to change)
	      (CAR (NLSETQ
		     (PROG (PWD PASSWORDADDR NEWNAME/PASS DISKNAME NSINFO)
		           (COND
			     (DIRECTORY (OR INFO (SETQ INFO (PUTHASH HOST (CONS)
								     LOGINPASSWORDS)))
					[SETQ NEWNAME/PASS (COND
					    ((NULL ALWAYSASK)
                                                             (* First time, guess that no password is needed)
					      (CONS DIRECTORY ""))
					    (T (\LOGIN.READ HOST DIRECTORY MSG T OSTYPE]
					[COND
					  (NEWNAME/PASS
					    (COND
					      [(SETQ NAME/PASS (ASSOC DIRECTORY (CDR INFO)))
						(RPLACD NAME/PASS (\ENCRYPT.PWD (CDR NEWNAME/PASS]
					      (T (RPLACD INFO (CONS (CONS (CAR NEWNAME/PASS)
									  (\ENCRYPT.PWD (CDR 
										     NEWNAME/PASS)))
								    (CDR INFO]
					(RETURN NEWNAME/PASS))
			     (T [COND
				  ((EQ (SYSTEMTYPE)
				       (QUOTE D))
				    [OR OSTYPE (SETQ OSTYPE (COND
					    (HOST (GETOSTYPE HOST))
					    (T (QUOTE LOCAL]
				    (COND
				      ([NOT (ZEROP (SETQ PASSWORDADDR (EMPASSWORDLOC]
					(SETQ PASSWORDADDR (EMPOINTER PASSWORDADDR]
				[COND
				  ((EQ OSTYPE (QUOTE NS))
				    (SETQ NSINFO (GETHASH (QUOTE NS::)
							  LOGINPASSWORDS]
				(SETQ DISKNAME (\ADJUST.USERNAME (USERNAME NIL T T)
								 OSTYPE))
				[SETQ DEFAULTNAME (COND
				    ((NOT DEFAULTNAME)
				      (OR (CAAR (OR NSINFO INFO))
					  DISKNAME))
				    (T (\ADJUST.USERNAME DEFAULTNAME OSTYPE]
				[COND
				  [(AND NSINFO (NULL ALWAYSASK))
                                                             (* For NS hosts, there is a uniform login.
							     Try that first)
				    (SETQ NAME/PASS (COPY (CAR NSINFO]
				  [(AND (NULL ALWAYSASK)
					PASSWORDADDR
					(EQ DEFAULTNAME DISKNAME)
					(IGREATERP (NCHARS (SETQ PWD (GetBcplString PASSWORDADDR)))
						   0))
				    [SETQ NAME/PASS (CONS DEFAULTNAME (SETQ PWD
							    (SELECTQ OSTYPE
								     (UNIX (L-CASE PWD))
								     (TENEX (U-CASE PWD))
								     PWD]
				    (\ENCRYPT.PWD PWD)
				    (COND
				      ((AND (EQ OSTYPE (QUOTE NS))
					    (NULL NSINFO))   (* Set NS default login as well)
					(PUTHASH (QUOTE NS::)
						 (LIST (COPY NAME/PASS))
						 LOGINPASSWORDS]
				  (T (SETQ NAME/PASS (\LOGIN.READ HOST DEFAULTNAME MSG NIL OSTYPE))
				     (SETQ INFOCHANGED T)
				     [COND
				       [(EQ OSTYPE (QUOTE NS))
                                                             (* Don't touch alto login)
					 (COND
					   ((OR (NULL NSINFO)
						(EQ (CAAR NSINFO)
						    (CAR NAME/PASS)))
					     (FRPLACA (OR NSINFO (PUTHASH (QUOTE NS::)
									  (CONS)
									  LOGINPASSWORDS))
						      NAME/PASS]
				       [(EQ (CAR NAME/PASS)
					    DISKNAME)
					 (AND PASSWORDADDR (SetBcplString PASSWORDADDR (CDR NAME/PASS]
				       ([OR (NULL HOST)
					    (AND PASSWORDADDR DISKNAME (ZEROP (\GETBASE PASSWORDADDR 
											0))
						 (NEQ (U-CASE (CAR NAME/PASS))
						      (QUOTE GUEST]
                                                             (* There was no password before, or user forced login)
					 (AND (GETD (QUOTE SETUSERNAME))
					      (SETUSERNAME (CAR NAME/PASS)))
					 (AND PASSWORDADDR (SetBcplString PASSWORDADDR (CDR NAME/PASS]
				     (\ENCRYPT.PWD (CDR NAME/PASS]
				(COND
				  ((NULL HOST)
				    (CLRHASH LOGINPASSWORDS)
				    (SETQ INFO)))
				(FRPLACA (OR INFO (PUTHASH HOST (CONS)
							   LOGINPASSWORDS))
					 NAME/PASS)))
		           (RETURN NAME/PASS]
          [COND
	    ((AND INFOCHANGED RESULT)
	      (for FN in \AFTERLOGINFNS
		 do                                          (* Report change to any user packages that cache user 
							     info)
		    (APPLY* FN HOST (CAR RESULT]
          (RETURN RESULT])

(\LOGIN.READ
  [LAMBDA (HOST DEFAULTNAME MSG CONNECTFLG OSTYPE)           (* bvm: "15-Aug-84 16:02")
    (PROG [(PROMPT (COND
		     ((NEQ OSTYPE (QUOTE NS))
		       "Login: ")
		     (HOST                                   (* This would get to be a pretty long line)
			   " (terminate input with <return>)
Login: ")
		     (T "Login (<return> to terminate): ")))
	   (HELPFN 
"
You are being asked for a user name and password for login.
Type <return> to accept the given user name, or <BS> to back
up over it, or type a new name followed by <return>.
")
	   (TERMINATIONS (COND
			   ((EQ OSTYPE (QUOTE NS))
			     (CHARCODE (CR LF)))
			   (T                                (* default)
			      NIL]
          (COND
	    (CONNECTFLG (SETQ PROMPT (CONCAT "Connect password for " DEFAULTNAME ": "))
			(SETQ HELPFN "Type <return> followed by the password for the directory.
")))
          [COND
	    (HOST (SETQ PROMPT (CONCAT "{" HOST "} " PROMPT]
          [COND
	    (MSG (SETQ PROMPT (CONCAT MSG (CONSTANT (CHARACTER (CHARCODE EOL)))
				      PROMPT]
          (RETURN (RESETLST (PROVIDE.PROMPTING.WINDOW "Password prompter")
			    (FRESHLINE T)
			    (PROG1 [RESETBUFS (COND
						(CONNECTFLG (CONS DEFAULTNAME
								  (PROMPTFORWORD PROMPT NIL NIL T
										 (QUOTE *)
										 T TERMINATIONS)))
						(T (PROG ((NAME (PROMPTFORWORD PROMPT DEFAULTNAME 
									       HELPFN T NIL T 
									       TERMINATIONS)))
						         [COND
							   ((AND HOST DEFAULTREGISTRY
								 (SELECTQ OSTYPE
									  ((NIL IFS)
									    T)
									  NIL)
								 (NOT (STRPOS "." NAME)))
							     (PRIN1 "." T)
							     (PRIN1 DEFAULTREGISTRY T)
							     (SETQ NAME (CONCAT NAME "." 
										DEFAULTREGISTRY]
						         (RETURN (CONS (MKATOM NAME)
								       (PROMPTFORWORD " (password) " 
										      NIL NIL T
										      (QUOTE *]
				   (TERPRI T])

(PROVIDE.PROMPTING.WINDOW
  [LAMBDA (TITLE REGION)                                     (* bvm: "26-Jul-84 16:39")

          (* * Called under RESETLST -- makes sure this process has a tty window; if it doesn't, makes a dramatic one which 
	  will be closed on exit.)


    (COND
      ((AND (WINDOWWORLD)
	    (NOT (HASTTYWINDOWP)))                           (* Make a nice tty window and clean up afterwards)
	(PROG ((W (CREATEW [OR REGION (PROGN (SETQ \TTYREGIONOFFSETSPTR (OR (CDR \TTYREGIONOFFSETSPTR)
									    TTYREGIONOFFSETS))
					     (CREATEREGION (IPLUS (CAAR \TTYREGIONOFFSETSPTR)
								  (fetch (REGION LEFT) of 
									  UNSCHEDULEDPROMPTREGION))
							   (IPLUS (CDAR \TTYREGIONOFFSETSPTR)
								  (fetch (REGION BOTTOM)
								     of UNSCHEDULEDPROMPTREGION))
							   (fetch (REGION WIDTH) of 
									  UNSCHEDULEDPROMPTREGION)
							   (fetch (REGION HEIGHT) of 
									  UNSCHEDULEDPROMPTREGION]
			   (CONCAT (OR TITLE "Special input window")
				   (COND
				     ((NOT (TTY.PROCESSP))
				       "    (click here to type)")
				     (T "")))
			   12)))
	      (RESETSAVE NIL (LIST (QUOTE CLOSEW)
				   W))
	      (RESETSAVE (TTYDISPLAYSTREAM W))
	      (RESETSAVE NIL (LIST (QUOTE WINDOWPROP)
				   W
				   (QUOTE CLOSEFN)
				   NIL))
	      [WINDOWPROP W (QUOTE CLOSEFN)
			  (FUNCTION (LAMBDA (WINDOW PROC)
			      (COND
				((AND (SETQ PROC (WINDOWPROP WINDOW (QUOTE PROCESS)))
				      (PROCESSP PROC))
				  (PROCESS.APPLY PROC (FUNCTION ERROR!))
				  (QUOTE DON'T]
	      (RETURN W])

(\ADJUST.USERNAME
  [LAMBDA (NAME OSTYPE)                                      (* bvm: "24-Jul-84 18:07")
    (PROG (POS)
          (SELECTQ OSTYPE
		   [(NIL IFS)
		     (COND
		       ((AND DEFAULTREGISTRY (NOT (STRPOS "." NAME)))
			 (SETQ NAME (PACK* NAME "." DEFAULTREGISTRY]
		   [LOCAL (COND
			    ((SETQ POS (STRPOS "." NAME))    (* For folks who login at the alto exec using a 
							     registry, get rid of it)
			      (SETQ NAME (SUBSTRING NAME 1 (SUB1 POS]
		   (UNIX (SETQ NAME (L-CASE NAME)))
		   [NS (COND
			 ((AND CH.DEFAULT.DOMAIN CH.DEFAULT.ORGANIZATION (NOT (STRPOS (QUOTE :)
										      NAME)))
			   (SETQ NAME (CONCAT NAME (QUOTE :)
					      CH.DEFAULT.DOMAIN
					      (QUOTE :)
					      CH.DEFAULT.ORGANIZATION]
		   NIL)
          (RETURN NAME])

(\ENCRYPT.PWD
  [LAMBDA (STR)                                              (* bvm: " 3-NOV-83 22:09")

          (* * Destructively disguises the characters of STR so that passwords are not stored in clear text anywhere.
	  Decode with \DECRYPT.PWD, or macro \DECRYPT.PWD.CHAR)


    (for I from 1 do (RPLCHARCODE STR I (LOGXOR (OR (NTHCHARCODE STR I)
						    (RETURN STR))
						73])

(\DECRYPT.PWD
  [LAMBDA (STR)                                              (* bvm: " 3-NOV-83 22:09")
                                                             (* undoes \ENCRYPT.PWD. Easy, it being its own inverse)
    (\ENCRYPT.PWD (CONCAT STR])
)

(RPAQ? LOGINPASSWORDS (HASHARRAY 8))

(RPAQ? \GETPASSWORD.LOCK (CREATE.MONITORLOCK "GetPassword"))

(RPAQ? DEFAULTREGISTRY )

(RPAQ? \AFTERLOGINFNS )

(RPAQ? UNSCHEDULEDPROMPTREGION (QUOTE (262 466 500 100)))
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS LOGINPASSWORDS USERNAME \GETPASSWORD.LOCK DEFAULTREGISTRY \AFTERLOGINFNS 
	    UNSCHEDULEDPROMPTREGION)
)
(DECLARE: EVAL@COMPILE DONTCOPY 

(PUTPROPS EMPASSWORDLOC DMACRO (LAMBDA NIL
                                                             (* lmm "24-MAR-83 06:46")
  (fetch (IFPAGE UserPswdAddr) of \InterfacePage)))

(* FOLLOWING DEFINITIONS EXPORTED)


(DECLARE: EVAL@COMPILE 

(PUTPROPS \DECRYPT.PWD.CHAR MACRO ((CHAR)
  (LOGXOR CHAR 73)))
)


(* END EXPORTED DEFINITIONS)

)
(MOVD? (QUOTE NILL)
       (QUOTE CLBUFS))



(* PROMPTFORWORD)

(DEFINEQ

(PROMPTFORWORD
  (LAMBDA (PROMPT.STR CANDIDATE.STR GENERATE?LIST.FN ECHO.CHANNEL DONTECHOTYPEIN.FLG URGENCY.OPTION 
		      TERMINCHARS.LST KEYBD.CHANNEL)         (* JonL " 4-Sep-84 21:59")
    (DECLARE (SPECVARS TERMINCHARS.LST ECHO.CHANNEL DONTECHOTYPEIN.FLG))
    (if (NOT (TERMTABLEP \PROMPTFORWORDTTBL))
	then                                                 (* Initializes the special readtable on the first time 
							     through.)
	     (SETQ \PROMPTFORWORDTTBL (bind (TTBL ←(COPYTERMTABLE (QUOTE ORIG))) for CHAR
					 from 0 to 31 do (SELCHARQ CHAR
								   ((EOL ESCAPE SPACE LF TAB))
								   (ECHOCONTROL CHAR (QUOTE INDICATE)
										TTBL))
					 finally (PROGN (ECHOMODE NIL TTBL)
							(CONTROL T TTBL)
							(RETURN TTBL)))))
    (RESETLST (RESETSAVE (SETTERMTABLE \PROMPTFORWORDTTBL))
	      (PROG ((CHARBUFFER (if CANDIDATE.STR
				     then (DREVERSE (CHCON CANDIDATE.STR))))
		     TTYD X0Y0 TIMELIMITEXPIRED? BELLBEENHEARD? CANDIDATATE.LENGTH CHAR BEGUNTYPING? 
		     RUBBING? ?HELPMSGTRIEDP ?HELPMSGLIST TIMER)
		    (DECLARE (SPECVARS TTYD X0Y0 TIMELIMITEXPIRED? BELLBEENHEARD? CHARBUFFER RUBBING?)
			     )
		    (if (EQMEMB (QUOTE TTY)
				URGENCY.OPTION)
			then                                 (* If we're going to switch the TTY process, better do 
							     it before looking for TTYDISPLAYSTREAM etc.)
			     (OR (TTY.PROCESSP)
				 (RESETSAVE (TTY.PROCESS (THIS.PROCESS))))
			     (AND \PROMPTFORWORD.CURSOR (RESETSAVE (CURSOR \PROMPTFORWORD.CURSOR)))
		      elseif (OR (FIXP URGENCY.OPTION)
				 (SELECTQ URGENCY.OPTION
					  ((NIL T)
					    T)
					  NIL))
		      else (\ILLEGAL.ARG URGENCY.OPTION))
		    (SETQ ECHO.CHANNEL (\OUTSTREAMARG (OR ECHO.CHANNEL T)))
                                                             (* Normalize the echo channel.)
		    (SETQ TTYD (DISPLAYSTREAMP ECHO.CHANNEL))
		    (if (AND TTYD (NEQ ECHO.CHANNEL (TTYDISPLAYSTREAM)))
			then (RESETSAVE (TTYDISPLAYSTREAM ECHO.CHANNEL)))
		    (if (AND DONTECHOTYPEIN.FLG (NEQ DONTECHOTYPEIN.FLG T))
			then (SETQ DONTECHOTYPEIN.FLG (if (EQ (NCHARS DONTECHOTYPEIN.FLG)
							      1)
							  then (NTHCHARCODE DONTECHOTYPEIN.FLG 1)
							else T)))
		    (if (NULL TERMINCHARS.LST)
			then (SETQ TERMINCHARS.LST (CHARCODE (EOL ESCAPE SPACE LF TAB)))
		      elseif (CHARCODEP TERMINCHARS.LST)
			then (SETQ TERMINCHARS.LST (LIST TERMINCHARS.LST))
		      elseif (OR (NLISTP TERMINCHARS.LST)
				 (for C in TERMINCHARS.LST bind CONVERTIBLEP unless (CHARCODEP C)
				    do (if (AND (OR (LITATOM C)
						    (STRINGP C))
						(EQ 1 (NCHARS C)))
					   then (SETQ CONVERTIBLEP T)
					 else (RETURN T))
				    finally (if CONVERTIBLEP
						then         (* List not all charcodes, but all are at least charcode
							     like)
						     (SETQ TERMINCHARS.LST
						       (MAPCAR TERMINCHARS.LST
							       (FUNCTION (LAMBDA (C)
								   (OR (FIXP C)
								       (CHCON1 C)))))))))
			then (\ILLEGAL.ARG TERMINCHARS.LST))
		    (if KEYBD.CHANNEL
			then (SETQ KEYBD.CHANNEL (GETSTREAM KEYBD.CHANNEL (QUOTE INPUT))))
		    (if URGENCY.OPTION
			then (SETQ TIMER (SETUPTIMER (OR (FIXP URGENCY.OPTION)
							 0)
						     NIL
						     (QUOTE SECONDS))))

          (* * Now ready to begin. Print the prompt, gather input)


		PROMPTAGAIN
		    (if PROMPT.STR
			then (PRIN3 PROMPT.STR ECHO.CHANNEL)
			     (PRIN3 " " ECHO.CHANNEL))
		    (if TTYD
			then (SETQ X0Y0 (create POSITION
						XCOORD ←(DSPXPOSITION NIL TTYD)
						YCOORD ←(DSPYPOSITION NIL TTYD))))
		    (if CHARBUFFER
			then 

          (* If there is input, e.g. the candidate string, echo it. This is the one place calling \PROMPTFORWORDRETYPE that 
	  doesn't want the line erased first.)


			     (\PROMPTFORWORDRETYPE))
		    (until (OR (NULL (SETQ CHAR (\PROMPTFORWORDBIN KEYBD.CHANNEL TTYD URGENCY.OPTION 
								   TIMER)))
			       (FMEMB CHAR TERMINCHARS.LST))
		       do (if (SELCHARQ CHAR
					((↑A BS RUBOUT DEL)
					  (if CHARBUFFER
					      then (SETQ BEGUNTYPING? T)
						   (\PROMPTFORWORDBS)
					    else (SETQ RUBBING?))
					  NIL)
					((↑R ↑Q)
					  (if CHARBUFFER
					      then (if (NEQ DONTECHOTYPEIN.FLG T)
						       then (\PROMPTFORWORDERASE))
						   (if (EQ CHAR (CHARCODE ↑R))
						       then (\PROMPTFORWORDRETYPE)
						     else (SETQ BEGUNTYPING? T)
							  (SETQ CHARBUFFER))
					    else (SETQ RUBBING?))
					  NIL)
					((↑W)
					  (if CHARBUFFER
					      then (SETQ BEGUNTYPING? T)
						   (bind (SPACEP ←(SYNTAXP (CAR CHARBUFFER)
									   (QUOTE SEPRCHAR)
									   T))
						      do (\PROMPTFORWORDBS)
							 (if (NULL CHARBUFFER)
							     then (RETURN))
							 (SETQ CHAR (CAR CHARBUFFER))
							 (if (OR (NOT SPACEP)
								 (NOT (SYNTAXP CHAR (QUOTE SEPRCHAR)
									       T)))
							     then 
                                                             (* Finished rubbing spaces, now rub meat)
								  (SETQ SPACEP NIL)
								  (if (SYNTAXP CHAR (QUOTE WORDSEPR))
								      then (RETURN))))
					    else (SETQ RUBBING?))
					  NIL)
					((↑V)
					  (if (NOT DONTECHOTYPEIN.FLG)
					      then 

          (* Well, so echo the ↑V SO THAT THE LOSER CAN SEE THAT HE'S IN THE STATE OF WAITING FOR THE NEXT CHARACTER AFTER A
	  ↑V)


						   (if (AND RUBBING? (NOT TTYD))
						       then (BOUT ECHO.CHANNEL (CHARCODE \))
							    (SETQ RUBBING?))
						   (PRIN3 (CONSTANT (CHARACTER (CHARCODE ↑V)))
							  ECHO.CHANNEL))
					  (if (NULL (SETQ CHAR (\PROMPTFORWORDBIN KEYBD.CHANNEL TTYD 
										  URGENCY.OPTION 
										  TIMER T)))
					      then (RETURN T))
					  (if (AND TTYD (NOT DONTECHOTYPEIN.FLG)
						   (NULL (DSPRUBOUTCHAR TTYD (CHARCODE ↑V))))
					      then           (* Well, we tried to erase the ↑V so that the typed-in 
							     charcter could be echoed, but apparently the ↑V was 
							     split between lines.)
						   (\PROMPTFORWORDERASE)
						   (\PROMPTFORWORDRETYPE))
					  T)
					((?)
					  (FRESHLINE ECHO.CHANNEL)
					  (if (AND GENERATE?LIST.FN (NOT ?HELPMSGTRIEDP))
					      then (SETQ ?HELPMSGLIST (OR (STRINGP GENERATE?LIST.FN)
									  (APPLY* GENERATE?LIST.FN 
										  PROMPT.STR 
										  CANDIDATE.STR)))
						   (SETQ ?HELPMSGTRIEDP T)
					    elseif (NOT ?HELPMSGTRIEDP)
					      then (SETQ ?HELPMSGLIST (QUOTE ??)))
					  (if (LISTP ?HELPMSGLIST)
					      then (PRIN3 (QUOTE {)
							  ECHO.CHANNEL)
						   (PRIN3 (CONSTANT (CHARACTER (CHARCODE SPACE)))
							  ECHO.CHANNEL)
						   (MAPC ?HELPMSGLIST
							 (FUNCTION (LAMBDA (X)
							     (PRIN1 X ECHO.CHANNEL)
							     (PRIN3 (CONSTANT (CHARACTER
										(CHARCODE SPACE)))
								    ECHO.CHANNEL))))
						   (PRIN3 (QUOTE })
							  ECHO.CHANNEL)
					    else (PRIN1 ?HELPMSGLIST ECHO.CHANNEL) 
                                                             (* FOO we'd really like this FRESHLINE to be just a 
							     MOVETO some initial position.))
					  (FRESHLINE ECHO.CHANNEL)
					  (GO PROMPTAGAIN))
					T)
			      then                           (* If the SELCHARQ does't select out any of its 
"special" characters, then just fall through here)
				   (if (AND (NOT BEGUNTYPING?)
					    CHARBUFFER)
				       then                  (* This is the case of the CANDIDATE.STR having been 
							     proffered, but the user starts typing something else.)
					    (if (NOT DONTECHOTYPEIN.FLG)
						then         (* Don't need to do anything if type-in isn't being 
							     echoed)
						     (\PROMPTFORWORDERASE))
					    (SETQ CHARBUFFER))
				   (push CHARBUFFER CHAR)
				   (SETQ BEGUNTYPING? T)
				   (if (NEQ DONTECHOTYPEIN.FLG T)
				       then                  (* Well, so echo the typed-in character already!)
					    (if (AND RUBBING? (NOT TTYD))
						then (PRIN3 (QUOTE \)
							    ECHO.CHANNEL)
						     (SETQ RUBBING?))
					    (PRIN3 (CHARACTER (OR DONTECHOTYPEIN.FLG CHAR))
						   ECHO.CHANNEL))))
		    (SETQ CHARBUFFER (if TIMELIMITEXPIRED?
					 then                (* Ha, we overflowed the time limit.)
					      (if CANDIDATE.STR
						  then (CONCAT CANDIDATE.STR))
				       elseif CHARBUFFER
					 then (CONCATCODES (DREVERSE CHARBUFFER))))
		    (if (AND \DRIBBLE.OFD (EQ ECHO.CHANNEL \TERM.OFD))
			then (if PROMPT.STR
				 then (PRIN1 PROMPT.STR \DRIBBLE.OFD)
				      (SPACES 1 \DRIBBLE.OFD))
			     (if (AND CHARBUFFER (NULL DONTECHOTYPEIN.FLG))
				 then (PRIN1 CHARBUFFER \DRIBBLE.OFD)))
		    (RETURN CHARBUFFER)))))

(\PROMPTFORWORDBIN
  (LAMBDA (INSTREAM DISPLAYECHOSTREAM URGENCY.OPTION TIMER)
                                                             (* JonL "29-Jul-84 22:05")
                                                             (* Takes in one character from the KEYBD.CHANNEL)
    (DECLARE (USEDFREE TERMINCHARS.LST TIMELIMITEXPIRED? BELLBEENHEARD?))
    (PROG ((WAITINTERVAL.secs 15)
	   (TTYWAITLIMIT (if URGENCY.OPTION
			     then (if BELLBEENHEARD?
				      then 30000
				    else 0)))
	   CHAR READABLE)
      NEXTROUND
          (if (AND URGENCY.OPTION (NOT (FIXP URGENCY.OPTION)))
	      then (SETUPTIMER WAITINTERVAL.secs TIMER (QUOTE SECONDS)))
      LP  (if (SETQ READABLE (OR INSTREAM (WAIT.FOR.TTY TTYWAITLIMIT)))
	      then                                           (* Ready to read)
		   (if (SETQ CHAR (if (NULL INSTREAM)
				      then (\GETSYSBUF)
				    elseif (READP INSTREAM T)
				      then (BIN INSTREAM)
				    elseif (\EOFP INSTREAM)
				      then (CAR TERMINCHARS.LST)))
		       then (RETURN CHAR))
		   (if DISPLAYECHOSTREAM
		       then                                  (* \TTYBACKGROUND so that a caret will flash)
			    (\TTYBACKGROUND)
		     else (BLOCK)))
          (if (AND TIMER (TIMEREXPIRED? TIMER (QUOTE SECONDS)))
	      then (if (NEQ URGENCY.OPTION T)
		       then (SETQ TIMELIMITEXPIRED? T)
			    (RETURN))
	    else (SETQ TTYWAITLIMIT 30000)
		 (AND READABLE (GO LP)))
          (if (NULL BELLBEENHEARD?)
	      then (SETQ BELLBEENHEARD? T)
		   (SELECTQ (MACHINETYPE)
			    (DANDELION (RINGBELLS))
			    NIL))
          (FLASHWINDOW DISPLAYECHOSTREAM NIL 350)
          (if (TTY.PROCESSP)
	      then (SETQ WAITINTERVAL.secs (IMIN (LLSH WAITINTERVAL.secs 1)
						 (TIMES 2 60))))
                                                             (* Double the wait interval time 
							     (the time between "flashings") up to about 2 minutes, so
							     that it doesn't become obnoxious)
          (GO NEXTROUND))))

(\PROMPTFORWORDERASE
  (LAMBDA NIL                                                (* JonL "29-Jul-84 21:45")
    (DECLARE (USEDFREE TTYD X0Y0 ECHO.CHANNEL))              (* Called whenever the CHARBUFFER is being cleared out, 
							     or when it is necessary to retype the whole series of 
							     input characters)

          (* If TTYD is non-null, then it is guaranteed to be a display stream. X0Y0 is a POSITION where the user started 
	  typing in (or where the default CANDIDATE was started) Erase that portion of the screen.)


    (if TTYD
	then (PROG ((Y (DSPYPOSITION NIL TTYD))
		    (0X (fetch XCOORD of X0Y0))
		    (0Y (fetch YCOORD of X0Y0)))
	           (MOVETO 0X 0Y TTYD)
	           (DSPCLEOL TTYD 0X)
	           (if (NOT (IEQP 0Y Y))
		       then                                  (* Foobar, how can you tell if the stupid window has 
							     been scrolling?)
			    (DSPCLEOL TTYD (DSPLEFTMARGIN NIL TTYD)
				      (IDIFFERENCE Y (FONTDESCENT TTYD))
				      (IDIFFERENCE 0Y Y))))
      else (TERPRI ECHO.CHANNEL))))

(\PROMPTFORWORDBS
  (LAMBDA NIL                                                (* JonL "29-Jul-84 21:47")
    (DECLARE (USEDFREE TTYD DONTECHOTYPEIN.FLG RUBBING? ECHO.CHANNEL CHARBUFFER))
    (PROG (C (CH (pop CHARBUFFER)))
          (if (NEQ DONTECHOTYPEIN.FLG T)
	      then (SETQ C (OR DONTECHOTYPEIN.FLG CH))
		   (if TTYD
		       then (if (NULL (DSPRUBOUTCHAR TTYD C))
				then (\PROMPTFORWORDERASE)
				     (\PROMPTFORWORDRETYPE))
		     else (if (NOT RUBBING?)
			      then (PRIN3 (QUOTE \)
					  ECHO.CHANNEL)
				   (SETQ RUBBING? T))
			  (PRIN3 (CHARACTER C)
				 ECHO.CHANNEL)))
          (RETURN C))))

(\PROMPTFORWORDRETYPE
  (LAMBDA NIL                                                (* JonL "29-Jul-84 21:52")
    (DECLARE (USEDFREE DONTECHOTYPEIN.FLG ECHO.CHANNEL CHARBUFFER))

          (* * Retypes input as seen so far. All callers except one have already done a \PROMPTFORWORDERASE so the 
	  ECHO.CHANNEL will be positioned correctly.)


    (if (NEQ DONTECHOTYPEIN.FLG T)
	then (for CHAR in (REVERSE CHARBUFFER) do (BOUT ECHO.CHANNEL (OR DONTECHOTYPEIN.FLG CHAR))))))
)

(RPAQ? \PROMPTFORWORDTTBL NIL)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS \PROMPTFORWORDTTBL)
)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(LOCALVARS)
)
(PUTPROPS PASSWORDS COPYRIGHT ("Xerox Corporation" 1982 1983 1984))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1259 12397 (LOGIN 1269 . 1933) (SETPASSWORD 1935 . 2549) (\INTERNAL/GETPASSWORD 2551 . 
7382) (\LOGIN.READ 7384 . 9314) (PROVIDE.PROMPTING.WINDOW 9316 . 10907) (\ADJUST.USERNAME 10909 . 
11711) (\ENCRYPT.PWD 11713 . 12127) (\DECRYPT.PWD 12129 . 12395)) (13252 26770 (PROMPTFORWORD 13262 . 
22312) (\PROMPTFORWORDBIN 22314 . 24442) (\PROMPTFORWORDERASE 24444 . 25572) (\PROMPTFORWORDBS 25574
 . 26252) (\PROMPTFORWORDRETYPE 26254 . 26768)))))
STOP