home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / M2V11-1.LHA / modula / amiga / IFFParse.def < prev    next >
Encoding:
Text File  |  1993-11-10  |  11.8 KB  |  380 lines

  1. DEFINITION FOR LIBRARY MODULE IFFParse ;
  2.  
  3. FROM SYSTEM    IMPORT ADDRESS, LONGSET, MAKEID, STRING ;
  4. FROM Exec    IMPORT MinNode, MsgPort ;
  5. FROM Clipboard    IMPORT IOClipReq ;
  6. FROM Utility    IMPORT HookPtr ;
  7.  
  8. TYPE
  9.   IFFHandlePtr        = POINTER TO IFFHandle ;
  10.   IFFStreamCmdPtr    = POINTER TO IFFStreamCmd ;
  11.   ContextNodePtr    = POINTER TO ContextNode ;
  12.   LocalContextItemPtr    = POINTER TO LocalContextItem ;
  13.   StoredPropertyPtr    = POINTER TO StoredProperty ;
  14.   CollectionItemPtr    = POINTER TO CollectionItem ;
  15.   ClipboardHandlePtr    = POINTER TO ClipboardHandle ;
  16.  
  17. (*===========================================================================*)
  18.  
  19.  
  20. (* Structure associated with an active IFF stream.                *)
  21. (* "iff_Stream" is a value used by the client's read/write/seek functions - *)
  22. (* it will not be accessed by the library itself and can have any value        *)
  23. (* (could even be a pointer or a BPTR).                        *)
  24. (* This structure can only be allocated by iffparse.library            *)
  25.  
  26.   IFFHandle = RECORD
  27.     iff_Stream : ADDRESS ;
  28.     iff_Flags  : LONGSET ;
  29.     iff_Depth  : LONGINT ; (*  Depth of context stack *)
  30.   END ;
  31.  
  32. (* bit masks for "iff_Flags" field *)
  33. CONST
  34.   IFFF_READ    = { } ;             (* read mode - default    *)
  35.   IFFF_WRITE    = {0} ;             (* write mode           *)
  36.   IFFF_RWBITS    = IFFF_READ+IFFF_WRITE ; (* read/write bits       *)
  37.   IFFF_FSEEK    = {1} ;             (* forward seek only       *)
  38.   IFFF_RSEEK    = {2} ;             (* random seek           *)
  39.   IFFF_RESERVED    = LONGSET(0FFFF0000H) ;     (* Don't touch these bits *)
  40.  
  41.  
  42. (*===========================================================================*)
  43.  
  44.  
  45. (* When the library calls your stream handler, you'll be passed a pointer *)
  46. (* to this structure as the "message packet".                  *)
  47.  
  48. TYPE
  49.   IFFStreamCmd = RECORD
  50.     sc_Command : LONGINT ;    (* Operation to be performed (IFFCMD_) *)
  51.     sc_Buf     : ADDRESS ;    (* Pointer to data buffer           *)
  52.     sc_NBytes  : LONGINT ;    (* Number of bytes to be affected      *)
  53.   END ;
  54.  
  55.  
  56. (*===========================================================================*)
  57.  
  58.  
  59. (* A node associated with a context on the iff_Stack. Each node        *)
  60. (* represents a chunk, the stack representing the current nesting    *)
  61. (* of chunks in the open IFF file. Each context node has associated    *)
  62. (* local context items in the (private) LocalItems list.  The ID, type,    *)
  63. (* size and scan values describe the chunk associated with this node.    *)
  64. (* This structure can only be allocated by iffparse.library        *)
  65.  
  66.  
  67.   ContextNode = RECORD
  68.     cn_Node : MinNode ;
  69.     cn_ID   : LONGINT ;
  70.     cn_Type : LONGINT ;
  71.     cn_Size : LONGINT ;    (*  Size of this chunk           *)
  72.     cn_Scan : LONGINT ;    (*  # of bytes read/written so far *)
  73.   END ;
  74.  
  75.  
  76. (*===========================================================================*)
  77.  
  78.  
  79. (* Local context items live in the ContextNode's.  Each class is identified *)
  80. (* by its lci_Ident code and has a (private) purge vector for when the        *)
  81. (* parent context node is popped.                        *)
  82. (* This structure can only be allocated by iffparse.library            *)
  83.  
  84.   LocalContextItem = RECORD
  85.     lci_Node  : MinNode ;
  86.     lci_ID    : LONGINT ;
  87.     lci_Type  : LONGINT ;
  88.     lci_Ident : LONGINT ;
  89.   END ;
  90.  
  91.  
  92. (*===========================================================================*)
  93.  
  94.  
  95. (* StoredProperty: a local context item containing the data stored    *)
  96. (* from a previously encountered property chunk.            *)
  97.  
  98.   StoredProperty = RECORD
  99.     sp_Size : LONGINT ;
  100.     sp_Data : ADDRESS ;
  101.   END ;
  102.  
  103.  
  104. (*===========================================================================*)
  105.  
  106.  
  107. (* Collection Item: the actual node in the collection list at which    *)
  108. (* client will look. The next pointers cross context boundaries so    *)
  109. (* that the complete list is accessable.                *)
  110.  
  111.   CollectionItem = RECORD
  112.     ci_Next : CollectionItemPtr ;
  113.     ci_Size : LONGINT ;
  114.     ci_Data : ADDRESS ;
  115.   END ;
  116.  
  117.  
  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.   ClipboardHandle = RECORD
  126.     cbh_Req        : IOClipReq ;
  127.     cbh_CBport        : MsgPort   ;
  128.     cbh_SatisfyPort : MsgPort   ;
  129.   END ;
  130.  
  131.  
  132. (*===========================================================================*)
  133.  
  134.  
  135. (* IFF return codes. Most functions return either zero for success or       *)
  136. (* one of these codes. The exceptions are the read/write functions which   *)
  137. (* return positive values for number of bytes or records read or written,  *)
  138. (* or a negative error code. Some of these codes are not errors per sae,   *)
  139. (* but valid conditions such as EOF or EOC (End of Chunk).           *)
  140.  
  141. CONST
  142.   IFFERR_EOF        =  -1 ;    (* Reached logical end of file    *)
  143.   IFFERR_EOC        =  -2 ;    (* About to leave context    *)
  144.   IFFERR_NOSCOPE    =  -3 ;    (* No valid scope for property    *)
  145.   IFFERR_NOMEM        =  -4 ;    (* Internal memory alloc failed *)
  146.   IFFERR_READ        =  -5 ;    (* Stream read error        *)
  147.   IFFERR_WRITE        =  -6 ;    (* Stream write error        *)
  148.   IFFERR_SEEK        =  -7 ;    (* Stream seek error        *)
  149.   IFFERR_MANGLED    =  -8 ;    (* Data in file is corrupt    *)
  150.   IFFERR_SYNTAX        =  -9 ;    (* IFF syntax error        *)
  151.   IFFERR_NOTIFF        = -10 ;    (* Not an IFF file        *)
  152.   IFFERR_NOHOOK        = -11 ;    (* No call-back hook provided    *)
  153.   IFF_RETURN2CLIENT    = -12 ;    (* Client handler normal return *)
  154.  
  155.  
  156. (*===========================================================================*)
  157.  
  158. CONST
  159. (* Universal IFF identifiers *)
  160.   ID_FORM        = MAKEID("FORM") ;
  161.   ID_LIST        = MAKEID("LIST") ;
  162.   ID_CAT        = MAKEID("CAT ") ;
  163.   ID_PROP        = MAKEID("PROP") ;
  164.   ID_NULL        = MAKEID("    ") ;
  165.  
  166. (* Identifier codes for universally recognized local context items *)
  167.   IFFLCI_PROP        = MAKEID("prop") ;
  168.   IFFLCI_COLLECTION    = MAKEID("coll") ;
  169.   IFFLCI_ENTRYHANDLER    = MAKEID("enhd") ;
  170.   IFFLCI_EXITHANDLER    = MAKEID("exhd") ;
  171.  
  172.  
  173. (*===========================================================================*)
  174.  
  175.  
  176. (* Control modes for ParseIFF() function *)
  177.   IFFPARSE_SCAN        = 0 ;
  178.   IFFPARSE_STEP        = 1 ;
  179.   IFFPARSE_RAWSTEP    = 2 ;
  180.  
  181.  
  182. (*===========================================================================*)
  183.  
  184.  
  185. (* Control modes for StoreLocalItem() function *)
  186.   IFFSLI_ROOT        = 1 ; (* Store in default context      *)
  187.   IFFSLI_TOP        = 2 ; (* Store in current context      *)
  188.   IFFSLI_PROP        = 3 ; (* Store in topmost FORM or LIST      *)
  189.  
  190.  
  191. (*===========================================================================*)
  192.  
  193.  
  194. (* Magic value for writing functions. If you pass this value in as a size *)
  195. (* to PushChunk() when writing a file, the parser will figure out the      *)
  196. (* size of the chunk for you. If you know the size, is it better to      *)
  197. (* provide as it makes things faster.                      *)
  198.  
  199.   IFFSIZE_UNKNOWN     = -1 ;
  200.  
  201.  
  202. (*===========================================================================*)
  203.  
  204.  
  205. (* Possible call-back command values *)
  206.   IFFCMD_INIT        = 0 ;    (* Prepare the stream for a session *)
  207.   IFFCMD_CLEANUP    = 1 ;    (* Terminate stream session        *)
  208.   IFFCMD_READ        = 2 ;    (* Read bytes from stream        *)
  209.   IFFCMD_WRITE        = 3 ;    (* Write bytes to stream        *)
  210.   IFFCMD_SEEK        = 4 ;    (* Seek on stream            *)
  211.   IFFCMD_ENTRY        = 5 ;    (* You just entered a new context   *)
  212.   IFFCMD_EXIT        = 6 ;    (* You're about to leave a context  *)
  213.   IFFCMD_PURGELCI    = 7 ;    (* Purge a LocalContextItem        *)
  214.  
  215.  
  216. (*===========================================================================*)
  217.  
  218.  
  219. (* Obsolete IFFParse definitions, here for source code compatibility only. *)
  220. (* Please do NOT use in new code.                       *)
  221. (*   IFFPARSE_V37_NAMES_ONLY to remove these older names           *)
  222.  
  223. CONST
  224.   IFFSCC_INIT     = IFFCMD_INIT ;
  225.   IFFSCC_CLEANUP = IFFCMD_CLEANUP ;
  226.   IFFSCC_READ     = IFFCMD_READ ;
  227.   IFFSCC_WRITE     = IFFCMD_WRITE ;
  228.   IFFSCC_SEEK     = IFFCMD_SEEK ;
  229.  
  230.  
  231. (*===========================================================================*)
  232.  
  233. VAR
  234.   IFFParseBase : ADDRESS ;
  235.  
  236. (*--- functions in V36 or higher (Release 2.0) ---*)
  237.  
  238. (* Basic functions *)
  239.  
  240. PROCEDURE AllocIFF( ) : IFFHandlePtr ;
  241. PROCEDURE OpenIFF ( iff : IFFHandlePtr ; rwMode : LONGSET ) : LONGINT ;
  242. PROCEDURE ParseIFF( iff : IFFHandlePtr ; control : LONGSET ) : LONGINT ;
  243. PROCEDURE CloseIFF( iff : IFFHandlePtr ) ;
  244. PROCEDURE FreeIFF ( iff : IFFHandlePtr ) ;
  245.  
  246. (* Read/Write functions *)
  247.  
  248. PROCEDURE ReadChunkBytes( iff : IFFHandlePtr ;
  249.               buf : ADDRESS ;
  250.               numBytes : LONGINT ) : LONGINT ;
  251.  
  252. PROCEDURE WriteChunkBytes( iff : IFFHandlePtr ;
  253.                buf : ADDRESS ;
  254.                numBytes : LONGINT ) : LONGINT ;
  255.  
  256. PROCEDURE ReadChunkRecords( iff : IFFHandlePtr ;
  257.                 buf : ADDRESS ;
  258.                 bytesPerRecord : LONGINT ;
  259.                 numRecords : LONGINT ) : LONGINT ;
  260.  
  261. PROCEDURE WriteChunkRecords( iff : IFFHandlePtr ;
  262.                  buf : ADDRESS ;
  263.                  bytesPerRecord : LONGINT ;
  264.                  numRecords : LONGINT ) : LONGINT ;
  265.  
  266. (* Context entry/exit *)
  267.  
  268. PROCEDURE PushChunk( iff  : IFFHandlePtr ;
  269.              type : LONGINT ;
  270.              id   : LONGINT ;
  271.              size : LONGINT ) : LONGINT ;
  272.  
  273. PROCEDURE PopChunk( iff : IFFHandlePtr ) : LONGINT ;
  274.  
  275. (* Low-level handler installation *)
  276.  
  277. PROCEDURE EntryHandler( iff     : IFFHandlePtr ;
  278.             type     : LONGINT  ;
  279.             id     : LONGINT ;
  280.             position : LONGINT ;
  281.             handler  : HookPtr ;
  282.             object   : ADDRESS ) : LONGINT ;
  283.  
  284. PROCEDURE ExitHandler( iff    : IFFHandlePtr ;
  285.                type    : LONGINT ;
  286.                id    : LONGINT ;
  287.                position : LONGINT ;
  288.                handler    : HookPtr ;
  289.                object    : ADDRESS ) : LONGINT ;
  290.  
  291. (* Built-in chunk/property handlers *)
  292.  
  293. PROCEDURE PropChunk( iff  : IFFHandlePtr ;
  294.              type : LONGINT ;
  295.              id   : LONGINT ) : LONGINT ;
  296.  
  297. PROCEDURE PropChunks( iff       : IFFHandlePtr ;
  298.               propArray : ADDRESS ;
  299.               numPairs  : LONGINT ) : LONGINT ;
  300.  
  301. PROCEDURE StopChunk( iff : IFFHandlePtr ; type, id : LONGINT ) : LONGINT ;
  302.  
  303. PROCEDURE StopChunks( iff    : IFFHandlePtr ;
  304.               propArray : ADDRESS ;
  305.               numPairs  : LONGINT ) : LONGINT ;
  306.  
  307. PROCEDURE CollectionChunk( iff : IFFHandlePtr ;
  308.                type, id : LONGINT ) : LONGINT ;
  309.  
  310. PROCEDURE CollectionChunks( iff          : IFFHandlePtr ;
  311.                 propArray : ADDRESS ;
  312.                 numPairs  : LONGINT ) : LONGINT ;
  313.  
  314. PROCEDURE StopOnExit( iff  : IFFHandlePtr ;
  315.               type : LONGINT ;
  316.               id   : LONGINT ) : LONGINT ;
  317.  
  318. (* Context utilities *)
  319.  
  320. PROCEDURE FindProp( iff  : IFFHandlePtr ;
  321.             type : LONGINT ;
  322.             id   : LONGINT ) : StoredPropertyPtr ;
  323.  
  324. PROCEDURE FindCollection( iff  : IFFHandlePtr ;
  325.               type : LONGINT ;
  326.               id   : LONGINT ) : CollectionItemPtr ;
  327.  
  328. PROCEDURE FindPropContext( iff : IFFHandlePtr ) : ContextNodePtr ;
  329. PROCEDURE CurrentChunk( iff : IFFHandlePtr ) : ContextNodePtr ;
  330. PROCEDURE ParentChunk( contextNode : ContextNodePtr ) : ContextNodePtr ;
  331.  
  332. (* LocalContextItem support functions *)
  333.  
  334. PROCEDURE AllocLocalItem( type       : LONGINT ;
  335.               id       : LONGINT ;
  336.               ident       : LONGINT ;
  337.               dataSize : LONGINT ) : LocalContextItemPtr ;
  338.  
  339. PROCEDURE LocalItemData( localItem : LocalContextItemPtr ) : ADDRESS ;
  340.  
  341. PROCEDURE SetLocalItemPurge( localItem : LocalContextItemPtr ;
  342.                  purgeHook : HookPtr ) ;
  343.  
  344. PROCEDURE FreeLocalItem( localItem : LocalContextItemPtr ) ;
  345.  
  346. PROCEDURE FindLocalItem( iff  : IFFHandlePtr ;
  347.              type : LONGINT ;
  348.              id   : LONGINT ;
  349.              ident: LONGINT ) : LocalContextItemPtr ;
  350.  
  351. PROCEDURE StoreLocalItem( iff        : IFFHandlePtr ;
  352.               localItem : LocalContextItemPtr ;
  353.               position  : LONGINT ) : LONGINT ;
  354.  
  355. PROCEDURE StoreItemInContext( iff      : IFFHandlePtr ;
  356.                   localItem      : LocalContextItemPtr ;
  357.                   contextNode : ContextNodePtr ) ;
  358.  
  359. (* IFFHandle initialization *)
  360.  
  361. PROCEDURE InitIFF( iff   : IFFHandlePtr ;
  362.            flags : LONGSET ;
  363.            streamHook : HookPtr ) ;
  364.  
  365. PROCEDURE InitIFFasDOS( iff : IFFHandlePtr ) ;
  366. PROCEDURE InitIFFasClip( iff : IFFHandlePtr ) ;
  367.  
  368. (* Internal clipboard support *)
  369.  
  370. PROCEDURE OpenClipboard( unitNumber : LONGINT ) : ClipboardHandlePtr ;
  371. PROCEDURE CloseClipboard( clipHandle : ClipboardHandlePtr ) ;
  372.  
  373. (* Miscellaneous *)
  374.  
  375. PROCEDURE GoodID( id : LONGINT ) : LONGINT ;
  376. PROCEDURE GoodType( type : LONGINT ) : LONGINT ;
  377. PROCEDURE IDtoStr( id : LONGINT ; buf : STRING ) : STRING ;
  378.  
  379. END IFFParse.
  380.