home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Atlanta_1990 / Atlanta-Devcon.2 / Libraries / IFFParse / Include / iffparse.h next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  6.7 KB  |  213 lines

  1. /*  :ts=8 bk=0
  2.  *
  3.  * iffparse.h:    Structure definitions for the all new good nifty IFF code.
  4.  *
  5.  * Stuart Ferguson (created)                8807.??
  6.  * ewhac: Semantic changes                8808.15
  7.  * shf:   Added rudimentary callback vectors and
  8.  *      read/write mode bits.  Added clipboard
  9.  *      functions and structures.            8808.31
  10.  * shf:   Modified for revised design Oct 88.        8810.12
  11.  * shf:   Updated to Dec 88 design revision.        8812.15
  12.  * shf:   Added IFF_PRIVATE symbol for denoting private
  13.  *      data structures.                8902.07
  14.  * ewhac: New InitIFF() declaration, and a change to
  15.  *      IFFM_MODE declaration.            8902.22
  16.  * ewhac: Removed private parts.            8903.07
  17.  * ewhac: Attempt at Lattice-ification and retrofit of
  18.  *      1.4 hooks.                    8912.06
  19.  * ewhac: Re-commenting.                9005.31
  20.  * ewhac: {Entry,Exit}Handler() redesign.        9006.04
  21.  */
  22. #ifndef IFF_IFFPARSE_H
  23. #define IFF_IFFPARSE_H
  24.  
  25. #ifndef EXEC_TYPES_H
  26. #include <exec/types.h>
  27. #endif
  28. #ifndef EXEC_LISTS_H
  29. #include <exec/lists.h>
  30. #endif
  31. #ifndef EXEC_PORTS_H
  32. #include <exec/ports.h>
  33. #endif
  34. #ifndef DEVICES_CLIPBOARD_H
  35. #include <devices/clipboard.h>
  36. #endif
  37.  
  38. /*
  39.  * Struct associated with an active IFF stream.
  40.  * "iff_Stream" is a value used by the client's read/write/seek functions -
  41.  * it will not be accessed by the library itself and can have any value
  42.  * (could even be a pointer or a BPTR).
  43.  */
  44. struct IFFHandle {
  45.     ULONG    iff_Stream;
  46.     ULONG    iff_Flags;
  47.     LONG    iff_Depth;    /*  Depth of context stack.  */
  48.     /*  There are private fields hiding here.  */
  49. };
  50.  
  51. /*
  52.  * Bit masks for "iff_Flags" field.
  53.  */
  54. #define IFFF_READ    0L            /* read mode - default */
  55. #define IFFF_WRITE    1L            /* write mode */
  56. #define IFFF_RWBITS    (IFFF_READ | IFFF_WRITE)    /* read/write bits */
  57. #define IFFF_FSEEK    (1L<<1)            /* forward seek only */
  58. #define IFFF_RSEEK    (1L<<2)            /* random seek */
  59. #define    IFFF_RESERVED    0xFFFF0000L        /* Don't touch these bits. */
  60.  
  61. /*
  62.  * When the library calls your stream handler, you'll be passed a pointer
  63.  * to this structure as the "message packet".
  64.  */
  65. struct IFFStreamCmd {
  66.     LONG    sc_Command;    /*  Operation to be performed (IFFCMD_)    */
  67.     APTR    sc_Buf;        /*  Pointer to data buffer        */
  68.     LONG    sc_NBytes;    /*  Number of bytes to be affected    */
  69. };
  70.  
  71. /*
  72.  * A node associated with a context on the iff_Stack.  Each node
  73.  * represents a chunk, the stack representing the current nesting 
  74.  * of chunks in the open IFF file.  Each context node has associated
  75.  * local context items in the (private) LocalItems list.  The ID, type,
  76.  * size and scan values describe the chunk associated with this node.
  77.  */
  78. struct ContextNode {
  79.     struct MinNode    cn_Node;
  80.     LONG        cn_ID;
  81.     LONG        cn_Type;
  82.     LONG        cn_Size;    /*  Size of this chunk           */
  83.     LONG        cn_Scan;    /*  # of bytes read/written so far */
  84.     /*  There are private fields hiding here.  */
  85. };
  86.  
  87. /*
  88.  * Local context items live in the ContextNode's.  Each class is identified
  89.  * by its lci_Ident code and has a (private) purge vector for when the
  90.  * parent context node is popped.
  91.  */
  92. struct LocalContextItem {
  93.     struct MinNode    lci_Node;
  94.     ULONG        lci_ID,
  95.             lci_Type,
  96.             lci_Ident;
  97.     /*  There are private fields hiding here.  */
  98. };
  99.  
  100. /*
  101.  * StoredProperty: a local context item containing the data stored
  102.  * from a previously encountered property chunk.
  103.  */
  104. struct StoredProperty {
  105.     LONG    sp_Size;
  106.     UBYTE    *sp_Data;
  107. };
  108.  
  109. /*
  110.  * Collection Item: the actual node in the collection list at which
  111.  * client will look.  The next pointers cross context boundaries so
  112.  * that the complete list is accessable.
  113.  */
  114. struct CollectionItem {
  115.     struct CollectionItem    *ci_Next;
  116.     LONG            ci_Size;
  117.     UBYTE            *ci_Data;
  118. };
  119.  
  120. /*
  121.  * Structure returned by OpenClipboard().  You may do CMD_POSTs and such
  122.  * using this structure.  However, once you call OpenIFF(), you may not
  123.  * do any more of your own I/O to the clipboard until you call CloseIFF().
  124.  */
  125. struct ClipboardHandle {
  126.     struct IOClipReq    cbh_Req;
  127.     struct MsgPort        cbh_CBport;
  128.     struct MsgPort        cbh_SatisfyPort;
  129. };
  130.  
  131. /*
  132.  * IFF return codes.  Most functions return either zero for success or
  133.  * one of these codes.  The exceptions are the read/write functions which
  134.  * return positive values for number of bytes or records read or written,
  135.  * or a negative error code.  Some of these codes are not errors per sae,
  136.  * but valid conditions such as EOF or EOC (End of Chunk).
  137.  */
  138. #define    IFFERR_EOF        -1L    /*  Reached logical end of file    */
  139. #define IFFERR_EOC        -2L    /*  About to leave context    */
  140. #define    IFFERR_NOSCOPE        -3L    /*  No valid scope for property    */
  141. #define    IFFERR_NOMEM        -4L    /*  Internal memory alloc failed*/
  142. #define    IFFERR_READ        -5L    /*  Stream read error        */
  143. #define    IFFERR_WRITE        -6L    /*  Stream write error        */
  144. #define    IFFERR_SEEK        -7L    /*  Stream seek error        */
  145. #define    IFFERR_MANGLED        -8L    /*  Data in file is corrupt    */
  146. #define    IFFERR_SYNTAX        -9L    /*  IFF syntax error        */
  147. #define    IFFERR_NOTIFF        -10L    /*  Not an IFF file        */
  148. #define    IFFERR_NOHOOK        -11L    /*  No call-back hook provided    */
  149. #define IFF_RETURN2CLIENT    -12L    /*  Client handler normal return*/
  150.  
  151. #define    MAKE_ID(a,b,c,d)    ((a<<24L) | (b<<16L) | (c<<8L) | d)
  152.  
  153. /*
  154.  * Universal IFF identifiers.
  155.  */
  156. #define    ID_FORM            MAKE_ID('F','O','R','M')
  157. #define    ID_LIST            MAKE_ID('L','I','S','T')
  158. #define    ID_CAT            MAKE_ID('C','A','T',' ')
  159. #define    ID_PROP            MAKE_ID('P','R','O','P')
  160. #define    ID_NULL            MAKE_ID(' ',' ',' ',' ')
  161.  
  162. /*
  163.  * Ident codes for universally recognized local context items.
  164.  */
  165. #define IFFLCI_PROP        MAKE_ID('p','r','o','p')
  166. #define IFFLCI_COLLECTION    MAKE_ID('c','o','l','l')
  167. #define IFFLCI_ENTRYHANDLER    MAKE_ID('e','n','h','d')
  168. #define IFFLCI_EXITHANDLER    MAKE_ID('e','x','h','d')
  169.  
  170. /*
  171.  * Control modes for ParseIFF() function.
  172.  */
  173. #define IFFPARSE_SCAN        0L
  174. #define IFFPARSE_STEP        1L
  175. #define IFFPARSE_RAWSTEP    2L
  176.  
  177. /*
  178.  * Control modes for StoreLocalItem().
  179.  */
  180. #define IFFSLI_ROOT        1L    /*  Store in default context       */
  181. #define IFFSLI_TOP        2L    /*  Store in current context       */
  182. #define IFFSLI_PROP        3L    /*  Store in topmost FORM or LIST  */
  183.  
  184. /*
  185.  * "Flag" for writing functions.  If you pass this value in as a size
  186.  * to PushChunk() when writing a file, the parser will figure out the
  187.  * size of the chunk for you.  (Chunk sizes >= 2**31 are forbidden by the
  188.  * IFF specification, so this works.)
  189.  */
  190. #define    IFFSIZE_UNKNOWN        -1L
  191.  
  192. /*
  193.  * Possible call-back command values.
  194.  */
  195. enum IFFCmdCode {
  196.     IFFCMD_INIT,        /*  Prepare your stream for a session    */
  197.     IFFCMD_CLEANUP,        /*  Terminate stream session        */
  198.     IFFCMD_READ,        /*  Read bytes from stream        */
  199.     IFFCMD_WRITE,        /*  Write bytes to stream        */
  200.     IFFCMD_SEEK,        /*  Seek on stream            */
  201.     IFFCMD_ENTRY,        /*  You just entered a new context    */
  202.     IFFCMD_EXIT,        /*  You're about to leave a context    */
  203.     IFFCMD_PURGELCI        /*  Purge a LocalContextItem        */
  204. };
  205. /*  Backward compatibility.  Don't use these in new code.  */
  206. #define    IFFSCC_INIT    IFFCMD_INIT
  207. #define    IFFSCC_CLEANUP    IFFCMD_CLEANUP
  208. #define    IFFSCC_READ    IFFCMD_READ
  209. #define    IFFSCC_WRITE    IFFCMD_WRITE
  210. #define    IFFSCC_SEEK    IFFCMD_SEEK
  211.  
  212. #endif
  213.