home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog-asm / talincod.lha / talincode.lha / writecliptext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-06  |  1.2 KB  |  45 lines

  1. /* ======================================================================== *
  2.     writecliptext.c - Subroutines to read and write text to the clipboard
  3.                                    By Talin.
  4.                   Compiled under Manx 5.0 with small code/data
  5.  * ======================================================================== */
  6.  
  7. #include <std_headers.h>
  8. #include <libraries/iffparse.h>
  9.  
  10. extern struct Library *IFFParseBase;
  11.  
  12. #define LEAVE    goto exitit
  13. #define FAIL(x)    { error = x; goto exitit; }
  14.  
  15. int WriteClipText(char *text, int length)
  16. {
  17.     struct IFFHandle    *iff = NULL;
  18.     long                error = FALSE;
  19.  
  20.     unless (iff = AllocIFF()) FAIL(-100);
  21.     unless (iff->iff_Stream = (ULONG) OpenClipboard (PRIMARY_CLIP)) FAIL(-101);
  22.     InitIFFasClip (iff);
  23.  
  24.     if (error = OpenIFF (iff, IFFF_WRITE)) LEAVE;
  25.  
  26.     if (error = PushChunk (iff, 'FTXT', 'FORM', IFFSIZE_UNKNOWN)) LEAVE;
  27.     if (error = PushChunk (iff, 0L, 'CHRS', IFFSIZE_UNKNOWN)) LEAVE;
  28.  
  29.     if (WriteChunkBytes (iff, (APTR) text, length) != length)
  30.         FAIL(IFFERR_WRITE);
  31.  
  32.     if (error = PopChunk (iff)) LEAVE;
  33.     if (error = PopChunk (iff)) LEAVE;
  34.  
  35. exitit:
  36.     if (iff)
  37.     {    CloseIFF (iff);
  38.         if (iff->iff_Stream)
  39.             CloseClipboard ((struct ClipboardHandle *)iff->iff_Stream);
  40.         FreeIFF (iff);
  41.     }
  42.     return error;
  43. }
  44.  
  45.