(DEFINE-FILE-INFO PACKAGE "INTERLISP" READTABLE "XCL" BASE 10)
(filecreated "30-Dec-87 11:37:35" |{POGO:AISNORTH:XEROX}<CUTTING>TMAX>TMAX-INDEX.;2| 35555  

      |previous| |date:| "11-Nov-87 11:51:31" |{POGO:AISNORTH:XEROX}<CUTTING>TMAX>TMAX-INDEX.;1|)


; Copyright (c) 1987 by Xerox Corporation.  All rights reserved.

(prettycomprint tmax-indexcoms)

(rpaqq tmax-indexcoms ((* |Developed| |under| |support| |from| nih |grant| rr-00785.)
                       (* |Written| |by| |Frank| |Gilmurray| |and| |Sami| |Shaio.|)
                       (* * tmax-indexnil |ImageObject| |functions|)
                       (fns indexobj indexobjp index.displayfn index.imageboxfn index.putfn 
                            index.getfn index.copyfn index.buttoneventinfn index.whendeletedfn)
                       (* * |Inserting| |indices|)
                       (fns insert.index insert.indexentry insert.known.index subitem.selectfn 
                            add.new.index)
                       (* * |Functions| |to| |change| |the| |Index/Extended| |Index|)
                       (fns change.index change.indexentry change.xindex.key change.xindex.entry 
                            change.xindex.font change.xindex.number)
                       (* * |Other| |misc| |functions|)
                       (fns gethash.index index.page.number index.manual.delimiter index.string 
                            get.indexentry.number index.list.refs list.of.indexentries)
                       (* * |Index| |file| |functions|)
                       (fns create.index.file view.index.file get.index.file write.index.file 
                            write.index.pagenumbers reset.index.pagenumbers)
                       (records index.entry.record)))



(* |Developed| |under| |support| |from| nih |grant| rr-00785.)




(* |Written| |by| |Frank| |Gilmurray| |and| |Sami| |Shaio.|)

(* * tmax-indexnil |ImageObject| |functions|)

