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

;;; Reason: Add a missing argument to the call to cerror in :launch-server.

;;;                           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 07/28/89 08:52:22 by jones,
;;; while running on HOBBS from band p616
;;; With SYSTEM 6.11, GC 6.3, VIRTUAL-MEMORY 6.1, MICRONET 6.0, MICRONET-COMM 6.1,
;;;  DISK-IO 6.0, DISK-LABEL 6.0, BASIC-PATHNAME 6.1, MAC-PATHNAME 6.0, NETWORK-SUPPORT-COLD 6.0,
;;;  BASIC-NAMESPACE 6.1, BASIC-FILE 6.2, RPC 6.1, NFS 6.0, EH 6.3, MAKE-SYSTEM 6.0,
;;;  MEMORY-AUX 6.0, COMPILER 6.9, TV 6.12, NVRAM 6.1, UCL 6.0, INPUT-EDITOR 6.0,
;;;  MACTOOLBOX 2.3, METER 6.1, ZWEI 6.3, DEBUG-TOOLS 6.3, WINDOW-MX 6.5, PRINTER 6.3,
;;;  MAC-PRINTER-TYPES 6.1, CLIPBOARD 6.1, NETWORK-PATHNAME 6.0, NETWORK-NAMESPACE 6.0,
;;;  DATALINK 6.0, CHAOSNET 6.0, NETWORK-SUPPORT 6.0, NETWORK-SERVICE 6.1, DATALINK-DISPLAYS 6.0,
;;;  MX-DATALINK 6.1, NAMESPACE-EDITOR 6.0, IP 3.47, NFS-SERVER 6.0, MX-SERIAL 6.1,
;;;  PRINTER-TYPES 6.1, IMAGEN 6.0, MAIL-DAEMON 6.2, MAIL-READER 6.1, TELNET 6.0,
;;;  VT100 6.0, STREAMER-TAPE 6.4, DECNET 1.69, VISIDOC 6.2, PROFILE 6.1, TI-CLOS 6.11,
;;;  CLEH 6.4, Experimental CLX 6.2, CLUE 6.9, Experimental BUG 11.10, Experimental ACTION 2.0,
;;;   microcode 138, Band Name: p616*2

#!C
; From file MAC-APPLICATIONS.LISP#> TOOLBOX-INTERFACE; MR-X:
#10R MACTOOLBOX#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "MACTOOLBOX"))
                          (SI:*LISP-MODE* :Common-lisp)
                          (*READTABLE* Sys:Common-lisp-readtable)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* Sys::*common-lisp-symbol-substitutions*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: TOOLBOX-INTERFACE; MAC-APPLICATIONS.#"


(defmethod (mac-application-internal :LAUNCH-SERVER) ()
  "Launch a toolbox server to service cals for application-number. Does nothing if the server is already launched."  
  
  (block launch
    ;; The server for channel 8 is in the driver and always active, so don't mess with it.
    (when (not (eq (add:find-channel 8) *application-channel*))
      
      ;; Setup AppParmHandle with trap-channel    
      (let* ((channel-number (add:channel-number *application-channel*))
	     (*application-channel* (add:find-channel 8))
	     (directories (generate-application-search-list directory)))

	;; Setup finder-info so that application will know what channel to use.
	(setf *finder-info* (or *finder-info* (make-instance 'FinderInfo)))
	(send *finder-info* :message 3)
	(send *finder-info* :trap-channel channel-number) 
	(stow (make-instance 'mac-pointer :pointer #xAEC) 0 (send *finder-info* :handle))

	;; Now loop down search list trying to launch it.
	(loop
	  (dolist (dir directories)
	    
	    (set-working-directory dir)
	    
	    ;; Launch it here.
	    (when (>= (launch server-name) 0)
	      (return-from launch)))
	  
	  (cerror "Try Again"
		  "The server file ~a was not found in any of the directories on ~s or was already running."
		  server-name directories))))))

))
