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