home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 192.lha / Snip_v1.3 / cbio.c < prev    next >
C/C++ Source or Header  |  1988-04-28  |  2KB  |  100 lines

  1.  
  2. /*
  3.  *  CBIO.C
  4.  *
  5.  *  This is the clipboard section of "snip". I am going to try and be as
  6.  *  faithful as possible to the C-A example code (for now :-). Probably
  7.  *  later I will economize and maybe add an extra bit of functionality
  8.  *  here and there.
  9.  *
  10.  *  John Russell    03-07-88
  11.  *
  12.  */
  13.  
  14. #include "exec/types.h"
  15. #include "exec/ports.h"
  16. #include "exec/io.h"
  17. #include "devices/clipboard.h"
  18.  
  19. /* never seen struct = 0 before */
  20.  
  21. struct IOClipReq cbIO = 0;
  22. struct MsgPort cbMsgPort = 0, satisfyMsgPort = 0;
  23.  
  24. int CBOpen(unit)    /* do initial open of clipboard device */
  25. register int unit;
  26. {
  27.     register int error;
  28.  
  29.     if ((error = OpenDevice("clipboard.device",unit,&cbIO,0)) != 0)
  30.                 return(error);
  31.  
  32.     /* open OK, need to set up MsgPort stuff (would be nice to have some support routines for this grunge work) */
  33.         /* still it's easy enough to make a macro out of it */
  34.  
  35.     cbMsgPort.mp_Node.ln_Type = NT_MSGPORT;
  36.     cbMsgPort.mp_Flags = 0;
  37.     cbMsgPort.mp_SigBit = AllocSignal(-1);
  38.     cbMsgPort.mp_SigTask = (struct Task *)FindTask((char *)NULL);
  39.     AddPort(&cbMsgPort);
  40.  
  41.     cbIO.io_Message.mn_ReplyPort = &cbMsgPort;
  42.  
  43.     satisfyMsgPort.mp_Node.ln_Type = NT_MSGPORT;
  44.     satisfyMsgPort.mp_Flags = 0;
  45.     satisfyMsgPort.mp_SigBit = AllocSignal(-1);
  46.     satisfyMsgPort.mp_SigTask = (struct Task *)FindTask((char *)NULL);
  47.     AddPort(&satisfyMsgPort);
  48.  
  49.     return(0);
  50. }
  51.  
  52. CBClose()
  53. {
  54.     RemPort(&satisfyMsgPort);
  55.     RemPort(&cbMsgPort);
  56.     CloseDevice(&cbIO);
  57. }
  58.  
  59. CBSatisfyPost(string,length)
  60. register char *string;
  61. int length;
  62. {
  63.     cbIO.io_Offset = 0;
  64.     writeLong("FORM");
  65.     length += 12;
  66.     writeLong(&length);
  67.     writeLong("FTXT");
  68.     writeLong("CHRS");
  69.     length -= 12;
  70.     writeLong(&length);
  71.  
  72.     cbIO.io_Command = CMD_WRITE;
  73.     cbIO.io_Data = string;
  74.     cbIO.io_Length = length;
  75.     DoIO(&cbIO);
  76.  
  77.     cbIO.io_Command = CMD_UPDATE;
  78.     return(DoIO(&cbIO));
  79. }
  80.  
  81. writeLong(data)
  82. register long *data;
  83. {
  84.     cbIO.io_Command = CMD_WRITE;
  85.     cbIO.io_Data = data;
  86.     cbIO.io_Length = 4;
  87.     DoIO(&cbIO);
  88. }
  89.  
  90. CBCut(string,length)
  91. register char *string;
  92. register int length;
  93. {
  94.     cbIO.io_ClipID = 0;
  95.     return(CBSatisfyPost(string,length));
  96. }
  97.  
  98. /* NB: since I only want to send things to the ClipBoard I don't include the "Paste" routine */
  99.  
  100.