(FILECREATED "24-Oct-85 17:49:01" {QV}<NOTECARDS>RELEASE1.2I>LIBRARY>LEXDEMO.;16 17489  

      changes to:  (FNS UNDERLINETEXT DISPLAYPAIRFROM DIALPHONENUMBER LISTEN DEALWITH 
			CHANGEDISPLAYSTATE GETCHARATTRIBUTE GETESCAPESEQUENCE PRINT.INPUTBLOCK 
			REVERSETEXT LEXDEMO.TURNON LEXDEMO.SHUTOFF SPECIALFUNCTIONKEYS TALK)
		   (VARS LEXDEMOCOMS)

      previous date: "23-Oct-85 23:31:01" {QV}<NOTECARDS>RELEASE1.2I>LIBRARY>LEXDEMO.;6)


(* Copyright (c) 1985 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT LEXDEMOCOMS)

(RPAQQ LEXDEMOCOMS ((FNS LEXDEMO.MakeMainMenu LEXDEMO.TURNON SPECIALFUNCTIONKEYS LISTEN 
			 CHANGEDISPLAYSTATE CREPLACE DEALWITH DIALPHONENUMBER DISPLAYPAIRFROM 
			 GETCHARATTRIBUTE GETESCAPESEQUENCE PHONEPADMENU PRINT.INPUTBLOCK REVERSETEXT 
			 UNDERLINETEXT TALK LEXDEMO.SHUTOFF)
	(P (LOAD? (QUOTE {ERIS}<SCHOEN>INTERMEZZO>RS232>DLRS232C.DCOM))
	   (LOAD? (QUOTE {ERIS}<SCHOEN>INTERMEZZO>RS232>RS232CHAT.DCOM)))
	(P (MOVEW (SETQ LEXDEMO.MainMenu (ADDMENU (LEXDEMO.MakeMainMenu NC.MainMenuWindow)))
		  (fetch LEFT of (GETWINDOWPROP NC.MainMenuWindow (QUOTE REGION)))
		  (DIFFERENCE (fetch BOTTOM of (GETWINDOWPROP NC.MainMenuWindow (QUOTE REGION)))
			      (fetch HEIGHT of (GETWINDOWPROP LEXDEMO.MainMenu (QUOTE REGION))))))))
