home *** CD-ROM | disk | FTP | other *** search
- /*-> c.ami_cbio */
- #include <proto/exec.h>
- #include <exec/io.h>
- #include <devices/clipboard.h>
- #include <iff/iff.h>
- #include "user/cbio.h"
-
- #include <string.h>
-
- #define FTXT MakeID('F','T','X','T')
- #define CHRS MakeID('C','H','R','S')
-
- struct IOClipReq *clipboardIO;
- struct MsgPort *clipboardMsgPort;
-
- long CBOpen(long unit)
- {
- long error;
-
- if ((clipboardMsgPort = CreatePort(0, 0)) == 0) return(-1);
-
- if ((clipboardIO = (struct IOClipReq *)CreateExtIO(clipboardMsgPort,
- sizeof(struct IOClipReq))) == 0) {
- DeletePort(clipboardMsgPort);
- return(-1);
- }
-
- if ((error = OpenDevice("clipboard.device", unit, (struct IORequest
- *)clipboardIO, 0)) != 0) {
- DeleteExtIO((struct IORequest *)clipboardIO, sizeof(struct IOClipReq));
- DeletePort(clipboardMsgPort);
- return(error);
- }
-
- return(0);
- }
-
- void CBClose(void)
- {
- if (clipboardIO) {
- CloseDevice((struct IORequest *)clipboardIO);
- DeleteExtIO((struct IORequest *)clipboardIO, sizeof(struct IOClipReq));
- }
- if (clipboardMsgPort) DeletePort(clipboardMsgPort);
- }
-
- void CBWrite(void *data, int length)
- {
- clipboardIO->io_Command = CMD_WRITE;
- clipboardIO->io_Data = data;
- clipboardIO->io_Length = length;
- DoIO((struct IORequest *)clipboardIO);
- }
-
-
- void CBCut(char *text)
- {
- ID writeID;
- long ifflen;
- int len = strlen(text);
-
- clipboardIO->io_Offset = 0;
- clipboardIO->io_ClipID = 0;
-
- writeID = FORM;
- CBWrite(&writeID, 4);
-
- ifflen = len + 12;
- CBWrite(&ifflen, 4);
-
- writeID = FTXT;
- CBWrite(&writeID, 4);
-
- writeID = CHRS;
- CBWrite(&writeID, 4);
-
- CBWrite(&len, 4);
- CBWrite(text, len);
-
- clipboardIO->io_Command = CMD_UPDATE;
- DoIO((struct IORequest *)clipboardIO);
- }
-
- BYTE *CBRead(void *data, int length)
- {
- clipboardIO->io_Command = CMD_READ;
- clipboardIO->io_Data = data;
- clipboardIO->io_Length = length;
- DoIO((struct IORequest *)clipboardIO);
-
- return(data);
- }
-
- BOOL CBPaste(char *string)
- {
- long length;
- BOOL success = FALSE;
- ID check;
-
- clipboardIO->io_ClipID = 0;
- clipboardIO->io_Offset = 0;
-
- CBRead(&check, 4);
- if (check == FORM) {
-
- CBRead(&check, 4);
- CBRead(&check, 4);
- if (check == FTXT) {
-
- CBRead(&check, 4);
- if (check == CHRS) {
-
- CBRead(&length, 4);
- CBRead(string, length);
- string[length] = '\0';
- success = TRUE;
- }
- }
- }
-
- while (clipboardIO->io_Actual != 0)
- CBRead(NULL, 1 << 30);
-
- return(success);
- }
-