home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 365.lha / CBDump / cbdump.c < prev    next >
C/C++ Source or Header  |  1990-04-10  |  3KB  |  115 lines

  1. /***
  2.   cbdump.c  Written By Stephen Vermeulen (403) 282-7990
  3.  
  4.             PO Box 3295, Station B,
  5.             Calgary, ALberta,
  6.             CANADA, T2M 4L8.
  7.  
  8.   Permission to use and distribute this code is granted so long
  9.   as Commodore's copyright notice stays intact.
  10.  
  11.   This program copys whatever is on the clipboard to the STDOUT
  12.   this is useful during debugging clipboard i/o so that one can
  13.   immediately examine the results of a clipboard write with a
  14.   CLI command like:
  15.  
  16.       cbdump | type opt h
  17. ***/
  18.  
  19. #include "exec/types.h"
  20. #include "exec/ports.h"
  21. #include "exec/io.h"
  22. #include "devices/clipboard.h"
  23. #include <functions.h>
  24. #include <libraries/dosextens.h>
  25. #include <stdio.h>
  26.  
  27. struct IOClipReq clipboardIO = 0;
  28. struct MsgPort clipboardMsgPort = 0;
  29. struct MsgPort satisfyMsgPort = 0;
  30.  
  31. main(argc, argv)
  32. int argc;
  33. char *argv[];
  34. {
  35.   UBYTE mem[256];
  36.   int len;
  37.  
  38.   if (argc == 1)
  39.   {
  40.       if (!CBOpen(0))
  41.       {
  42.         clipboardIO.io_Offset = 0;
  43.         clipboardIO.io_ClipID = 0;
  44.         do
  45.         {
  46.           len = CBPasteS(mem, 256);
  47.           if (len) fwrite(mem, len, 1, stdout);
  48.         } while (len) ;
  49.         CBClose();
  50.       }
  51.   }
  52.   else
  53.     puts("<cbdump>  dumps the clipboard to stdout");
  54. }
  55.  
  56. /*********************************************************************/
  57. /*                                                                   */
  58. /*  Program name:  cbio                                              */
  59. /*                                                                   */
  60. /*  Purpose:  To provide standard clipboard device interface routines*/
  61. /*            such as Open, Post, Read, Write, etc.                  */
  62. /*  (C) 1986 Commodore-Amiga, Inc.                                   */
  63. /* Permission given to use and distribute this code as long as this  */
  64. /* notice remains intact.                                            */
  65. /*********************************************************************/
  66.  
  67. int CBOpen(unit)
  68. int unit;
  69. {
  70.     int error;
  71.  
  72.     /* open the clipboard device */
  73.     if ((error = OpenDevice("clipboard.device", (long) unit, &clipboardIO, 0L)) != 0)
  74.         return(error);
  75.  
  76.     /* Set up the message port in the I/O request */
  77.     clipboardMsgPort.mp_Node.ln_Type = NT_MSGPORT;
  78.     clipboardMsgPort.mp_Flags = 0;
  79.     clipboardMsgPort.mp_SigBit = AllocSignal(-1L);
  80.     clipboardMsgPort.mp_SigTask = (struct Task *) FindTask((char *) NULL);
  81.     AddPort(&clipboardMsgPort);
  82.     clipboardIO.io_Message.mn_ReplyPort = &clipboardMsgPort;
  83.  
  84.     satisfyMsgPort.mp_Node.ln_Type = NT_MSGPORT;
  85.     satisfyMsgPort.mp_Flags = 0;
  86.     satisfyMsgPort.mp_SigBit = AllocSignal(-1L);
  87.     satisfyMsgPort.mp_SigTask = (struct Task *) FindTask((char *) NULL);
  88.     AddPort(&satisfyMsgPort);
  89.     return(0);
  90. }
  91.  
  92. CBClose()
  93. {
  94.     if (clipboardMsgPort.mp_SigBit > 0)
  95.        FreeSignal(clipboardMsgPort.mp_SigBit);
  96.     if (satisfyMsgPort.mp_SigBit > 0)
  97.        FreeSignal(satisfyMsgPort.mp_SigBit);
  98.  
  99.     RemPort(&satisfyMsgPort);
  100.     RemPort(&clipboardMsgPort);
  101.     CloseDevice(&clipboardIO);
  102. }
  103.  
  104. int
  105. CBPasteS(mem, len)
  106. UBYTE *mem;
  107. int len;
  108. {
  109.     clipboardIO.io_Command = CMD_READ;
  110.     clipboardIO.io_Data = (STRPTR) mem;
  111.     clipboardIO.io_Length = len;
  112.     DoIO(&clipboardIO);
  113.     return((int) clipboardIO.io_Actual);
  114. }
  115.