(FILECREATED " 8-Jan-86 21:50:06" {ERIS}<CUTTING>LISP>PATCH>HELPSYS.;1 14700  

      changes to:  (FNS \IRM.DISPLAY.REF)

      previous date: "13-Sep-85 12:19:09" {ERIS}<LISP>KOTO>LIBRARY>HELPSYS.;2)


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

(PRETTYCOMPRINT HELPSYSCOMS)

(RPAQQ HELPSYSCOMS [(FILES HASH TEDIT)
		      (FNS HELPSYS IRM.LOOKUP IRM.SMART.LOOKUP IRM.INIT \IRM.DISPLAY.REF 
			   \IRM.DISPLAY.FROM.MENU \IRM.GET.IRMWINDOW \IRM.PROMPT.FOR.LOOKUP 
			   \IRM.WILD.LOOKUP \IRM.WILDCARD \IRM.WILD.MATCH \IRM.GET.HASHFILE 
			   \IRM.GET.KEYWORDS)
		      (RECORDS IRMREFERENCE)
		      (INITVARS (IRM.HOST&DIR)
				(IRM.HASHFILE.NAME)
				(IRM.FONT (FONTCREATE (QUOTE HELVETICA)
						      10 NIL NIL (QUOTE DISPLAY)))
				(IRMWINDOWREGION (CREATE REGION LEFT ← (DIFFERENCE SCREENWIDTH 401)
							 BOTTOM ← 1 HEIGHT ← 350 WIDTH ← 400))
				(IRMWINDOW)
				(\IRM.HASHFILE)
				(\IRM.KEYWORDS))
		      (GLOBALVARS IRM.HASHFILE.NAME IRM.HOST&DIR IRM.FONT IRMWINDOWREGION IRMWINDOW 
				  \IRM.HASHFILE \IRM.KEYWORDS)
		      (LISPXMACROS help HELP)
		      (P (MOVD (QUOTE HELPSYS)
			       (QUOTE XHELPSYS])
(FILESLOAD HASH TEDIT)
(DEFINEQ

(HELPSYS
  [LAMBDA (FN PROPS)                                         (* drc: "15-Aug-85 16:33")

          (* * This is called by TTYIN <actually XHELPSYS is...> when FN...? <CR> is typed.)


    (COND
      ((EQ PROPS (QUOTE ARGS))                               (* HELPSYS is called by SMARTARGLIST to get args, but 
							     this implementation of HELPSYS does not support that.)
	NIL)
      ((NOT IRM.HOST&DIR)
	(PROMPTPRINT "HELPSYS is unavailable.  Set IRM.HOST&DIR.")
	NIL)
      ((FGETD FN)
	(IRM.LOOKUP FN (QUOTE Function)
		    IRMWINDOW))
      ((for MACRO.TYPE in MACROPROPS thereis (GETPROP FN MACRO.TYPE))
	(IRM.LOOKUP FN (QUOTE Macro)
		    IRMWINDOW))
      [(SELECTQ (CAR (GETPROP FN (QUOTE CLISPWORD)))
		(NIL)
		(FORWORD (IRM.LOOKUP FN (QUOTE I.S.Operator)
				     IRMWINDOW))
		(RECORDTRAN (IRM.LOOKUP FN (QUOTE RecordOperator)
					IRMWINDOW))
		(PROGN (IRM.LOOKUP FN NIL IRMWINDOW]
      (T                                                     (* DO?CMD in TTYIN interprets an error to mean 
							     undefined function and flashes the screen.)
	 (ERROR FN "UNDEFINED CAR OF FORM")))
    T])

(IRM.LOOKUP
  [LAMBDA (KEYWORD TYPE WINDOW)                              (* drc: "10-Sep-85 23:25")

          (* * Does a lookup in the IRM index for KEYWORD and displays the reference found. If TYPE is not specified then any 
	  reference is used. If more than one reference is found, a pop-up menu is raised for selection of which reference to 
	  display. WINDOW defaults to IRMWINDOW.)


    (\IRM.GET.HASHFILE)
    (SETQ KEYWORD (MKATOM (U-CASE KEYWORD)))
    (OR (WINDOWP WINDOW)
	(SETQ WINDOW (\IRM.GET.IRMWINDOW)))
    (if (OBTAIN.MONITORLOCK (WINDOWPROP WINDOW (QUOTE MONITORLOCK))
			    T)
	then [LET* (SAMEFLG (REFS (if (EQ KEYWORD (WINDOWPROP WINDOW (QUOTE PREVIOUS.KEYWORD)))
				      then (SETQ SAMEFLG T)
					   (WINDOWPROP WINDOW (QUOTE IRM.REFS))
				    else (GETHASHFILE KEYWORD \IRM.HASHFILE)))
			    REF)
	           (WINDOWPROP WINDOW (QUOTE PREVIOUS.KEYWORD)
			       KEYWORD)
	           (WINDOWPROP WINDOW (QUOTE IRM.REFS)
			       REFS)
	           (COND
		     ((NULL REFS)
		       (OPENW WINDOW)
		       (PRINTOUT (GETPROMPTWINDOW WINDOW)
				 T "No manual entry for " (OR (AND TYPE (CONCAT TYPE " "))
							      "")
				 KEYWORD))
		     ((NULL TYPE)
		       (if (NULL (CDR REFS))
			   then (\IRM.DISPLAY.REF (CAR REFS)
						  WINDOW)
			 else (\IRM.DISPLAY.FROM.MENU REFS WINDOW KEYWORD SAMEFLG)))
		     ((SETQ REF (OR (for REF in REFS thereis
						      (if (AND (EQ (fetch (IRMREFERENCE TYPE)
								      of REF)
								   TYPE)
							       (fetch (IRMREFERENCE PRIMARYFLG)
								  of REF))
							  then REF))
				    (FASSOC TYPE REFS)))
		       (\IRM.DISPLAY.REF REF WINDOW))
		     (T (OPENW WINDOW)
			(PRINTOUT (GETPROMPTWINDOW WINDOW)
				  T "No " TYPE " entry in manual for " KEYWORD]
	     (RELEASE.MONITORLOCK (WINDOWPROP WINDOW (QUOTE MONITORLOCK)))
      else (FLASHWINDOW WINDOW])

(IRM.SMART.LOOKUP
  [LAMBDA (KEYWORD WINDOW)                                   (* drc: "10-Sep-85 23:26")
    (\IRM.GET.HASHFILE)
    (SETQ KEYWORD (MKATOM (U-CASE KEYWORD)))
    (OR (WINDOWP WINDOW)
	(SETQ WINDOW (\IRM.GET.IRMWINDOW)))
    (if (OBTAIN.MONITORLOCK (WINDOWPROP WINDOW (QUOTE MONITORLOCK))
			    T)
	then (RESETLST [OR (TTY.PROCESSP (THIS.PROCESS))
			   (PROGN (TTY.PROCESS (THIS.PROCESS))
				  (RESETSAVE (TTYDISPLAYSTREAM (GETPROMPTWINDOW WINDOW]
		       (if (NULL KEYWORD)
			   then NIL
			 elseif (STRPOS "*" KEYWORD)
			   then (\IRM.WILD.LOOKUP KEYWORD WINDOW)
			 elseif \IRM.KEYWORDS
			   then (LET ((CORRECTED (MISSPELLED? KEYWORD 50 \IRM.KEYWORDS T)))
				     (if CORRECTED
					 then (IRM.LOOKUP CORRECTED NIL WINDOW)
				       else (OPENW WINDOW)
					    (PRINTOUT (GETPROMPTWINDOW WINDOW)
						      T KEYWORD " not in IRM.")))
			 else (IRM.LOOKUP KEYWORD NIL WINDOW)))
	     (RELEASE.MONITORLOCK (WINDOWPROP WINDOW (QUOTE MONITORLOCK)))
      else (FLASHWINDOW WINDOW])

(IRM.INIT
  [LAMBDA (HOST&DIR)                                         (* drc: "21-Aug-85 17:35")
    (if HOST&DIR
	then (SETQ IRM.HOST&DIR HOST&DIR))

          (* * First reset IRM)


    (AND (WINDOWP IRMWINDOW)
	 (PROGN (OPENW IRMWINDOW)
		(CLOSEW IRMWINDOW)
		(SETQ IRMWINDOW)))
    (CLOSEF? \IRM.HASHFILE)
    (SETQ \IRM.HASHFILE)

          (* * Then set it up again)


    (\IRM.GET.IRMWINDOW)
    (\IRM.GET.KEYWORDS IRMWINDOW T)
    NIL])

(\IRM.DISPLAY.REF
  [LAMBDA (REFERENCE WINDOW)                                 (* drc: "19-Dec-85 13:22")

          (* * Displays REFERENCE in WINDOW, where REFERENCE is an IRMREFERENCE fetched from \IRM.HASHFILE.)


    (LET [(TEXTSTREAM (WINDOWPROP WINDOW (QUOTE TEXTSTREAM]
         (AND TEXTSTREAM (PROGN (TEDIT.KILL TEXTSTREAM)
				    (CLOSEF? TEXTSTREAM)))
         [SETQ TEXTSTREAM (OPENTEXTSTREAM (PACKFILENAME (QUOTE HOST)
							      (FILENAMEFIELD IRM.HOST&DIR
									       (QUOTE HOST))
							      (QUOTE DEVICE)
							      (FILENAMEFIELD IRM.HOST&DIR
									       (QUOTE DEVICE))
							      (QUOTE DIRECTORY)
							      (FILENAMEFIELD IRM.HOST&DIR
									       (QUOTE DIRECTORY))
							      (QUOTE NAME)
							      (fetch (IRMREFERENCE CHAPTER)
								 of REFERENCE)
							      (QUOTE EXTENSION)
							      (QUOTE TXT))
					      WINDOW
					      (fetch (IRMREFERENCE FROM#) of REFERENCE)
					      (fetch (IRMREFERENCE TO#) of REFERENCE)
					      (BQUOTE (READONLY T CLEARGET T NOTITLE T PARALOOKS
								  (PARALEADING 5 POSTPARALEADING 5 
									       QUAD JUSTIFIED)
								  FONT , IRM.FONT]
                                                             (* This is to make the window say something reasonable
							     when shrunk.)
         (replace TXTFILE of (TEXTOBJ TEXTSTREAM) with (WINDOWPROP WINDOW (QUOTE TITLE)))
         (TERPRI (GETPROMPTWINDOW WINDOW])

(\IRM.DISPLAY.FROM.MENU
  [LAMBDA (REFS WINDOW KEYWORD SAMEFLG)                      (* drc: "10-Sep-85 23:39")
    (MENU (create MENU
		  CENTERFLG ← T
		  TITLE ←(MKSTRING KEYWORD)
		  ITEMS ←(for REF in REFS collect (LIST (LET ((TYPE (fetch (IRMREFERENCE TYPE)
								       of REF)))
							     (if (fetch (IRMREFERENCE PRIMARYFLG)
								    of REF)
								 then (PACK* "* " TYPE " *")
							       else TYPE))
							(LIST (FUNCTION \IRM.DISPLAY.REF)
							      (KWOTE REF)
							      (KWOTE WINDOW))
							(CONCAT "Lookup " KEYWORD " as "
								(fetch (IRMREFERENCE TYPE)
								   of REF])

(\IRM.GET.IRMWINDOW
  [LAMBDA (NO.MENU NEW)                                      (* drc: "13-Sep-85 12:18")
    (COND
      ((AND (NOT NEW)
	    (WINDOWP IRMWINDOW)))
      (T (SETQ IRMWINDOW (CREATEW (if NEW
				      then NIL
				    else IRMWINDOWREGION)
				  "Interlisp Reference Manual"))
	 (OR NO.MENU (ATTACHMENU (create MENU
					 ITEMS ←(BQUOTE ((Lookup (\IRM.PROMPT.FOR.LOOKUP , IRMWINDOW)
								 
					      "Will prompt for and lookup a term.  Wildcards OK.")))
					 CENTERFLG ← T)
				 IRMWINDOW))
	 (WINDOWPROP IRMWINDOW (QUOTE MONITORLOCK)
		     (CREATE.MONITORLOCK (QUOTE IRM)))
	 [WINDOWADDPROP IRMWINDOW (QUOTE CLOSEFN)
			(FUNCTION (LAMBDA (WINDOW)
			    (CLOSEHASHFILE \IRM.HASHFILE)
			    (CLOSEF? (WINDOWPROP WINDOW (QUOTE TEXTSTREAM]
	 (replace TXTFILE of (TEXTOBJ (OPENTEXTSTREAM "" IRMWINDOW)) with (WINDOWPROP IRMWINDOW
										      (QUOTE TITLE)))
	 IRMWINDOW])

(\IRM.PROMPT.FOR.LOOKUP
  [LAMBDA (WINDOW)                                           (* drc: "22-Aug-85 21:16")
    (if (OBTAIN.MONITORLOCK (WINDOWPROP WINDOW (QUOTE MONITORLOCK))
			    T)
	then (RESETLST (PROCESSPROP (THIS.PROCESS)
				    (QUOTE NAME)
				    "IRM Lookup")
		       (RESETSAVE (TTYDISPLAYSTREAM (GETPROMPTWINDOW WINDOW)))
		       (RESETSAVE (TTY.PROCESS (THIS.PROCESS)))
		       [RESETSAVE NIL (QUOTE (AND RESETSTATE (PRINTOUT T " [aborted]"]
		       (TERPRI)
		       (LET [(KEYWORD (MKATOM (U-CASE (PROMPTFORWORD "Lookup :" (WINDOWPROP
								       WINDOW
								       (QUOTE IRM.KEYWORD))
								     NIL T NIL (QUOTE TTY]
			    (WINDOWPROP WINDOW (QUOTE IRM.KEYWORD)
					KEYWORD)
			    (IRM.SMART.LOOKUP KEYWORD WINDOW)))
      else (FLASHWINDOW WINDOW])

(\IRM.WILD.LOOKUP
  [LAMBDA (KEYWORD WINDOW)                                   (* drc: "26-Aug-85 22:40")
    (OPENW WINDOW)
    (LET* [SAMEFLG (MATCHES (if (EQ KEYWORD (WINDOWPROP WINDOW (QUOTE IRM.WILD.KEYWORD)))
				then (SETQ SAMEFLG T)
				     (WINDOWPROP WINDOW (QUOTE IRM.MATCHES))
			      else (PROG2 (PRINTOUT (GETPROMPTWINDOW WINDOW)
						    T "Matching wildcard(s)...")
					  (\IRM.WILDCARD KEYWORD (\IRM.GET.KEYWORDS WINDOW))
					  (PRINTOUT (GETPROMPTWINDOW WINDOW)
						    "OK"]
          (WINDOWPROP WINDOW (QUOTE IRM.WILD.KEYWORD)
		      KEYWORD)
          (WINDOWPROP WINDOW (QUOTE IRM.MATCHES)
		      MATCHES)
          (if MATCHES
	      then [if (NULL (CDR MATCHES))
		       then (IRM.LOOKUP (CAR MATCHES)
					NIL WINDOW)
		     else (OR SAMEFLG (WINDOWPROP WINDOW (QUOTE WILD.MENU)
						  (create MENU
							  ITEMS ←(for MATCH in MATCHES
								    collect
								     (LIST MATCH (LIST (QUOTE 
										       IRM.LOOKUP)
										       (KWOTE MATCH)
										       NIL WINDOW)
									   (CONCAT "Will lookup " 
										   MATCH 
									   " in IRM if selected.")))
							  CENTERFLG ← T
							  TITLE ← KEYWORD)))
			  (MENU (WINDOWPROP WINDOW (QUOTE WILD.MENU]
	    else (PRINTOUT (GETPROMPTWINDOW WINDOW)
			   T "No matches found for " KEYWORD])

(\IRM.WILDCARD
  [LAMBDA (WILDATOM LIST)                                    (* drc: "31-Jul-85 13:01")
    (LET ((SCRATCH1 (CONS))
	  (SCRATCH2 (CONS)))
         (DECLARE (SPECVARS LIST WILDATOM SCRATCH1 SCRATCH2))
         (for ATOM in LIST join (if (\IRM.WILD.MATCH (DUNPACK WILDATOM SCRATCH1)
						     (DUNPACK ATOM SCRATCH2))
				    then (LIST ATOM])

(\IRM.WILD.MATCH
  [LAMBDA (WILDLIST LIST)                                    (* drc: "30-Jul-85 22:28")
    (COND
      ((AND (NULL WILDLIST)
	    (NULL LIST)))
      [(EQ (CAR WILDLIST)
	   (QUOTE *))
	(OR (NULL (CDR WILDLIST))
	    (for TAIL on LIST thereis (\IRM.WILD.MATCH (CDR WILDLIST)
						       TAIL]
      ((EQ (CAR WILDLIST)
	   (CAR LIST))
	(\IRM.WILD.MATCH (CDR WILDLIST)
			 (CDR LIST)))
      (T NIL])

(\IRM.GET.HASHFILE
  [LAMBDA NIL                                                (* drc: "31-Jul-85 12:55")
    (OR (ARRAYP \IRM.HASHFILE)
	(SETQ \IRM.HASHFILE (OPENHASHFILE (OR IRM.HASHFILE.NAME (PACK* IRM.HOST&DIR (QUOTE 
										     IRM.HASHFILE)))
					  (QUOTE INPUT])

(\IRM.GET.KEYWORDS
  [LAMBDA (WINDOW QUIETFLG)                                  (* drc: "21-Aug-85 17:28")
    (OR \IRM.KEYWORDS (PROG2 (OR QUIETFLG (PRINTOUT (GETPROMPTWINDOW WINDOW)
						    T "Loading keyword list..."))
			     (SETQ \IRM.KEYWORDS (GETHASHFILE (QUOTE irm.keywords)
							      (\IRM.GET.HASHFILE])
)
[DECLARE: EVAL@COMPILE 

(RECORD IRMREFERENCE (TYPE ITEM PRIMARYFLG CHAPTER FROM# TO#))
]

(RPAQ? IRM.HOST&DIR )

(RPAQ? IRM.HASHFILE.NAME )

(RPAQ? IRM.FONT (FONTCREATE (QUOTE HELVETICA)
			      10 NIL NIL (QUOTE DISPLAY)))

(RPAQ? IRMWINDOWREGION (CREATE REGION LEFT ← (DIFFERENCE SCREENWIDTH 401)
				 BOTTOM ← 1 HEIGHT ← 350 WIDTH ← 400))

(RPAQ? IRMWINDOW )

(RPAQ? \IRM.HASHFILE )

(RPAQ? \IRM.KEYWORDS )
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS IRM.HASHFILE.NAME IRM.HOST&DIR IRM.FONT IRMWINDOWREGION IRMWINDOW \IRM.HASHFILE 
	    \IRM.KEYWORDS)
)

(ADDTOVAR LISPXMACROS [help (COND ((CAR LISPXLINE)
				     (IRM.SMART.LOOKUP (CAR LISPXLINE)))
				    (T (PRINTOUT T "Use: %"HELP <variable or function name>%"" T]
			[HELP (COND ((CAR LISPXLINE)
				     (IRM.SMART.LOOKUP (CAR LISPXLINE)))
				    (T (PRINTOUT T "Use: %"HELP <variable or function name>%"" T])
(MOVD (QUOTE HELPSYS)
      (QUOTE XHELPSYS))
(PUTPROPS HELPSYS COPYRIGHT ("Xerox Corporation" 1985 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1187 13658 (HELPSYS 1197 . 2448) (IRM.LOOKUP 2450 . 4580) (IRM.SMART.LOOKUP 4582 . 5783
) (IRM.INIT 5785 . 6300) (\IRM.DISPLAY.REF 6302 . 7893) (\IRM.DISPLAY.FROM.MENU 7895 . 8601) (
\IRM.GET.IRMWINDOW 8603 . 9637) (\IRM.PROMPT.FOR.LOOKUP 9639 . 10556) (\IRM.WILD.LOOKUP 10558 . 12047)
 (\IRM.WILDCARD 12049 . 12466) (\IRM.WILD.MATCH 12468 . 12978) (\IRM.GET.HASHFILE 12980 . 13295) (
\IRM.GET.KEYWORDS 13297 . 13656)))))
STOP