;;; -*- Mode:Common-Lisp; Package:MACTOOLBOX; Base:10; Fonts:(CPTFONT HL10B HL12I CPTFONT CPTFONTB) -*-

;;;			    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, AUSTIN, TEXAS 78769
;;; Ï1     Ï*Copyright (C) 1989 Texas Instruments Incorporated. Ï1 Ï*All rights reserved.


(defun Ï4ACTIVE-POINTER-P Ï*(object)
  "Ï2Returns true if OBJECT is a TB:MAC-POINTER instance with an active,
i.e., non-disposed, pointer.Ï*"
  (and (typep object 'mac-pointer)
       (typep (send object :pointer) '(integer 0 *))))


(defun Ï4NONNIL-ACTIVE-POINTER-P Ï*(object)
  "Ï2Returns true if OBJECT is a TB:MAC-POINTER instance with an active,
i.e., non-disposed, pointer which is non-NIL.Ï*"
  (and (typep object 'mac-pointer)
       (typep (send object :pointer) '(integer 1 *))))


(defun Ï4DISPOSE-POINTER-MAYBE Ï*(object)
  "Ï2Dispose of OBJECT if it is a MAC-POINTER object which has not previoused been disposed and
is non-NIL.Ï*"
  (declare (inline nonnil-active-pointer-p))
  (when (nonnil-active-pointer-p object)
    (!DisposPtr object)))


(defun Ï4!NILPTR-P Ï*(object)
  "Ï2Returns true if OBJECT is an active TB:MAC-POINTER instance pointing to NIL.Ï*"
  (declare (inline active-pointer-p))
  (and (active-pointer-p object)
       (zerop (send object :pointer))))


(defun Ï4MAKE-POINTER Ï*(&optional (macintosh-address 0))
  "Ï2Returns a TB:MAC-POINTER instance with :POINTER intialized to MACINTOSH-ADDRESS.Ï*"
  (make-instance 'mac-pointer :pointer macintosh-address))


(defun Ï4ACTIVE-HANDLE-P Ï*(object)
  "Ï2Returns true if OBJECT is a TB:MAC-HANDLE instance with an active,
i.e.,  non-disposed, handle.Ï*"
  (and (typep object 'mac-pointer)
       (typep (send object :handle) '(integer 0 *))))


(defun Ï4NONNIL-ACTIVE-HANDLE-P Ï*(object)
  "Ï2Returns true if OBJECT is a TB:MAC-HANDLE instance with an active,
i.e.,  non-disposed, handle which is non-NIL.Ï*"
  (and (typep object 'mac-pointer)
       (typep (send object :handle) '(integer 1 *))))


(defun Ï4DISPOSE-HANDLE-MAYBE Ï*(object)
  "Ï2Dispose of OBJECT if it is a MAC-HANDLE object which has not previoused been disposed 
and is non-NIL.Ï*"
  (declare (inline nonnil-active-handle-p))
  (when (nonnil-active-handle-p object)
    (!DisposHandle object)))


(defun Ï4!NILHNDL-P Ï*(object)
  "Ï2Returns true if OBJECT is an active TB:MAC-HANDLE instance pointing  indirectly to NIL.Ï*"
  (declare (inline active-handle-p))
  (and (active-handle-p object)
       (zerop (send object :handle))))


(defun Ï4ADDRESS-EQ Ï*(object-1 object-2)
  "Ï2Returns true if arguements are handles or pointers (mixed or matched) which 
ultimately refer to the same Macintosh address.Ï*"
  (declare (inline active-handle-p active-pointer-p))
  (cond ((active-handle-p object-1)
	 (cond ((active-handle-p object-2)
		;Ï1; case of (eq handle-1 handle-2)Ï*
		(or (eq object-1 object-2)
		    (= (send object-1 :handle) (send object-2 :handle))
		    (= (logand #xFFFFFF 
			       (fetch (make-instance 'mac-pointer :pointer 
						    (send object-1 :handle)) 0))
		       (logand #xFFFFFF
			       (fetch (make-instance 'mac-pointer :pointer 
						    (send object-2 :handle)) 0)))))
	       ((active-pointer-p object-2)
		;Ï1;case of (eq handle-1 pointer-2)Ï*
		(= (logand #xFFFFFF 
			       (fetch (make-instance 'mac-pointer :pointer 
						     (send object-1 :handle)) 0))
		   (send object-2 :pointer)))
	       (t nil)))			       ;Ï1object-2 not a handle or pointerÏ*
	((active-pointer-p object-1)
	 (cond ((active-handle-p object-2)
		;Ï1; case of (eq pointer-1 handle-2)Ï*
		(= (send object-1 :pointer)
		   (logand #xFFFFFF 
			       (fetch (make-instance 'mac-pointer :pointer 
						     (send object-2 :handle)) 0))))
	       ((active-pointer-p object-2)
		;Ï1; case of (eq pointer-1 pointer-2)Ï*
		(or (eq object-1 object-2)
		    (= (send object-1 :pointer) (send object-2 :pointer))))
	       (t nil)))			       ;Ï1object-2 not a handle or pointerÏ*
	(t nil))				       ;Ï1object-1  not a handle or pointerÏ*
  );Ï1;address-eq

Ï3(Ï*Ï*provide "TOOLBOX-AUX-FUNCTIONS")
