home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warphead.zip / H / TOCENTS.H < prev    next >
C/C++ Source or Header  |  1997-02-28  |  36KB  |  677 lines

  1. /* @(#)Z 1.6 com/src/cm/TOCEnts.h, odstorage, od96os2, odos29646d 96/11/15 15:27:16 (96/10/29 09:19:33) */
  2. /*====START_GENERATED_PROLOG======================================
  3.  */
  4. /*
  5.  *   COMPONENT_NAME: odstorage
  6.  *
  7.  *   CLASSES: none
  8.  *
  9.  *   ORIGINS: 82,27
  10.  *
  11.  *
  12.  *   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13.  *   All Rights Reserved
  14.  *   Licensed Materials - Property of IBM
  15.  *   US Government Users Restricted Rights - Use, duplication or
  16.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17.  *       
  18.  *   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19.  *   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20.  *   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21.  *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22.  *   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23.  *   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24.  *   OR PERFORMANCE OF THIS SOFTWARE.
  25.  */
  26. /*====END_GENERATED_PROLOG========================================
  27.  */
  28.  
  29. /*
  30.     File:         TOCEnts.h  
  31.  
  32.     Contains:    Container Manager TOC Entry Interfaces
  33.  
  34.     Written by:    Ira L. Ruben
  35.  
  36.     Owned by:    Ed Lai
  37.  
  38.     Copyright:    ⌐ 1991-1994 by Apple Computer, Inc., all rights reserved.
  39.  
  40.     Change History (most recent first):
  41.  
  42.          <2>     8/26/94    EL        #1181622 Ownership update.
  43.          <3>     5/10/94    EL        #1162327. ValueDoNotFree is no longer
  44.                                                     needed.
  45.          <2>     3/31/94    EL        Export cmFreeProperties. #1150214
  46.          <1>      2/3/94    EL        first checked in
  47.          <2>      1/6/94    EL        Add ValueDoNotFree to value flag.
  48.  
  49.     To Do:
  50. */
  51.  
  52. /*---------------------------------------------------------------------------*
  53.  |                                                                           |
  54.  |                            <<<  TOCEnts.h   >>>                           |
  55.  |                                                                           |
  56.  |                   Container Manager TOC Entry Interfaces                  |
  57.  |                                                                           |
  58.  |                               Ira L. Ruben                                |
  59.  |                                 12/02/91                                  |
  60.  |                                                                           |
  61.  |                  Copyright Apple Computer, Inc. 1991-1994                 |
  62.  |                           All rights reserved.                            |
  63.  |                                                                           |
  64.  *---------------------------------------------------------------------------*
  65.  
  66.  This file contains the interfaces to the manipulation routines to handle TOC objects
  67.  below the object level.  The objects and the means to get at them are maintained in
  68.  TOCObjects.c.  The split is done this way to keep the accessing of objects separate from
  69.  the stuff represented by those objects.  See  TOCObjs.c   for complete details.
  70. */
  71.  
  72. #ifndef __TOCENTRIES__
  73. #define __TOCENTRIES__
  74.  
  75.  
  76. #include <setjmp.h>
  77. #include <stdio.h>
  78.  
  79. /*------------------------------------------------------------------------------------*
  80.  | W A R N I N G - - -> this header as well as  TOCObjs.h   and  TOCEnts.h   all have |
  81.  |                      mutual references.  The include order is NOT arbitrary.  It's |
  82.  |                      the only one that works!  Even with it we have to do some     |
  83.  |                      forward struct pointer references of the form "struct foo *p" |
  84.  *------------------------------------------------------------------------------------*/
  85.  
  86. #ifndef __CMTYPES__
  87. #include "CMTypes.h"
  88. #endif
  89. #ifndef __CM_API_TYPES__
  90. #include "CMAPITyp.h"
  91. #endif
  92. #ifndef __TOCOBJECTS__
  93. #include "TOCObjs.h"   
  94. #endif
  95. #ifndef __CONTAINEROPS__
  96. #include "Containr.h"  
  97. #endif
  98. #ifndef __DYNAMICVALUES__
  99. #include "DynValus.h"     
  100. #endif
  101. #ifndef __GLOBALNAMES__
  102. #include "GlbNames.h"   
  103. #endif
  104. #ifndef __UPDATING__
  105. #include "Update.h"  
  106. #endif
  107. #ifndef __LISTMGR__
  108. #include "ListMgr.h"
  109. #endif
  110.  
  111. struct TOCProperty;
  112. struct TOCValueHdr;
  113. struct DynValueHdrExt;
  114.  
  115.                                                                  CM_CFUNCTIONS
  116.  
  117.                                                         /*-------------------*
  118.                                                          | Values (segments) |
  119.                                                          *-------------------*
  120.  
  121.                                 W A R N I N G !!
  122.  
  123. This union may be the source of portability problems on machines that don't have 4-byte
  124. longs, 2-byte shorts, and 1-byte bytes.  Byte ordering may also lead to portability        
  125. problems.                                                                                                                                                                */
  126.  
  127. union TOCValueBytes {                                    /* Layout of value/length fields:                                    */
  128.     struct {                                                        /*         value if not immediate(not explicitly here):*/
  129.         CM_ULONG value;                                        /*                offset to value if not immediate                */
  130.         CM_ULONG valueLen;                                /*                value length if not immediate                     */
  131.     } notImm;
  132.     
  133.     struct {                                                        /*         value for a global name                                            */
  134.         CM_ULONG                     offset;                    /*                offset to value in container                        */
  135.         struct GlobalName    *globalNameSymbol;/*            ptr value for a global name (in memory)    */
  136.     } globalName;
  137.     
  138.     union {                                                            /*        actual value if immediate placed here:            */
  139.         CM_UCHAR     ucharsValue[2*sizeof(CM_ULONG)];/*value if immediate unsigned char(s)            */
  140.         CM_ULONG     ulongValue;                            /*                value if immediate unsigned long                */
  141.         CM_USHORT ushortValue;                        /*                value if immediate unsigned short                */
  142.         CM_UCHAR    ubyteValue;                            /*                value if immediate unsigned byte                */
  143.         void              *ptrValue;                            /*                value if immediate pointer                            */
  144.     } imm;
  145. };
  146. typedef union TOCValueBytes TOCValueBytes, *TOCValueBytesPtr;
  147.  
  148. struct TOCValue {                                            /* Layout of a TOC type's value:                                    */
  149.     ListLinks                     valueLinks;            /*        links to next/prev value         (must be first)    */
  150.     struct TOCValueHdr *theValueHdr;        /*        ptr back to ValueHdr "owning" this value        */
  151.     ContainerPtr               container;                /*        ptr to "owning" container control block            */
  152.     CMValueFlags            flags;                        /*        flags                                                                                */
  153.     TOCValueBytes           value;                        /*        value and length or immediate value                    */
  154.     CM_ULONG                     logicalOffset;        /*        original (unedited) logical offset                    */
  155. };
  156. typedef struct TOCValue TOCValue, *TOCValuePtr;
  157.  
  158. enum ConstValueType {                                    /* Data types used to copy data into TOCValue's:    */
  159.     Value_NotImm,                                                /*        not immediate    ==> value and valueLen            */
  160.     Value_GlobalName,                                        /*        global name ptr  ==> in-memory str ptr             */
  161.     Value_Imm_Chars,                                        /*        immediate, chars ==> ucharsValue                        */
  162.     Value_Imm_Long,                                            /*        immediate, long     ==> ulongValue                            */
  163.     Value_Imm_Short,                                        /*        immediate, short ==> ushortValue                        */
  164.     Value_Imm_Byte                                            /*        immediate, byte  ==> ushortValue                        */
  165. };
  166. typedef enum ConstValueType ConstValueType;
  167.  
  168. /* Note: The "owning" container control block of a value segment may not necessarily be    */
  169. /*             the same as the one that owns the value header of the segments (shwon below).    */
  170. /*              The owner of the value header is always the container control block associated    */
  171. /*              with the TOC for that container.  The owner of a value segment, however, may        */
  172. /*              be a DIFFERENT TOC due to one container "editing" another.     Editing is also        */
  173. /*              the reason for the originalOffset field in value segments.  Using it we can        */
  174. /*             determine inserts, deletes, and overwrites.                                                                        */
  175.  
  176.  
  177.                                                             /*---------------*
  178.                                                              | Value Headers |
  179.                                                              *---------------*/
  180.                                                              
  181. struct TOCValueHdr {                                    /* Layout of a TOC property type:                                    */
  182.     ListLinks                            valueHdrLinks;    /*        links to next/prev value hdr (must be first)*/
  183.     struct TOCProperty     *theProperty;        /*        ptr to "owning" property                                        */
  184.     ListHdr                                valueList;            /*        list of actual values                                                */
  185.     CMObjectID                        typeID;                    /*        the value's type ID                                                    */
  186.     ContainerPtr                  container;            /*        ptr to "owning" container control block            */
  187.     CM_ULONG                        size;                        /*        total current size of the value data                */
  188.     CM_ULONG                         logicalSize;        /*        original (unupdated) size of the value data    */
  189.     CM_USHORT                        valueFlags;            /*        flags indicating stuff about the value            */
  190.     CMGeneration                generation;            /*        generation number                                                        */
  191.     CM_ULONG                       useCount;                /*        count of nbr of times "used"                                */
  192.     CMRefCon                          valueRefCon;        /*        user's value refCon                                                    */
  193.     TouchedListEntryPtr touch;                    /*         ptr to updating touched list entry                    */
  194.     union {                                                            /*         this field depends on kind of value hdr:        */
  195.         struct TOCValueHdr         *dynValue;    /*                ptr to dynamic value hdr or NULL                */
  196.         struct DynValueHdrExt *extensions;/*                ptr to dynamic value hdr extensions            */
  197.     } dynValueData;                                            /*        [extensions only when it's a dynamic value]    */
  198.     union {                                                            /*        references recorded by this value                        */
  199.         TOCObjectPtr refDataObject;                /*                associated ref object; NULL if no refs    */
  200.         ListHdrPtr      refShadowList;                /*                or shadow list of the actual data                */
  201.     } references;                                                /*                (refShadowList only in recording value)    */
  202. };
  203. typedef struct TOCValueHdr TOCValueHdr, *TOCValueHdrPtr;
  204.  
  205. struct DynValueHdrExt {                                /* Extensions to TOCValueHdr for a dynamic value:    */
  206.     TOCValueHdrPtr       baseValue;                /*        ptr to base value of this dynamic value            */
  207.     DynamicValueVector dynValueVector;    /*        dynamic value handler vector                                */
  208.     CMMetaHandler             metaHandler;            /*        metahandler to get handler addresses                */
  209. };
  210. typedef struct DynValueHdrExt DynValueHdrExt, *DynValueHdrExtPtr;
  211.  
  212. /* Some of following valueFlags echo the flags field a TOCValue entry. That is because     */
  213. /* a CMValue "refNum" that an API user is given and in turn given back to us is a             */
  214. /* pointer to a TOCValueHdr.  It is sometimes more convenient therefore to check the         */
  215. /* kind of value we have by looking at the header then "going out" to the value. In all */
  216. /* but continued values there is only one TOCValue entry on the valueList anyway.  So     */
  217. /* echoing is more efficient than always going after the tail or head (they're the same)*/
  218. /* of a valueList just to see the flags and the kind of value.                                                    */
  219.  
  220. #define    ValueDeleted            0x0001U            /* valueFlags: 1 ==> deleted value                                */
  221. #define ValueContinued        0x0002U            /*                              ==> continued                                        */
  222. #define ValueGlobal                0x0004U            /*                             ==> global name                                    */
  223. #define ValueImmediate        0x0008U            /*                             ==> immediate value                            */
  224. #define ValueOffPropChain    0x0800U            /*                             ==> dynamic value off prop chain    */
  225. #define ValueDynamic            0x1000U            /*                             ==> dynamic value                                */
  226. #define ValueUndeletable    0x2000U            /*                             ==> can't be deleted                         */
  227. #define ValueProtected        0x4000U            /*                             ==> locked/protected value                */
  228. #define ValueDefined            0x8000U            /*                             ==> fully defined (in read only)    */
  229.  
  230. /* Note: ValueUndeletable and ValueProtected are levels of protection bits. They protect*/
  231. /*              a value from certain operations like writing to them or deleting them. The            */
  232. /*             ValueProtected is a superset of ValueUndeletable.  ValueUndeletable says just     */
  233. /*             than ond only that, i.e., you can do anything to it except delete it.                    */
  234.  
  235. #define ValueCstFlags (ValueDefined       | /* These flags are generally set in various     */\
  236.                                              ValueProtected     | /* places and must remain set when we do the    */\
  237.                                              ValueUndeletable | /* standard echoing of the value flags in            */\
  238.                                              ValueDynamic         | /* cmSetTOCValueHdrFlags() in TOCEntries.c.        */\
  239.                                              ValueOffPropChain|    /* This mask is used there.                                        */\
  240.                                              ValueContinued)
  241.                                              
  242. /* In order to make dealing with dynamic values easier, the following macros are                */
  243. /* provided.  One is a more self-documented test to see if a TOCValueHdr is indeed a         */
  244. /* dynamic value, while the other allows simpler notational access to a dynamic value        */
  245. /* header's extension fields.                                                                                                                        */
  246.  
  247. #define IsDynamicValue(v)    ((((TOCValueHdrPtr)(v))->valueFlags & ValueDynamic) != 0)
  248.  
  249. #define DYNEXTENSIONS(v)                             /* to make access to extensions a "little" easier!*/\
  250.                                                      (((TOCValueHdrPtr)(v))->dynValueData.extensions)
  251.  
  252.  
  253.                                                                     /*------------*
  254.                                                                      | Properties |
  255.                                                                      *------------*/
  256.  
  257. struct TOCProperty {                                    /* Layout of a TOC object property:                                */
  258.     ListLinks          propertyLinks;                    /*        links to next/prev property (must be first)    */
  259.     TOCObjectPtr theObject;                            /*         ptr to "owning" object                                            */
  260.     CMObjectID      propertyID;                        /*        the property's ID                                                         */
  261.     ListHdr             valueHdrList;                    /*         list of the property's values                                */
  262. };
  263. typedef struct TOCProperty TOCProperty, *TOCPropertyPtr;
  264.         
  265.     
  266. CM_USHORT cmSetTOCValueHdrFlags(TOCValueHdrPtr theValueHdr, const CM_USHORT flags);
  267.     /*
  268.     This routine is used to echo the settings of a value's flags in the value header which
  269.     "owns" the value (TOCValue's are on a list whose header is in a TOCValueHdr).  This is
  270.     done because a CMValue "refNum" that an API user is given and in turn given back to us
  271.     is a pointer to a TOCValueHdr.  It is sometimes more convenient therefore to check the
  272.     kind of value we have by looking at the header then "going out" to the value. In all but
  273.     continued values there is only one TOCValue entry on the valueList anyway.  So echoing
  274.     is more efficient than always going after the tail or head (they're the same) of a
  275.     valueList just to see the flags and the kind of value.    
  276.     
  277.     The function updates the valueFlags field in the passed TOCValueHdr according to the
  278.     value flags also passed.  The updated valueFlags are also returned as the function
  279.     result.
  280.     */
  281.     
  282.  
  283. TOCValueBytesPtr cmSetValueBytes(const ContainerPtr container,
  284.                                                                  TOCValueBytesPtr theValueBytes,
  285.                                                                   ConstValueType dataType, CM_ULONG data,
  286.                                                                   CM_ULONG dataLength);
  287.     /*
  288.     This routine is used to just set the value (theValueBytes) with the specified data. The
  289.     data is placed in theValueBytes as a function of the specified type, dataType.  There
  290.     are 7 types:
  291.      
  292.     (1). Value_NotImm                This is the "normal" case for a non-immediate value data (a
  293.                                                     container offset) and data length.  The value/valueLen (i.e.,
  294.                                                     notImm) variant of a TOCValueBytes is used.
  295.                                                      
  296.     (2). Value_Imm_Chars    All of these use the corresponding imm variant of the ptr to the
  297.     (3). Value_Imm_Long     TOCValueBytes struct passed here.  The data is placed in the
  298.     (4). Value_Imm_Short    field according to type and, for the fun of it, the notImm
  299.     (5). Value_Imm_Byte          valueLen field set accordingly.  Note signed and unsigned are
  300.     (6). Value_Imm_Ptr      treated alike.
  301.                                                      
  302.     (7). Value_GlobalName        This is a special case for global name strings. The data is
  303.                                                     assumed to be a pointer to a global name string.  A global name
  304.                                                     symbol table entry is created (using cmDefineGlobalName()) with
  305.                                                     the string.  The pointer to the symbol table entry is set as
  306.                                                     the value data. Note, a global name symbol table entry also
  307.                                                     has a back pointer to its "owning" TOCValue. THE CALLER MUST
  308.                                                     SET THIS FIELD!  Here we only deal with the value bytes.
  309.                                                      
  310.     The function returns the input theValueBytes pointer as its result.  NULL is returned
  311.     for Value_GlobalName if the allocation fails and an error will have been reported.
  312.     */
  313.  
  314.  
  315. TOCValuePtr cmCreateValueSegment(TOCValueHdrPtr theValueHdr, TOCValueBytesPtr value,
  316.                                                                  const CM_USHORT flags);
  317.     /*
  318.     This routine is called to create a new value segment and to fill in its fields with the
  319.     passed parameters.  A pointer to the newly created value segment is returned.  NULL is
  320.     returned if there is an allocation error.
  321.     
  322.     Segments are created generally created for continued values and appended on to the value
  323.     chain whose header is container in a value header.  However, due to such things like
  324.     value inserts a value segment may not necessarily be appended to the end of its chain.
  325.     Thus this routine, which brings a value segment into existence, is a separate routine.
  326.     
  327.     Note, only the segment is created here.  It is up to the caller to chain it to its value
  328.     header and echo the flags in that header.
  329.     */
  330.     
  331.  
  332. TOCValuePtr cmAppendValue(TOCValueHdrPtr theValueHdr, TOCValueBytesPtr value,
  333.                                                     const CM_USHORT flags);
  334.     /*
  335.     This routine takes a pointer to a value definition (the actual bytes) and its flags
  336.     and creates a TOCValue struct which is appended to the specified value header.  The
  337.     function returns the value pointer as its result (i.e. pointer to the newly created
  338.     value).  NULL is returned and an error reported if the allocation of the TOCValue fails.
  339.     
  340.     This routine is used to append actual values to an existing value header.  It is allowed
  341.     to call cmDefineObject() with a NULL value bytes pointer.  In that case an object is 
  342.     created with a value header but no value sublist off of that header.  This routine can
  343.     be called to build that sublist.
  344.     */
  345.     
  346.  
  347. TOCObjectPtr cmDefineObject(ContainerPtr container, CM_ULONG objectID,
  348.                                                        const CM_ULONG propertyID, const CM_ULONG typeID, 
  349.                                                          TOCValueBytesPtr value, const CM_ULONG generation,
  350.                                                         const CM_USHORT flags, const CM_USHORT objectFlags,
  351.                                                         TOCValueHdrPtr *theValueHdr);
  352.     /*
  353.     This routine is called to define a new TOC entry for an object.  We may have either a
  354.     new object (id) or a preexisting one for which a new property and value are to be 
  355.     defined.  All the fields for a TOC entry are passed.  The objectFlags indicate the
  356.     type of the object (more about this later).
  357.     
  358.   Note, the value associated with the property is appended to the the end of the
  359.     property's value list.  The caller has the option of getting the pointer to the value
  360.     header (theValueHdr) when theValueHdr is not passed as NULL.
  361.     
  362.     The function returns a pointer to the object if it was successfully created and NULL if
  363.     it wasn't.  An error is reported if NULL is returned.  Note, while error calls are not
  364.     supposed to return we assume here they due just to be safe!
  365.     
  366.     The objectFlags determine how we treat the object and all the object fields (the other
  367.     parameters).  There are four possible objectFlags:
  368.     
  369.     (1). UndefinedObject        Set if the object is to be created, but we don't yet know what
  370.                                                     its TOC entries are.  Basically a null object (or placeholder)
  371.                                                     is created.  It is an incomplete object in that there are no
  372.                                                     properties or types chained to the object (yet).  This flag may
  373.                                                     be used in combination with the others if we know that the 
  374.                                                     object ID corresponds to a property, type, or neither.
  375.                                                      
  376.     (2). ObjectObject                This flags is used when we don't know the type of the object but
  377.                                                     we know a property and type for it.  If the object already exists
  378.                                                     and it's undefined (UndefinedObject) it is now considered as
  379.                                                     defined.  If it was an undefined property or type, it now becomes
  380.                                                     a defined property or type.  Of course, duplicate definitions
  381.                                                     are an error.
  382.     
  383.     (3). PropertyObject            This is similar to ObjectObject, but here we know the object is
  384.                                                     for a property.  It has to either not exist previously, or was
  385.                                                   previously flagged as UndefinedObject and PropertyObject.
  386.     
  387.     (4). TypeObject                    Same as PropertyObject, but for type objects.
  388.  
  389.     This routine is the "main control" of Container Manager object creation.  It is used
  390.     for "normal" object creation and while loading in a TOC from a preexisting container
  391.     (i.e., from loadTOC()). After loadTOC(), or if we are writing and never do a loadTOC()
  392.     we have the "normal" case.  "We control the horizontal. Do not adjust your TV set". We
  393.     always know what we are creating (yeah, I got a bridge to sell you too).  So we never
  394.     have undefined entries.  Thus in that case we can link the objects to their master lists. 
  395.  
  396.     For loadTOC() however, we are creating objects as we see thier id's in each TOC entry as
  397.     we read them.  We can have forward references to undefined and yet to be fully
  398.     created objects and backward references to existing objects.  We can also have multiple
  399.     properties and values for the same object.  Hence the flags and all they imply.  We also
  400.     do not link the objects.  That is delayed until the TOC is completely read in.  At that
  401.     point the entire TOC is walked sequentially and the links built.  We can also do some
  402.     additional validation to make sure that everything is defined after the read in.
  403.     */
  404.  
  405.  
  406. void cmMarkValueDeleted(ContainerPtr container, TOCValueHdrPtr theValueHdr,
  407.                                                 CMBoolean deleteHdr);
  408.     /*
  409.     This routine takes a pointer to a value header in the specified container and deletes it.
  410.     If the value was the only one for its property, the property is also deleted.
  411.     
  412.     Note, properties and values actually have their memory freed up.  The value headers are
  413.     placed on the deletedValues list to keep them around, but out of the TOC.  This is to
  414.     prevent dangling references from API user "refNum"s, because it is value header pointers
  415.     that we give to the user as those "refNum"s.  Such value headers are marked as "deleted"
  416.     to prevent future use by the user.
  417.     
  418.     The moving of the deleted value headers to the deletedValues list can be suppressed by 
  419.     passing the deleteHdr parameter as true.  Its memory is simply freed along with the rest.
  420.     This is used currently in only one place for error recovery when dynamic value setup
  421.     fails.  There we want to free all the dynamic value layers (which are headers), and
  422.     finally the base "real" value itself.  It is that final value that is passed to here to
  423.     get rid of.
  424.     */
  425.  
  426.  
  427. void cmDeleteProperty(ContainerPtr container, TOCPropertyPtr theProperty);
  428.     /*
  429.     This routine takes a pointer to a property in the specified container and deletes it and
  430.     all its values.
  431.     
  432.     Note, properties and values actually have their memory freed up.  The value headers are
  433.     placed on the deletedValues list to keep them around, but out of the TOC.  This is to
  434.     prevent dangling references from API user "refNum"s, because it is value header pointers
  435.     that we give to the user as those "refNum"s.  Such value headers are marked as "deleted"
  436.     to prevent future use by the user.
  437.     */
  438.  
  439.  
  440. void cmMarkObjectDeleted(ContainerPtr container, TOCObjectPtr theObject);
  441.     /*
  442.     This routine is called to remove an entire object from the TOC for the specified
  443.     container.  All its associated structures (properties and values) are made unavailable
  444.     from the TOC.  The space for the object is NOT freed. The object is placed on a list of
  445.     deleted objects and marked as deleted.  By doing it this way, any outstanding "refNum"s
  446.     we gave the API user (which are pointers to this stuff) will still be "valid" (sort of
  447.     -- at least not looking at garbage).
  448.     */
  449.     
  450.     
  451. void cmFreeTOC(ContainerPtr container, void **toc);
  452.     /*
  453.     This routine is called to free all the structures in a TOC. For updating, a container may
  454.     have its own TOC and the target TOC.  Thus the TOC pointer is an explicit parameter. It
  455.   is passed as a pointer to the toc pointer because freeing the TOC will NULL out the
  456.   caller's pointer.
  457.     
  458.     All memory for objects, properties, and types is freed.  On return the toc pointer in the
  459.     container is NULL as well as all the master link head/tail pointers.
  460.     */
  461.  
  462.  
  463. TOCPropertyPtr cmGetObjectProperty(TOCObjectPtr theObject, CM_ULONG propertyID);
  464.     /*
  465.   This routine takes a pointer to an object and scans its properties for the specified ID.
  466.   The pointer to the property on the object's property chain is returned if found.  NULL is
  467.   returned if not found.
  468.     */
  469.  
  470.  
  471. TOCValueHdrPtr cmGetPropertyType(TOCPropertyPtr theProperty, CM_ULONG typeID);
  472.     /*
  473.     This routine takes a pointer to a object's property and scans its value headers for one
  474.     containing the specified type ID.  The pointer to the value header is returned if found.
  475.     NULL is returned if not found.
  476.     */
  477.     
  478.     
  479. CM_ULONG cmGet1ValueSize(TOCValuePtr theValue);
  480.     /*
  481.     This routine takes a pointer to a value (NOT a value header -- continued values are not
  482.     worried about here) and returns the size represented by that value.  For non-immediate
  483.     values we simply return the length field from the value.  Immediate value sizes are
  484.     dependent on their type.
  485.     */
  486.  
  487.  
  488. #if CMVALIDATE
  489. #define cmValidateCMObject(object)          cmValidateCMObjects((CMObject)(object),   0xFFFFU)
  490. #define cmValidateCMProperty(property) cmValidateCMObjects((CMObject)(property), PropertyObject)
  491. #define cmValidateCMType(type)                  cmValidateCMObjects((CMObject)(type),          TypeObject)
  492. CMBoolean cmValidateCMValue(CMValue value);
  493. CMBoolean cmValidateCMObjects(CMObject object, CM_USHORT objectFlags);
  494.     /*
  495.     CMObject, CMProperty, CMType, and CMValue "refNum"s in the API are implemented in the
  496.     Container Manager as pointers to TOCObject structs (CMObject, CMProperty, and CMType) and
  497.     TOCValueHdr structs (CMValue).  These routines is used to filter "bad" object "refNum"s
  498.     passed to the higher level API interface  ("CM...") routines.  False is returned if the
  499.     object, property, type or value is considered as "bad" and true otherwise.
  500.     
  501.     As currently implemented we return false but do NOT report an error for NULL pointers.
  502.     That is because we return NULL from everthing we error out of earlier.  The NULL test is
  503.     just protection from letting such pointer from ever being used.
  504.     
  505.     Another check we do without reporting an error is on the container pointer.  The refNums
  506.     have a pointer to their container.  The container has a special pointer pointing to 
  507.     itself.  We check against this pointer.  If we think we don't have a valid container
  508.     pointer then we assume we have a bad refNum and return false.  No error can be reported
  509.     because, wiut a container pointer, there is no way to do it!
  510.     
  511.     We DO report an error for attempting to use a deleted object, property, type, or value.
  512.     Deleted TOCObject's and TOCValueHdr's are NOT freed.  Rather they are put on a list
  513.     (separate lists) of deleted objects or value headers and flagged as deleted just for the
  514.     purpose of testing by these routines.  If we had freed them, then we would be getting
  515.     pointers to "garbage".  By keeping them around we have valid pointers and we can do the
  516.     test.
  517.     
  518.     For types and properties we also validate that such "refNum"s are indeed types or
  519.     properties.
  520.     
  521.     Note, for objects, types, and properties, the macros defined above should be used.  They
  522.     expand to calls to cmValidateCMObjects().
  523.     */
  524. #endif
  525.     
  526.     
  527. enum TOCWalkReturns {                                    /* cmWalkThroughEntireTOC() action return codes:    */
  528.     WalkNextTOCObject,                                    /*         do next object                                                            */
  529.     WalkNextTOCProperty,                                /*                        property                                                        */
  530.     WalkNextTOCValueHdr,                                /*                        value header                                                */
  531.     WalkNextTOCValue                                        /*                        value segment                                                */
  532. };
  533. typedef enum TOCWalkReturns TOCWalkReturns;
  534.     /*
  535.     The WalkReturns are the return codes that each cmWalkThroughEntireTOC() action routine is
  536.     to return to direct the walking through the TOC.  cmWalkThroughEntireTOC() is described
  537.     below.  It takes action routines to apply to each data structure of the TOC as it is
  538.     walked.  These return codes allow tighter control over the walking.
  539.     
  540.     The action routines should return the codes shown in the following table:
  541.             
  542.                       Walk...  NextTOCObject | NextTOCProperty | NextTOCValueHdr | NextTOCValue
  543.         ===============|===============|=================|=================|==============
  544.         objectAction   |  next object  |  next property* |                 |
  545.         propertyAction |  next object  |  next property  | next value hdr* |
  546.         valueHdrAction |  next object  |  next property  | next value hdr  | next segment*
  547.         valueAction    |  next object  |  next property  | next value hdr  | next segment*
  548.         ---------------+---------------+-----------------+-----------------+--------------
  549.         
  550.         * The entries marked with "*" are the returns that should be used in the normal case
  551.           to fully walk each data structure of the TOC.  Those not marked with "*" are for
  552.             special cases to abort the walk to go to the next indicated data structure.  Walks
  553.             are sequential through the TOC by ascending object ID.  Thus skipping a particular
  554.             walk of one structure only makes sense if the skip is possible.  That is the reason
  555.             not all returns are allowed in all action routines.  In reality, only the non-starred
  556.             returns are checked on return from an action routine. So the default is the starred
  557.             return (i.e., keep walking normally) if a non-starred is not returned.
  558.         
  559.     */
  560.  
  561.  
  562. int cmWalkThroughEntireTOC(ContainerPtr container, void *toc, 
  563.                                                      CMObjectID startingID, CMObjectID endingID,
  564.                                                      CMRefCon refCon,
  565.                                                       TOCWalkReturns (*objectAction)(ContainerPtr container, TOCObjectPtr theObject, CMRefCon refCon),
  566.                                                       TOCWalkReturns (*propertyAction)(ContainerPtr container, TOCPropertyPtr theProperty, CMRefCon refCon),
  567.                                                       TOCWalkReturns (*valueHdrAction)(ContainerPtr container, TOCValueHdrPtr theValueHdr, CMRefCon refCon),
  568.                                                       TOCWalkReturns (*valueAction)(ContainerPtr container, TOCValuePtr theValue, CMRefCon refCon));
  569.     /*
  570.     This routine is called to walk the entire specified TOC by ascending object ID, starting 
  571.     with object ID's greater than or equal to the startingID and less than or equal to
  572.     endingID, and to call an action routine appropriate for each kind of structure: object,
  573.     property, value header, and value.  
  574.     
  575.     Pointers to the four action routines are passed with headers as shown in the definition. 
  576.     If a pointer is passed as NULL, no action will be performed for the corresponding
  577.     structure.  Each function has return codes (type TOCWalkReturns) that direct the walking
  578.     through the TOC.    The action routines should return the codes shown in the following
  579.     table:
  580.              
  581.                          Walk...  NextTOCObject | NextTOCProperty | NextTOCValueHdr | NextTOCValue
  582.          ===============|===============|=================|=================|==============
  583.          objectAction   |  next object  |  next property* |                 |
  584.          propertyAction |  next object  |  next property  | next value hdr* |
  585.          valueHdrAction |  next object  |  next property  | next value hdr  | next segment*
  586.          valueAction    |  next object  |  next property  | next value hdr  | next segment*
  587.          ---------------+---------------+-----------------+-----------------+--------------
  588.  
  589.     The entries marked with "*" are the returns that should be used in the normal case to
  590.     fully walk each data structure of the TOC.  Those not marked with "*" are for special
  591.     cases to abort the walk to go to the next indicated data structure.  Walks are sequential
  592.     through the TOC by ascending object ID.  Thus skipping a particular walk of one structure
  593.     only makes sense if the skip is possible.  That is the reason not all returns are allowed
  594.     in all action routines.  In reality, only the non-starred returns are checked on return
  595.     from an action routine. So the default is the starred return (i.e., keep walking normally)
  596.     if a non-starred is not returned.
  597.     
  598.     A "refCon" is also passed which the caller can use as a communication facility to convey
  599.     additional info to the action routines.  
  600.     
  601.     This function returns 0 to indicate successful completion, and non-zero otherwise.  Thus
  602.     if AbortWalkThroughEntireTOC(x) is used to abort processing, the x should be a positive
  603.     non-zero integer.
  604.     
  605.     Note, if the property, value header, and value action routines are supplied as NULL,
  606.     then cmWalkThroughEntireTOC() is functionally equivalent to cmForEachObject() which just
  607.     applies a single action routine to the objects.  Thus if only the objects are to be
  608.     walked, it is recommended that cmForEachObject() be used instead of
  609.     cmWalkThroughEntireTOC().
  610.     
  611.     Note also, this routine uses cmForEachObject() to walk the TOC objects with walkObject()
  612.     defined above as the action routine.  It handles the walking of the structures "below"
  613.     the object level. We use the refCon parameter to cmForEachObject() to communicate to
  614.     walkObject() all the action routine pointers and the caller's refCon.  In particular,
  615.     the refCon is a pointer to the container.  In the container is a pointer BACK to a local
  616.     data structure we set up here with all the info.
  617.     */
  618.  
  619.  
  620. #define AbortWalkThroughEntireTOC(x) longjmp(*(jmp_buf *)container->tocActions, x)
  621.     /*
  622.     Use this in routines passed to cmWalkThroughEntireTOC() to abort the walk. The value of x
  623.     is returned from cmWalkThroughEntireTOC(). It should be non-zero since 0 is the "success"
  624.     return value for cmWalkThroughEntireTOC().
  625.     */
  626.  
  627.  
  628. int cmWalkObject(ContainerPtr container, TOCObjectPtr theObject, CMRefCon refCon,
  629.                                  TOCWalkReturns (*objectAction)(ContainerPtr container, TOCObjectPtr theObject, CMRefCon refCon),
  630.                                  TOCWalkReturns (*propertyAction)(ContainerPtr container, TOCPropertyPtr theProperty, CMRefCon refCon),
  631.                                  TOCWalkReturns (*valueHdrAction)(ContainerPtr container, TOCValueHdrPtr theValueHdr, CMRefCon refCon),
  632.                                  TOCWalkReturns (*valueAction)(ContainerPtr container, TOCValuePtr theValue, CMRefCon refCon));
  633.     /*
  634.     This routine is called to walk a single object (theObject) and call an action routine
  635.     appropriate for each kind of structure: object, property, value header, and value. 
  636.     Pointers to the four action routines are passed with headers as shown in the definition.
  637.     If a pointer is passed as NULL, no action will be performed for the corresponding
  638.     structure.  The returns are the same as cmWalkThroughEntireTOC().  See it for further
  639.     details.
  640.     
  641.     A "refCon" is also passed which the caller can use as a communication facility to convey
  642.     additional info to the action routines. 0 is returned to indicate successfull completion.
  643.     Use the AbortWalkObject(x) (a macro) in an action routine to abort the walk.  The "x" is
  644.     a integer which is returned from cmWalkObject() so it should not be 0.
  645.     */
  646.  
  647.  
  648. #define AbortWalkObject(x) longjmp(*(jmp_buf *)container->tocActions, x)
  649.     /*
  650.     Use this in routines passed to cmWalkObject() to abort the walk. The value of x is
  651.     returned from cmWalkObject(). It should be non-zero since 0 is the "success" return value
  652.     for AbortWalkObject().
  653.     */
  654.  
  655. void cmFreeProperties(TOCObjectPtr theObject, CMRefCon refCon);
  656.  
  657. /*
  658.  
  659.  This routine is called to unconditionally free all the properties for an
  660.  objects and the values and other data structures associated with those properties.  It is
  661.  done when an TOC is deleted, i.e, for cmFreeTOC().
  662.  
  663.  Note, here we can just free the properties and associated data structures.  We don't have
  664.  to respect the fact that they are on a list whose header belongs to the the object.  That
  665.  is because we know we are going to delete the object too.
  666.  
  667.  This routine differs from deleteProperties(), and cmDeleteProperty() in that we just free
  668.  the data.  There is no list maintenance and we do not have to worry about moving deleted
  669.  objects or value headers to their delete lists.
  670.  
  671.  Note, this "static" is intentionally left to default memory model under DOS since it is
  672.  passed as a function pointer to cmDestroyTOC().
  673. */
  674.  
  675.                                                           CM_END_CFUNCTIONS
  676. #endif
  677.