home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / k95source / ckoco5.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  6KB  |  212 lines

  1. /* C K O C O 5 . C */
  2.  
  3. /*
  4.   Author: Frank da Cruz  (fdc@columbia.edu, FDCCU@CUVMA.BITNET),
  5.             Columbia University Academic Information Systems, New York City.
  6.           Jeffrey E Altman (jaltman@secure-endpoints.com)
  7.             Secure Endpoints Inc., New York City
  8.  
  9.   Copyright (C) 1985, 2004, Trustees of Columbia University in the City of New
  10.   York.
  11. */
  12.  
  13. #ifndef NT
  14. #include "ckcdeb.h"
  15.  
  16. #define INCL_WIN
  17. #define INCL_VIO
  18. #define INCL_ERRORS
  19. #define INCL_DOSPROCESS
  20. #define INCL_DOSSEMAPHORES
  21. #define INCL_DOSDEVIOCTL
  22. #define INCL_WINCLIPBOARD
  23. #define INCL_DOSDATETIME
  24. #define INCL_DOSMEMMGR
  25. #include <os2.h>
  26. #undef COMMENT                /* COMMENT is defined in os2.h */
  27.  
  28. #include "ckocon.h"
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31.  
  32. extern int tnlm, tn_nlm;        /* Terminal newline mode, ditto for TELNET */
  33. extern videobuffer vscrn[];
  34. extern enum markmodes markmodeflag ;
  35. extern bool xprintff, printon ;
  36. extern HAB hab ;
  37.  
  38. HMUX hmuxClipbrdSrv = 0 ;
  39. HEV hevClipbrdGet  = 0 ;
  40. HEV hevClipbrdPut = 0 ;
  41. HEV hevClipbrdData = 0 ;
  42. HEV hevClipbrdDone = 0 ;
  43.  
  44. APIRET
  45. OpenClipboardServer( void )
  46. {
  47.     APIRET rc = 0 ;
  48.  
  49.     rc = DosOpenMutexSem( "\\SEM32\\CKERMIT\\CLIPBRD\\MUX", &hmuxClipbrdSrv ) ;
  50.     if ( rc ) {
  51.         return rc ;
  52.         }
  53.  
  54.     rc = DosOpenEventSem( "\\SEM32\\CKERMIT\\CLIPBRD\\GET", &hevClipbrdGet ) ;
  55.     if ( rc ) {
  56.         DosCloseMutexSem( hmuxClipbrdSrv ) ;
  57.         return rc ;
  58.         }
  59.  
  60.     rc = DosOpenEventSem( "\\SEM32\\CKERMIT\\CLIPBRD\\DATA", &hevClipbrdData ) ;
  61.     if ( rc ) {
  62.         DosCloseMutexSem( hmuxClipbrdSrv ) ;
  63.         DosCloseEventSem( hevClipbrdGet ) ;
  64.         return rc ;
  65.         }
  66.  
  67.     rc = DosOpenEventSem( "\\SEM32\\CKERMIT\\CLIPBRD\\DONE", &hevClipbrdDone ) ;
  68.     if ( rc ) {
  69.         DosCloseMutexSem( hmuxClipbrdSrv ) ;
  70.         DosCloseEventSem( hevClipbrdGet ) ;
  71.         DosCloseEventSem( hevClipbrdData ) ;
  72.         return rc ;
  73.         }
  74.  
  75.     rc = DosOpenEventSem( "\\SEM32\\CKERMIT\\CLIPBRD\\PUT", &hevClipbrdPut ) ;
  76.     if ( rc ) {
  77.         DosCloseMutexSem( hmuxClipbrdSrv ) ;
  78.         DosCloseEventSem( hevClipbrdGet ) ;
  79.         DosCloseEventSem( hevClipbrdData ) ;
  80.         DosCloseEventSem( hevClipbrdDone ) ;
  81.         return rc ;
  82.         }
  83.     return rc ;
  84. }
  85.  
  86. APIRET
  87. CloseClipboardServer( void )
  88. {
  89.     if ( hmuxClipbrdSrv )
  90.         DosCloseMutexSem( hmuxClipbrdSrv ) ;
  91.     if ( hevClipbrdGet )
  92.         DosCloseEventSem( hevClipbrdGet ) ;
  93.     if ( hevClipbrdPut )
  94.         DosCloseEventSem( hevClipbrdPut ) ;
  95.     if ( hevClipbrdData )
  96.         DosCloseEventSem( hevClipbrdData ) ;
  97.     if ( hevClipbrdDone )
  98.         DosCloseEventSem( hevClipbrdDone ) ;
  99.  
  100.     hmuxClipbrdSrv = 0 ;
  101.     hevClipbrdGet  = 0 ;
  102.     hevClipbrdData = 0 ;
  103.     hevClipbrdDone = 0 ;
  104.     return 0 ;
  105. }
  106.  
  107. void
  108. SetPtrWait( void )
  109. {
  110.     WinSetPointer( HWND_DESKTOP,
  111.         WinQuerySysPointer( HWND_DESKTOP, FALSE, SPTR_WAIT ) ) ;
  112. }
  113.  
  114. void
  115. SetPtrArrow( void )
  116. {
  117.     WinSetPointer( HWND_DESKTOP,
  118.         WinQuerySysPointer( HWND_DESKTOP, FALSE, SPTR_ARROW ) ) ;
  119. }
  120.  
  121. BOOL
  122. PutTextToClipboardServer( PCHAR pString )
  123. {
  124.     ULONG postcount = 0 ;
  125.     PCHAR pSharedMem = NULL ;
  126.     APIRET rc = 0 ;
  127.  
  128.     if ( !hmuxClipbrdSrv && OpenClipboardServer() ) {
  129.         debug( F100,"CLIP Server not available","",0);
  130.         return FALSE ;
  131.         }
  132.  
  133.     if ( rc = DosRequestMutexSem( hmuxClipbrdSrv, 1000 ) ) {
  134.         debug( F101, "CLIP Request Mutex failed rc","",rc ) ;
  135.         CloseClipboardServer() ;
  136.         return FALSE ;
  137.         }
  138.  
  139.     rc = DosGetNamedSharedMem( (PPVOID) &pSharedMem,
  140.         "\\SHAREMEM\\CKERMIT\\CLIPBRD\\DATA",  PAG_WRITE ) ;
  141.     debug( F101, "CLIP Get Named Shared RAM rc","",rc ) ;
  142.  
  143.     /* We now have exclusive access to the named shared memory */
  144.  
  145.     if ( !rc && pSharedMem ) {
  146.         strncpy( pSharedMem, pString, 65535 ) ;
  147.         pSharedMem[65534] = '\0' ;
  148.         }
  149.  
  150.     /* Now signal the Clipboard Server that we have something for it to do */
  151.     rc = DosPostEventSem( hevClipbrdPut ) ;
  152.     debug( F101, "CLIP Post Put Sem rc","",rc ) ;
  153.  
  154.     /* Now wait for it to tell us it is done */
  155.     rc = DosWaitEventSem( hevClipbrdDone, SEM_INDEFINITE_WAIT ) ;
  156.     debug( F101, "CLIP Wait Done Sem rc","",rc ) ;
  157.     rc = DosResetEventSem( hevClipbrdDone, &postcount ) ;
  158.  
  159.     rc = DosReleaseMutexSem( hmuxClipbrdSrv ) ;
  160.     return TRUE ;
  161. }
  162.  
  163. PCHAR
  164. GetTextFromClipboardServer( void )
  165. {
  166.     ULONG postcount = 0 ;
  167.     PCHAR pSharedMem = NULL ;
  168.     PCHAR pString = NULL ;
  169.     APIRET rc = 0 ;
  170.  
  171.     if ( !hmuxClipbrdSrv && OpenClipboardServer() ) {
  172.         debug( F100,"CLIP Server not available","",0);
  173.         return NULL ;
  174.         }
  175.  
  176.     if ( rc = DosRequestMutexSem( hmuxClipbrdSrv, 1000 ) ) {
  177.         debug( F101, "CLIP Request Mutex failed rc","",rc ) ;
  178.         CloseClipboardServer() ;
  179.         return NULL ;
  180.         }
  181.  
  182.     rc = DosPostEventSem( hevClipbrdGet ) ;
  183.     debug( F101, "CLIP Post Get Sem rc","",rc ) ;
  184.  
  185.     if ( rc = DosWaitEventSem( hevClipbrdData, 1000 ) ) {
  186.         debug( F101, "CLIP Wait Data Sem failed rc","",0 ) ;
  187.         rc = DosReleaseMutexSem( hmuxClipbrdSrv ) ;
  188.         CloseClipboardServer();
  189.         return NULL ;
  190.         }
  191.  
  192.     rc = DosResetEventSem( hevClipbrdData, &postcount ) ;
  193.     debug( F101, "CLIP Reset Data Sem rc","",rc ) ;
  194.  
  195.     rc = DosGetNamedSharedMem( (PPVOID) &pSharedMem,
  196.         "\\SHAREMEM\\CKERMIT\\CLIPBRD\\DATA",  PAG_READ ) ;
  197.     debug( F101, "CLIP Get Named Shared RAM rc","",rc ) ;
  198.  
  199.     if ( !rc && pSharedMem ) {
  200.         pString = strdup( pSharedMem ) ;
  201.         DosFreeMem( pSharedMem ) ;
  202.         }
  203.  
  204.     rc = DosPostEventSem( hevClipbrdDone ) ;
  205.     debug( F101, "CLIP Post Done Sem rc","",rc ) ;
  206.     rc = DosReleaseMutexSem( hmuxClipbrdSrv ) ;
  207.     return pString ;
  208. }
  209. #endif /* NT */
  210.  
  211.  
  212.