home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
365.lha
/
VSnap
/
clip.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-04-10
|
3KB
|
91 lines
/* This is just plain clipboard handling */
#include "snap.h"
IMPORT struct IOClipReq *ClipReq;
ULONG ReadClip(ClipReq, Buf, BufSize, Action)
struct IOClipReq *ClipReq;
STRPTR Buf;
ULONG BufSize;
SHORT Action;
{
ULONG Length;
ClipReq->io_Command = CMD_READ;
ClipReq->io_Data = Buf;
ClipReq->io_Length = BufSize-1L; /* space for '\0' */
if (Action == CLIP_FIRST) {
ClipReq->io_Offset = 0L;
ClipReq->io_ClipID = 0L;
}
DoIO(ClipReq);
Length = ClipReq->io_Actual;
Buf[Length] = '\0';
if (Action == CLIP_LAST) {
ClipReq->io_Command = CMD_READ;
ClipReq->io_Data = NULL;
ClipReq->io_Length = 1L;
DoIO(ClipReq); /* Null read to terminate */
}
return(Length);
}
VOID WriteClip(ClipReq, Buf, BufSize, Action)
struct IOClipReq *ClipReq;
STRPTR Buf;
ULONG BufSize;
SHORT Action;
{
if (Action == CLIP_FIRST) {
ClipReq->io_Offset = 0L;
ClipReq->io_ClipID = 0L;
}
ClipReq->io_Command = CMD_WRITE;
ClipReq->io_Data = Buf;
ClipReq->io_Length = BufSize;
DoIO(ClipReq);
if (Action == CLIP_LAST) {
ClipReq->io_Command = CMD_UPDATE;
DoIO(ClipReq);
}
}
VOID SaveClip(SnapSpace, SnapSize)
UBYTE *SnapSpace;
ULONG SnapSize;
{
ULONG Len;
WriteClip(ClipReq, "FORM", 4L, CLIP_FIRST);
Len = SnapSize+12;
WriteClip(ClipReq, &Len, 4L, CLIP_CONT);
WriteClip(ClipReq, "FTXT", 4L, CLIP_CONT);
WriteClip(ClipReq, "CHRS", 4L, CLIP_CONT);
Len = SnapSize;
WriteClip(ClipReq, &Len, 4L, CLIP_CONT);
WriteClip(ClipReq, SnapSpace, Len, CLIP_LAST);
}
UBYTE *FetchClip()
{
UBYTE *SnapSpace = NULL;
ULONG SnapSize;
ULONG ID[2];
(VOID)ReadClip(ClipReq, (STRPTR)&ID, 5L, CLIP_FIRST); /* FORM */
if (!strcmp((STRPTR)&ID, "FORM")) {
(VOID)ReadClip(ClipReq, (STRPTR)&ID, 5L, CLIP_CONT); /* size */
(VOID)ReadClip(ClipReq, (STRPTR)&ID, 5L, CLIP_CONT); /* FTXT */
if (!strcmp((STRPTR)&ID, "FTXT")) {
(VOID)ReadClip(ClipReq, (STRPTR)&ID, 5L, CLIP_CONT); /* CHRS */
if (!strcmp((STRPTR)&ID, "CHRS")) {
(VOID)ReadClip(ClipReq, (STRPTR)&ID, 5L, CLIP_CONT); /* #chars */
SnapSize = ID[0];
SnapSpace = AllocMem(SnapSize+5L, MEMF_PUBLIC|MEMF_CLEAR);
*(ULONG *)SnapSpace = SnapSize+5L; /* Save size */
ReadClip(ClipReq, SnapSpace+4L, SnapSize+1L, CLIP_LAST);
}
}
}
return(SnapSpace);
}