home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmsmp.zip / GETHOST.E < prev    next >
Text File  |  1995-01-16  |  9KB  |  187 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.  | Updated 93/04/26 to support the 32-bit EPM 6.00.
  12.  
  13.    Larry Margolis                                                      */
  14.  
  15. ; The compiled GETHOST.EX will load from disk and execute if you enter
  16. ; the GETHOST command on the E command line.  If you want to make it a
  17. ; little faster, you could include it in E by either adding a line:
  18. ;    include 'gethost.e'  -- Include when you compile E.E
  19. ; or the two lines:
  20. ;    definit
  21. ;       link 'gethost'    -- Link in when you load E.
  22. ; to your MYSTUFF.E.  This will compile properly either way.
  23.  
  24. compile if not defined(SMALL)  -- If being compiled separately:
  25.  include 'STDCONST.E'      -- Need to include standard constants
  26.  define INCLUDING_FILE = 'GETHOST.E'
  27. const
  28.    tryinclude 'MYCNF.E'        -- the user's configuration customizations.
  29.  
  30.  compile if not defined(SITE_CONFIG)
  31.     const SITE_CONFIG = 'SITECNF.E'
  32.  compile endif
  33.  compile if SITE_CONFIG
  34.     tryinclude SITE_CONFIG
  35.  compile endif
  36.  
  37.  defmain                   -- Executed at link time.
  38. compile else
  39.  defc gethost
  40. compile endif
  41.                              -- Routine to get a copy of the host screen.
  42.    parse value upcase(arg(1)) with session_name .
  43.                                         -- *** Query sessions ***
  44.    EHLLAPI_data_string = substr('',1,252)
  45.    EHLLAPI_data_string_length = atoi(252)
  46.    EHLLAPI_host_PS_position = atoi(0)
  47.  
  48.    result=HLLAPI_call(atoi(10),
  49.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  50.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  51.  
  52.    if result then
  53.       sayerror 'Error 'result' trying to query sessions.'
  54.       stop
  55.    endif
  56.    short_id = ''
  57.    do i=1 to itoa(EHLLAPI_data_string_length,10)
  58.       posn = (i-1) * 12 + 1
  59.       if substr(EHLLAPI_data_string,posn+9,1) <> 'H' then iterate; endif --Host
  60.       if substr(EHLLAPI_data_string,posn,1) = session_name or
  61.          substr(EHLLAPI_data_string,posn+1,8) = session_name or
  62.          session_name = ''                  -- If null, use first host session.
  63.       then
  64.          shortid = substr(EHLLAPI_data_string,posn,1)
  65.          size = itoa(substr(EHLLAPI_data_string,posn+10,2),10)
  66.          leave
  67.       endif
  68.    end
  69.    if shortid='' then
  70.       sayerror "Couldn't find host session "session_name
  71.       stop
  72.    endif
  73.                                         -- *** Query session status ***
  74.    EHLLAPI_data_string = substr(shortid,1,18)
  75.    EHLLAPI_data_string_length = atoi(18)
  76.    EHLLAPI_host_PS_position = atoi(0)
  77.  
  78.    result=HLLAPI_call(atoi(22),
  79.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  80.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  81.    if result then
  82.       sayerror 'Error 'result' trying to query session status.'
  83.       stop
  84.    endif
  85.    rows = itoa(substr(EHLLAPI_data_string,12,2),10)
  86.    cols = itoa(substr(EHLLAPI_data_string,14,2),10)
  87.  
  88.    EHLLAPI_data_string = shortid        -- *** Connect to host PS ***
  89.    EHLLAPI_data_string_length = atoi(1) -- Data string length or buffer size
  90.    EHLLAPI_host_PS_position = atoi(0)   -- Host presentation space position
  91.    result=HLLAPI_call(atoi(1),
  92.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  93.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  94.    if result<>0 & result<>4 & result<>5 then  -- 0=all OK; 4=busy; 5=locked
  95.       sayerror 'Error 'result' trying to connect to host session 'session_name
  96.       stop
  97.    endif
  98. ;                                       *** Copy host presentation space ***
  99.    bufhndl = buffer(CREATEBUF, 'HLLAPI', size, 1)  -- get a private buffer
  100.    if not bufhndl then
  101.       sayerror 'CREATEBUF error number 'RC
  102.       call EHLLAPI_DISC()
  103.       stop
  104.    endif
  105.    EHLLAPI_data_string_length = atoi(size)
  106.    EHLLAPI_host_PS_position = atoi(1)   -- N/A
  107.    result=HLLAPI_call(atoi(5), atoi(bufhndl), atoi(0),
  108.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  109.    if result=0 | result=4 | result=5 then
  110.       do i=0 to rows-1
  111.          insertline peek(bufhndl, i*cols, cols), .line + i + 1
  112.       end
  113.    else
  114.       sayerror 'Error 'result' trying to copy host screen.'
  115.    endif
  116.    success = buffer(FREEBUF, bufhndl)
  117.    if not success then sayerror 'FREEBUF error number 'RC; endif
  118.    call EHLLAPI_DISC()    -- *** Disconnect from host presentation space ***
  119.  
  120. defproc EHLLAPI_DISC
  121.    EHLLAPI_data_string = ''
  122.    EHLLAPI_data_string_length = atoi(0) -- Data string length or buffer size
  123.    EHLLAPI_host_PS_position = atoi(0)   -- Host presentation space position
  124.  
  125.    return HLLAPI_call(atoi(2),
  126.                       selector(EHLLAPI_data_string), offset(EHLLAPI_data_string),
  127.                       EHLLAPI_data_string_length, EHLLAPI_host_PS_position)
  128.  
  129. compile if not defined(HOST_SUPPORT)
  130.  compile if not SMALL
  131.    HOST_SUPPORT = 'STD'
  132.  compile else
  133.    HOST_SUPPORT = ''
  134.  compile endif
  135. compile endif
  136.  
  137. ; The following routine is defined in E3EMUL.E if using EPM; no need to
  138. ; define it twice:
  139. compile if EVERSION < 5 | (HOST_SUPPORT <> 'EMUL' & HOST_SUPPORT <> 'E3EMUL')
  140. ; HLLAPI_call is the general interface for calling the EHLLAPI dynalink.
  141. ; Parameters are always the same - an EHLLAPI function number, selector of
  142. ; the data string, offset of the data string, the data string length, and
  143. ; the host presentation space position.  They might not be used in all calls,
  144. ; but EHLLAPI requires that they all be present.
  145. ;
  146. ; The data string is passed via selector and offset rather than as a VAR string,
  147. ; since some calls (e.g., copying the entire host screen) require a string
  148. ; larger than 255 bytes, and so we must allocate a buffer and pass that.
  149. defproc HLLAPI_call(EHLLAPI_function_number,
  150.                     sel_EHLLAPI_data_string, ofs_EHLLAPI_data_string,
  151.                 var EHLLAPI_data_string_length, -- Data str. len. or buffer size
  152.                 var EHLLAPI_host_PS_position)   -- Host presentation space posn.
  153.                                                 -- (on return, RC)
  154.    rc = 0        -- Prepare for missing DLL library
  155.  compile if EPM32
  156.    result=dynalink('ACS3EHAP',                  -- dynamic link library name
  157.                    'HLLAPI',                    -- HLLAPI direct call
  158.                     Thunk(offset(EHLLAPI_function_number)    || selector(EHLLAPI_function_number))    ||
  159.                     Thunk(ofs_EHLLAPI_data_string            || sel_EHLLAPI_data_string)              ||
  160.                     Thunk(offset(EHLLAPI_data_string_length) || selector(EHLLAPI_data_string_length)) ||
  161.                     Thunk(offset(EHLLAPI_host_PS_position)   || selector(EHLLAPI_host_PS_position)) )
  162.  compile elseif EVERSION >= '5.51'
  163.    result=dynalink('ACS3EHAP',                  -- dynamic link library name
  164.                    'HLLAPI',                    -- HLLAPI direct call
  165.                    address(EHLLAPI_function_number)     ||
  166.                    sel_EHLLAPI_data_string              ||
  167.                    ofs_EHLLAPI_data_string              ||
  168.                    address(EHLLAPI_data_string_length)  ||
  169.                    address(EHLLAPI_host_PS_position))
  170.  compile else
  171.    result=dynalink('ACS3EHAP',     /* dynamic link library name       */
  172.                    'HLLAPI',       /* HLLAPI direct call              */
  173.                    selector(EHLLAPI_function_number)   ||
  174.                    offset(EHLLAPI_function_number)     ||
  175.                    sel_EHLLAPI_data_string             ||
  176.                    ofs_EHLLAPI_data_string             ||
  177.                    selector(EHLLAPI_data_string_length)||
  178.                    offset(EHLLAPI_data_string_length)  ||
  179.                    selector(EHLLAPI_host_PS_position)  ||
  180.                    offset(EHLLAPI_host_PS_position))
  181.  compile endif
  182.    if rc then sayerror 'Error 'rc' from HLLAPI dynalink call.'; stop; endif
  183.    return result
  184.  
  185. compile endif
  186.  
  187.