home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Utilities / GDir / clipftxt.c < prev    next >
C/C++ Source or Header  |  2000-08-02  |  3KB  |  107 lines

  1. /* write string to clipboard.device */
  2.  
  3. #include <exec/types.h>
  4. #include <exec/ports.h>
  5. #include <exec/io.h>
  6. #include <exec/memory.h>
  7. #include <exec/exec.h>
  8. #include <devices/clipboard.h>
  9. #include <libraries/dosextens.h>
  10. #include <libraries/dos.h>
  11. #include <ctype.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14.  
  15. /*--Functions--*/
  16.  
  17. int WriteLong(struct IOClipReq *,long *);
  18. struct IOClipReq *CBOpen(ULONG);
  19. int CBWFTXT(struct IOClipReq *,char *);
  20. void CBClose(struct IOClipReq *);
  21.  
  22.  
  23. int WriteLong(ior, ldata)
  24. struct IOClipReq *ior;
  25. long *ldata;
  26. {
  27. ior->io_Data    = (STRPTR)ldata;
  28. ior->io_Length  = 4L;
  29. ior->io_Command = CMD_WRITE;
  30. DoIO( (struct IORequest *) ior);
  31. if (ior->io_Actual == 4)
  32.     {
  33.     return( ior->io_Error ? FALSE : TRUE);
  34.     }
  35. return(FALSE);
  36. }
  37.  
  38.  
  39. struct IOClipReq *CBOpen(ULONG unit)
  40. {
  41. struct MsgPort *mp;
  42. struct IOStdReq *ior;
  43.  
  44. if(mp = CreatePort(0L,0L))
  45.     {
  46.     if(ior=CreateExtIO(mp,sizeof(struct IOClipReq)))
  47.         {
  48.         if (!(OpenDevice("clipboard.device",unit,ior,0L)))
  49.             {
  50.             return((struct IOClipReq *)ior);
  51.             }
  52.         DeleteExtIO(ior);
  53.         }
  54.     DeletePort(mp);
  55.     }
  56. return(NULL);
  57. }
  58.  
  59. int CBWFTXT(struct IOClipReq *ior,char *string)
  60. {
  61. ULONG length, slen;
  62. BOOL odd;
  63. int success;
  64. slen = strlen(string);
  65. odd = (slen & 1);               /* pad byte flag */
  66. length = (odd) ? slen+1 : slen;
  67. /* initial set-up for Offset, Error, and ClipID */
  68. ior->io_Offset = 0;
  69. ior->io_Error  = 0;
  70. ior->io_ClipID = 0;
  71. /* Create the IFF header information */
  72. WriteLong(ior, (long *) "FORM");     /* "FORM"             */
  73. length+=12L;                         /* + "[size]FTXTCHRS" */
  74. WriteLong(ior, &length);             /* total length       */
  75. WriteLong(ior, (long *) "FTXT");     /* "FTXT"             */
  76. WriteLong(ior, (long *) "CHRS");     /* "CHRS"             */
  77. WriteLong(ior, &slen);               /* string length      */
  78. /* Write string */
  79. ior->io_Data    = (STRPTR)string;
  80. ior->io_Length  = slen;
  81. ior->io_Command = CMD_WRITE;
  82. DoIO( (struct IORequest *) ior);
  83. /* Pad if needed */
  84. if (odd)
  85.     {
  86.     ior->io_Data   = (STRPTR)"";
  87.     ior->io_Length = 1L;
  88.     DoIO( (struct IORequest *) ior);
  89.     }
  90. /* Tell the clipboard we are done writing */
  91. ior->io_Command=CMD_UPDATE;
  92. DoIO( (struct IORequest *) ior);
  93. /* Check if io_Error was set by any of the preceding IO requests */
  94. success = ior->io_Error ? FALSE : TRUE;
  95. return(success);
  96. }
  97.  
  98. void CBClose(struct IOClipReq *ior)
  99. {
  100. struct MsgPort *mp;
  101. mp = ior->io_Message.mn_ReplyPort;
  102. CloseDevice((struct IOStdReq *)ior);
  103. DeleteExtIO((struct IOStdReq *)ior);
  104. DeletePort(mp);
  105. }
  106.  
  107.