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 / readcliptext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-06  |  1.2 KB  |  47 lines

  1. /* ======================================================================== *
  2.        readcliptext.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.  
  14. int ReadClipText(char *text, int maxlength)
  15. {    struct IFFHandle    *iff = NULL;
  16.     long                result = FALSE;
  17.  
  18.     unless (iff = AllocIFF()) { result = -100; LEAVE; }
  19.     unless (iff->iff_Stream = (ULONG) OpenClipboard (PRIMARY_CLIP))
  20.     {    result = -101; LEAVE; }
  21.     InitIFFasClip (iff);
  22.  
  23.     if (result = OpenIFF (iff, IFFF_READ)) LEAVE;
  24.     if (result = StopChunk (iff, 'FTXT', 'CHRS')) LEAVE;
  25.  
  26.     while (maxlength > 0)
  27.     {    long error; 
  28.  
  29.         error = ParseIFF (iff, IFFPARSE_SCAN);
  30.  
  31.         if (error == IFFERR_EOF) LEAVE;
  32.         if ((result = ReadChunkBytes (iff, (APTR)text, maxlength)) <= 0)
  33.             LEAVE;
  34.         text += result;
  35.         maxlength -= result;
  36.     }
  37.  
  38. exitit:
  39.     if (iff)
  40.     {    CloseIFF (iff);
  41.         if (iff->iff_Stream)
  42.             CloseClipboard ((struct ClipboardHandle *)iff->iff_Stream);
  43.         FreeIFF (iff);
  44.     }
  45.     return result;
  46. }
  47.