home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / cstepm.zip / gethost.e < prev    next >
Text File  |  1993-10-06  |  7KB  |  151 lines

  1. /* The following routine uses EHLLAPI calls to copy the CM host screen
  2.    to the current file.  It accepts as argument a long or short session
  3.    name.  The short name is usually 'A', 'B', etc., while the long name
  4.    can be defined by the user to be something more meaningful.  The
  5.    default, if no session name is given, is the first host session found.
  6.  
  7.    Note:  This should work for any size host screen.  If you only have
  8.    a single host session with a 24 x 80 screen, the following could be
  9.    simplified.
  10.  
  11.    Larry Margolis, MARGOLI at YKTVMV                                   */
  12.  
  13. ; The compiled GETHOST.EX will load from disk and execute if you enter
  14. ; the GETHOST command on the E command line.  If you want to make it a
  15. ; little faster, you could include it in E by either adding a line:
  16. ;    include 'gethost.e'  -- Include when you compile E.E
  17. ; or the two lines:
  18. ;    definit
  19. ;       link 'gethost'    -- Link in when you load E.
  20. ; to your MYSTUFF.E.  This will compile properly either way.
  21.  
  22. compile if not defined(SMALL)  -- If being compiled separately:
  23.  include 'STDCONST.E'      -- Need to include standard constants
  24.  
  25.  defmain                   -- Executed at link time.
  26. compile else
  27.  defc gethost
  28. compile endif
  29.                              -- Routine to get a copy of the host screen.
  30.    parse value upcase(arg(1)) with session_name .
  31.                                         -- *** Query sessions ***
  32.    EHLLAPI_data_string = substr('',1,252)
  33.    EHLLAPI_data_string_length = atoi(252)
  34.    EHLLAPI_host_PS_position = atoi(0)
  35.  
  36.    result=HLLAPI_call(atoi(10),
  37.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  38.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  39.  
  40.    if result then
  41.       sayerror 'Error 'result' trying to query sessions.'
  42.       stop
  43.    endif
  44.    short_id = ''
  45.    do i=1 to itoa(EHLLAPI_data_string_length,10)
  46.       posn = (i-1) * 12 + 1
  47.       if substr(EHLLAPI_data_string,posn+9,1) <> 'H' then iterate; endif --Host
  48.       if substr(EHLLAPI_data_string,posn,1) = session_name or
  49.          substr(EHLLAPI_data_string,posn+1,8) = session_name or
  50.          session_name = ''                  -- If null, use first host session.
  51.       then
  52.          shortid = substr(EHLLAPI_data_string,posn,1)
  53.          size = itoa(substr(EHLLAPI_data_string,posn+10,2),10)
  54.          leave
  55.       endif
  56.    end
  57.    if shortid='' then
  58.       sayerror "Couldn't find host session "session_name
  59.       stop
  60.    endif
  61.                                         -- *** Query session status ***
  62.    EHLLAPI_data_string = substr(shortid,1,18)
  63.    EHLLAPI_data_string_length = atoi(18)
  64.    EHLLAPI_host_PS_position = atoi(0)
  65.  
  66.    result=HLLAPI_call(atoi(22),
  67.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  68.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  69.    if result then
  70.       sayerror 'Error 'result' trying to query session status.'
  71.       stop
  72.    endif
  73.    rows = itoa(substr(EHLLAPI_data_string,12,2),10)
  74.    cols = itoa(substr(EHLLAPI_data_string,14,2),10)
  75.  
  76.    EHLLAPI_data_string = shortid        -- *** Connect to host PS ***
  77.    EHLLAPI_data_string_length = atoi(1) -- Data string length or buffer size
  78.    EHLLAPI_host_PS_position = atoi(0)   -- Host presentation space position
  79.    result=HLLAPI_call(atoi(1),
  80.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  81.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  82.    if result<>0 & result<>4 & result<>5 then  -- 0=all OK; 4=busy; 5=locked
  83.       sayerror 'Error 'result' trying to connect to host session 'session_name
  84.       stop
  85.    endif
  86. ;                                       *** Copy host presentation space ***
  87.    bufhndl = buffer(CREATEBUF, 'HLLAPI', size, 1)  -- get a private buffer
  88.    if not bufhndl then
  89.       sayerror 'CREATEBUF error number 'RC
  90.       call EHLLAPI_DISC()
  91.       stop
  92.    endif
  93.    EHLLAPI_data_string_length = atoi(size)
  94.    EHLLAPI_host_PS_position = atoi(1)   -- N/A
  95.    result=HLLAPI_call(atoi(5), atoi(bufhndl), atoi(0),
  96.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  97.    if result=0 | result=4 | result=5 then
  98.       do i=0 to rows-1
  99.          insertline peek(bufhndl, i*cols, cols), .line + i + 1
  100.       end
  101.    else
  102.       sayerror 'Error 'result' trying to copy host screen.'
  103.    endif
  104.    success = buffer(FREEBUF, bufhndl)
  105.    if not success then sayerror 'FREEBUF error number 'RC; endif
  106.    call EHLLAPI_DISC()    -- *** Disconnect from host presentation space ***
  107.  
  108. defproc EHLLAPI_DISC
  109.    EHLLAPI_data_string = ''
  110.    EHLLAPI_data_string_length = atoi(0) -- Data string length or buffer size
  111.    EHLLAPI_host_PS_position = atoi(0)   -- Host presentation space position
  112.  
  113.    return HLLAPI_call(atoi(2),
  114.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  115.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  116.  
  117. ; HLLAPI_call is the general interface for calling the EHLLAPI dynalink.
  118. ; Parameters are always the same - an EHLLAPI function number, selector of
  119. ; the data string, offset of the data string, the data string length, and
  120. ; the host presentation space position.  They might not be used in all calls,
  121. ; but EHLLAPI requires that they all be present.
  122. ;
  123. ; The data string is passed via selector and offset rather than as a VAR string,
  124. ; since some calls (e.g., copying the entire host screen) require a string
  125. ; larger than 255 bytes, and so we must allocate a buffer and pass that.
  126. defproc HLLAPI_call(EHLLAPI_function_number,
  127.                     sel_EHLLAPI_data_string, ofs_EHLLAPI_data_string,
  128.                 var EHLLAPI_data_string_length, -- Data str. len. or buffer size
  129.                 var EHLLAPI_host_PS_position)   -- Host presentation space posn.
  130.                                                 -- (on return, RC)
  131.    rc = 0        -- Prepare for missing DLL library
  132.  compile if EPM32
  133.    result=dynalink('ACS3EHAP',                  -- dynamic link library name
  134.                    'HLLAPI',                    -- HLLAPI direct call
  135.                     Thunk(offset(EHLLAPI_function_number)    || selector(EHLLAPI_function_number))    ||
  136.                     Thunk(ofs_EHLLAPI_data_string            || sel_EHLLAPI_data_string)              ||
  137.                     Thunk(offset(EHLLAPI_data_string_length) || selector(EHLLAPI_data_string_length)) ||
  138.                     Thunk(offset(EHLLAPI_host_PS_position)   || selector(EHLLAPI_host_PS_position)) )
  139.  compile else
  140.    result=dynalink('ACS3EHAP',                  -- dynamic link library name
  141.                    'HLLAPI',                    -- HLLAPI direct call
  142.                    address(EHLLAPI_function_number)     ||
  143.                    sel_EHLLAPI_data_string              ||
  144.                    ofs_EHLLAPI_data_string              ||
  145.                    address(EHLLAPI_data_string_length)  ||
  146.                    address(EHLLAPI_host_PS_position))
  147.  compile endif
  148.    if rc then sayerror 'Error 'rc' from HLLAPI dynalink call.'; stop; endif
  149.    return result
  150.  
  151.