(defineq

(indexobj
  (lambda (key indexentry.parms)                             (* |fsg| "10-Jul-87 15:59")
          (* * |Create| |an| |instance| |of| |an| |Index| |or| |Extended| |Index| 
          |imageobject.| |The| |difference| |between| |the| |two| |is| |the| objectdatum.
          |For| \a |simple| |Index,| objectdatum |is| nil.
          |For| |an| |Extended| |Index,| objectdatum |is| \a |record| |containing| |the| 
          |Entry,| |Entry's| |font,| |and| |Number| |option.|
          i\n |either| |case,| |the| index.key |property| |is| |the| |hash| |key| |and| 
          |is| |also| |the| |text| |to| |index| |for| \a |simple| |Index.|
          |NOTE...Extended| |Index| |used| |to| |be| |called| |IndexEntry| |after| |the| 
          |Scribe| |cmd| |of| |the| |same| |name.|)

    (let ((newobj (imageobjcreate indexentry.parms \\indexobj.imagefns)))
         (imageobjprop newobj 'index.key key)
         (imageobjprop newobj 'type 'indexobj)
         newobj)))

(indexobjp
  (lambda (obj)                                              (* |ss:| "27-Jun-87 15:53")
          (* * |Tests| |an| |imageobject| |to| |see| |if| |it| |an| |Index| |or| 
          |Extended| |Index| |imageobject.| b\y |convention,| |testing| |functions| |for| 
          |an| |imageobject| |are| |named| <concat |type-of-imageobj| "P" >.)

    (and obj (eq (imageobjprop obj 'type)
                 'indexobj))))

(index.displayfn
  (lambda (obj stream)                                       (* |fsg| "17-Sep-87 11:14")
          (* * |Display| |an| |Index| |imageobject.|
          i\f |the| |stream-type| |is| |display,| |then| |just| |type| |Index| |or| 
          |Extended| |Index| |followed| |by| |their| |args.|
          |Otherwise| |the| |stream-type| |is| |hardcopy.|
          i\n |this| |case,| |type| |nothing| |and| |replace| |the| car |of| |the| |hash| 
          |array| |entry| |with| \a |list| |of| |page| |numbers| |in| |which| |this| 
          |index| |appears.|)

    (selectq (imagestreamtype stream)
        (display (dspfont |GP.DefaultFont| stream)
                 (tmax.shadeobj obj stream)
                 (prin3 (index.string obj)
                        stream))
        (let* ((pgs/imobjs (gethash.index obj))
               (current.page (index.page.number (|with| textobj textobj (car \\window)))))
              (cond
                 (pgs/imobjs (cond
                                ((listp (car pgs/imobjs))
                                 (or (memb current.page (car pgs/imobjs))
                                     (rplaca pgs/imobjs (append (car pgs/imobjs)
                                                               (list current.page)))))
                                (t (rplaca pgs/imobjs (list current.page)))))
                 (t (error "No array entry for this INDEX" (imageobjprop obj 'index.key))))))))

(index.imageboxfn
  (lambda (obj stream currentx rightmargin)                  (* |ss:| "27-Jun-87 15:50")
          (* * |Return| |the| |ImageBox| |for| |an| |Index| |or| |Extended| |Index.|)

    (selectq (imagestreamtype stream)
        (display (|create| imagebox
                        xsize ← (stringwidth (index.string obj)
                                       |GP.DefaultFont|)
                        ysize ← (fontprop |GP.DefaultFont| 'height)
                        ydesc ← (fontprop |GP.DefaultFont| 'descent)
                        xkern ← 0))
        (|create| imagebox
               xsize ← 0
               ysize ← 0
               ydesc ← 0
               xkern ← 0))))

(index.putfn
  (lambda (obj stream)                                       (* |ss:| "27-Jun-87 15:51")
          (* * |Puts| |the| |Index| |or| |Extended| |Index| |imageobject| |in| \a |file.|)

    (let ((datum (|fetch| objectdatum |of| obj))
          (index.put.arg (list '|Index| (imageobjprop obj 'index.key))))
         (and datum (nconc1 index.put.arg datum))
         (prin2 index.put.arg stream))))

(index.getfn
  (lambda (stream copy.object)                               (* |fsg| "20-Aug-87 14:57")
          (* * |Create| |the| |Index| |or| |Extended| |Index| |imageobject| |when| |it| 
          |is| |read| |from| |file.|)

    (let* ((index.args (or copy.object (cdr (read stream))))
           (newobj (apply (function indexobj)
                          index.args))
           (window (|with| textobj textobj (car \\window))))
          (tsp.setup.fmmenu window)
          (add.new.index window (car index.args)
                 newobj)
          newobj)))

(index.copyfn
  (lambda (image.obj source.stream target.stream)            (* |fsg| "23-Jul-87 12:01")
          (* * |Here| |to| copy |an| |Index| |or| |Extended| |Index| |Image| |Object.|)

    (selectq (imagestreamtype target.stream)
        (text (let ((textobj (textobj target.stream)))
                   (apply* (imageobjprop image.obj 'getfn)
                          target.stream
                          (list (imageobjprop image.obj 'index.key)
                                (|fetch| objectdatum |of| image.obj)))))
        (error "Unknown TARGET stream type" (imagestreamtype target.stream)))))

(index.buttoneventinfn
  (lambda (obj stream sel relx rely window hoststream button)(* |fsg| "29-Jul-87 10:50")
          (* * |Process| |the| |middle| |button| |pressed| |inside| |an| |Index| |or| 
          |Extended| |Index| |imageobject.| |This| |means| |the| |user| |wants| |to| 
          |Change| |this| |index.|)

    (and (mousestate middle)
         (let* ((datum (|fetch| objectdatum |of| obj))
                (new.index (menu (|create| menu
                                        title ← '|Index Menu|
                                        items ← (list (cond
                                                         (datum '(|Change Extended Index| t 
                                                                        "Change Extended Index"))
                                                         (t '(|Change Index| t "Change Index"))))
                                        centerflg ← t))))
               (and new.index (car (setq new.index (cond
                                                      (datum (change.indexentry obj stream))
                                                      (t (change.index obj stream)))))
                    (progn (index.whendeletedfn obj stream)
                           (imageobjprop obj 'index.key (car new.index))
                           (and datum (|replace| objectdatum |of| obj |with| (cadr new.index)))
                           (add.new.index window (car new.index)
                                  obj)
                           'changed))))))

(index.whendeletedfn
  (lambda (obj window)                                       (* |ss:| "27-Jun-87 15:52")
          (* * |Delete| |the| |selected| |Index| |or| |Extended| |Index| |imageobject.|)

    (let* ((indexkey (imageobjprop obj 'index.key))
           (index.array (windowprop window 'tsp.index.array))
           (hash.value (gethash indexkey index.array)))
          (cond
             ((dremove obj (cond
                              ((|fetch| objectdatum |of| obj)
                               (caddr hash.value))
                              (t (cadr hash.value))))
              nil)
             (t (dsubst nil (list obj)
                       hash.value)
                (puthash indexkey (cond
                                     ((or (cadr hash.value)
                                          (caddr hash.value))
                                      hash.value)
                                     (t nil))
                       index.array)))
          nil)))
)
(* * |Inserting| |indices|)

(defineq

(insert.index
  (lambda (stream window)                                    (* |fsg| "10-Mar-87 14:02")
          (* * |Process| |the| "Index" |function| |in| |the| |ImageObjects| |menu.|)

    (let ((newindex.key (mkatom (convert.tabs.to.spaces (tedit.getinput stream "Index Key:")))))
         (and newindex.key (let ((new.index.obj (indexobj newindex.key)))
                                (add.new.index window newindex.key new.index.obj)
                                (tedit.insert.object new.index.obj stream)))
         (tedit.promptprint stream "" t))))

(insert.indexentry
  (lambda (stream window)                                    (* |fsg| "19-Mar-87 11:56")
          (* * |Process| |the| "Extended Index" |function| |in| |the| |ImageObjects| 
          |menu.| |NOTE...Extended| |Index| |use| |to| |be| |called| |IndexEntry| |after| 
          |the| |Scribe| |cmd| |of| |the| |same| |name.|)

    (let ((newindex.key (mkatom (convert.tabs.to.spaces (tedit.getinput stream "Extended Index Key:")
                                       ))))
         (and newindex.key (let ((new.index.obj
                                  (indexobj newindex.key
                                         (|create| index.entry.record
                                                index.entry ←
                                                (or (mkatom (convert.tabs.to.spaces
                                                             (tedit.getinput stream 
                                                                    "Extended Index Entry:"
                                                                    (mkstring newindex.key))))
                                                    newindex.key)
                                                index.entryfont ←
                                                (let (newindex.font)
                                                     (tedit.promptprint stream 
                                                            "Extended Index Entry font..." t)
                                                     (|until| (setq newindex.font (get.tsp.font
                                                                                   window 
                                                                                   |GP.DefaultFont|))
                                                        |do| (tedit.promptprint stream 
                                                            "Invalid font specification...try again." 
                                                                    t))
                                                     newindex.font)
                                                index.number ← (progn (tedit.promptprint stream 
                                                                    "Extended Index Number option..." 
                                                                             t)
                                                                      (get.indexentry.number))))))
                                (add.new.index window newindex.key new.index.obj)
                                (tedit.insert.object new.index.obj stream)))
         (tedit.promptprint stream "" t))))

(insert.known.index
  (lambda (stream window)                                    (* |fsg| "16-Sep-87 11:31")
          (* * |Process| |the| "Known Indices" |function| |in| |the| |ImageObjects| 
          |menu.| a |menu| |of| |all| |the| |known| |Indices| |and| |Extended| |Indices| 
          |pops| |up| |and| |the| |user| |may| |button| |one| |of| |these| |to| |insert| 
          |the| |corrsponding| |Index| |or| |Extended| |Index.|)

    (let* ((previndices (index.list.refs window))
           (newindex.key (cond
                            (previndices (let ((menu.selection
                                                (menu (|create| menu
                                                             title ← "Index Keys"
                                                             items ← previndices
                                                             menucolumns ← (fix (sqrt (length 
                                                                                          previndices
                                                                                             )))
                                                             centerflg ← t
                                                             whenselectedfn ← (function 
                                                                               subitem.selectfn)))))
                                              (and menu.selection (or (listp menu.selection)
                                                                      (list menu.selection)))))
                            (t (tedit.promptprint stream 
                                      "There are no Indices/Extended Indices in this document." t)
                               nil))))
          (and newindex.key (let ((newindex.obj (apply 'indexobj newindex.key)))
                                 (add.new.index window (car newindex.key)
                                        newindex.obj)
                                 (tedit.insert.object newindex.obj stream)
                                 (tedit.promptprint stream "" t))))))

(subitem.selectfn
  (lambda (item menu key)                                    (* |fsg| "16-Sep-87 13:28")
          (* * |Function| |to| |handle| |multiple| |column| |menu| |when| |some| |items| 
          |have| |subitems.|)

    (prog (submenu subitems (submenus (getmenuprop menu 'submenus)))
          (|if| (and (listp item)
                     (setq subitems (cdr (assoc 'subitems (cdddr item)))))
              |then| (|if| (setq submenu (cdr (sassoc subitems submenus)))
                       |else| (setq submenu (|create| menu
                                                   items ← subitems
                                                   centerflg ← t))
                             (putmenuprop menu 'submenus (cons (cons subitems submenu)
                                                               submenus)))
                    (return (menu submenu))
            |else| (return (defaultwhenselectedfn item menu key))))))

(add.new.index
  (lambda (window indexkey obj)                              (* |ss:| "27-Jun-87 15:44")
          (* * |Add| |an| |Index| |or| |Extended| |Index| |imageobject| |to| |our| 
          |index| |array.| i\f |at| |least| |one| |already| |exists| |for| |this| |index| 
          |key,| |then| |just| |append| |this| |imageobject| |to| |the| |list.|
          |Otherwise| |create| \a |new| |array| |entry| |for| |this| |imageobject.|
          |The| |list| |contains| |three| |elements;|
          \a |string,| \a |list| |of| |Index| |imageobjects,| |and| \a |list| |of| 
          |Extended| |Index| |imageobjects.|)

    (let* ((code.array (windowprop window 'tsp.index.array))
           (hash.value (gethash indexkey code.array))
           (index.objs (cadr hash.value))
           (entry.objs (caddr hash.value)))
          (cond
             ((|fetch| objectdatum |of| obj)
              (setq entry.objs (append entry.objs (list obj))))
             (t (setq index.objs (append index.objs (list obj)))))
          (puthash indexkey (list nil index.objs entry.objs)
                 code.array))))
)
(* * |Functions| |to| |change| |the| |Index/Extended| |Index|)

(defineq

(change.index
  (lambda (obj stream)                                       (* |ss:| "27-Jun-87 15:44")
          (* * |Here| |when| change |buttoned| |inside| |an| |Index| |ImageObject.|)

    (list (mkatom (convert.tabs.to.spaces (tedit.getinput stream (concat "Change Index key \""
                                                                        (imageobjprop obj
                                                                               'index.key)
                                                                        "\" to:")))))))

(change.indexentry
  (lambda (obj stream)                                       (* |fsg| "10-Mar-87 11:52")
          (* * |Here| |when| change |buttoned| |inside| |an| |Extended| |Index| 
          |ImageObject.| |NOTE...Extended| |Index| |used| |to| |be| |called| |IndexEntry| 
          |after| |the| |Scribe| |cmd| |of| |the| |same| |name.|)

    (prog1 (list (change.xindex.key obj stream)
                 (|create| index.entry.record
                        index.entry ← (change.xindex.entry obj stream)
                        index.entryfont ← (change.xindex.font obj stream)
                        index.number ← (change.xindex.number obj stream)))
           (tedit.promptprint stream "" t))))

(change.xindex.key
  (lambda (obj stream)                                       (* |ss:| "27-Jun-87 15:45")
          (* * |Change| |the| |key| |of| |an| |Extended| |Index.|)

    (let ((oldindex.key (imageobjprop obj 'index.key)))
         (or (mkatom (convert.tabs.to.spaces (tedit.getinput stream (concat 
                                                                       "Change Extended Index Key \"" 
                                                                           oldindex.key "\" to:"))))
             oldindex.key))))

(change.xindex.entry
  (lambda (obj stream)                                       (* |fsg| "10-Mar-87 11:31")
          (* * |Change| |the| |entry| |of| |an| |Extended| |Index.|)

    (let ((oldindex.entry (|fetch| index.entry |of| (|fetch| objectdatum |of| obj))))
         (or (mkatom (convert.tabs.to.spaces (tedit.getinput stream (concat 
                                                                     "Change Extended Index Entry \"" 
                                                                           oldindex.entry "\" to:")))
                    )
             oldindex.entry))))

(change.xindex.font
  (lambda (obj stream)                                       (* |fsg| " 8-Jul-87 16:42")
          (* * |Change| |the| |font| |of| |an| |Extended| |Index.|)

    (let ((oldindex.font (|fetch| index.entryfont |of| (|fetch| objectdatum |of| obj)))
          newindex.font)
         (tedit.promptprint stream (concat "Change Extended Index Entry's font " (abbreviate.font
                                                                                  oldindex.font)
                                          " to...")
                t)
         (|until| (setq newindex.font (get.tsp.font (\\tedit.mainw stream)
                                             (or oldindex.font |GP.DefaultFont|)))
            |do| (tedit.promptprint stream "Invalid font specification...try again." t))
         newindex.font)))

(change.xindex.number
  (lambda (obj stream)                                       (* |fsg| "19-Mar-87 11:51")
          (* * |Change| |the| |number| |option| |of| |an| |Extended| |Index.|)

    (let ((oldindex.nbr (|fetch| index.number |of| (|fetch| objectdatum |of| obj))))
         (tedit.promptprint stream (concat "Change Extended Index Number option \"" oldindex.nbr 
                                          "\" to...")
                t)
         (get.indexentry.number oldindex.nbr))))
)
(* * |Other| |misc| |functions|)

(defineq

(gethash.index
  (lambda (indexobj)                                         (* |fsg| "13-Jul-87 11:09")
          (* * |Get| |the| |hash| |array| |entry| |for| |this| |Index| |or| |Extended| 
          |Index.|)

    (gethash (imageobjprop indexobj 'index.key)
           (windowprop (|with| textobj textobj (car \\window))
                  'tsp.index.array))))

(index.page.number
  (lambda (window)                                           (* |fsg| "16-Jul-87 10:08")
          (* * |Return| |the| |index| |page| |number;|
          |either| |the| |page| |number| |or| |manual-style| |page| |number.|)

    (mkatom (cond
               ((manualindex.enabled? window)
                (let ((index.page "")
                      (template.list (append (windowprop window 'manualtemplates)))
                      index.template)
                     (|while| (setq index.template (|pop| template.list))
                        |do| (|with| ngtemplate index.template (setq index.page
                                                                (concat index.page (or ng.text-before 
                                                                                       "")
                                                                       (ngroup.chartype.convert
                                                                        ng.chartype ng.currentval)
                                                                       (index.manual.delimiter
                                                                        ng.text-after
                                                                        (car template.list))))))
                     (concat index.page (car formattingstate))))
               (t (car formattingstate))))))

(index.manual.delimiter
  (lambda (after.delimiter next.template)                    (* |fsg| "16-Jul-87 10:00")
          (* * |Return| |the| |delimiter| |between| |NGroups| |and| |the| |page| |number| 
          |for| \a |Manual| |Index| |page| |reference.|)

    (or (cond
           (next.template (cond
                             ((|fetch| (ngtemplate ng.text-before) |of| next.template)
                              "")
                             (t nil)))
           (t (cond
                 ((or (null after.delimiter)
                      (strequal after.delimiter ""))
                  ".")
                 (t nil))))
        after.delimiter)))

(index.string
  (lambda (index.obj)                                        (* |ss:| "27-Jun-87 15:52")
          (* * |Returns| |the| |display| |imagestream| |text| |for| |an| |Index| |or| 
          |Extended| |Index| |ImageObject.|)

    (let ((objdatum (|fetch| objectdatum |of| index.obj))
          (indexkey (mkatom (imageobjprop index.obj 'index.key))))
         (cond
            (objdatum (|with| index.entry.record objdatum (concat "{Index Key=" indexkey ",Entry=" 
                                                                 index.entry
                                                                 (selectq index.number
                                                                     (yes ",Yes}")
                                                                     (no ",No}")
                                                                     (concat "," index.number "}"))))
                   )
            (t (concat "{Index " indexkey "}"))))))

(get.indexentry.number
  (lambda (defaultnumber)                                    (* |ss:| "27-Jun-87 15:47")
          (* * |Get| |the| number |argument| |for| |an| |IndexEntry| |ImageObject.|
          |The| number |can| |be| "YES" \, "NO" \, |or| |an| |integer.|)

    (or (menu (|create| menu
                     title ← "Number?"
                     centerflg ← t
                     items ← '(yes no value)
                     whenselectedfn ← (function (lambda (item)
                                                  (cond
                                                     ((eq item 'value)
                                                      (numberpad.read (create.numberpad.reader 
                                                                             "NUMBER value?" nil nil 
                                                                             nil t)))
                                                     (t item))))))
        defaultnumber
        'yes)))

(index.list.refs
  (lambda (window)                                           (* |ss:| "27-Jun-87 15:51")
          (* * |Return| \a |sorted| |list| |of| |the| |Index| |and| |Extended| |Index| 
          |keys.| |Simple| |Index| |keys| |are| |just| |added| |to| |the| |list.|
          |For| |an| |Extended| |Index| |key,| |there| |are| subitems |for| |each| 
          |Extended| |Index| |for| |this| |key.| |This| |list| |can| |be| |used| |as| 
          |the| items |field| |in| |the| |Known| |Indices| |menu| |or| |for| |creating| 
          |the| |index| |file.|)

    (let ((index.array (windowprop window 'tsp.index.array))
          (index.keylist nil)
          (index.items (cons))
          index.value)
         (maphash index.array (function (lambda (val ky)
                                          (setq index.keylist (cons ky index.keylist)))))
         (|for| key |in| (sort index.keylist 'ualphorder)
            |do| (setq index.value (gethash key index.array))
                 (and (cadr index.value)
                      (nconc index.items (list key)))
                 (and (caddr index.value)
                      (nconc index.items (list (list key nil "Select an Extended Index subitem."
                                                     (cons 'subitems (list.of.indexentries
                                                                      key
                                                                      (caddr index.value))))))))
         (cdr index.items))))

(list.of.indexentries
  (lambda (key objlist)                                      (* |fsg| " 8-Jul-87 16:46")
          (* * |Returns| \a |list| |of| |the| |Extended| |Indices| |of| |the| |given| 
          |key| |sorted| |by| |Entry.|)

    (let ((entry.list (cons))
          datum)
         (|for| obj |in| objlist
            |do| (setq datum (|fetch| objectdatum |of| obj))
                 (nconc entry.list (list (list (concat (|fetch| index.entry |of| datum)
                                                      "  "
                                                      (abbreviate.font (|fetch| index.entryfont
                                                                          |of| datum))
                                                      "  "
                                                      (|fetch| index.number |of| datum))
                                               (kwote (list key datum))))))
         (sort (intersection (cdr entry.list)
                      (cdr entry.list))
               (function (lambda (a b)
                           (ualphorder (caadr (cadadr a))
                                  (caadr (cadadr b)))))))))
)
(* * |Index| |file| |functions|)

(defineq

(create.index.file
  (lambda (stream window)                                    (* |fsg| "13-Aug-87 09:05")
          (* * |Writes| |the| |indices| |and| |their| |corresponding| |page| |numbers| 
          |to| |the| |index| |file.| |The| |indices| |are| |sorted| |alphabetically| 
          |regardless| |of| |case.|)

    (let* ((index.array (windowprop window 'tsp.index.array))
           (index.list (index.list.refs window))
           (index.file (get.index.file (windowprop window 'imageobj.menuw)))
           index.stream)
          (cond
             ((and index.list index.file)
              (tedit.promptprint stream (concat "Putting Indices into file " index.file "...")
                     t)
              (write.index.file (setq index.stream (opentextstream))
                     index.list index.array)
              (tedit.promptprint stream "done")
              (tedit.put index.stream index.file)
              (closef? index.file)
              index.file)
             (index.list (tedit.promptprint stream "Specify a file name for the Indices first." t)
                    nil)
             (t (tedit.promptprint stream "There are no Indices/Extended Indices in this document." t
                       )
                nil)))))

(view.index.file
  (lambda (stream window)                                    (* |fsg| "12-Aug-87 16:34")
          (* * |Writes| |out| |the| |index| |file| |via| create.index.file |and| |then| 
          |opens| |another| |TEdit| |window| |where| |this| |new| |file| |is| 
          |displayed.|)

    (let ((index.file (create.index.file stream window)))
         (and index.file (progn (or (windowprop window 'index.window)
                                    (windowprop window 'index.window (createw nil (concat 
                                                                                "Viewing Index file " 
                                                                                         index.file))
                                           ))
                                (tedit index.file (windowprop window 'index.window)))))))

(get.index.file
  (lambda (menuw)                                            (* \; "Edited 29-Sep-87 14:34 by fsg")

          (* * |Return| |the| |user| |specified| |index| |file| |name.|)

    (let ((filename (fm.itemprop (fm.getitem 'index.file nil menuw)
                           'label)))
         (and (not (strequal filename ""))
              (mkatom filename)))))

(write.index.file
  (lambda (index.stream index.list index.array)              (* |fsg| "13-Aug-87 10:43")
          (* * |For| |each| |Index,| |the| |Key| |is| |printed| |followed| |by| |the| 
          |list| |of| |page| |numbers| |in| |which| |this| |Index| |Key| |appears.|
          |Each| |Extended| |Index| |is| |printed| |on| \a |separate| |line| |and| |the| 
          |page| |number| |depends| |on| |the| |Extended| |Index| |Number| |option.|)

    (dspfont (fontcreate '(helvetica 14 brr))
           index.stream)
    (printout index.stream "Index" t t)
    (|for| index.item |in| index.list
       |do| (cond
               ((listp index.item)
          (* * |Extended| |Index|)

                (let ((pgs.and.imobjs (gethash (car index.item)
                                             index.array)))
                     (|for| index.subitem |in| (cdr (cadddr index.item))
                        |do| (|for| (index.entryargs index.font) |in| (cdr (cadadr index.subitem))
                                |do| (dspfont (setq index.font (fontcreate (cadr index.entryargs)))
                                            index.stream)
                                     (printout index.stream (mkstring (car index.entryargs)))
                                     (write.index.pagenumbers index.stream pgs.and.imobjs
                                            (caddr index.entryargs))
                                     (dspfont index.font index.stream)
                                     (printout index.stream t)))))
               (t 
          (* * |Simple| |Index|)

                  (dspfont |GP.DefaultFont| index.stream)
                  (let ((pgs.and.imobjs (gethash index.item index.array)))
                       (printout index.stream (mkstring index.item))
                       (write.index.pagenumbers index.stream pgs.and.imobjs nil)
                       (printout index.stream t)))))))

(write.index.pagenumbers
  (lambda (stream pages/imobjs number.option)                (* |fsg| "11-Mar-87 11:04")
          (* * |Here| |to| |write| |the| |actual| |pages| |nubers| |that| |this| |Index| 
          |or| |Extended| |Index| |appears| |in.| number.option |is| |the| |Number| 
          |field| |of| |an| |Extended| |Index.|)

    (dspfont |GP.DefaultFont| stream)
    (let ((page.nbrs (cond
                        (number.option (selectq number.option
                                           (no "")
                                           (yes (car pages/imobjs))
                                           (mkstring number.option)))
                        (t (car pages/imobjs))))
          (page.string "    "))
         (cond
            ((listp page.nbrs)
             (setq page.string (concat page.string (car page.nbrs)))
             (|for| page |in| (cdr page.nbrs) |do| (setq page.string (concat page.string ", " page))
                |finally| (printout stream page.string)))
            (t (printout stream (concat page.string page.nbrs)))))))

(reset.index.pagenumbers
  (lambda (window)                                           (* |fsg| "13-Aug-87 10:43")
          (* * |Here| |before| |hardcopying| |the| |TMAX/TEdit| |window.|
          |Reset| |the| |page| |number| |list| |to| nil |so| |the| |hardcopy| displayfn 
          |will| |create| \a |new| |list| |of| |index| |page| |numbers.|)

    (let ((index.array (windowprop window 'tsp.index.array)))
         (and index.array (maphash index.array (function (lambda (val key)
                                                           (rplaca val nil))))))))
)
(declare\: eval@compile

(record index.entry.record (index.entry index.entryfont index.number))
)
(putprops tmax-index copyright ("Xerox Corporation" 1987))
(declare\: dontcopy
  (filemap (nil (1955 9950 (indexobj 1965 . 2988) (indexobjp 2990 . 3438) (index.displayfn 3440 . 4944) 
(index.imageboxfn 4946 . 5666) (index.putfn 5668 . 6098) (index.getfn 6100 . 6694) (index.copyfn 6696
 . 7331) (index.buttoneventinfn 7333 . 8931) (index.whendeletedfn 8933 . 9948)) (9985 17606 (
insert.index 9995 . 10581) (insert.indexentry 10583 . 13290) (insert.known.index 13292 . 15445) (
subitem.selectfn 15447 . 16441) (add.new.index 16443 . 17604)) (17676 21607 (change.index 17686 . 
18254) (change.indexentry 18256 . 19006) (change.xindex.key 19008 . 19566) (change.xindex.entry 19568
 . 20201) (change.xindex.font 20203 . 21072) (change.xindex.number 21074 . 21605)) (21647 29018 (
gethash.index 21657 . 22047) (index.page.number 22049 . 23486) (index.manual.delimiter 23488 . 24179) 
(index.string 24181 . 25191) (get.indexentry.number 25193 . 26213) (index.list.refs 26215 . 27774) (
list.of.indexentries 27776 . 29016)) (29058 35371 (create.index.file 29068 . 30362) (view.index.file 
30364 . 31250) (get.index.file 31252 . 31642) (write.index.file 31644 . 33652) (
write.index.pagenumbers 33654 . 34772) (reset.index.pagenumbers 34774 . 35369)))))
stop