home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 192.lha / Snip_v1.3 / stash.c < prev    next >
C/C++ Source or Header  |  1988-04-28  |  4KB  |  140 lines

  1.  
  2. /*
  3.  *  This function will store the characters read from the screen, whether
  4.  *  this is by printing them to the CLI, saving them to a file, or pasting
  5.  *  them to the clipboard.
  6.  *
  7.  *  I have just added some "saver" code to the interpretation routine. Now
  8.  *  the stash function can determine how to handle the section that has been
  9.  *  cut. At the moment I am tending towards including two possible stash
  10.  *  methods -- saving to the clipboard, or writing to a PIPE: file so that
  11.  *  programs without clipboard support can still receive the text.
  12.  *
  13.  *  (This is like late '87)
  14.  *
  15.  *  OK, I finally got some clipboard code (from AmigaMail, free plug). It
  16.  *  ought to be very simple to integrate. I don't know if I have anything
  17.  *  to test it out on though... doesn't speak very well for the widespread
  18.  *  acceptance of the clipboard as a standard!
  19.  *
  20.  *  John    03-07-88
  21.  *
  22.  *  Found a very old example of controlling mouse movements via software.
  23.  *  Adapted to send phoney keyboard events very easily.
  24.  *
  25.  *  John    04-25-88
  26.  */
  27.  
  28. #include "snip:defs.h"
  29. #include "intuition/intuitionbase.h"
  30.  
  31. extern struct IntuitionBase *IntuitionBase;
  32.  
  33. extern short save_format, scratchheight, scratchwidth;
  34. extern struct FileHandle *fp, *outfilehandle;
  35. extern char *scratch;
  36. extern struct Window *w;
  37. extern BOOL reactivate;
  38.  
  39. stash()
  40. {
  41.     register short counter = 0;
  42.     register short y;
  43.     register struct FileHandle *out = Output();
  44.     register struct IntuiMessage *msg;
  45.     register BOOL done = FALSE, printcr = TRUE;
  46.  
  47.     switch (save_format)
  48.     {
  49.         case PRINT_STDOUT:
  50.  
  51.             if (outfilehandle)
  52.                 out = outfilehandle;
  53.  
  54.             for (y = 0; y < scratchheight; y++)
  55.             {
  56.                 Wrlen(out,&scratch[counter]);
  57.                 Wr(out,"\n");
  58.                 counter += (scratchwidth + 1);  /* jump to next line */
  59.             }
  60.             break;
  61.  
  62.         case WRITE_PIPE:
  63.             if ((fp = Open("PIPE:snip",MODE_NEWFILE)) == NULL)
  64.             {
  65.                 Wr(out,"Error: PIPE device not available\n");
  66.                 break;
  67.             }
  68.  
  69.             for (y = 0; y < scratchheight; y++)
  70.             {
  71.                 Wrlen(fp,&scratch[counter]);
  72.                 Wr(fp,"\n");
  73.                 counter += (scratchwidth + 1);
  74.             }
  75.             Close(fp);     /* so we can do multiple cuts */
  76.             fp = NULL;
  77.             break;
  78.  
  79.         case PASTE_CLIPBOARD:
  80.             if (CBOpen(0))
  81.             {
  82.                 Wr(out,"Error: ClipBoard not available\n");
  83.                 goto CBERROR;
  84.             }
  85.  
  86.             for (y = 0; y < scratchheight; y++)
  87.             {
  88.                 register char *ptr = &scratch[counter];
  89.  
  90.                 CBCut(ptr,strlen(ptr));
  91.                 counter += (scratchwidth + 1);
  92.             }
  93. CBERROR:
  94.             CBClose();
  95.             break;
  96.  
  97.         case KEYBOARD_NOCR:
  98.             printcr = FALSE;
  99.         case TYPE_KEYBOARD:
  100. /*
  101.  *  This is an interesting one: I can't actually put the text down until
  102.  *  some other window gets selected; if the window is closed I'll just close
  103.  *  everything and exit without doing the paste.
  104.  *
  105.  */
  106.  
  107.             while (!done)
  108.             {
  109.                 WaitPort(w->UserPort);
  110.                 while (msg = (struct IntuiMessage *)GetMsg(w->UserPort))
  111.                 {
  112.                     if (msg->Class == INACTIVEWINDOW)
  113.                     {
  114.                         ReplyMsg(msg);
  115.                         done = TRUE;
  116.                     }
  117.                     else if (msg->Class == CLOSEWINDOW)
  118.                     {
  119.                         ReplyMsg(msg);
  120.                         _abort();
  121.                     }
  122.                 }
  123.             }
  124.  
  125.             for (y = 0; y < scratchheight; y++)
  126.             {
  127.                 sendline(&scratch[counter],printcr);
  128.                 counter += (scratchwidth + 1);  /* jump to next line */
  129.             }
  130.  
  131.             if (reactivate)     ActivateWindow(w);
  132.  
  133.             break;
  134.  
  135.         default:
  136.             break;
  137.     }
  138. }
  139.  
  140.