home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 3 Comm
/
03-Comm.zip
/
clpsrv.zip
/
getclip.xed
< prev
next >
Wrap
Text File
|
1993-08-24
|
6KB
|
224 lines
/*------------------------------------------------------------------
* getclip.xedit : macro to read OS/2 clipboard data from the
* ClipServ server
*------------------------------------------------------------------
* 08-13-92 originally by Patrick J. Mueller
* 08-24-93 updated to use REXX/SOCKETS 2.01
*------------------------------------------------------------------*/
parse source . . me .
trace off
/*------------------------------------------------------------------
* get parms
*------------------------------------------------------------------*/
parse arg host port
if (host <> "") & (port = "") then
Usage()
else if (host <> "") | (port <> "") then
address command "GLOBALV SELECT CLIPSERV PUTP HOST PORT"
else
do
address command "GLOBALV SELECT CLIPSERV GET HOST PORT"
if (host = "") | (port = "") then
do
"EMSG" me": GLOBALV storage not correct, specify full parameters"
Usage()
end
end
/*------------------------------------------------------------------
* make sure the cursor is in the file
*------------------------------------------------------------------*/
"COMMAND EXTRACT /CURSOR/"
yCursor = cursor.3
xCursor = cursor.4
if (xCursor = -1) | (yCursor = -1) then
do
"COMMAND EMSG" me ": Cursor not in file"
exit
end
/*------------------------------------------------------------------
* initialize socket function package
*------------------------------------------------------------------*/
sockInfo = socket("INITIALIZE","GETCLIP")
parse var sockInfo src .
if (src <> 0) then
do
parse var sockInfo src token desc
msg1 = "Error" src "initializing REXX/SOCKETS function package."
msg2 = token ":" desc
rc = Error(-1,src,msg1,msg2)
end
/*------------------------------------------------------------------
* open socket
*------------------------------------------------------------------*/
sockInfo = socket("SOCKET","AF_INET","SOCK_STREAM","IPPROTO_TCP")
parse var sockInfo src sock .
if (src <> 0) then
do
parse var sockInfo src token desc
msg1 = "Error" src "obtaining new socket."
msg2 = token ":" desc
rc = Error(-1,src,msg1,msg2)
end
signal on halt
signal on syntax
/*------------------------------------------------------------------
* connect socket
*------------------------------------------------------------------*/
sockInfo = socket("CONNECT",sock,"AF_INET" port host)
parse var sockInfo src .
if (src <> 0) then
do
parse var sockInfo src token desc
msg1 = "Error" src "connecting to ClipServ server."
msg2 = token ":" desc
rc = Error(sock,src,msg1,msg2)
end
/*------------------------------------------------------------------
* get the clipboard data
*------------------------------------------------------------------*/
rc = socket("SETSOCKOPT",sock,"SOL_SOCKET","SO_ASCII","ON")
data = ""
do forever
chunkInfo = socket("RECV",sock,1000)
parse var chunkInfo src length chunk
if (length = 0) | (src <> 0) then
leave
data = data || chunk
end
/*------------------------------------------------------------------
* close the socket
*------------------------------------------------------------------*/
rc = socket("CLOSE",sock)
rc = socket("TERMINATE","GETCLIP")
/*------------------------------------------------------------------
* now reformat the data
*------------------------------------------------------------------*/
crlf = d2c(13) || d2c(37)
clipLine.0 = 0
lineMax = 0
do while (data <> "")
p = pos(crlf,data)
if (p = 0) then
do
line = data
data = ""
end
else
do
line = substr(data,1,p-1)
data = substr(data,p+2)
end
if (line = "") & (data = "") then
leave
o = clipLine.0 + 1
clipLine.0 = o
clipLine.o = line
lineMax = max(lineMax,length(line))
end
/*------------------------------------------------------------------
* blank fill lines on the right
*------------------------------------------------------------------*/
do i = 1 to clipLine.0
clipLine.i = left(clipLine.i,lineMax)
end
/*------------------------------------------------------------------
* insert lines
*------------------------------------------------------------------*/
"COMMAND EXTRACT /CURSOR/LINE/"
yCursor = cursor.3
xCursor = cursor.4
curLine = line.1
if (xCursor = -1) | (yCursor = -1) then
do
"COMMAND EMSG" me ": Cursor not in file"
exit
end
"COMMAND :"yCursor
do i = 1 to clipLine.0
"COMMAND EXTRACT /CURLINE/"
oldLine = curline.3
newLine = overlay(clipLine.i,oldLine,xCursor)
"COMMAND REPLACE" newLine
"COMMAND 1"
end
"COMMAND :"curLine
"COMMAND CURSOR FILE" yCursor xCursor
exit
/*------------------------------------------------------------------
* exit with a message and return code
*------------------------------------------------------------------*/
Error: procedure expose !.
parse source . . me .
sock = arg(1)
retc = arg(2)
if (sock <> -1) then
rc = socket("CLOSE",sock)
rc = socket("TERMINATE","GETCLIP")
do i = 3 to arg()
"EMSG" me ":" arg(i)
end
exit retc
/*------------------------------------------------------------------
* what to do when halted
*------------------------------------------------------------------*/
Halt:
parse source . . me .
Error(sock,1,me "halted on line" sigl ".")
/*------------------------------------------------------------------
* what to do when halted
*------------------------------------------------------------------*/
Syntax:
parse source . . me .
Error(sock,1,me "has syntax error on line" sigl ".")
Usage:
"EMSG" me
"EMSG usage:"
"EMSG " me
"EMSG " me "serverAddress port"
"EMSG If an address and port are not specified, the values last used"
"EMSG will be used (stored in LASTING GLOBALV). The first time you"
"EMSG run" me "you need to pass in the address and port"
exit