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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: openiff.c,v 1.1 1997/02/03 16:44:27 digulla Exp $
  4.  
  5.     Desc:
  6.     Lang: english
  7. */
  8. #include "iffparse_intern.h"
  9.  
  10. /*****************************************************************************
  11.  
  12.     NAME */
  13. #include <proto/iffparse.h>
  14.  
  15.     AROS_LH2(LONG, OpenIFF,
  16.  
  17. /*  SYNOPSIS */
  18.     AROS_LHA(struct IFFHandle *, iff, A0),
  19.     AROS_LHA(LONG              , rwMode, D0),
  20.  
  21. /*  LOCATION */
  22.     struct Library *, IFFParseBase, 6, IFFParse)
  23.  
  24. /*  FUNCTION
  25.     Initializes an IFFHandle struct for a new session of reading or writing.
  26.     The direction of the I/O is determined by the rwMode flags supplied
  27.     ( IFFF_READ or IFFF_WRITE ).
  28.  
  29.     INPUTS
  30.     iff      - pointer to IFFHandle struct.
  31.     ewMode    - IFFF_READ or IFFF_WRITE
  32.  
  33.  
  34.     RESULT
  35.     error     -  0 if successfull, IFFERR_#? elsewise.
  36.  
  37.     NOTES
  38.      This function tells the custom stream handler to initialize
  39.     by sending it a IFFCMD_INIT IFFStreamCmd.
  40.  
  41.     EXAMPLE
  42.  
  43.     BUGS
  44.  
  45.     SEE ALSO
  46.     CloseIFF(), InitIFF()
  47.  
  48.     INTERNALS
  49.  
  50.     HISTORY
  51.   27-11-96    digulla automatically created from
  52.       iffparse_lib.fd and clib/iffparse_protos.h
  53.  
  54. *****************************************************************************/
  55. {
  56.     AROS_LIBFUNC_INIT
  57.     AROS_LIBBASE_EXT_DECL(struct Library *,IFFParseBase)
  58.  
  59.  
  60.     LONG  err;
  61.  
  62.     struct IFFStreamCmd cmd;
  63.  
  64.  
  65.     struct ContextNode *cn;
  66.  
  67.  
  68.     /* Check that a valid StreamHandler Hook has been supplied */
  69.     if
  70.     (
  71.     !( GetIntIH(iff)->iff_StreamHandler )
  72.     )
  73.     return (IFFERR_NOHOOK);
  74.     /* Tell the custom stream to initialize itself */
  75.  
  76.     cmd.sc_Command = IFFCMD_INIT;
  77.     err = CallHookPkt
  78.     (
  79.     GetIntIH(iff)->iff_StreamHandler,
  80.     iff,
  81.     &cmd
  82.     );
  83.     if (err) return (err);
  84.  
  85.     /* Set the acess mode, and mark the stream as opened */
  86.     iff->iff_Flags |= (rwMode | IFFF_OPEN);
  87.  
  88.  
  89.     /* If we are opend in read mode we should test if we have a valid IFF-File */
  90.     if (rwMode == IFFF_READ)
  91.     {
  92.  
  93.     /* Get header of iff-stream */
  94.     err = GetChunkHeader(iff, IPB(IFFParseBase));
  95.     /* Valid IFF header ? */
  96.     if (err == IFFERR_MANGLED) return (IFFERR_NOTIFF);
  97.  
  98.     /* We have now entried the chunk */
  99.     GetIntIH(iff)->iff_CurrentState = IFFSTATE_COMPOSITE;
  100.  
  101.     cn = TopChunk(iff);
  102.  
  103.     /* We must see if we have a IFF header ("FORM", "CAT" or "LIST") */
  104.     if (!GetIntCN(cn)->cn_Composite)
  105.         return (IFFERR_NOTIFF);
  106.  
  107.     }
  108.  
  109.  
  110.     return (NULL); /* No error */
  111.  
  112.     AROS_LIBFUNC_EXIT
  113. } /* OpenIFF */
  114.