(DEFINEQ

(LEXDEMO.MakeMainMenu
  [LAMBDA (MAINWINDOW)                                       (* Todd "28-Aug-85 16:26")
    (create MENU
	    ITEMS ←[LIST (LIST "ON" (QUOTE (LEXDEMO.TURNON)))
			 (LIST "OFF" (QUOTE (LEXDEMO.SHUTOFF]
	    TITLE ← "Lexis Interface"
	    CENTERFLG ← T
	    MENUFONT ←(FONTCREATE (QUOTE HELVETICA)
				  12
				  (QUOTE BRR))
	    MENUCOLUMNS ← 2
	    ITEMHEIGHT ← 25
	    ITEMWIDTH ←(IQUOTIENT (DIFFERENCE (fetch WIDTH of (GETWINDOWPROP MAINWINDOW (QUOTE REGION)
									     ))
					      2)
				  2)
	    MENUBORDERSIZE ← 1])

(LEXDEMO.TURNON
  (LAMBDA NIL                                                (* fgh: "24-Oct-85 00:05")

          (* * LEXDEMO.TURNON initiates an RS232 interface to a LEXIS/NEXIS host machine. It creates a record of the 
	  transception, which is saved as {DSK}<LISPFILES>LEXIS-SESSION, and provides a shift-selection capability while the 
	  transception is in progress. --- John Todd)


    (PROG ((LEXSTREAM (OPENSTREAM (QUOTE {CORE}LEXIS-SESSION)
				  (QUOTE BOTH)))
	   (LEXWINDOW (CREATEW (GETBOXREGION 600 400 NIL NIL NIL 
					     "Please specify area for LEXIS display window")
			       "LEXIS display window"))
	   (REPLYWINDOW (CREATEW (CREATEREGION 0 0 600 80)
				 NIL 8))
	   TextStream TempString TempStringStream InsertString RS232InputStream RS232OutputStream 
	   FUNCTIONKEYS.MENU)
          (SETQ TextStream (OPENTEXTSTREAM NIL LEXWINDOW NIL NIL (QUOTE (READONLY T))))
          (SETQ TempStringStream (OPENSTRINGSTREAM (SETQ TempString (ALLOCSTRING 8000))
						   (QUOTE BOTH)))
          (SETQ InsertString "")
          (ATTACHWINDOW REPLYWINDOW LEXWINDOW (QUOTE BOTTOM)
			(QUOTE LEFT))
          (SETQ FUNCTIONKEYS.MENU (ADDMENU (SPECIALFUNCTIONKEYS LEXWINDOW)))
          (SETQ LEXDEMOWINDOWS (LIST LEXWINDOW REPLYWINDOW FUNCTIONKEYS.MENU))
          (ATTACHWINDOW FUNCTIONKEYS.MENU LEXWINDOW (QUOTE RIGHT)
			(QUOTE BOTTOM))
          (RS232C.INIT 1200 7 (QUOTE EVEN)
		       1)
          (SETQ RS232InputStream (OPENSTREAM (QUOTE {RS232})
					     (QUOTE INPUT)))
          (SETQ RS232OutputStream (RS232C.OTHER.STREAM RS232InputStream))
          (WINDOWPROP FUNCTIONKEYS.MENU (QUOTE RS232OutputStream)
		      RS232OutputStream)
          (WINDOWPROP LEXWINDOW (QUOTE RS232OutputStream)
		      RS232OutputStream)
          (WINDOWPROP LEXWINDOW (QUOTE RS232InputStream)
		      RS232InputStream)
          (DIALPHONENUMBER RS232OutputStream)
          (ADD.PROCESS (LIST (QUOTE LISTEN)
			     LEXSTREAM LEXWINDOW FUNCTIONKEYS.MENU TextStream TempString 
			     TempStringStream InsertString RS232InputStream RS232OutputStream))
          (ADD.PROCESS (LIST (QUOTE TALK)
			     REPLYWINDOW RS232OutputStream)))))

(SPECIALFUNCTIONKEYS
  (LAMBDA (WINDOW)                                           (* fgh: "23-Oct-85 23:57")
    (create MENU
	    ITEMS ←(QUOTE (("NEXT PAGE" ".NP")
			    ("PREVIOUS PAGE" ".PP")
			    ("FIRST PAGE" ".FP")
			    ("NEXT DOCUMENT" ".ND")
			    ("PREVIOUS DOCUMENT" ".PD")
			    ("FIRST DOCUMENT" ".FD")
			    ("KWIC" ".KW")
			    ("FULL" ".FU")
			    ("CITE" ".CI")
			    ("SEGMTS" ".SE")
			    ("SELECT SERV" ".SS")
			    ("EXIT SERV" ".ES")
			    ("PRINT DOCUMENT" ".PR")
			    ("MAIL IT" ".MI")
			    ("SCREEN PRINT" ".SP")
			    ("NEW SEARCH" ".NS")
			    ("CHANGE FILE" ".CF")
			    ("CHANGE LIBRARY" ".CL")
			    ("SIGN OFF" ".SO")))
	    TITLE ← "SPECIAL KEY FUNCTIONS"
	    CENTERFLG ← T
	    MENUFONT ←(FONTCREATE (QUOTE HELVETICA)
				  10
				  (QUOTE BOLD))
	    MENUCOLUMNS ← 2
	    MENUBORDERSIZE ← 1
	    WHENSELECTEDFN ←(FUNCTION (LAMBDA (ITEM MENUNAME MOUSEKEY)
		(LET ((RS232OutputStream (WINDOWPROP (WFROMMENU MENUNAME)
						     (QUOTE RS232OutputStream))))
		  (PRIN1 (CONCAT (CADR ITEM)
				 (CHARACTER 13))
			 RS232OutputStream)
		  (FORCEOUTPUT RS232OutputStream)))))))

(LISTEN
  (LAMBDA (LEXSTREAM LEXWINDOW FUNCTIONKEYS.MENU TextStream TempString TempStringStream InsertString 
		     RS232InputStream RS232OutputStream)     (* fgh: "24-Oct-85 09:58")

          (* * comment)


    (LET ((ReadpEvent (RS232C.READP.EVENT RS232InputStream)))
      (PUTWINDOWPROP LEXWINDOW (QUOTE CHARDISPLAYBEGIN)
		     0)
      (PUTWINDOWPROP LEXWINDOW (QUOTE CHARDISPLAYSTATE)
		     (QUOTE NORMAL))
      (PUTWINDOWPROP LEXWINDOW (QUOTE PAGEBEGIN)
		     0)
      (PUTWINDOWPROP LEXWINDOW (QUOTE REVLIST)
		     (TCONC NIL 1))
      (PUTWINDOWPROP LEXWINDOW (QUOTE UNDLIST)
		     (TCONC NIL 1))
      (while T
	 do (AWAIT.EVENT ReadpEvent)
	    (while (READP RS232InputStream) do (DEALWITH (BIN RS232InputStream)
							 RS232InputStream TempStringStream LEXSTREAM 
							 LEXWINDOW))
	    (PRINT.INPUTBLOCK TempString TempStringStream InsertString TextStream LEXWINDOW)))))

(CHANGEDISPLAYSTATE
  (LAMBDA (DISPLAYWINDOW NEWSTATE TempStringStream)          (* fgh: "24-Oct-85 09:17")
    (LET ((CHARDISPLAYSTATE (GETWINDOWPROP DISPLAYWINDOW (QUOTE CHARDISPLAYSTATE)))
       (CHARDISPLAYBEGIN (GETWINDOWPROP DISPLAYWINDOW (QUOTE CHARDISPLAYBEGIN))))
      (COND
	((EQUAL CHARDISPLAYSTATE NEWSTATE)
	  NIL)
	(T (COND
	     ((EQUAL CHARDISPLAYSTATE (QUOTE REVERSE))
	       (TCONC (GETWINDOWPROP DISPLAYWINDOW (QUOTE REVLIST))
		      (DISPLAYPAIRFROM CHARDISPLAYBEGIN TempStringStream)))
	     ((EQUAL CHARDISPLAYSTATE (QUOTE UNDERLINE))
	       (TCONC (GETWINDOWPROP DISPLAYWINDOW (QUOTE UNDLIST))
		      (DISPLAYPAIRFROM CHARDISPLAYBEGIN TempStringStream))))
	   (WINDOWPROP DISPLAYWINDOW (QUOTE CHARDISPLAYBEGIN)
		       (GETFILEPTR TempStringStream))))
      NEWSTATE)))

(CREPLACE
  [LAMBDA (INCHAR)                                           (* Todd "13-Jun-85 16:42")
    (SELECTQ INCHAR
	     (0 32)
	     (10 32)
	     (127 32)
	     (NIL 32)
	     (LOGAND 127 INCHAR])

(DEALWITH
  (LAMBDA (INCHAR RS232InputStream TempStringStream LEXSTREAM LEXWINDOW)
                                                             (* fgh: "24-Oct-85 09:58")

          (* * Looking for acceptable control characters.)


    (AND LEXSTREAM (BOUT LEXSTREAM INCHAR))
    (SELECTQ (CREPLACE INCHAR)
	     (7 (RINGBELLS))
	     (27 (GETESCAPESEQUENCE LEXWINDOW (BIN RS232InputStream)
				    RS232InputStream TempStringStream))
	     (BOUT TempStringStream (CREPLACE INCHAR)))))

(DIALPHONENUMBER
  (LAMBDA (RS232OutputStream)                                (* fgh: "24-Oct-85 14:49")

          (* * comment)


    (PROG (PrintString CH (KEYPADMENU (ADDMENU (PHONEPADMENU))))
          (PROMPTPRINT "Please dial desired telephone number.")
          (PUTWINDOWPROP KEYPADMENU (QUOTE PROCESS)
			 (THIS.PROCESS))
          (WINDOWPROP KEYPADMENU (QUOTE DIALEVENT)
		      (CREATE.EVENT))
          (PUTWINDOWPROP KEYPADMENU (QUOTE BUFFER)
			 NIL)
          (SETQ PrintString (CONCAT "I" (CHARACTER 13)))
          (while (SETQ CH (GNC PrintString))
	     do (PRIN1 CH RS232OutputStream)
		(FORCEOUTPUT RS232OutputStream))
          (DISMISS 10000)
          (SETQ PrintString (CONCAT (CHARACTER 5)
				    (CHARACTER 13)))
          (while (SETQ CH (GNC PrintString))
	     do (PRIN1 CH RS232OutputStream)
		(FORCEOUTPUT RS232OutputStream))
          (DISMISS 1000)
          (SETQ PrintString (CONCAT "D" (CHARACTER 13)))
          (while (SETQ CH (GNC PrintString))
	     do (PRIN1 CH RS232OutputStream)
		(FORCEOUTPUT RS232OutputStream))
          (DISMISS 1000)
          (SETQ PrintString (CONCAT (PROGN (AWAIT.EVENT (WINDOWPROP KEYPADMENU (QUOTE DIALEVENT)))
					   (WINDOWPROP KEYPADMENU (QUOTE BUFFER)))
				    (CHARACTER 13)))
          (while (SETQ CH (GNC PrintString))
	     do (PRIN1 CH RS232OutputStream)
		(FORCEOUTPUT RS232OutputStream))
          (DISMISS 1000)
          (SETQ PrintString (CONCAT (CHARACTER 13)))
          (while (SETQ CH (GNC PrintString))
	     do (PRIN1 CH RS232OutputStream)
		(FORCEOUTPUT RS232OutputStream)))))

(DISPLAYPAIRFROM
  (LAMBDA (DISPLAYBEGIN TempStringStream)                    (* fgh: "24-Oct-85 17:04")

          (* * comment)


    (CONS (ADD1 DISPLAYBEGIN)
	  (DIFFERENCE (GETFILEPTR TempStringStream)
		      (ADD1 DISPLAYBEGIN)))))

(GETCHARATTRIBUTE
  (LAMBDA (LEXWINDOW INCHAR RS232InputStream TempStringStream)
                                                             (* fgh: "24-Oct-85 09:18")

          (* * Control character indicates a change of display mode. What to change it to?)


    (SELECTQ (CREPLACE INCHAR)
	     (48 (WINDOWPROP LEXWINDOW (QUOTE CHARDISPLAYSTATE)
			     (CHANGEDISPLAYSTATE LEXWINDOW (QUOTE NORMAL)
						 TempStringStream))
		 (GETCHARATTRIBUTE LEXWINDOW (BIN RS232InputStream)
				   RS232InputStream TempStringStream))
	     (50 (CREPLACE (BIN RS232InputStream)))
	     (52 (WINDOWPROP LEXWINDOW (QUOTE CHARDISPLAYSTATE)
			     (CHANGEDISPLAYSTATE LEXWINDOW (QUOTE UNDERLINE)
						 TempStringStream))
		 (GETCHARATTRIBUTE LEXWINDOW (BIN RS232InputStream)
				   RS232InputStream TempStringStream))
	     (55 (WINDOWPROP LEXWINDOW (QUOTE CHARDISPLAYSTATE)
			     (CHANGEDISPLAYSTATE LEXWINDOW (QUOTE REVERSE)
						 TempStringStream))
		 (GETCHARATTRIBUTE LEXWINDOW (BIN RS232InputStream)
				   RS232InputStream TempStringStream))
	     NIL)))

(GETESCAPESEQUENCE
  (LAMBDA (LEXWINDOW NEXTCHAR RS232InputStream TempStringStream)
                                                             (* fgh: "24-Oct-85 09:19")

          (* * Found conrol character. What does it mean?)


    (SELECTQ (CREPLACE NEXTCHAR)
	     (61 NIL)
	     (91 (GETCHARATTRIBUTE LEXWINDOW (BIN RS232InputStream)
				   RS232InputStream TempStringStream))
	     NIL)))

(PHONEPADMENU
  [LAMBDA NIL                                                (* GSC "17-Oct-85 23:42")
    (create MENU
	    ITEMS ←(QUOTE (1 2 3 4 5 6 7 8 9 * 0 # "," "Done" "Redial"))
	    TITLE ← "Phone keypad"
	    CENTERFLG ← T
	    MENUCOLUMNS ← 3
	    MENUFONT ←(FONTCREATE (QUOTE HELVETICA)
				  12
				  (QUOTE BRR))
	    ITEMHEIGHT ← 30
	    ITEMWIDTH ← 45
	    MENUBORDERSIZE ← 1
	    WHENSELECTEDFN ←(FUNCTION (LAMBDA (ITEM MENU BUTTON)
		(COND
		  ((EQUAL ITEM "Done")
		    (NOTIFY.EVENT (WINDOWPROP (WFROMMENU MENU)
					      (QUOTE DIALEVENT)))
		    (CLOSEW (WFROMMENU MENU))
		    (CLEARW PROMPTWINDOW))
		  ((EQUAL ITEM "Redial")
		    (WINDOWPROP (WHICHW)
				(QUOTE BUFFER)
				NIL)
		    (PROMPTPRINT "Please dial desired telephone number."))
		  (T (PRIN1 ITEM PROMPTWINDOW)
		     (WINDOWPROP (WHICHW)
				 (QUOTE BUFFER)
				 (COND
				   ((NULL (GETWINDOWPROP (WHICHW)
							 (QUOTE BUFFER)))
				     (MKSTRING ITEM))
				   (T (CONCAT (GETWINDOWPROP (WHICHW)
							     (QUOTE BUFFER))
					      ITEM])

(PRINT.INPUTBLOCK
  (LAMBDA (TempString TempStringStream InsertString TextStream LEXWINDOW)
                                                             (* fgh: "24-Oct-85 09:56")

          (* * The host machine has stopped transmitting for WAITTIME. Respond by displaying the host machine's output.)


    (LET (InsertPoint)
      (AND (SUBSTRING TempString 1 (GETFILEPTR TempStringStream)
		      InsertString)
	   (TEDIT.INSERT TextStream InsertString (SETQ InsertPoint (GETEOFPTR TextStream))
			 NIL NIL))
      (SETFILEPTR TempStringStream 0)
      (WINDOWPROP LEXWINDOW (QUOTE REVLIST)
		  (REVERSETEXT LEXWINDOW TextStream InsertPoint))
      (WINDOWPROP LEXWINDOW (QUOTE UNDLIST)
		  (UNDERLINETEXT LEXWINDOW TextStream InsertPoint))
      (WINDOWPROP LEXWINDOW (QUOTE CHARDISPLAYBEGIN)
		  0)
      NIL)))

(REVERSETEXT
  (LAMBDA (DISPLAYWINDOW TextStream InsertPoint)             (* fgh: "24-Oct-85 09:54")

          (* * An input block has been read. Given the positions and lengths of reverse-videod sections in REVLIST, display 
	  the text block.)


    (PROG ((REVLIST (GETWINDOWPROP DISPLAYWINDOW (QUOTE REVLIST)))
	   SELECTION)
          (for X in (NTH (CAR REVLIST)
			 2)
	     do (SETQ SELECTION (TEDIT.SETSEL TextStream (IPLUS InsertPoint (CAR X))
					      (CDR X)
					      (QUOTE LEFT)))
		(TEDIT.LOOKS TextStream (QUOTE (FACE BRR))))
          (TEDIT.SHOWSEL TextStream NIL)
          (RETURN (TCONC NIL 1)))))

(UNDERLINETEXT
  (LAMBDA (DISPLAYWINDOW TextStream InsertPoint)             (* fgh: "24-Oct-85 17:48")

          (* * An input block has been read. Given the positions and lengths of underlined sections in UNDLIST, display the 
	  text block.)


    (AND NIL (PROG ((UNDLIST (GETWINDOWPROP DISPLAYWINDOW (QUOTE UNDLIST)))
		    SELECTION)
	           (for X in (NTH (CAR UNDLIST)
				  2)
		      do (SETQ SELECTION (TEDIT.SETSEL TextStream (IPLUS InsertPoint (CAR X))
						       (CDR X)
						       (QUOTE LEFT)))
			 (TEDIT.LOOKS TextStream (QUOTE (UNDERLINE ON))))
	           (TEDIT.SHOWSEL TextStream NIL)
	           (RETURN (TCONC NIL 1))))))

(TALK
  (LAMBDA (REPLYWINDOW RS232OutputStream)                    (* fgh: "23-Oct-85 23:54")

          (* * comment)


    (TTY.PROCESS (THIS.PROCESS))
    (while T
       do (PRIN1 (CONCAT (COND
			   ((PROMPTFORWORD ">" NIL NIL REPLYWINDOW NIL NIL
					   (LIST 9 10 13 27)))
			   (T ""))
			 (CHARACTER 13))
		 RS232OutputStream)
	  (FORCEOUTPUT RS232OutputStream)
	  (TERPRI REPLYWINDOW))))

(LEXDEMO.SHUTOFF
  (LAMBDA NIL                                                (* fgh: "24-Oct-85 00:02")

          (* * comment)


    (DEL.PROCESS (QUOTE TALK))
    (DEL.PROCESS (QUOTE LISTEN))                             (* CLOSEF RS232InputStream)
                                                             (* CLOSEF RS232OutputStream)
    (COND
      ((BOUNDP (QUOTE LEXDEMOWINDOWS))
	(for WINDOW in LEXDEMOWINDOWS do (CLOSEW WINDOW))))
    (CLEARW PROMPTWINDOW)
    (PRIN1 (CONCAT "Closing LEXIS connection ... " (CHARACTER 13))
	   PROMPTWINDOW)
    (COND
      ((OPENP (QUOTE {CORE}LEXIS-SESSION))
	(CLOSEF (QUOTE {CORE}LEXIS-SESSION))
	(PRIN1 (CONCAT "A record of your LEXIS session is stored as " (COPYFILE (QUOTE 
									      {CORE}LEXIS-SESSION)
										(QUOTE 
								    {DSK}<LISPFILES>LEXIS-SESSION))
		       (CHARACTER 13))
	       PROMPTWINDOW)
	(DELFILE (QUOTE {CORE}LEXIS-SESSION))))
    (PRIN1 "... connection closed." PROMPTWINDOW)
    (TERPRI PROMPTWINDOW)))
)
(LOAD? (QUOTE {ERIS}<SCHOEN>INTERMEZZO>RS232>DLRS232C.DCOM))
(LOAD? (QUOTE {ERIS}<SCHOEN>INTERMEZZO>RS232>RS232CHAT.DCOM))
(MOVEW (SETQ LEXDEMO.MainMenu (ADDMENU (LEXDEMO.MakeMainMenu NC.MainMenuWindow)))
       (fetch LEFT of (GETWINDOWPROP NC.MainMenuWindow (QUOTE REGION)))
       (DIFFERENCE (fetch BOTTOM of (GETWINDOWPROP NC.MainMenuWindow (QUOTE REGION)))
		   (fetch HEIGHT of (GETWINDOWPROP LEXDEMO.MainMenu (QUOTE REGION)))))
(PUTPROPS LEXDEMO COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1282 16975 (LEXDEMO.MakeMainMenu 1292 . 1921) (LEXDEMO.TURNON 1923 . 4284) (
SPECIALFUNCTIONKEYS 4286 . 5478) (LISTEN 5480 . 6475) (CHANGEDISPLAYSTATE 6477 . 7372) (CREPLACE 7374
 . 7591) (DEALWITH 7593 . 8127) (DIALPHONENUMBER 8129 . 9988) (DISPLAYPAIRFROM 9990 . 10260) (
GETCHARATTRIBUTE 10262 . 11417) (GETESCAPESEQUENCE 11419 . 11845) (PHONEPADMENU 11847 . 13024) (
PRINT.INPUTBLOCK 13026 . 13914) (REVERSETEXT 13916 . 14631) (UNDERLINETEXT 14633 . 15382) (TALK 15384
 . 15841) (LEXDEMO.SHUTOFF 15843 . 16973)))))
STOP