home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d534 / term.lha / Term / Source.LZH / termClip.c < prev    next >
C/C++ Source or Header  |  1991-07-06  |  2KB  |  114 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
  4.  *
  5.  *    Name .....: TermClip.c
  6.  *    Created ..: Monday 21-Jan-91 20:12
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    21-Jan-91       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  
  15. #include "TermGlobal.h"
  16.  
  17.     /* SaveClip(UBYTE *Buffer,LONG Size):
  18.      *
  19.      *    Send a given text buffer to the clipboard.
  20.      */
  21.  
  22. BYTE
  23. SaveClip(UBYTE *Buffer,LONG Size)
  24. {
  25.     struct IFFHandle    *Handle;
  26.     BYTE             Success = FALSE;
  27.  
  28.     if(Handle = AllocIFF())
  29.     {
  30.         if(Handle -> iff_Stream = (ULONG)OpenClipboard(PRIMARY_CLIP))
  31.         {
  32.             InitIFFasClip(Handle);
  33.  
  34.             if(!OpenIFF(Handle,IFFF_WRITE))
  35.             {
  36.                 if(!PushChunk(Handle,'FTXT','FORM',IFFSIZE_UNKNOWN))
  37.                 {
  38.                     if(!PushChunk(Handle,0,'CHRS',IFFSIZE_UNKNOWN))
  39.                     {
  40.                         if(WriteChunkBytes(Handle,Buffer,Size) == Size)
  41.                         {
  42.                             if(!PopChunk(Handle))
  43.                                 Success = TRUE;
  44.                         }
  45.                     }
  46.                 }
  47.  
  48.                 if(Success)
  49.                 {
  50.                     if(PopChunk(Handle))
  51.                         Success = FALSE;
  52.                 }
  53.  
  54.                 CloseIFF(Handle);
  55.             }
  56.  
  57.             CloseClipboard((struct ClipboardHandle *)Handle -> iff_Stream);
  58.         }
  59.  
  60.         FreeIFF(Handle);
  61.     }
  62.  
  63.     return(Success);
  64. }
  65.  
  66.     /* LoadClip(UBYTE *Buffer,LONG Size):
  67.      *
  68.      *    Put the contents of the clipboard into a given
  69.      *    buffer.
  70.      */
  71.  
  72. LONG
  73. LoadClip(UBYTE *Buffer,LONG Size)
  74. {
  75.     struct IFFHandle    *Handle;
  76.     LONG             Bytes = 0;
  77.  
  78.     if(Handle = AllocIFF())
  79.     {
  80.         if(Handle -> iff_Stream = (ULONG)OpenClipboard(PRIMARY_CLIP))
  81.         {
  82.             InitIFFasClip(Handle);
  83.  
  84.             if(!OpenIFF(Handle,IFFF_READ))
  85.             {
  86.                 if(!StopChunk(Handle,'FTXT','CHRS'))
  87.                 {
  88.                     if(!ParseIFF(Handle,IFFPARSE_SCAN))
  89.                     {
  90.                         struct ContextNode *ContextNode;
  91.  
  92.                         if(ContextNode = CurrentChunk(Handle))
  93.                         {
  94.                             if(Size > ContextNode -> cn_Size)
  95.                                 Size = ContextNode -> cn_Size;
  96.  
  97.                             if(ReadChunkRecords(Handle,Buffer,Size,1))
  98.                                 Bytes = Size;
  99.                         }
  100.                     }
  101.                 }
  102.  
  103.                 CloseIFF(Handle);
  104.             }
  105.  
  106.             CloseClipboard((struct ClipboardHandle *)Handle -> iff_Stream);
  107.         }
  108.  
  109.         FreeIFF(Handle);
  110.     }
  111.  
  112.     return(Bytes);
  113. }
  114.