home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
cstepm.zip
/
gethost.e
< prev
next >
Wrap
Text File
|
1993-10-06
|
7KB
|
151 lines
/* The following routine uses EHLLAPI calls to copy the CM host screen
to the current file. It accepts as argument a long or short session
name. The short name is usually 'A', 'B', etc., while the long name
can be defined by the user to be something more meaningful. The
default, if no session name is given, is the first host session found.
Note: This should work for any size host screen. If you only have
a single host session with a 24 x 80 screen, the following could be
simplified.
Larry Margolis, MARGOLI at YKTVMV */
; The compiled GETHOST.EX will load from disk and execute if you enter
; the GETHOST command on the E command line. If you want to make it a
; little faster, you could include it in E by either adding a line:
; include 'gethost.e' -- Include when you compile E.E
; or the two lines:
; definit
; link 'gethost' -- Link in when you load E.
; to your MYSTUFF.E. This will compile properly either way.
compile if not defined(SMALL) -- If being compiled separately:
include 'STDCONST.E' -- Need to include standard constants
defmain -- Executed at link time.
compile else
defc gethost
compile endif
-- Routine to get a copy of the host screen.
parse value upcase(arg(1)) with session_name .
-- *** Query sessions ***
EHLLAPI_data_string = substr('',1,252)
EHLLAPI_data_string_length = atoi(252)
EHLLAPI_host_PS_position = atoi(0)
result=HLLAPI_call(atoi(10),
selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
if result then
sayerror 'Error 'result' trying to query sessions.'
stop
endif
short_id = ''
do i=1 to itoa(EHLLAPI_data_string_length,10)
posn = (i-1) * 12 + 1
if substr(EHLLAPI_data_string,posn+9,1) <> 'H' then iterate; endif --Host
if substr(EHLLAPI_data_string,posn,1) = session_name or
substr(EHLLAPI_data_string,posn+1,8) = session_name or
session_name = '' -- If null, use first host session.
then
shortid = substr(EHLLAPI_data_string,posn,1)
size = itoa(substr(EHLLAPI_data_string,posn+10,2),10)
leave
endif
end
if shortid='' then
sayerror "Couldn't find host session "session_name
stop
endif
-- *** Query session status ***
EHLLAPI_data_string = substr(shortid,1,18)
EHLLAPI_data_string_length = atoi(18)
EHLLAPI_host_PS_position = atoi(0)
result=HLLAPI_call(atoi(22),
selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
if result then
sayerror 'Error 'result' trying to query session status.'
stop
endif
rows = itoa(substr(EHLLAPI_data_string,12,2),10)
cols = itoa(substr(EHLLAPI_data_string,14,2),10)
EHLLAPI_data_string = shortid -- *** Connect to host PS ***
EHLLAPI_data_string_length = atoi(1) -- Data string length or buffer size
EHLLAPI_host_PS_position = atoi(0) -- Host presentation space position
result=HLLAPI_call(atoi(1),
selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
if result<>0 & result<>4 & result<>5 then -- 0=all OK; 4=busy; 5=locked
sayerror 'Error 'result' trying to connect to host session 'session_name
stop
endif
; *** Copy host presentation space ***
bufhndl = buffer(CREATEBUF, 'HLLAPI', size, 1) -- get a private buffer
if not bufhndl then
sayerror 'CREATEBUF error number 'RC
call EHLLAPI_DISC()
stop
endif
EHLLAPI_data_string_length = atoi(size)
EHLLAPI_host_PS_position = atoi(1) -- N/A
result=HLLAPI_call(atoi(5), atoi(bufhndl), atoi(0),
EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
if result=0 | result=4 | result=5 then
do i=0 to rows-1
insertline peek(bufhndl, i*cols, cols), .line + i + 1
end
else
sayerror 'Error 'result' trying to copy host screen.'
endif
success = buffer(FREEBUF, bufhndl)
if not success then sayerror 'FREEBUF error number 'RC; endif
call EHLLAPI_DISC() -- *** Disconnect from host presentation space ***
defproc EHLLAPI_DISC
EHLLAPI_data_string = ''
EHLLAPI_data_string_length = atoi(0) -- Data string length or buffer size
EHLLAPI_host_PS_position = atoi(0) -- Host presentation space position
return HLLAPI_call(atoi(2),
selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
; HLLAPI_call is the general interface for calling the EHLLAPI dynalink.
; Parameters are always the same - an EHLLAPI function number, selector of
; the data string, offset of the data string, the data string length, and
; the host presentation space position. They might not be used in all calls,
; but EHLLAPI requires that they all be present.
;
; The data string is passed via selector and offset rather than as a VAR string,
; since some calls (e.g., copying the entire host screen) require a string
; larger than 255 bytes, and so we must allocate a buffer and pass that.
defproc HLLAPI_call(EHLLAPI_function_number,
sel_EHLLAPI_data_string, ofs_EHLLAPI_data_string,
var EHLLAPI_data_string_length, -- Data str. len. or buffer size
var EHLLAPI_host_PS_position) -- Host presentation space posn.
-- (on return, RC)
rc = 0 -- Prepare for missing DLL library
compile if EPM32
result=dynalink('ACS3EHAP', -- dynamic link library name
'HLLAPI', -- HLLAPI direct call
Thunk(offset(EHLLAPI_function_number) || selector(EHLLAPI_function_number)) ||
Thunk(ofs_EHLLAPI_data_string || sel_EHLLAPI_data_string) ||
Thunk(offset(EHLLAPI_data_string_length) || selector(EHLLAPI_data_string_length)) ||
Thunk(offset(EHLLAPI_host_PS_position) || selector(EHLLAPI_host_PS_position)) )
compile else
result=dynalink('ACS3EHAP', -- dynamic link library name
'HLLAPI', -- HLLAPI direct call
address(EHLLAPI_function_number) ||
sel_EHLLAPI_data_string ||
ofs_EHLLAPI_data_string ||
address(EHLLAPI_data_string_length) ||
address(EHLLAPI_host_PS_position))
compile endif
if rc then sayerror 'Error 'rc' from HLLAPI dynalink call.'; stop; endif
return result