(FILECREATED "15-Aug-85 16:33:26" {ERIS}<CUTTING>LISP>HELPSYS.;15 13201  

      changes to:  (VARS HELPSYSCOMS)
		   (LISPXMACROS help HELP)
		   (FNS HELPSYS IRM.LOOKUP IRM.SMART.LOOKUP \IRM.PROMPT.FOR.LOOKUP IRM.INIT 
			\IRM.WINDOW.CREATE)

      previous date: " 1-Aug-85 12:20:14" {ERIS}<CUTTING>LISP>HELPSYS.;11)


(* Copyright (c) 1985 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.WINDOW.CREATE \IRM.PROMPT.FOR.LOOKUP 
			 \IRM.WILD.LOOKUP \IRM.WILDCARD \IRM.WILD.MATCH \IRM.GET.HASHFILE 
			 \IRM.GET.KEYWORDS)
		    (DECLARE: DONTCOPY EVAL@COMPILE (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))
		    (GLOBALVARS IRM.HASHFILE.NAME IRM.HOST&DIR IRM.FONT IRMWINDOWREGION IRMWINDOW 
				\IRM.HASHFILE)
		    (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: "15-Aug-85 16:24")

          (* * 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)
    [OR (WINDOWP WINDOW)
	(SETQ WINDOW (OR (WINDOWP IRMWINDOW)
			 (SETQ IRMWINDOW (\IRM.WINDOW.CREATE]
    (if (OBTAIN.MONITORLOCK (WINDOWPROP WINDOW (QUOTE MONITORLOCK))
			    T)
	then [LET ((REFS (GETHASHFILE KEYWORD \IRM.HASHFILE))
		   REF)
	          (COND
		    ((NULL REFS)
		      (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)))
		    ((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 (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: "15-Aug-85 16:28")
    (\IRM.GET.HASHFILE)
    [OR (WINDOWP WINDOW)
	(SETQ WINDOW (OR (WINDOWP IRMWINDOW)
			 (SETQ IRMWINDOW (\IRM.WINDOW.CREATE]
    (if (OBTAIN.MONITORLOCK (WINDOWPROP WINDOW (QUOTE MONITORLOCK))
			    T)
	then (if (NULL KEYWORD)
		 then NIL
	       elseif (STRPOS "*" KEYWORD)
		 then (\IRM.WILD.LOOKUP KEYWORD WINDOW)
	       elseif (SETQ KEYWORD (MISSPELLED? KEYWORD 50 (\IRM.GET.KEYWORDS WINDOW)
						 T))
		 then (IRM.LOOKUP KEYWORD NIL WINDOW)
	       else (PRINTOUT T T (WINDOWPROP WINDOW (QUOTE LOOKUP.WORD))
			      " not in IRM."))
	     (RELEASE.MONITORLOCK (WINDOWPROP WINDOW (QUOTE MONITORLOCK)))
      else (FLASHWINDOW WINDOW])

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

          (* * First reset IRM)


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

          (* * Then set it up again)


    (SETQ IRMWINDOW (\IRM.WINDOW.CREATE))
    (\IRM.GET.KEYWORDS IRMWINDOW)
    NIL])

(\IRM.DISPLAY.REF
  [LAMBDA (REFERENCE WINDOW)                                 (* drc: "31-Jul-85 17:17")

          (* * 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 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]
                                                             (* have to do this every time, as OPENTEXTSTREAM 
							     trashes this windowprop)
         [WINDOWPROP WINDOW (QUOTE CLOSEFN)
		     (FUNCTION (LAMBDA (WINDOW)
			 (CLOSEHASHFILE \IRM.HASHFILE)
			 (CLOSEF? (WINDOWPROP WINDOW (QUOTE TEXTSTREAM)))
			 (CLOSEATTACHEDWINDOWS WINDOW]       (* 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)                              (* drc: "31-Jul-85 12:10")
    (MENU (create MENU
		  CENTERFLG ← T
		  TITLE ←(MKSTRING KEYWORD)
		  ITEMS ←(for REF in REFS collect (LIST (fetch (IRMREFERENCE TYPE) of REF)
							(LIST (FUNCTION \IRM.DISPLAY.REF)
							      (KWOTE REF)
							      (KWOTE WINDOW))
							(CONCAT "select the definiton of " KEYWORD 
								" you are interested in"])

(\IRM.WINDOW.CREATE
  [LAMBDA NIL                                                (* drc: "15-Aug-85 14:10")
    (LET ((W (CREATEMENUEDWINDOW (create MENU
					 ITEMS ←(QUOTE ((Lookup (\IRM.PROMPT.FOR.LOOKUP
								  (WINDOWPROP (WHICHW)
									      (QUOTE MAINWINDOW)))
								
					      "Will prompt for and lookup a term.  Wildcards OK.")))
					 CENTERFLG ← T)
				 "Interlisp Reference Manual" NIL IRMWINDOWREGION)))
         (WINDOWPROP W (QUOTE MONITORLOCK)
		     (CREATE.MONITORLOCK (QUOTE IRM)))
         (replace TXTFILE of (TEXTOBJ (OPENTEXTSTREAM "" W)) with (WINDOWPROP W (QUOTE TITLE)))
     W])

(\IRM.PROMPT.FOR.LOOKUP
  [LAMBDA (WINDOW)                                           (* drc: "15-Aug-85 16:28")
    (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 LOOKUP.WORD))
								     NIL T NIL (QUOTE TTY]
			    (WINDOWPROP WINDOW (QUOTE LOOKUP.WORD)
					KEYWORD)
			    (IRM.SMART.LOOKUP KEYWORD WINDOW)))
      else (FLASHWINDOW WINDOW])

(\IRM.WILD.LOOKUP
  [LAMBDA (KEYWORD WINDOW)                                   (* drc: "31-Jul-85 18:04")
    (LET [(MATCHES (PROG2 (PRINTOUT (GETPROMPTWINDOW WINDOW)
				    T "Matching wildcard(s)...")
			  (\IRM.WILDCARD KEYWORD (\IRM.GET.KEYWORDS WINDOW))
			  (PRINTOUT (GETPROMPTWINDOW WINDOW)
				    "OK"]
         (if MATCHES
	     then (if (NULL (CDR MATCHES))
		      then (IRM.LOOKUP (CAR MATCHES)
				       NIL WINDOW)
		    else (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)))
	   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)                                           (* drc: "31-Jul-85 15:58")
    (OR (WINDOWPROP WINDOW (QUOTE KEYWORDS))
	(PROGN (PRINTOUT (GETPROMPTWINDOW WINDOW)
			 T "Loading keyword list...")
	       (WINDOWPROP WINDOW (QUOTE KEYWORDS)
			   (GETHASHFILE (QUOTE irm.keywords)
					(\IRM.GET.HASHFILE)))
	       (PRINTOUT (GETPROMPTWINDOW WINDOW)
			 "OK")
	       (WINDOWPROP WINDOW (QUOTE KEYWORDS])
)
(DECLARE: DONTCOPY EVAL@COMPILE 
[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 )
(DECLARE: DOEVAL@COMPILE DONTCOPY

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

(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))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1304 12177 (HELPSYS 1314 . 2565) (IRM.LOOKUP 2567 . 4248) (IRM.SMART.LOOKUP 4250 . 5145
) (IRM.INIT 5147 . 5658) (\IRM.DISPLAY.REF 5660 . 7364) (\IRM.DISPLAY.FROM.MENU 7366 . 7870) (
\IRM.WINDOW.CREATE 7872 . 8567) (\IRM.PROMPT.FOR.LOOKUP 8569 . 9486) (\IRM.WILD.LOOKUP 9488 . 10429) (
\IRM.WILDCARD 10431 . 10848) (\IRM.WILD.MATCH 10850 . 11360) (\IRM.GET.HASHFILE 11362 . 11677) (
\IRM.GET.KEYWORDS 11679 . 12175)))))
STOP