home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff274.lzh / HP11 / amiga / cbio.c < prev    next >
C/C++ Source or Header  |  1989-11-16  |  2KB  |  123 lines

  1. #include <proto/exec.h>
  2. #include <exec/io.h>
  3. #include <devices/clipboard.h>
  4. #include <iff/iff.h>
  5. #include "user/cbio.h"
  6.  
  7. #include <string.h>
  8.  
  9. #define FTXT MakeID('F','T','X','T')
  10. #define CHRS MakeID('C','H','R','S')
  11.  
  12. struct IOClipReq *clipboardIO;
  13. struct MsgPort *clipboardMsgPort;
  14.  
  15. long CBOpen(long unit)
  16. {
  17.    long error;
  18.  
  19.    if ((clipboardMsgPort = CreatePort(0, 0)) == 0) return(-1);
  20.  
  21.    if ((clipboardIO = (struct IOClipReq *)CreateExtIO(clipboardMsgPort, sizeof(struct IOClipReq))) == 0) {
  22.       DeletePort(clipboardMsgPort);
  23.       return(-1);
  24.    }
  25.  
  26.    if ((error = OpenDevice("clipboard.device", unit, (struct IORequest *)clipboardIO, 0)) != 0) {
  27.       DeleteExtIO((struct IORequest *)clipboardIO, sizeof(struct IOClipReq));
  28.       DeletePort(clipboardMsgPort);
  29.       return(error);
  30.    }
  31.  
  32.    return(0);
  33. }
  34.  
  35. void CBClose(void)
  36. {
  37.    if (clipboardIO) {
  38.       CloseDevice((struct IORequest *)clipboardIO);
  39.       DeleteExtIO((struct IORequest *)clipboardIO, sizeof(struct IOClipReq));
  40.    }
  41.    if (clipboardMsgPort) DeletePort(clipboardMsgPort);
  42. }
  43.  
  44. void CBWrite(void *data, int length)
  45. {
  46.    clipboardIO->io_Command = CMD_WRITE;
  47.    clipboardIO->io_Data = data;
  48.    clipboardIO->io_Length = length;
  49.    DoIO((struct IORequest *)clipboardIO);
  50. }
  51.  
  52.  
  53. void CBCut(char *text)
  54. {
  55.    ID writeID;
  56.    long ifflen;
  57.    int len = strlen(text);
  58.  
  59.    clipboardIO->io_Offset = 0;
  60.    clipboardIO->io_ClipID = 0;
  61.  
  62.    writeID = FORM;
  63.    CBWrite(&writeID, 4);
  64.  
  65.    ifflen = len + 12;
  66.    CBWrite(&ifflen, 4);
  67.  
  68.    writeID = FTXT;
  69.    CBWrite(&writeID, 4);
  70.  
  71.    writeID = CHRS;
  72.    CBWrite(&writeID, 4);
  73.  
  74.    CBWrite(&len, 4);
  75.    CBWrite(text, len);
  76.  
  77.    clipboardIO->io_Command = CMD_UPDATE;
  78.    DoIO((struct IORequest *)clipboardIO);
  79. }
  80.  
  81. BYTE *CBRead(void *data, int length)
  82. {
  83.    clipboardIO->io_Command = CMD_READ;
  84.    clipboardIO->io_Data = data;
  85.    clipboardIO->io_Length = length;
  86.    DoIO((struct IORequest *)clipboardIO);
  87.  
  88.    return(data);
  89. }
  90.  
  91. BOOL CBPaste(char *string)
  92. {
  93.    long length;
  94.    BOOL success = FALSE;
  95.    ID check;
  96.  
  97.    clipboardIO->io_ClipID = 0;
  98.    clipboardIO->io_Offset = 0;
  99.  
  100.    CBRead(&check, 4);
  101.    if (check == FORM) {
  102.  
  103.       CBRead(&check, 4);
  104.       CBRead(&check, 4);
  105.       if (check == FTXT) {
  106.  
  107.      CBRead(&check, 4);
  108.      if (check == CHRS) {
  109.  
  110.         CBRead(&length, 4);
  111.         CBRead(string, length);
  112.         string[length] = '\0';
  113.         success = TRUE;
  114.      }
  115.       }
  116.    }
  117.  
  118.    while (clipboardIO->io_Actual != 0)
  119.       CBRead(NULL, 1 << 30);
  120.  
  121.    return(success);
  122. }
  123.