home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / commodity / newedit18b / newedit_source.lha / ClipBoard.c < prev    next >
C/C++ Source or Header  |  1994-05-30  |  2KB  |  85 lines

  1. #include <libraries/iffparse.h>
  2.  
  3. #include <clib/dos_protos.h>
  4. #include <clib/exec_protos.h>
  5. #include <clib/iffparse_protos.h>
  6. #include <clib/locale_protos.h>
  7.  
  8. #include <pragmas/dos_pragmas.h>
  9. #include <pragmas/exec_pragmas.h>
  10. #include <pragmas/iffparse_pragmas.h>
  11. #include<pragmas/locale_pragmas.h>
  12.  
  13. #define ID_FTXT MAKE_ID('F','T','X','T')
  14. #define ID_CHRS MAKE_ID('C','H','R','S')
  15.  
  16. extern struct Library *DOSBase, *SysBase;
  17. struct Library *IFFParseBase = NULL;
  18. struct IFFHandle *Iff = NULL;
  19.  
  20. BOOL init_iffparse( void )
  21. {
  22.     if ( ( IFFParseBase = OpenLibrary( "iffparse.library", 37L ) ) != NULL )
  23.     {
  24.         if ( (Iff = AllocIFF() ) != NULL )
  25.         {
  26.             if ( ( Iff->iff_Stream = (ULONG)OpenClipboard( 0 ) ) != NULL )
  27.             {
  28.                 InitIFFasClip( Iff );
  29.                 return TRUE;
  30.             }
  31.         }
  32.     }
  33.   return FALSE;
  34. }
  35.  
  36. void close_iffparse( void )
  37. {
  38.     if ( Iff != NULL  &&  Iff->iff_Stream != NULL )
  39.         CloseClipboard( (void *)Iff->iff_Stream );
  40.  
  41.     if ( Iff != NULL ) FreeIFF( Iff );
  42.  
  43.     if ( IFFParseBase != NULL ) CloseLibrary( IFFParseBase );
  44. }
  45.  
  46. ULONG read_clip( UBYTE *buffer, ULONG buflen )
  47. {
  48.     struct ContextNode  *cn;
  49.     ULONG length = 0;
  50.  
  51.     OpenIFF( Iff, IFFF_READ );
  52.     if ( StopChunk( Iff, ID_FTXT, ID_CHRS ) == 0 )
  53.     {
  54.         while ( ParseIFF( Iff, IFFPARSE_SCAN ) == 0 )
  55.         {
  56.             cn = CurrentChunk( Iff );
  57.  
  58.             if ( ( cn ) && ( cn->cn_Type == ID_FTXT ) && ( cn->cn_ID == ID_CHRS ) )
  59.             {
  60.                 length = ReadChunkBytes( Iff, buffer, buflen );
  61.                 break;
  62.             }
  63.         }
  64.     }
  65.  
  66.     CloseIFF( Iff );
  67.     return length;
  68. }
  69.  
  70. void write_clip( UBYTE *data, ULONG length )
  71. {
  72.     OpenIFF( Iff, IFFF_WRITE );
  73.  
  74.     if ( PushChunk( Iff, ID_FTXT, ID_FORM, IFFSIZE_UNKNOWN ) == 0 )
  75.     {
  76.         if ( PushChunk( Iff, 0, ID_CHRS, IFFSIZE_UNKNOWN ) == 0 )
  77.         {
  78.             WriteChunkBytes( Iff, data, length );
  79.             PopChunk( Iff );
  80.         }
  81.         PopChunk (Iff);
  82.     }
  83.     CloseIFF( Iff );
  84. }
  85.