/*** cbdump.c Written By Stephen Vermeulen (403) 282-7990 PO Box 3295, Station B, Calgary, ALberta, CANADA, T2M 4L8. Permission to use and distribute this code is granted so long as Commodore's copyright notice stays intact. This program copys whatever is on the clipboard to the STDOUT this is useful during debugging clipboard i/o so that one can immediately examine the results of a clipboard write with a CLI command like: cbdump | type opt h ***/ #include "exec/types.h" #include "exec/ports.h" #include "exec/io.h" #include "devices/clipboard.h" #include #include #include struct IOClipReq clipboardIO = 0; struct MsgPort clipboardMsgPort = 0; struct MsgPort satisfyMsgPort = 0; main(argc, argv) int argc; char *argv[]; { UBYTE mem[256]; int len; if (argc == 1) { if (!CBOpen(0)) { clipboardIO.io_Offset = 0; clipboardIO.io_ClipID = 0; do { len = CBPasteS(mem, 256); if (len) fwrite(mem, len, 1, stdout); } while (len) ; CBClose(); } } else puts(" dumps the clipboard to stdout"); } /*********************************************************************/ /* */ /* Program name: cbio */ /* */ /* Purpose: To provide standard clipboard device interface routines*/ /* such as Open, Post, Read, Write, etc. */ /* (C) 1986 Commodore-Amiga, Inc. */ /* Permission given to use and distribute this code as long as this */ /* notice remains intact. */ /*********************************************************************/ int CBOpen(unit) int unit; { int error; /* open the clipboard device */ if ((error = OpenDevice("clipboard.device", (long) unit, &clipboardIO, 0L)) != 0) return(error); /* Set up the message port in the I/O request */ clipboardMsgPort.mp_Node.ln_Type = NT_MSGPORT; clipboardMsgPort.mp_Flags = 0; clipboardMsgPort.mp_SigBit = AllocSignal(-1L); clipboardMsgPort.mp_SigTask = (struct Task *) FindTask((char *) NULL); AddPort(&clipboardMsgPort); clipboardIO.io_Message.mn_ReplyPort = &clipboardMsgPort; satisfyMsgPort.mp_Node.ln_Type = NT_MSGPORT; satisfyMsgPort.mp_Flags = 0; satisfyMsgPort.mp_SigBit = AllocSignal(-1L); satisfyMsgPort.mp_SigTask = (struct Task *) FindTask((char *) NULL); AddPort(&satisfyMsgPort); return(0); } CBClose() { if (clipboardMsgPort.mp_SigBit > 0) FreeSignal(clipboardMsgPort.mp_SigBit); if (satisfyMsgPort.mp_SigBit > 0) FreeSignal(satisfyMsgPort.mp_SigBit); RemPort(&satisfyMsgPort); RemPort(&clipboardMsgPort); CloseDevice(&clipboardIO); } int CBPasteS(mem, len) UBYTE *mem; int len; { clipboardIO.io_Command = CMD_READ; clipboardIO.io_Data = (STRPTR) mem; clipboardIO.io_Length = len; DoIO(&clipboardIO); return((int) clipboardIO.io_Actual); }