home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / h / hp11 / Amiga_Code / c_ami / ami_cbio next >
Encoding:
Text File  |  1992-05-07  |  2.5 KB  |  126 lines

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