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

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: closeiff.c,v 1.1 1997/02/03 16:44:22 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_LH1(void, CloseIFF,
  16.  
  17. /*  SYNOPSIS */
  18.     AROS_LHA(struct IFFHandle *, iff, A0),
  19.  
  20. /*  LOCATION */
  21.     struct Library *, IFFParseBase, 8, IFFParse)
  22.  
  23. /*  FUNCTION
  24.     Completes a read or write session by closing the IFF handle.
  25.     The IFFHandle struct is ready for reuse in another session,
  26.     it's just to open it again with OpenIFF(). This function
  27.     also automatically cleans up if a read or write fails halfway through.
  28.  
  29.     INPUTS
  30.     iff - Pointer to an IFFhandle struct previously opened with OpenIFF()
  31.  
  32.     RESULT
  33.  
  34.     NOTES
  35.     This function tells the custom stream handler to clean up
  36.     by sending it a IFFCMD_CLEANUP IFFStreamCmd.
  37.  
  38.     EXAMPLE
  39.  
  40.     BUGS
  41.  
  42.     SEE ALSO
  43.     OpenIFF(), InitIFF()
  44.  
  45.     INTERNALS
  46.     This function checks that buffers for buffered streams
  47.     have been freed. This is not very elegant and should have been
  48.     done at an earlier stadium. It is not a real bug though.
  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.     LONG count;
  60.  
  61.     struct IFFStreamCmd    cmd;
  62.  
  63.     /* clear the IFFF_OPEN bit to mark IFF stream closed */
  64.     iff->iff_Flags &= !IFFF_OPEN;
  65.  
  66.     /* Pop of all contextnodes so that only the default one is remaining */
  67.  
  68.     for (count = iff->iff_Depth; count; count -- )
  69.     PopContextNode(iff, IPB(IFFParseBase));
  70.  
  71.  
  72.     /* This is for safety:
  73.       It might be in PopChunk that seeking or writing to streams failed.
  74.       In that case the memory for eventual buffered setreams
  75.       were not freed, so we should free it here.
  76.  
  77.       (Yes, it is is a kludge !)
  78.     */
  79.     if ( GetIntIH(iff)->iff_BufferStartDepth)
  80.     {
  81.     FreeBuffer((struct BufferList*)iff->iff_Stream, IPB(IFFParseBase));
  82.  
  83.     GetIntIH(iff)->iff_BufferStartDepth = 0;
  84.     }
  85.  
  86.  
  87.     /* Tell the custom stream to cleanup */
  88.     cmd.sc_Command = IFFCMD_CLEANUP;
  89.     CallHookPkt
  90.     (
  91.     GetIntIH(iff)->iff_StreamHandler,
  92.     iff,
  93.     &cmd
  94.     );
  95.  
  96.  
  97.     return;
  98.  
  99.  
  100.     AROS_LIBFUNC_EXIT
  101. } /* CloseIFF */
  102.