;;; -*- Mode: Common-Lisp; Package: ZWEI; Base: 10.; Patch-File: T -*-

;;; Reason: Fixed doc-viewer-top-level , it was returning the wrong argument from get-stuff-from-doc-server.[10668]

;;;                           RESTRICTED RIGHTS LEGEND
;;;
;;; Use, duplication, or disclosure by the Government is subject to
;;; restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
;;; Technical Data and Computer Software clause at 52.227-7013.
;;;
;;;   TEXAS INSTRUMENTS INCORPORATED      
;;;   P.O. BOX 2909, M/S 2151             
;;;   AUSTIN, TEXAS 78769                 
;;;
;;; Copyright (C) 1989 Texas Instruments Incorporated.
;;; All rights reserved.

;;; Written 12/01/89 15:15:41 by BERGER,
;;; while running on ARIES from band LODX
;;; With SYSTEM 6.26, VIRTUAL-MEMORY 6.3, EH 6.5, MAKE-SYSTEM 6.2, MICRONET 6.0, LOCAL-FILE 6.1,
;;;  BASIC-PATHNAME 6.2, NETWORK-SUPPORT-COLD 6.2, BASIC-NAMESPACE 6.7, NETWORK-NAMESPACE 6.0,
;;;  DISK-IO 6.2, DISK-LABEL 6.0, BASIC-FILE 6.6, MAC-PATHNAME 6.0, NETWORK-PATHNAME 6.0,
;;;  COMPILER 6.14, TV 6.19, DATALINK 6.0, CHAOSNET 6.5, GC 6.3, MEMORY-AUX 6.0, NVRAM 6.2,
;;;  SYSLOG 6.2, STREAMER-TAPE 6.5, UCL 6.0, INPUT-EDITOR 6.0, METER 6.1, ZWEI 6.8,
;;;  DEBUG-TOOLS 6.3, NETWORK-SUPPORT 6.1, NETWORK-SERVICE 6.2, DATALINK-DISPLAYS 6.0,
;;;  FONT-EDITOR 6.1, SERIAL 6.0, PRINTER 6.3, MAC-PRINTER-TYPES 6.1, PRINTER-TYPES 6.2,
;;;  IMAGEN 6.1, SUGGESTIONS 6.1, MAIL-DAEMON 6.4, MAIL-READER 6.6, TELNET 6.0, VT100 6.0,
;;;  NAMESPACE-EDITOR 6.4, PROFILE 6.2, VISIDOC 6.5, TI-CLOS 6.26, CLEH 6.5, IP 3.56,
;;;  Experimental CLX 6.7, CLUE 6.35, X11M 6.17, Experimental BUG 11.17, VISIDOC-SERVER 6.1,
;;;   microcode 429, Band Name: REL 6.0 + SLE 11/28

#!C
; From file DOCUMENT-VIEWER.LISP#> VISIDOC; SYS:
#10R ZWEI#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "ZWEI"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* SYS:COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: VISIDOC; DOCUMENT-VIEWER.#"


(defun doc-viewer-top-level (fname &optional (manual nil) (nth nil) &aux index temp-fname)
  "Top level function to enter the Document Server.  
FNAME is the name of what we want to document.
MANUAL is the keyword (ie. :LISP, :IO, :WINDOWS) identifying the manual in which FNAME is found.
NTH is the index into the list returned from the (ENTRIES-ALIST) function for FNAME."
  (DECLARE (inline object-manual-name))
  (PKG-BIND (FIND-PACKAGE 'zwei)	;;prevent wierdness when constructing diagram lines
    (SETQ FNAME (STRING-UPCASE (STRING-TRIM '(#\SPACE) FNAME)))
    (WHEN (AND (SETQ index (STRING-SEARCH-SET '(#\:) fname))
	       (<  0 index)
	       (FIND-PACKAGE (ignore-errors (READ-FROM-STRING fname t nil :end index)))) ; DAB 08-31-89
      (SETQ temp-fname (SUBSEQ fname (1+ index))))
    (LET* ((info-list (or (get-stuff-from-doc-server fname :manual manual :nth nth)
			  (and  temp-fname  ; DAB 08-31-89
				(let ((stuff (get-stuff-from-doc-server temp-fname :manual manual :nth nth)))
				  (when stuff ; DAB 12-01-89 If we got something here, reset fname
				    (setf fname temp-fname)
				    stuff  ; DAB 12-01-89 BUt return stuff.
				    )))))
	   object buffer node key)
      ;;Get-stuff-from-doc-server returns a list where the CAR is a keyword,
      ;;and the CDR is one of five values:
      ;;
      ;;    keyword                          rest of list
      ;;   --------              -----------------------------------------------------------------------
      ;;1) :NODE                 a node instance if nth was specified and that reference has been created before
      ;;2) :NODES                a list of nodes if ALL multiple references for a manual have been viewed before
      ;;3) :ITEM                 a list of the object, its nth position in the name's own (ENTRIES-ALIST..) 
      ;;                           value, and a list of lists of subordinate object and nth pairs
      ;;4) :MULTIPLE-ATTRIBUTES  a list of the object, and the object's (ENTRIES-ALIST..) value
      ;;5) :MULTIPLE-OBJECTS     a list of the OBJECTS
      ;;
      ;;   A return value of NIL means no object was found.
      
      (SETQ key (CAR info-list)
	    info-list (CDR info-list))
      ;;If there is no entry, go to the local machine and pull up any internal documentation.
      (CASE key
	(NIL
	 (format t "~%~%There is no on-line Manual Documentation for ~a~%" fname)
	 (if (position #\space (the string fname) :test #'CHAR=)
	     (format t "~&~s was not found~%" fname)
	     (doc-viewer-long-documentation (READ-FROM-STRING (STRING fname)))))
	;;;This is a BRAND NEW ENTRY and needs to be put into a node 'n linked 'n stuff.
	(:item
	 (SETQ object (CAR info-list)
	       manual (OR manual (object-manual-name object))
	       buffer (find-doc-viewer-buffer-named manual))
	 (insert-and-select fname (entries-alist fname manual) (SECOND info-list) (THIRD info-list) manual buffer))
	;;A single node was returned
	(:node
	 (select-buffer-and-expand-node (CAR info-list)))
	;;;All references have been pulled into the doc viewer before.
	;;;Do something to pick and go to the right node.
	(:nodes
	 (SETQ info-list (CAR info-list))
	 (IF (< 1 (LENGTH info-list))
	     (WHEN (SETQ node (choose-a-node info-list)) (select-buffer-and-expand-node node))
	     (select-buffer-and-expand-node (CAR info-list))))
	;;;There are multiple references
	(:multiple-attributes
	 (SETQ nth (pick-the-right-one fname (SECOND info-list)))
	 (WHEN nth (doc-viewer-top-level fname (object-manual-name (CAR info-list)) nth)))
	;;There are multiple OBJECTS!!!
	(:multiple-objects
	 (MULTIPLE-VALUE-SETQ (nth manual)
	   (pick-the-right-one fname (CAR info-list)))
	 (WHEN (AND manual nth) (doc-viewer-top-level fname manual nth)))
	))
    dis-none))
))
