home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Messaging / OSL / OSLDspse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  5.5 KB  |  220 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        OSLDspse.c (Orignal name: OSLDispose.c)
  3.  
  4.     Contains:    
  5.  
  6.     Owned by:    Nick Pilch
  7.  
  8.     Copyright:    © 1992 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <4>     6/23/95    NP        125932: Call system handlers if app
  13.                                     handlers fail.
  14.          <3>     1/12/95    jpa        Don't use obsolete Toolbox names [1211211]
  15.          <2>     8/19/94    NP        1181622: Ownership fix.
  16.          <7>      5/2/94    eeh        bug #1160654: various PPC native changes
  17.          <6>    10/18/93    NP        Added DisposeTokenProc callback support for
  18.                                     OpenDoc.
  19.          <5>     8/16/93    NP        Adjusted for latest OSL proposal.
  20.          <4>     7/29/93    NP        Added missing return value for
  21.                                     OLSDisposeToken.
  22.          <3>     7/28/93    NP        Mods for new token type, OSLToken.
  23.          <2>     7/21/93    NP        Fixed #includes.
  24.          <1>     7/21/93    NP        first checked in
  25.  
  26.     To Do:
  27.     In Progress:
  28. */
  29.  
  30. #ifndef __MIXEDMODE__
  31. #include <MixedMode.h>
  32. #endif
  33.  
  34. #ifndef _OSLPRIV_
  35. #include "OSLPriv.h"
  36. #endif
  37.  
  38. #pragma segment AEObjSuppt
  39.  
  40. // ———————————————————————— InternalDisposeToken ————————————————————————
  41.  
  42.         // disposes of OSLTokens without calling app's dispose token routine
  43.  
  44. pascal OSErr
  45. InternalDisposeToken( OSLToken* token )
  46. {
  47.     return AEDisposeDesc(token);
  48. }
  49.  
  50. // ———————————————————————— DisposeCompEvnt ————————————————————————
  51.  
  52.         // disposes of CompEvnt Handles
  53.  
  54. static void
  55. DisposeCompEvnt( CompareEvent c )
  56. {
  57.     if ( c != NULL )
  58.     {
  59.         IgnoreOSErr( AEDisposeDesc( &(*c)->theCompEvtInput )) ;
  60.         IgnoreOSErr( AEDisposeDesc( &(*c)->eventWParams ) ) ;
  61.         DisposeHandle((Handle)c ) ;
  62.     }
  63. } // DisposeCompEvnt
  64.  
  65.     /*———————————————————————— DisposeCompare ————————————————————————*/
  66.  
  67.         /*disposes of comparison Handles*/
  68. void
  69. DisposeCompare( Comparison c )
  70. {
  71.     if ( c != NULL )
  72.     {
  73.         IgnoreOSErr( AEDisposeDesc( &(*c)->theCompInput )) ;
  74.         DisposeObj( (*c)->obj1 ) ;
  75.         DisposeObj( (*c)->obj2 );
  76.         DisposeHandle((Handle)c ) ;
  77.     }
  78. } // DisposeCompare
  79.  
  80.     /*———————————————————————— DisposeLogical ————————————————————————*/
  81.  
  82. void
  83. DisposeLogical( Logical l )
  84. {
  85.     if ( l != NULL )
  86.     {
  87.         IgnoreOSErr( AEDisposeDesc( &(*l)->theLogicalInput ) ) ;
  88.         DisposeTerm( (*l)->firstTerm ) ;
  89.         DisposeHandle( (Handle)l ) ;
  90.     }
  91.  
  92.         
  93.     /*———————————————————————— DisposeTerm ————————————————————————*/
  94.  
  95. void
  96. DisposeTerm( Term t )
  97. /*disposes of test term Handles*/
  98.  
  99. {
  100.     if ( t != NULL )
  101.     {
  102.         DisposeTerm( (*t)->next ) ;
  103.         IgnoreOSErr( AEDisposeDesc( &(*t)->theTermInput ) ) ;
  104.  
  105.         switch ( (*t)->ttype )
  106.         {
  107.             case kCompare :
  108.                 DisposeCompare( (Comparison)(*t)->u.compar ) ;
  109.                 break ;
  110.             case kCompareEvt :
  111.                 DisposeCompEvnt( (CompareEvent)(*t)->u.cEvt ) ;
  112.                 break ;
  113.             case kLogical :
  114.                 DisposeLogical( (Logical)(*t)->u.log ) ;
  115.                 break ;
  116.         }
  117.             
  118.         DisposeHandle( (Handle)t ) ;
  119.     }
  120. } /*DisposeTerm*/
  121.  
  122.  
  123.     /*———————————————————————— DisposeWhose ————————————————————————*/
  124.  
  125. void
  126. DisposeWhose( Whose w )
  127.     /*disposes of Whose Handles*/
  128.     if ( w != NULL )
  129.     {
  130.         DisposeTerm( (*w)->theTerm ) ;
  131.         IgnoreOSErr( AEDisposeDesc( &(*w)->theWhoseInput )) ;
  132.         DisposeHandle( (Handle)w ) ;
  133.         /* don't dispose of whose value, it is an end product! */
  134.     }
  135. } /*DisposeWhose*/
  136.  
  137.  
  138.     /*———————————————————————— DisposeObj ————————————————————————*/
  139.  
  140. void
  141. DisposeObj( Object o )
  142. /*disposes of object records in comparison Handles*/
  143.  
  144. {
  145.     if ( o != NULL )
  146.     {
  147.         HLock( (Handle) o ) ;            /* AEDisposeDesc may write back, so don't let it move */
  148. //        WITH o** DO                        /* ...and as long as we're locking... */
  149.         {
  150.             ObjRecordPtr op = *o ;
  151.             DisposeObj( op->objContainer );
  152.             DisposeWhose( (Whose)op->objTheWhose );
  153.             IgnoreOSErr( AEDisposeDesc( &op->objSelectionData )) ;
  154.             IgnoreOSErr( AEDisposeDesc( &op->theObjInput )) ;
  155.  
  156.             /* objValue is sometimes a token, sometimes not.  eg in the case where
  157.               we are comparing a word with text obj2 has the text as its value. */
  158.  
  159.             if ( op->objRedo )
  160.             {
  161.             if ( !op->valIsExmn )
  162.                 IgnoreOSErr( iAEDisposeToken( &op->objValue ) ) ;
  163.             }
  164.             else if ( ! (op->objClass == typeToken) )            /* test added 4/4 as part of ccnt conversion */
  165. //                IgnoreOSErr( AEDisposeDesc( &op->objValue ) ) ;
  166.                 IgnoreOSErr( OSLDisposeToken( &op->objValue ) ) ;
  167.  
  168.         }
  169.         DisposeHandle( (Handle) o ) ;
  170.     }
  171. } /*DisposeObj*/
  172.  
  173.  
  174. ////////////////////////////////////////////////////////////////////////////////
  175. // iAEDisposeToken
  176. // if the app calls disposeToken and there is no such proc, it should return
  177. // an error -- NoSuchProcErr toka.  But if I call it and there is none,
  178. // AEDisposeDesc should be called instead.  Best solution for now is not
  179. // to treat the absence of a proc as an error; just default to disposeDesc().
  180. ////////////////////////////////////////////////////////////////////////////////
  181.  
  182. static OSErr
  183. TryOneProc( GlobalRecHandle aGlobalRef, OSLToken *theDesc )
  184. {
  185.     OSErr err = errAENotASpecialFunction ;        // with "|" below, fixes LLD-UPG-8 }
  186.     if ( aGlobalRef != NULL )
  187.     {
  188.         OSLDisposeTokenUPP aProcPtr = (*aGlobalRef)->diposeTokenProcPtr ;
  189.         if ( aProcPtr != NULL ) 
  190.             err = CallOSLDisposeTokenProc(aProcPtr, theDesc);
  191.     }
  192.     return err ;
  193. }
  194.  
  195.  
  196. pascal OSErr
  197. iAEDisposeToken( OSLToken *theDesc ) // Directly from Ed's stuff; not a word changed }
  198. {
  199.     OSErr err ;
  200.         
  201.     if ( theDesc->descriptorType != typeNull )
  202.     {
  203.         err = NewCallDisposeToken(theDesc);
  204. //        err = TryOneProc( GetGlobalRef(), theDesc ) ;
  205.         if ((err == errAEEventNotHandled)
  206.                 || (err == errAENotASpecialFunction) ) 
  207.             err = TryOneProc( GetSysGlobal(), theDesc ) ; // not there? then try the system-wide one
  208.         if (( err == errAEEventNotHandled)
  209.                 || (err == errAENotASpecialFunction) ) 
  210.             err = AEDisposeDesc( theDesc ) ;        // <eeh> here is err where i=166 from command-2
  211.     }
  212.     else
  213.         err = noErr ;
  214.  
  215.     return err ;
  216. } // iAEDisposeToken
  217.  
  218.