Import Amiga applications and desktop tools
This commit is contained in:
commit
1c144c9a3c
347 files changed
+423483
No files matched your search
@@ -0,0 +1,12 @@
|
||||
#include <exec/types.h>
|
||||
#include <devices/clipboard.h>
|
||||
#include <proto/exec.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "clipboard.h"
|
||||
static struct MsgPort*port;static struct IOClipReq*io;
|
||||
static int openclip(void){port=CreateMsgPort();if(!port)return 0;io=(struct IOClipReq*)CreateIORequest(port,sizeof(*io));if(!io){DeleteMsgPort(port);return 0;}if(OpenDevice("clipboard.device",0,(struct IORequest*)io,0)){DeleteIORequest((struct IORequest*)io);DeleteMsgPort(port);return 0;}io->io_ClipID=io->io_Offset=0;return 1;}
|
||||
static void closeclip(void){CloseDevice((struct IORequest*)io);DeleteIORequest((struct IORequest*)io);DeleteMsgPort(port);}
|
||||
static unsigned long be(const unsigned char*s){return ((unsigned long)s[0]<<24)|((unsigned long)s[1]<<16)|((unsigned long)s[2]<<8)|s[3];}
|
||||
int clip_read(char*out,int cap){unsigned char*data;unsigned long got,at,len;char dummy;int count=0;if(cap<1)return 0;out[0]=0;data=malloc(65536);if(!data)return 0;if(!openclip()){free(data);return 0;}io->io_Command=CMD_READ;io->io_Data=(char*)data;io->io_Length=65536;DoIO((struct IORequest*)io);got=io->io_Actual;io->io_Offset=0x7ffffffe;io->io_Data=&dummy;io->io_Length=1;DoIO((struct IORequest*)io);closeclip();if(got>=12&&!memcmp(data,"FORM",4)&&!memcmp(data+8,"FTXT",4)){for(at=12;at+8<=got;){len=be(data+at+4);if(len>got-at-8)break;if(!memcmp(data+at,"CHRS",4)){unsigned long j;for(j=0;j<len&&count<cap-1;j++){unsigned char c=data[at+8+j];if(c=='\n'||c=='\r'||c=='\t')c=' ';if(c>=32&&c!=127)out[count++]=c;}}at+=8+len+(len&1);}}out[count]=0;free(data);return count;}
|
||||
int clip_write(const char*text){unsigned long len=strlen(text),size=20+len+(len&1),n;unsigned char*data=calloc(1,size);int ok;if(!data)return 0;memcpy(data,"FORM",4);n=size-8;data[4]=n>>24;data[5]=n>>16;data[6]=n>>8;data[7]=n;memcpy(data+8,"FTXTCHRS",8);data[16]=len>>24;data[17]=len>>16;data[18]=len>>8;data[19]=len;memcpy(data+20,text,len);if(!openclip()){free(data);return 0;}io->io_Command=CMD_WRITE;io->io_Data=(char*)data;io->io_Length=size;ok=!DoIO((struct IORequest*)io);if(ok){io->io_Command=CMD_UPDATE;ok=!DoIO((struct IORequest*)io);}closeclip();free(data);return ok;}
|
||||
Reference in new issue
Block a user