home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 493.lha / SmallIFFParseLibrary / sources / cutclip.c next >
Encoding:
C/C++ Source or Header  |  1991-04-06  |  2.3 KB  |  87 lines

  1. /*
  2.  * Usage:       CutClip [string]
  3.  * Function:    Put a given in the clipboard as a FTXT-chunk.
  4.  * Description: This is an example of the standard way of using the 
  5.  *              iffparser when you want to write data to the clipboard
  6.  *              (It works the same way for files).
  7.  *
  8.  * Written by:  Michael Jansson. 1990-12-08
  9.  */
  10.  
  11.  
  12. #include <libraries/iffparse.h>
  13. #include <proto/iffparse.h>
  14. #include <setjmp.h>
  15.  
  16. #define NAME        "Error in cutclip: "
  17. #define ERR_USE     "Usage: CutClip [string]"
  18. #define ERR_LIB     NAME "Could not open iffparse.library!"
  19. #define ERR_MEM     NAME "Out of memory!"
  20. #define ERR_CLIP    NAME "Could not open the clipboard!"
  21. #define ERR_OPEN    NAME "Could not open primary clip in clipboard!"
  22. #define ERR_FAILED  NAME "Failed to read the clipboard (Error Code: %ld)\n!"
  23. #define LEVEL       ". "
  24. #define DONE        "Done!"
  25. #define SUCCESS     0L
  26. #define Safe(fnc)   if ((error=(fnc))<0L) longjmp(env, (int)error)
  27.  
  28. struct Library *IFFParseBase;
  29.  
  30. void
  31. main(int argc, char **argv)
  32. {
  33.     struct IFFHandle *iff = NULL;
  34.     jmp_buf env;
  35.     long error;
  36.     
  37.     if (argc!=2) {
  38.         puts(ERR_USE);
  39.         goto die;
  40.     }
  41.  
  42.     /* Open all the stuff that is needed! */
  43.     if ((IFFParseBase=OpenLibrary("iffparse.library", 0L))==NULL) {
  44.         puts(ERR_LIB);
  45.         goto die;
  46.     }
  47.     if ((iff = AllocIFF())==NULL) {
  48.         puts(ERR_MEM);
  49.         goto die;
  50.     }
  51.     if ((iff->iff_Stream=(ULONG)OpenClipboard(0L))==0L) {
  52.         puts(ERR_CLIP);
  53.         goto die;
  54.     }
  55.     InitIFFasClip(iff);
  56.     if (OpenIFF(iff, IFFF_WRITE)) {
  57.         puts(ERR_OPEN);
  58.         goto die;
  59.     }
  60.  
  61.     /* Let's be very careful... */
  62.     if (!(error=setjmp(env))) {
  63.         /* Start on the FORM-FTXT chunk... */
  64.         Safe(PushChunk(iff, 'FTXT', 'FORM', IFFSIZE_UNKNOWN));
  65.  
  66.             /* ...continue on the CHRS-FTXT chunk.*/
  67.             Safe(PushChunk(iff, 0L, 'CHRS', IFFSIZE_UNKNOWN));
  68.             Safe(WriteChunkBytes(iff, (APTR)argv[1], (long)strlen(argv[1])));
  69.             Safe(PopChunk(iff));
  70.  
  71.         /* Finish the outer most chunk. */
  72.         Safe(PopChunk(iff));
  73.     }
  74.  
  75.     /* Exit gracefully. */
  76. die:
  77.     if (iff) {
  78.         CloseIFF(iff);
  79.         if (iff->iff_Stream)
  80.            CloseClipboard((struct ClipboardHandle *)iff->iff_Stream);
  81.         FreeIFF(iff);
  82.     }
  83.     if (IFFParseBase)
  84.         CloseLibrary(IFFParseBase);
  85.     exit(0);
  86. }
  87.