home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / workbench / libs / iffparse / iffparse_intern.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-03  |  7.6 KB  |  290 lines

  1. #ifndef IFFPARSE_INTERN_H
  2. #define IFFPARSE_INTERN_H
  3.  
  4. /* Include files */
  5.  
  6. #ifndef EXEC_TYPES_H
  7. #   include <exec/types.h>
  8. #endif
  9. #ifndef PROTO_EXEC_H
  10. #   include <proto/exec.h>
  11. #endif
  12. #ifndef PROTO_DOS_H
  13. #   include <proto/dos.h>
  14. #endif
  15. #ifndef PROTO_UTILITY_H
  16. #   include <proto/utility.h>
  17. #endif
  18. #ifndef PROTO_ALIB_H
  19. #   include <proto/alib.h>
  20. #endif
  21. #ifndef PROTO_IFFPARSE_H
  22. #   include <proto/iffparse.h>
  23. #endif
  24. #ifndef LIBRARIES_IFFPARSE_H
  25. #   include <libraries/iffparse.h>
  26. #endif
  27. #ifndef EXEC_MEMORY_H
  28. #   include <exec/memory.h>
  29. #endif
  30. #ifndef EXEC_LIBRARIES_H
  31. #   include <exec/libraries.h>
  32. #endif
  33. #ifndef AROS_LIBCALL_H
  34. #   include <aros/libcall.h>
  35. #endif
  36. #ifndef DOS_DOS_H
  37. #   include <dos/dos.h>
  38. #endif
  39. #include <stdlib.h>
  40.  
  41.  
  42. /* Some external stuff (iffparse_init.c) */
  43.  
  44.  
  45. struct IFFParseBase_intern; /* prerefrence */
  46.  
  47. /* Internal prototypes */
  48. LONG ReadStream      (struct IFFHandle *, APTR, LONG, struct IFFParseBase_intern *);
  49. LONG ReadStreamLong  (struct IFFHandle *, APTR, struct IFFParseBase_intern *);
  50. LONG WriteStream     (struct IFFHandle *, APTR, LONG, struct IFFParseBase_intern *);
  51. LONG WriteStreamLong (struct IFFHandle *, APTR, struct IFFParseBase_intern *);
  52. VOID PurgeLCI         (struct LocalContextItem *, struct IFFParseBase_intern *);
  53.  
  54. LONG PushContextNode (struct IFFHandle *, LONG ,LONG, LONG, LONG, struct IFFParseBase_intern *);
  55. VOID PopContextNode  (struct IFFHandle *, struct IFFParseBase_intern *);
  56. LONG GetChunkHeader  (struct IFFHandle *, struct IFFParseBase_intern *);
  57. LONG InvokeHandlers  (struct IFFHandle *, LONG, LONG, struct IFFParseBase_intern *);
  58. LONG SeekStream      (struct IFFHandle *, LONG, struct IFFParseBase_intern *);
  59.  
  60. /* Some system entry & exit handlers (hook funcs) ß*/
  61. LONG StopFunc        (struct Hook *, APTR, APTR);
  62. LONG PropFunc        (struct Hook *, struct IFFHandle *, APTR);
  63. LONG CollectionFunc (struct Hook *, struct IFFHandle *, APTR);
  64.  
  65. /* A system purge hook for purging the LCIs installed by PropChunk and CollectionChunk */
  66. IPTR CollectionPurgeFunc (struct Hook *, struct LocalContextItem *, ULONG);
  67. IPTR PropPurgeFunc     (struct Hook *, struct LocalContextItem *, ULONG);
  68.  
  69. /* Buffer functions */
  70. struct BufferList * AllocBuffer (ULONG, struct IFFParseBase_intern *);
  71. VOID            FreeBuffer    (struct BufferList *, struct IFFParseBase_intern *);
  72.  
  73. struct BufferNode * AllocBufferNode (struct BufferList *, struct IFFParseBase_intern *);
  74.  
  75. LONG WriteToBuffer  (struct BufferList *, UBYTE *, LONG, struct IFFParseBase_intern *);
  76. BOOL SeekBuffer     (struct BufferList *, LONG);
  77.  
  78. BOOL BufferToStream (struct BufferList *, struct IFFHandle *, struct IFFParseBase_intern *);
  79.  
  80. /* StreamHandler hooks */
  81.  
  82. IPTR DOSStreamHandler  (struct Hook *, struct IFFHandle *, struct IFFStreamCmd *);
  83. IPTR ClipStreamHandler (struct Hook *, struct IFFHandle *, struct IFFStreamCmd *);
  84. IPTR BufStreamHandler  (struct Hook *, struct IFFHandle *, struct IFFStreamCmd *);
  85.  
  86. /* Message port help functions */
  87.  
  88. BOOL InitPort  (struct MsgPort *, struct Task *, struct IFFParseBase_intern *);
  89. VOID ClosePort (struct MsgPort *, struct IFFParseBase_intern *);
  90.  
  91.  
  92. /* Buffered stream install/deinstall */
  93. LONG InitBufferedStream (struct IFFHandle*, struct IFFParseBase_intern *);
  94. LONG ExitBufferedStream (struct IFFHandle*, struct IFFParseBase_intern *);
  95.  
  96. /* Endian conversion */
  97. LONG SwitchIfLittleEndian(LONG);
  98.  
  99. /* Private flags */
  100.  
  101. #define IFFF_OPEN        (1L << 19)
  102.  
  103. /*
  104.     The different states the parser can be in.
  105.     Chose values so that the compiler easily can create a jump table
  106. */
  107. #define IFFSTATE_COMPOSITE  0
  108. #define IFFSTATE_PUSHCHUNK  1
  109. #define IFFSTATE_ATOMIC     2
  110. #define IFFSTATE_SCANEXIT   3
  111. #define IFFSTATE_EXIT        4
  112. #define IFFSTATE_POPCHUNK   5
  113.  
  114. /* Size of one tile of a buffer to use in buffering of chunks */
  115. #define BUFFERNODESIZE        10000
  116.  
  117. /* Size of buffer fake a forward seek with Read()s */
  118. #define SEEKBUFSIZE        10000
  119.  
  120.  
  121. /************************/
  122. /* Internal structures    */
  123. /************************/
  124.  
  125. /* Structure for maintaing a list of buffers for buffering */
  126. struct BufferList
  127. {
  128.     struct MinList bl_ListHeader;
  129.  
  130.     /* The size of each buffer */
  131.     ULONG bl_BufferNodeSize;
  132.  
  133.     /* The current position of the Write/Seek pointer */
  134.  
  135.     /* A buffer node */
  136.     struct BufferNode * bl_CurrentNode;
  137.     /* An offset pointer into that particular node. */
  138.     ULONG bl_CurrentOffset;
  139.     /*
  140.     The number of the current buffernode (the number in the list).
  141.     First buffenode is number 1 (not 0)
  142.     */
  143.     ULONG bl_CurrentNodeNum;
  144.  
  145.     /* Number of bytes written to the bufferlist */
  146.     ULONG bl_BufferSize;
  147.  
  148.     /* Number of nodes in the list */
  149.  
  150. };
  151.  
  152. /*
  153.     One node in the bufferlist.
  154.     Contains a pointer to the buffer - tile itself
  155. */
  156.  
  157. struct BufferNode
  158. {
  159.     struct MinNode bn_Node;
  160.     UBYTE     * bn_BufferPtr;
  161.  
  162. };
  163.  
  164.  
  165. /*
  166.     Internal version of a ContextNode. Contains a list of
  167.     LocalContextItems.
  168. */
  169. struct IntContextNode
  170. {
  171.     struct ContextNode CN;
  172.     struct MinList     cn_LCIList;
  173.  
  174.     /* True if this chunk is a FORM, LIST or CAT */
  175.     BOOL           cn_Composite;
  176. };
  177.  
  178. #define GetIntCN(cn)   ((struct IntContextNode *)(cn))
  179. #define GetCN(cn)      (&GetIntCN(cn)->CN))
  180.  
  181.  
  182. /*
  183.     Internal version of the IffHandle data structure. Contains quite a bit
  184.     of useful information, eg the current context etc.
  185. */
  186.  
  187.  
  188. struct IntIFFHandle
  189. {
  190.     struct IFFHandle IH;
  191.  
  192.     /* The default context node is built-in into the iffhandle */
  193.     struct IntContextNode iff_DefaultCN;
  194.  
  195.     /* A linkedlist simulated stack with context nodes */
  196.     struct MinList iff_CNStack;
  197.  
  198.     /* containd the state in which the parser currently is */
  199.     ULONG iff_CurrentState;
  200.  
  201.     /*
  202.     The context depth at which we have started buffering.
  203.     0 if no buffering is needed.
  204.     */
  205.     ULONG iff_BufferStartDepth;
  206.  
  207.     /* Here InitIff store it's parameters */
  208.     struct Hook * iff_StreamHandler;
  209.  
  210.     /*
  211.     Entrys to preserve the StreamHandler, stream  and the stream flags
  212.     whenever the buffering streamhandle is inserted
  213.     */
  214.  
  215.     struct Hook * iff_PreservedHandler;
  216.     LONG      iff_PreservedFlags;
  217.     IPTR      iff_PreservedStream;
  218. };
  219. #define GetIntIH(ih) ((struct IntIFFHandle *)(ih))
  220. #define GetIH(ih)    (&GetIntIH(ih)->IH)
  221.  
  222. /*
  223.     Internal version of the LocalContextItem structure. Contains
  224.     the dataSize and a Hook for purging...
  225. */
  226.  
  227. struct IntLocalContextItem
  228. {
  229.     struct LocalContextItem LCI;
  230.  
  231.     struct Hook * lci_PurgeHook;
  232.     UBYTE    * lci_UserData;
  233.     ULONG      lci_UserDataSize;
  234. };
  235.  
  236. #define GetIntLCI(lci) ((struct IntLocalContextItem *)(lci))
  237. #define GetLCI(lci)    (&GetIntLCI(lci)->LCI)
  238.  
  239. /* LocalItem data in IFFLCI_ENTRY/EXITHANDLER LCIs */
  240.  
  241. struct HandlerInfo
  242. {
  243.     struct Hook * hi_Hook;
  244.     APTR      hi_Object;
  245. };
  246.  
  247.  
  248. /* LocalItem data inside IFFLCI_PROP LCIs */
  249. struct CIPtr
  250. {
  251.     struct CollectionItem * FirstCI;
  252. };
  253.  
  254.  
  255.  
  256. /* Usefull macros */
  257. #define TopChunk( iff ) (struct ContextNode*)GetIntIH(iff)->iff_CNStack.mlh_Head
  258. #define RootChunk(iff) (struct ContextNode*)GetIntIH(iff)->iff_CNStack.mlh_TailPred
  259.  
  260. struct IFFParseBase_intern
  261. {
  262.     struct Library    library;
  263.     struct ExecBase * sysbase;
  264.     BPTR          seglist;
  265.     struct Library  * dosbase;
  266.     struct Library  * utilitybase;
  267.  
  268.     struct Hook       stophook;
  269.     struct Hook       prophook;
  270.     struct Hook       collectionhook;
  271.     struct Hook       doshook;
  272.     struct Hook       cliphook;
  273.     struct Hook       bufhook;
  274.     struct Hook       collectionpurgehook;
  275.     struct Hook       proppurgehook;
  276. };
  277.  
  278. #define IPB(ipb)        ((struct IFFParseBase_intern *)ipb)
  279. #undef SysBase
  280. #define SysBase (IPB(IFFParseBase)->sysbase)
  281. #undef DOSBase
  282. #define DOSBase (IPB(IFFParseBase)->dosbase)
  283. #undef UtilityBase
  284. #define UtilityBase (IPB(IFFParseBase)->utilitybase)
  285.  
  286. #define expunge() \
  287. AROS_LC0(BPTR, expunge, struct IFFParseBase_intern *, IFFParseBase, 3, IFFParse)
  288.  
  289. #endif /* IFFPARSE_INTERN_H */
  290.