home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / languages / obrn-a_1.5_lib.lha / oberon-a / source1.lha / source / amiga / IFFParse.mod < prev    next >
Encoding:
Text File  |  1995-01-26  |  15.0 KB  |  524 lines

  1. (**************************************************************************
  2.  
  3.      $RCSfile: IFFParse.mod $
  4.   Description: Interface to iffparse.library
  5.  
  6.    Created by: fjc (Frank Copeland)
  7.     $Revision: 3.7 $
  8.       $Author: fjc $
  9.         $Date: 1995/01/26 02:39:55 $
  10.  
  11.   Includes Release 40.15
  12.  
  13.   (C) Copyright 1985-1993 Commodore-Amiga, Inc.
  14.       All Rights Reserved
  15.  
  16.   Oberon-A interface Copyright © 1994-1995, Frank Copeland.
  17.   This file is part of the Oberon-A Interface.
  18.   See Oberon-A.doc for conditions of use and distribution.
  19.  
  20. ***************************************************************************)
  21.  
  22. <* STANDARD- *> <* INITIALISE- *> <* MAIN- *>
  23. <*$ CaseChk-  IndexChk- LongVars+ NilChk-  *>
  24. <*$ RangeChk- StackChk- TypeChk-  OvflChk- *>
  25.  
  26. MODULE [2] IFFParse;
  27.  
  28. IMPORT
  29.   SYS := SYSTEM, Kernel, e := Exec, c := Clipboard, u := Utility,
  30.   s := Sets;
  31.  
  32. (*
  33. **      $VER: iffparse.h 39.1 (1.6.92)
  34. **
  35. **      iffparse.library structures and constants
  36. *)
  37.  
  38.  
  39. TYPE
  40.  
  41. (* Structure associated with an active IFF stream.
  42.  * "stream" is a value used by the client's read/write/seek functions -
  43.  * it will not be accessed by the library itself and can have any value
  44.  * (could even be a pointer or a BPTR).
  45.  *
  46.  * This structure can only be allocated by iffparse.library
  47.  *)
  48.   IFFHandlePtr * = POINTER TO IFFHandle;
  49.   IFFHandle * = RECORD
  50.     stream * : e.ULONG;
  51.     flags *  : s.SET32;
  52.     depth *  : LONGINT;      (*  Depth of context stack.  *)
  53.   END; (* IFFHandle *)
  54.  
  55. (*
  56.  * Bit masks for "IFFHandle.flags" field.
  57.  *)
  58.  
  59. CONST
  60.  
  61.   read *       = {};                     (* read mode - default *)
  62.   write *      = {0};                    (* write mode *)
  63.   rwBits *     = read + write;           (* read/write bits *)
  64.   fSeek *      = {1};                    (* forward seek only *)
  65.   rSeek *      = {2};                    (* random seek *)
  66.   reserved *   = {16 .. 31};             (* Don't touch these bits. *)
  67.  
  68. (*****************************************************************************)
  69.  
  70. (*
  71.  * When the library calls your stream handler, you'll be passed a pointer
  72.  * to this structure as the "message packet".
  73.  *)
  74.  
  75. TYPE
  76.  
  77.   IFFStreamCmdPtr * = POINTER TO IFFStreamCmd;
  78.   IFFStreamCmd * = RECORD
  79.     command * : LONGINT;     (*  Operation to be performed (cmd...) *)
  80.     buf *     : e.APTR;      (*  Pointer to data buffer              *)
  81.     nBytes *  : LONGINT;     (*  Number of bytes to be affected      *)
  82.   END; (* IFFStreamCmd *)
  83.  
  84. (*****************************************************************************)
  85.  
  86. (*
  87.  * A node associated with a context on the iffStack.  Each node
  88.  * represents a chunk, the stack representing the current nesting
  89.  * of chunks in the open IFF file.  Each context node has associated
  90.  * local context items in the (private) LocalItems list.  The ID, type,
  91.  * size and scan values describe the chunk associated with this node.
  92.  *
  93.  * This structure can only be allocated by iffparse.library
  94.  *)
  95.  
  96. TYPE
  97.  
  98.   ContextNodePtr * = POINTER TO ContextNode;
  99.   ContextNode * = RECORD (e.MinNodeBase)
  100.     node * : e.MinNode;
  101.     id *   : LONGINT;
  102.     type * : LONGINT;
  103.     size * : LONGINT;        (*  Size of this chunk             *)
  104.     scan * : LONGINT;        (*  # of bytes read/written so far *)
  105.   END; (* ContextNode *)
  106.  
  107. (*****************************************************************************)
  108.  
  109. (*
  110.  * Local context items live in the ContextNode's.  Each class is identified
  111.  * by its lciIdent code and has a (private) purge vector for when the
  112.  * parent context node is popped.
  113.  *
  114.  * This structure can only be allocated by iffparse.library
  115.  *)
  116.  
  117. TYPE
  118.  
  119.   LocalContextItemPtr * = POINTER TO LocalContextItem;
  120.   LocalContextItem * = RECORD (e.MinNodeBase)
  121.     node *  : e.MinNode;
  122.     id *    : e.ULONG;
  123.     type *  : e.ULONG;
  124.     ident * : e.ULONG;
  125.   END; (* LocalContextItem *)
  126.  
  127. (*****************************************************************************)
  128.  
  129. (*
  130.  * StoredProperty: a local context item containing the data stored
  131.  * from a previously encountered property chunk.
  132.  *)
  133.  
  134. TYPE
  135.  
  136.   StoredPropertyPtr * = POINTER TO StoredProperty;
  137.   StoredProperty * = RECORD
  138.     size * : LONGINT;
  139.     data * : e.APTR;
  140.   END; (* StoredProperty *)
  141.  
  142. (*****************************************************************************)
  143.  
  144. (*
  145.  * Collection Item: the actual node in the collection list at which
  146.  * client will look.  The next pointers cross context boundaries so
  147.  * that the complete list is accessable.
  148.  *)
  149.  
  150. TYPE
  151.  
  152.   CollectionItemPtr * = POINTER TO CollectionItem;
  153.   CollectionItem * = RECORD
  154.     next * : CollectionItemPtr;
  155.     size * : LONGINT;
  156.     data * : e.APTR;
  157.   END; (* CollectionItem *)
  158.  
  159. (*****************************************************************************)
  160.  
  161. (*
  162.  * Structure returned by OpenClipboard().  You may do cmdPosts and such
  163.  * using this structure.  However, once you call OpenIFF(), you may not
  164.  * do any more of your own I/O to the clipboard until you call CloseIFF().
  165.  *)
  166.  
  167. TYPE
  168.  
  169.   ClipboardHandlePtr * = POINTER TO ClipboardHandle;
  170.   ClipboardHandle * = RECORD (c.IOClipReqBase)
  171.     req *         : c.IOClipReq;
  172.     cbport *      : e.MsgPort;
  173.     satisfyPort * : e.MsgPort;
  174.   END; (* ClipboardHandle *)
  175.  
  176. (*****************************************************************************)
  177.  
  178. (*
  179.  * IFF return codes.  Most functions return either zero for success or
  180.  * one of these codes.  The exceptions are the read/write functions which
  181.  * return positive values for number of bytes or records read or written,
  182.  * or a negative error code.  Some of these codes are not errors per sae,
  183.  * but valid conditions such as EOF or EOC (End of Chunk).
  184.  *)
  185.  
  186. CONST
  187.  
  188.   errEOF *              = -1;     (*  Reached logical end of file *)
  189.   errEOC *              = -2;     (*  About to leave context      *)
  190.   errNoScope *          = -3;     (*  No valid scope for property *)
  191.   errNoMem *            = -4;     (*  Internal memory alloc failed*)
  192.   errRead *             = -5;     (*  Stream read error           *)
  193.   errWrite *            = -6;     (*  Stream write error          *)
  194.   errSeek *             = -7;     (*  Stream seek error           *)
  195.   errMangled *          = -8;     (*  Data in file is corrupt     *)
  196.   errSyntax *           = -9;     (*  IFF syntax error            *)
  197.   errNotIFF *           = -10;    (*  Not an IFF file             *)
  198.   errNoHook *           = -11;    (*  No call-back hook provided  *)
  199.   return2Client *       = -12;    (*  Client handler normal return*)
  200.  
  201. (*****************************************************************************)
  202.  
  203. (*
  204.  * Universal IFF identifiers.
  205.  *)
  206.  
  207. CONST
  208.  
  209.   idFORM *   = 0464F524DH;  (* MakeID('F','O','R','M') *)
  210.   idLIST *   = 04C495354H;  (* MakeID('L','I','S','T') *)
  211.   idCAT *    = 043415420H;  (* MakeID('C','A','T',' ') *)
  212.   idPROP *   = 050524F50H;  (* MakeID('P','R','O','P') *)
  213.   idNULL *   = 020202020H;  (* MakeID(' ',' ',' ',' ') *)
  214.  
  215. (*
  216.  * Identifier codes for universally recognized local context items.
  217.  *)
  218.  
  219. CONST
  220.  
  221.   lciPROP *         = 070726F70H;  (* MakeID('p','r','o','p') *)
  222.   lciCOLLECTION *   = 0636F6C6CH;  (* MakeID('c','o','l','l') *)
  223.   lciENTRYHANDLER * = 0656E6864H;  (* MakeID('e','n','h','d') *)
  224.   lciEXITHANDLER *  = 065786864H;  (* MakeID('e','x','h','d') *)
  225.  
  226. (*****************************************************************************)
  227.  
  228. (*
  229.  * Control modes for ParseIFF() function.
  230.  *)
  231.  
  232. CONST
  233.  
  234.   parseScan *           = 0;
  235.   parseStep *           = 1;
  236.   parseRawStep *        = 2;
  237.  
  238. (*****************************************************************************)
  239.  
  240. (*
  241.  * Control modes for StoreLocalItem().
  242.  *)
  243.  
  244. CONST
  245.  
  246.   sliRoot *             = 1;      (*  Store in default context       *)
  247.   sliTop *              = 2;      (*  Store in current context       *)
  248.   sliProp *             = 3;      (*  Store in topmost FORM or LIST  *)
  249.  
  250. (*****************************************************************************)
  251.  
  252. (* Magic value for writing functions. If you pass this value in as a size
  253.  * to PushChunk() when writing a file, the parser will figure out the
  254.  * size of the chunk for you. If you know the size, is it better to
  255.  * provide as it makes things faster.
  256.  *)
  257.  
  258.   sizeUnknown *         = -1;
  259.  
  260. (*****************************************************************************)
  261.  
  262. (*
  263.  * Possible call-back command values.  (Using 0 as the value for iffCmdInit
  264.  * was, in retrospect, probably a bad idea.)
  265.  *)
  266.  
  267. CONST
  268.  
  269.   cmdInit *     = 0;       (*  Prepare the stream for a session    *)
  270.   cmdCleanup *  = 1;       (*  Terminate stream session            *)
  271.   cmdRead *     = 2;       (*  Read bytes from stream              *)
  272.   cmdWrite *    = 3;       (*  Write bytes to stream               *)
  273.   cmdSeek *     = 4;       (*  Seek on stream                      *)
  274.   cmdEntry *    = 5;       (*  You just entered a new context      *)
  275.   cmdExit *     = 6;       (*  You're about to leave a context     *)
  276.   cmdPurgeLCI * = 7;       (*  Purge a LocalContextItem            *)
  277.  
  278. (*****************************************************************************)
  279.  
  280. (* Obsolete IFFParse definitions, here for source code compatibility only.
  281.  * Please do NOT use in new code.
  282.  *)
  283. CONST
  284.  
  285.   sccInit *     = cmdInit;
  286.   sccCleanup *  = cmdCleanup;
  287.   sccRead *     = cmdRead;
  288.   sccWrite *    = cmdWrite;
  289.   sccSeek *     = cmdSeek;
  290.  
  291.  
  292. (*-- Library Base variable --------------------------------------------*)
  293.  
  294. CONST
  295.  
  296.   iffparseName * = "iffparse.library";
  297.  
  298. VAR
  299.  
  300.   base * : e.LibraryPtr;
  301.  
  302.  
  303. (*-- Library Functions ------------------------------------------------*)
  304.  
  305. (*
  306. **      $VER: iffparse_protos.h 39.1 (1.6.92)
  307. *)
  308.  
  309. (*--- functions in V36 or higher (Release 2.0) ---*)
  310.  
  311. (* ------ Basic functions ------*)
  312.  
  313. PROCEDURE AllocIFF* [base,-30] ()
  314.   : IFFHandlePtr;
  315. PROCEDURE OpenIFF* [base,-36]
  316.   ( iff    [8] : IFFHandlePtr;
  317.     rwMode [0] : s.SET32 )
  318.   : LONGINT;
  319. PROCEDURE ParseIFF* [base,-42]
  320.   ( iff     [8] : IFFHandlePtr;
  321.     control [0] : LONGINT )
  322.   : LONGINT;
  323. PROCEDURE CloseIFF* [base,-48]
  324.   ( iff [8] : IFFHandlePtr );
  325. PROCEDURE FreeIFF* [base,-54]
  326.   ( iff [8] : IFFHandlePtr );
  327.  
  328. (* ------ Read/Write functions ------*)
  329.  
  330. PROCEDURE ReadChunkBytes* [base,-60]
  331.   ( iff      [8] : IFFHandlePtr;
  332.     VAR buf  [9] : ARRAY OF SYS.BYTE;
  333.     size     [0] : LONGINT )
  334.   : LONGINT;
  335. PROCEDURE WriteChunkBytes* [base,-66]
  336.   ( iff  [8] : IFFHandlePtr;
  337.     buf  [9] : ARRAY OF SYS.BYTE;
  338.     size [0] : LONGINT )
  339.   : LONGINT;
  340. PROCEDURE ReadChunkRecords* [base,-72]
  341.   ( iff            [8] : IFFHandlePtr;
  342.     VAR buf        [9] : ARRAY OF SYS.BYTE;
  343.     bytesPerRecord [0] : LONGINT;
  344.     nRecords       [1] : LONGINT )
  345.   : LONGINT;
  346. PROCEDURE WriteChunkRecords* [base,-78]
  347.   ( iff            [8] : IFFHandlePtr;
  348.     buf            [9] : ARRAY OF SYS.BYTE;
  349.     bytesPerRecord [0] : LONGINT;
  350.     nRecords       [1] : LONGINT )
  351.   : LONGINT;
  352.  
  353. (* ------ Context entry/exit ------*)
  354.  
  355. PROCEDURE PushChunk* [base,-84]
  356.   ( iff  [8] : IFFHandlePtr;
  357.     type [0] : LONGINT;
  358.     id   [1] : LONGINT;
  359.     size [2] : LONGINT )
  360.   : LONGINT;
  361. PROCEDURE PopChunk* [base,-90]
  362.   ( iff [8] : IFFHandlePtr )
  363.   : LONGINT;
  364.  
  365. (* ------ Low-level handler installation ------*)
  366.  
  367. PROCEDURE EntryHandler* [base,-102]
  368.   ( iff      [8] : IFFHandlePtr;
  369.     type     [0] : LONGINT;
  370.     id       [1] : LONGINT;
  371.     position [2] : LONGINT;
  372.     handler  [9] : u.HookPtr;
  373.     object  [10] : e.APTR )
  374.   : LONGINT;
  375. PROCEDURE ExitHandler* [base,-108]
  376.   ( iff      [8] : IFFHandlePtr;
  377.     type     [0] : LONGINT;
  378.     id       [1] : LONGINT;
  379.     position [2] : LONGINT;
  380.     handler  [9] : u.HookPtr;
  381.     object  [10] : e.APTR )
  382.   : LONGINT;
  383.  
  384. (* ------ Built-in chunk/property handlers ------*)
  385.  
  386. PROCEDURE PropChunk* [base,-114]
  387.   ( iff  [8] : IFFHandlePtr;
  388.     type [0] : LONGINT;
  389.     id   [1] : LONGINT )
  390.   : LONGINT;
  391. PROCEDURE PropChunks* [base,-120]
  392.   ( iff       [8] : IFFHandlePtr;
  393.     propArray [9] : ARRAY OF LONGINT;
  394.     nProps    [0] : LONGINT )
  395.   : LONGINT;
  396. PROCEDURE StopChunk* [base,-126]
  397.   ( iff  [8] : IFFHandlePtr;
  398.     type [0] : LONGINT;
  399.     id   [1] : LONGINT )
  400.   : LONGINT;
  401. PROCEDURE StopChunks* [base,-132]
  402.   ( iff       [8] : IFFHandlePtr;
  403.     propArray [9] : ARRAY OF LONGINT;
  404.     nProps    [0] : LONGINT )
  405.   : LONGINT;
  406. PROCEDURE CollectionChunk* [base,-138]
  407.   ( iff  [8] : IFFHandlePtr;
  408.     type [0] : LONGINT;
  409.     id   [1] : LONGINT )
  410.   : LONGINT;
  411. PROCEDURE CollectionChunks* [base,-144]
  412.   ( iff       [8] : IFFHandlePtr;
  413.     propArray [9] : ARRAY OF LONGINT;
  414.     nProps    [0] : LONGINT )
  415.   : LONGINT;
  416. PROCEDURE StopOnExit* [base,-150]
  417.   ( iff  [8] : IFFHandlePtr;
  418.     type [0] : LONGINT;
  419.     id   [1] : LONGINT )
  420.   : LONGINT;
  421.  
  422. (* ------ Context utilities ------*)
  423.  
  424. PROCEDURE FindProp* [base,-156]
  425.   ( iff  [8] : IFFHandlePtr;
  426.     type [0] : LONGINT;
  427.     id   [1] : LONGINT )
  428.   : StoredPropertyPtr;
  429. PROCEDURE FindCollection* [base,-162]
  430.   ( iff  [8] : IFFHandlePtr;
  431.     type [0] : LONGINT;
  432.     id   [1] : LONGINT )
  433.   : CollectionItemPtr;
  434. PROCEDURE FindPropContext* [base,-168]
  435.   ( iff [8] : IFFHandlePtr )
  436.   : ContextNodePtr;
  437. PROCEDURE CurrentChunk* [base,-174]
  438.   ( iff [8] : IFFHandlePtr )
  439.   : ContextNodePtr;
  440. PROCEDURE ParentChunk* [base,-180]
  441.   ( contextNode [8] : ContextNodePtr )
  442.   : ContextNodePtr;
  443.  
  444. (* ------ LocalContextItem support functions ------*)
  445.  
  446. PROCEDURE AllocLocalItem* [base,-186]
  447.   ( type     [0] : LONGINT;
  448.     id       [1] : LONGINT;
  449.     ident    [2] : LONGINT;
  450.     dataSize [3] : LONGINT )
  451.   : LocalContextItemPtr;
  452. PROCEDURE LocalItemData* [base,-192]
  453.   ( localItem [8] : LocalContextItemPtr )
  454.   : e.APTR;
  455. PROCEDURE SetLocalItemPurge* [base,-198]
  456.   ( localItem [8] : LocalContextItemPtr;
  457.     purgeHook [9] : u.HookPtr );
  458. PROCEDURE FreeLocalItem* [base,-204]
  459.   ( localItem [8] : LocalContextItemPtr );
  460. PROCEDURE FindLocalItem* [base,-210]
  461.   ( iff   [8] : IFFHandlePtr;
  462.     type  [0] : LONGINT;
  463.     id    [1] : LONGINT;
  464.     ident [2] : LONGINT )
  465.   : LocalContextItemPtr;
  466. PROCEDURE StoreLocalItem* [base,-216]
  467.   ( iff       [8] : IFFHandlePtr;
  468.     localItem [9] : LocalContextItemPtr;
  469.     position  [0] : LONGINT )
  470.   : LONGINT;
  471. PROCEDURE StoreItemInContext* [base,-222]
  472.   ( iff          [8] : IFFHandlePtr;
  473.     localItem    [9] : LocalContextItemPtr;
  474.     contextNode [10] : ContextNodePtr );
  475.  
  476. (* ------ IFFHandle initialization ------*)
  477.  
  478. PROCEDURE InitIFF* [base,-228]
  479.   ( iff        [8] : IFFHandlePtr;
  480.     flags      [0] : s.SET32;
  481.     streamHook [9] : u.HookPtr );
  482. PROCEDURE InitIFFasDOS* [base,-234]
  483.   ( iff [8] : IFFHandlePtr );
  484. PROCEDURE InitIFFasClip* [base,-240]
  485.   ( iff [8] : IFFHandlePtr );
  486.  
  487. (* ------ Internal clipboard support ------*)
  488.  
  489. PROCEDURE OpenClipboard* [base,-246]
  490.   ( unitNum [0] : LONGINT )
  491.   : ClipboardHandlePtr;
  492. PROCEDURE CloseClipboard* [base,-252]
  493.   ( clipboard [8] : ClipboardHandlePtr );
  494.  
  495. (* ------ Miscellaneous ------*)
  496.  
  497. PROCEDURE GoodID* [base,-258]
  498.   ( id [0] : LONGINT )
  499.   : LONGINT;
  500. PROCEDURE GoodType* [base,-264]
  501.   ( type [0] : LONGINT )
  502.   : LONGINT;
  503. PROCEDURE IDtoStr* [base,-270]
  504.   ( id      [0] : LONGINT;
  505.     VAR buf [8] : ARRAY OF CHAR )
  506.   : e.LSTRPTR;
  507.  
  508.  
  509. (*-- Library Base variable --------------------------------------------*)
  510.  
  511. <*$LongVars-*>
  512.  
  513. (*-----------------------------------*)
  514. PROCEDURE* [0] CloseLib (VAR rc : LONGINT);
  515.  
  516. BEGIN (* CloseLib *)
  517.   IF base # NIL THEN e.CloseLibrary (base) END
  518. END CloseLib;
  519.  
  520. BEGIN
  521.   base := e.OpenLibrary (iffparseName, e.libraryMinimum);
  522.   IF base # NIL THEN Kernel.SetCleanup (CloseLib) END
  523. END IFFParse.
  524.