home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / editor / epmtools / lampdq / lampdq.e next >
Encoding:
Text File  |  1994-01-31  |  28.1 KB  |  764 lines

  1. ; The following makes LAMPDQ.E separately compilable, so you can include the
  2. ; host functions in EPM even if not using the rest of LaMail.
  3.  
  4. ; Compilation logic:
  5. ;   If SMALL is defined, then we're being compiled into the base.
  6. ;   else, if INI_REPLY is defined, then we're being compiled into MAIL
  7. ;   otherwise, we're being compiled as a stand-alone routine that
  8. ;   can be linked in at run time.
  9.  
  10. const
  11. compile if not defined(SMALL)
  12.   tryinclude 'mycnf.e'                 -- Include user's configuration
  13. const
  14.  compile if not defined(HOST_SUPPORT)
  15.     HOST_SUPPORT = 'STD'
  16.  compile endif
  17.  compile if HOST_SUPPORT='STD'
  18.   compile if not defined(HOSTDRIVE)
  19.      HOSTDRIVE= 'H:'
  20.   compile endif
  21.  compile endif
  22. compile endif  -- not defined(SMALL)
  23. compile if not defined(RSCS)
  24.    RSCS = 'RSCS'
  25. compile endif
  26. compile if not defined(YKT_stuff)
  27. ; This determines whether the Yorktown-specific stuff is included
  28.    YKT_STUFF=0
  29. compile endif
  30. compile if not defined(CORE_stuff)
  31. ; This determines whether the CORE-specific stuff is included
  32.    CORE_STUFF=0
  33. compile endif
  34. compile if not defined(YKT_SERVICES)
  35. ; This determines whether the Yorktown-specific commands (CORE, PHONE, QLUNCH,
  36. ; etc.) are included in the macros and in the menus.
  37.    YKT_SERVICES=0
  38. compile endif
  39. compile if not defined(TILDE_CHAR)
  40.  compile if EVERSION < '5.21'
  41.    TILDE_CHAR = ''
  42.  compile else
  43.    TILDE_CHAR = '~'
  44.  compile endif
  45. compile endif
  46. compile if not defined(HOSTCOPYDRIVE)
  47.    HOSTCOPYDRIVE= 'H'
  48. compile endif
  49. compile if not defined(AUTO_LAMSERV)
  50. ; This determines whether LAMSERV should be started automatically
  51.    AUTO_LAMSERV = 0
  52. compile endif
  53.  
  54. compile if defined(SMALL) or not defined(INI_REPLY)  -- If in base or standalone
  55. definit
  56.    universal host_lt, defaultmenu, activemenu
  57.    universal host_printers
  58.  compile if defined(my_LT)
  59.    host_lt=my_LT           -- Used by LaMail.E; needed for E3EMUL if multiple LTs.
  60.  compile elseif HOST_SUPPORT = 'EMUL' | HOST_SUPPORT = 'E3EMUL'
  61.    host_lt='A'             -- In case user has HOST_LT_REQUIRED = 1
  62.  compile else
  63.    host_lt=''              -- Used by LaMail.E; needed for SLSRPI if multiple LTs.
  64.  compile endif
  65.  compile if defined(my_HOST_PRINTERS)
  66.    host_printers=my_HOST_PRINTERS  -- List of default host printers
  67.  compile else
  68.    host_printers=''
  69.  compile endif
  70.    deletemenu defaultmenu, 6, 0, 0  -- delete the existing Help menu (we want it to stay at the right)
  71.    call add_VM_cmds_to_menu(defaultmenu)  -- add the VM commands to the action bar
  72.    call add_help_menu(defaultmenu, dos_version()>=1020)  -- rebuild the help menu
  73.  compile if not defined(INI_REPLY)  -- If standalone; if in base, MAIN.E will do this.
  74.    if activemenu=defaultmenu then
  75.       showmenu activemenu  -- show the updated EPM menu
  76.    endif
  77.  compile endif
  78.  
  79. defproc add_VM_cmds_to_menu(menu)
  80.    buildsubmenu menu, 16, TILDE_CHAR'VM cmds', ''\1'Menus for invoking VM-related commands', 0 , 0
  81.      buildmenuitem menu, 16, 1600, 'output ~Inserted here...'\9'VMI',   'commandline VMI '\1'Execute a VM command, and have the output inserted into the current file',0,0
  82.      buildmenuitem menu, 16, 1601, 'output in ~New file...'\9'VMN',     'commandline VMN '\1'Execute a VM command, and see the output in a new file',0,0
  83.      buildmenuitem menu, 16, 1602, 'output in new ~window...'\9'VM',    'commandline VM '\1'Execute a VM command, and see the output in a new edit window',0,0
  84.      buildmenuitem menu, 16, 1620, '~Get a copy of host screen'\9'GETHOST', 'gethostd'\1'Insert a copy of the default host screen after the cursor line',0,0
  85.      buildmenuitem menu, 16, 1603, \0,                                '',      4, 0
  86.      buildmenuitem menu, 16, 1604, '~List host files...'\9'HLIST',    'hlistprompt'\1'Load a filelist of host files into an edit window',0,0
  87.      buildmenuitem menu, 16, 1605, \0,                                '',      4, 0
  88.      buildmenuitem menu, 16, 1606, '~Print current file on host...'\9'HOSTPRT', 'hostprt'\1'Print the current file on a host printer',0,0
  89.      buildmenuitem menu, 16, 1607, \0,                                '',      4, 0
  90.      buildmenuitem menu, 16, 1608, '~Query host for messages'\9'QMSG', 'qmsg'\1'Check to see if any new messages arrived since you started LAMSERV',0, 0
  91.  compile if YKT_SERVICES
  92.      buildmenuitem menu, 16, 1609, \0,                                '',      4, 0
  93.      buildmenuitem menu, 16, 1610, 'Look up p~hone number...'\9'PHONE', 'commandline Phone '\1'Invoke the Yorktown PHONE exec',0, 0
  94.      buildmenuitem menu, 16, 1611, 'Look up ~services...'\9'SERVICES',  'commandline Services '\1'Invoke the Yorktown SERVICES exec',0, 0
  95.      buildmenuitem menu, 16, 1612, \0,                                '',      4, 0
  96.      buildmenuitem menu, 16, 1613, 'See lunch ~menu'\9'QLUNCH',  'VM QLUNCH (NOCLEAR NOHILIGHT'\1'Invoke the Yorktown QLUNCH exec',0, 0
  97.      buildmenuitem menu, 16, 1614, 'See ~coffee cart schedule'\9'QCOFFEE',  'VM QCOFFEE NOCLEAR'\1'Invoke the Yorktown QCOFFEE exec',0, 0
  98. ;; CORE command is only defined if we're in MAIL.E
  99. ;;   buildmenuitem menu, 16, 1615, \0,                                '',      4, 0
  100. ;;   buildmenuitem menu, 16, 1616, 'Append CORE forum'\9'CORE',  'CORE',0, 0
  101.  compile endif
  102. compile endif
  103.  
  104. ;       Procedures for dealing with PDQ from within EPM.
  105. ;
  106. ; Adds the following commands:
  107. ;    VM:    Sends a command to the host; displays the result on the DOS screen.
  108. ;    VMI:   Sends a command to the host; inserts the result into the current file.
  109. ;    VMQ:   Sends a command to the host; throws away the result.
  110. ;    TELL:  Shorthand for VM TELL.
  111. ;    POLL:  Used to restart the poll loop if exited by Ctrl-break.
  112. ;    QMSG:  Queries the host for messages.  (Normally done by POLL)
  113.  
  114. ; Keys defined:
  115. ;    c_M is defined to pop-up the message window whenever a message is
  116. ;        received.  If no message has been received since the last time
  117. ;        the key was pressed, then it will display all previously received
  118. ;        messages (up to 40 lines).
  119.  
  120. ; 88/02/10  Added retry to hostconnect in case user quit PDQ on host, then
  121. ;           restarted it.  Fixed VMI in cases when RC <> 0.  Return RCs as
  122. ;           numbers if in range -32768 .. 32767; else as string x'12345678'.
  123.  
  124. ; 88/05/16  Modified for EOS2.  Uses LAMPDQ for host commands.
  125.  
  126. const
  127. /* SRPI dynalink functions basic constants */
  128.    SA_GET      = 1              /* downloading a file */
  129.    SA_EXEC     = 3              /* executing a command */
  130.  
  131. defc host
  132.    universal host_lt
  133.    parse value upcase(arg(1)) with arg1 rest
  134.    if arg1='?' then
  135.       sayerror 'Current host session is "'host_lt'".'
  136.    elseif arg(1)='' or (length(arg1)=1 & arg1>='A' & arg1<='Z') then
  137.       if not isoption(rest,'Q') then
  138.          sayerror 'Host session was "'host_lt'", now changed to "'arg1'".'
  139.       endif
  140.       host_lt = arg1
  141.    else
  142.       sayerror 'Invalid argument.  ? to query; blank or A-E to set.'
  143.    endif
  144.  
  145. defc TELL
  146.    'VME TELL' arg(1)
  147.  
  148. defc RQ
  149.    'VME RQUERY' arg(1)
  150.  
  151. defc VME
  152.    cmd_rc=sendhostcmdgetrslts(arg(1),hostrc,result)
  153.    if cmd_rc then
  154.       sayerror 'Error' cmd_rc 'trying to issue command.'
  155.       return rc
  156.    endif
  157.    if hostrc then
  158.       parse value upcase(arg(1)) with w1 w2 .
  159.       if w1='CP' | w1='EXEC' then w1=w1 w2; endif
  160.       sayerror w1 'error' hostrc': ' result
  161.    endif
  162.  
  163. defc PHONE
  164.    parse arg who
  165.    if who='' then
  166.       sayerror 'PHONE <name>  Looks up that person in the on-line directory.  PHONE ? for help.'
  167.       return
  168.    endif
  169.    'VMN PHONE' who
  170.    if rc=100 then sayerror 1; endif
  171.  
  172. defc HLIST                    ---- With features by TJR
  173.   if arg(1) = '' then
  174.       hfilespec = '* * A'
  175.   else
  176.       hfilespec = upcase(arg(1))
  177.   endif
  178.   sayerror 'Loading 'hfilespec' host files...'
  179.   'VMN LISTFILE' hfilespec '(HEADER DATE'
  180.   if not rc then
  181.      down; down
  182.      sayerror 'Move cursor to desired file and press Alt-1 to load it.'
  183.   endif
  184.  
  185. defc HLISTPROMPT
  186. compile if EVERSION >= '5.50'
  187.    display -8
  188. compile endif
  189.    sayerror 'Enter file specification.  E.g.,  * SCRIPT *  or  * XEDIT S.  Default is * * A'
  190. compile if EVERSION >= '5.50'
  191.    display 8
  192. compile endif
  193.    'commandline HLIST '
  194. compile if EVERSION < '5.50'
  195.    sayerror 0
  196. compile endif
  197.  
  198. compile if YKT_SERVICES
  199. defc SERVICES
  200.    'VMN SERVICES' arg(1)
  201.    if rc=100 then sayerror 1; endif
  202. compile endif
  203.  
  204. defc VM           -- Send command to VM & display output on DOS screen.
  205.    universal host_lt
  206.    if host_lt then hst='"host' host_lt '/Q" '; else hst=''; endif
  207.    'open' hst"'Postme VM_OPEN_CMD" arg(1)"'"
  208.  
  209. defc VM_OPEN_CMD      -- Passed by VM command as argument of a new session.
  210.    .autosave = 0
  211.    replaceline 'Processing host command' arg(1)
  212.    .filename = '.Output from' arg(1)
  213.    settitletext(.filename)
  214. ;; call showwindow('ON')
  215. ;; repaint_window()
  216.    size=.last
  217.    rc=vmi(arg(1),hostrc)
  218.    if rc then
  219.       msg = 'Error' rc 'attempting to issue host command.'
  220.       replaceline msg
  221.       sayerror msg
  222.    elseif size=.last then
  223.       if hostrc then replaceline '[Host cmd failed with RC' hostrc 'and no output.]'
  224.       else replaceline '[No output]'
  225.       endif
  226.    else
  227.       deleteline 1
  228.       .modify = 0
  229.       if hostrc<>0 then sayerror 'Host cmd failed with RC' hostrc; endif
  230.    endif
  231.    call windowsize1(min(.last+1,24),.windowwidth,0,0,1)  -- Size window to size of file
  232.  
  233. defc VMI          -- Send command to VM & insert output into current file.
  234.    size=.last
  235.    rc=vmi(arg(1),hostrc)
  236.    if rc then
  237.       sayerror 'Error' rc 'attempting to issue host command.'
  238.       return
  239.    endif
  240.    if size=.last then
  241.       if hostrc then sayerror 'Host cmd failed with RC' hostrc 'and no output.'
  242.       else sayerror '[No output]'
  243.       endif
  244.    else
  245.       insertline '.*----- Output from "'arg(1)'" -----',.line+1
  246.       insertline '.*----- [end, RC='hostrc'] -----',.line + .last - size + 1
  247.       if hostrc<>0 then sayerror 'Host cmd failed with RC' hostrc; endif
  248.    endif
  249.    rc=hostrc
  250.  
  251. defproc VMI(cmd,var host_rc)  -- Send command to VM & insert output into current file.
  252.    universal vTEMP_PATH
  253. compile if HOST_SUPPORT = 'SRPI'
  254.    universal hostrc
  255. compile endif
  256.  
  257. compile if HOST_SUPPORT = 'SRPI'
  258.    call issuehostcommand('',cmd)
  259. compile else
  260.    call issuehostcommand(vTEMP_PATH'HOSTCMD.TMP',cmd)
  261. compile endif
  262.    if rc then return rc; endif
  263. compile if HOST_SUPPORT = 'SRPI'
  264.    host_rc = hostrc
  265. compile else
  266.    'get' vTEMP_PATH'HOSTCMD.TMP'
  267.    getline host_rc,.line+1
  268.    deleteline .line+1
  269. compile endif
  270.  
  271. defc VMN       -- Send command to VM & insert output into a new file.
  272.    parse value upcase(arg(1)) with w1 w2 .
  273.    if w1='EXEC' | w1='CP' then w1=w2; endif
  274.    if w1='Q' then w1='QUERY'; endif    -- Assumes user didn't change default.
  275.    getfileid cmdfileid,w1 'OUTPUT'
  276.    if cmdfileid='' then
  277.       'E /n /q /c .tmp'
  278.       deleteline 1
  279.       .filename=w1 'OUTPUT'
  280.       oldmodify=0
  281.    else
  282.       activatefile cmdfileid
  283.       .last
  284.       oldmodify=.modify
  285.    endif
  286.    oldsize=.last
  287.    'VMI' arg(1)
  288.    hostrc=rc
  289.    .modify=oldmodify
  290.    if .last=0 then 'Q'
  291.    else
  292.       .cursory=1           -- Position so first new line is at top of screen.
  293.       oldsize+1
  294.    endif
  295.    rc=hostrc
  296.  
  297. defc VMQ     -- VM Quiet; send command and throw away output.
  298.    universal vTEMP_PATH
  299. compile if HOST_SUPPORT = 'SRPI'
  300.    call issuehostcommand(vTEMP_PATH'HOSTCMD.TMP',arg(1),'nul')
  301. compile else
  302.    call issuehostcommand(vTEMP_PATH'HOSTCMD.TMP',arg(1))
  303.    call erasetemp(vTEMP_PATH'HOSTCMD.TMP')
  304. compile endif
  305.  
  306. defc gethostd     -- Get a copy of the default host screen; uses the current default.
  307.    universal host_lt
  308.    'gethost' host_lt
  309.  
  310. defc hostprt          -- Print current edit file on host.
  311.    universal host_printers, host_lt
  312. compile if HOST_SUPPORT='EMUL' or HOST_SUPPORT='SRPI'
  313.    universal hostdrive
  314. compile endif
  315.    printer = 3
  316.    if host_printers then
  317.       printer=listbox('Select a host printer',' 'strip(host_printers),'/Print/Cancel/Select other/')
  318.       if printer='' then return; endif
  319.    endif
  320.    if printer=3 then
  321.       printer = entrybox('Enter name of host printer','/Print')
  322.    endif
  323.    if printer then
  324.       'save 'leftstr(hostdrive,1) || host_lt':lamail tmpprt a'
  325.       if rc then
  326.          sayerror 'Error' rc 'trying to save to host; print canceled.'
  327.          return
  328.       endif
  329.       stat=sendhostcommand('lamail files print PC2TEMP 'printer' lamail tmpprt a',hostrc)
  330.       sayerror 0
  331.       if stat then return hostcmderror(stat); endif
  332.       if hostrc then
  333.          sayerror 'Host returned error code' hostrc
  334.       endif
  335.    endif
  336.  
  337. defproc sendhostcommand(cmd,var hostrc)
  338. ;       Throw away results
  339.    return sendhostcmdgetrslts(cmd,hostrc,result)
  340. ;; ret =  sendhostcmdgetrslts(cmd,hostrc,result)            -- Alternative to above,
  341. ;; sayerror 'sendhostcmdgetrslts('cmd') returned "'ret'"'   -- for debugging
  342. ;; return ret
  343.  
  344. ; For SRPI and ECF, this routine gets the output into an E file, and the RC
  345. ; into the variable HOSTRC.
  346. ; For Send/Receive and CP78, the output comes via a disk file, and the RC is
  347. ; given on the first line.
  348. ; The differences are masked by COMPILE IFs in the callers.  (This routine
  349. ; is internal to this file.)
  350.  
  351. defproc issuehostcommand(pcfile, host_cmd)
  352. compile if HOST_SUPPORT = 'EMUL'         -- If using E3EMUL assume SEND/RECEIVE.
  353.    universal host_lt
  354.    universal hostcopy, hostcmd
  355.  compile if USING = 'IBM'
  356. ;; quietshell 'RECEIVE' pcfile host_LT':HOSTCMD ('host_cmd'>nul'
  357.    rc = EHLLAPI_SEND_RECEIVE(91, pcfile host_LT':HOSTCMD ('host_cmd)
  358.  compile elseif USING = 'CM'
  359.   compile if EVERSION >= 5
  360.    call send_HLLAPI_string('@CLAMPDQ HOSTCMD' host_cmd'@E')
  361.   compile else
  362.    if host_lt then
  363.       lt='/'host_lt' '
  364.    else
  365.       lt=''
  366.    endif
  367.    quietshell hostcmd lt'@CLAMPDQ HOSTCMD' host_cmd
  368.   compile endif
  369.    call dynalink('DOSCALLS', '#32', atol_swap(2000))  /* 2 second DOSSLEEP */
  370.    quietshell hostcopy  HOSTCOPYDRIVE||host_LT':HOSTCMD CMSUT1 * 'pcfile' /q /ascii'
  371.  compile endif
  372. compile elseif HOST_SUPPORT = 'STD'      -- If using SAVELOAD assume CP78.
  373.    quietshell 'CP78CMD LAMPDQ HOSTCMD' host_cmd'>nul'
  374.    quietshell 'CP78COPY H:HOSTCMD CMSUT1 *' pcfile '/q'
  375. compile elseif HOST_SUPPORT = 'SRPI'     -- If using SRPI then load directly.
  376.    universal exec_server, file_server, hostrc, host_lt
  377.  
  378.    if arg(3) then queue_name=arg(3)\0
  379.    else queue_name = '\QUEUES\EXEQUEUE.000'\0
  380.    endif
  381.    f_s = leftstr(file_server || host_lt, 8)\0
  382.    e_s = leftstr(exec_server || host_lt, 8)\0
  383. compile if AUTO_LAMSERV
  384.    do i=1 to 2
  385. compile endif
  386.    command = host_cmd\0  -- Set inside loop, because after first call it's EBCDIC
  387.    /* call SRPI support for command */
  388.    request = offset(e_s)||selector(e_s)||
  389.              atoi(SA_EXEC)||
  390.              '0000000000'||             /* return codes */
  391.              offset(command)||selector(command)||
  392.              offset(queue_name)||selector(queue_name)||
  393.              offset(f_s)||selector(f_s)||
  394.              '0000'             -- Bytes 29-32 --> command return code
  395.    rc=0
  396.    result= dynalink('SRPILCC',
  397.                     'SERVEXEC',
  398.                     selector(request)||offset(request))
  399.    dynalink_RC = rc
  400.    if rc=sayerror('Dynalink: Unrecognized library name') then
  401.       if arg(3)='' then call cleanup(queue_name); endif
  402.       if arg(4) then
  403.          call poll('OFF')
  404.          sayerror 'SRPILCC.DLL not found; polling turned off.'
  405.          return '^'             -- Abort chk_msgs.
  406.       else
  407.          messageNwait('SRPILCC.DLL not found; host support can not be used.  Press a key.')
  408.          return dynalink_RC
  409.       endif
  410.    endif
  411.  
  412.    if result <> 0 then
  413. compile if AUTO_LAMSERV
  414.       if not arg(4) then  -- Don't bother if checking messages.
  415.          if sent_LAMSERV(result, request, i, host_LT) then
  416.             if arg(3)='' then call cleanup(queue_name); endif
  417.             iterate;
  418.          endif
  419.       endif
  420. compile endif
  421.       if arg(3)='' then call cleanup(queue_name); endif
  422.       if arg(4) & (result=2) & (ltoa(substr(request, 7, 4), 16)=1000402) then
  423.          return '^' -- No CMSSERV screen active.
  424.       endif
  425.       call show_error(result, request)
  426.       if arg(4) then return '^'; endif  -- Some other error.  Abort chk_msgs.
  427.       rc = result
  428.       return result
  429.    endif
  430. compile if AUTO_LAMSERV
  431.    leave
  432.    enddo
  433. compile endif
  434. /*
  435. temp = substr(request,29,4)
  436. sayerror 'temp=' temp
  437. sayerror 'after cleanup'
  438. display 1
  439. messageNwait('RC = "'temp'" =' asc(leftstr(temp,1)) asc(substr(temp,2,1)) asc(substr(temp,3,1)) asc(substr(temp,4,1)) )
  440. */
  441.    hostrc = ltoa(substr(request,29,4),10)
  442.    if arg(3)='' then  -- read output from the command and insert it in the file
  443.       if pcfile<>'' then 'xcom e /c' pcfile; deleteline 1; endif
  444.       call grabqueue(queue_name)
  445.    endif
  446.    rc = 0
  447. compile else
  448.    messageNwait('No host command support for' HOST_SUPPORT'. Press a key...')
  449.    stop
  450. compile endif
  451.  
  452. defproc gethostfile(pcfile, hostfile, bin)
  453.    universal host_lt
  454. compile if HOST_SUPPORT = 'EMUL'         -- If using E3EMUL assume SEND/RECEIVE.
  455.    universal hostcopy
  456.  compile if USING = 'IBM'
  457.    if bin='B' then opts=''; else opts='(ASCII CRLF'; endif
  458. ;; quietshell 'RECEIVE' pcfile host_LT':'hostfile opts'>nul'
  459.    rc = EHLLAPI_SEND_RECEIVE(91, pcfile host_LT':'hostfile opts)
  460.  compile elseif USING = 'CM'
  461.    if bin='B' then opts='/b'; else opts='/ASCII'; endif
  462.    quietshell hostcopy  HOSTCOPYDRIVE || host_LT':'hostfile pcfile' /q 'opts
  463.  compile endif
  464. compile elseif HOST_SUPPORT = 'STD'      -- If using SAVELOAD assume CP78.
  465.    if bin='B' then opts='/B'; else opts=''; endif
  466.    quietshell 'CP78COPY H:'hostfile pcfile opts '/q'
  467. compile elseif HOST_SUPPORT = 'SRPI'     -- If using SRPI then load directly.
  468.    universal file_server, host_lt
  469.  
  470.    pc_name = pcfile\0
  471.    host_file = hostfile\0
  472. ;; if bin='B' then flag=0; else flag=1; endif    --> flag = bin<>'B'
  473.    f_s = leftstr(file_server || host_lt, 8)\0
  474.    /* building a request */
  475.    request = offset(f_s)||selector(f_s)||
  476.              atoi(SA_GET)||
  477.              '0000000000'||             /* return codes */
  478.              offset(host_file)||selector(host_file)||
  479.              offset(pc_name)||selector(pc_name)||
  480.              atoi(bin<>'B')
  481.  
  482.    /* calling the dynalink function */
  483.    rc = dynalink('SRPILCC',
  484.                  'SERVGET',
  485.                  selector(request)||offset(request))
  486.    if rc <> 0 then sayerror 'File transfer failed with RC' rc; endif
  487.    return rc
  488. compile else
  489.    messageNwait("Can't use host support" HOST_SUPPORT'. Press a key...')
  490.    stop
  491. compile endif
  492.  
  493. defproc sendhostcmdgetrslts(cmd,var host_rc,var result)
  494.    universal vTEMP_PATH
  495. compile if HOST_SUPPORT = 'SRPI'
  496.    universal hostrc
  497. compile endif
  498.    call issuehostcommand(vTEMP_PATH'HOSTCMD.TMP',arg(1))
  499.    if rc then /* sayerror 'Uh-oh:  RC =' rc; */ return rc; endif
  500. compile if HOST_SUPPORT = 'SRPI'
  501.    result=''
  502.    if arg(4) then              -- Flag to concatenate all lines
  503.       do i=1 to .last
  504.          result=result || textline(i) || \13
  505.          if length(result)=255 then leave; endif
  506.       enddo
  507.    elseif .last then getline result,1
  508.    endif
  509.    host_rc = hostrc              -- Set local parm to universal var. value
  510.    .modify = 0
  511. compile else
  512.    'xcom e /d /q' vTEMP_PATH'HOSTCMD.TMP'
  513.    getline host_rc,1
  514.    if .last=1 then
  515.       result=''
  516.    else
  517.       getline result,2
  518.    endif
  519.    call erasetemp(vTEMP_PATH'HOSTCMD.TMP')
  520. compile endif
  521.    'xcom q'
  522.    return 0
  523.  
  524. ;*****************     Stuff to support message polling follows:   **********
  525. ;  Also, add "Call Poll()" to MYMAIN.E
  526.  
  527.  
  528. defc qmsg    -- Query messages - if you don't want to wait for a time-out.
  529.    universal host_msg_file,msg_file_size
  530.    if host_msg_file <> '' then      -- Make sure it's still valid
  531.       getfileid fileid
  532.       display -2
  533.       rc = 0
  534.       activatefile host_msg_file
  535.       if rc then
  536.          host_msg_file = ''
  537.          msg_file_size = 0
  538.       else
  539.          activatefile fileid
  540.       endif
  541.       display 2
  542.    endif
  543.    if host_msg_file = '' then
  544.       'xcom e /n /q host_messages'
  545.       .titletext = 'Host messages'
  546.       getfileid host_msg_file
  547.       .autosave=0
  548.       deleteline 1
  549.    endif
  550.    status_=chkmsgs()
  551.    if host_msg_file.last=0 then
  552.       .modify = 0
  553.       'xcom q'
  554.       host_msg_file = ''
  555.    endif
  556.    if status_ then
  557.       activatefile host_msg_file
  558.       .cursory = 1
  559.       msg_file_size+1      -- Set .line to first new line.
  560.       msg_file_size = host_msg_file.last
  561.       if status_=1 then call pplay(1)
  562.       elseif status_=2 then call pplay(2)
  563.       elseif status_=3 then call pplay(3)
  564.       endif
  565.    else
  566.       sayerror 'No new messages.'
  567.    endif
  568.  
  569. defproc chkmsgs
  570.    universal msgflag, host_lt
  571.    universal host_msg_file
  572.    universal vTEMP_PATH
  573.    universal hostcopy, hostcmd
  574. compile if HOST_SUPPORT = 'SRPI'     -- If using SRPI then load directly.
  575.    universal hostrc, hostdrive
  576.    if '^' = issuehostcommand('','LAMSERV CHKMSGS','NUL',1)
  577.    then return 0       -- CMSSERV screen not active
  578.    endif
  579.    if hostrc <> 1 then return 0; endif  -- No messages
  580.    getfileid startfile
  581.    call loadfile(hostdrive || host_lt':LAMAIL MSGLOG A','/D /Q')
  582.    call issuehostcommand('','ERASE LAMAIL MSGLOG A','NUL',1)
  583. compile else
  584.    string='12345678'  -- reserve 8 bytes.
  585.    call dynalink('VIOCALLS',        /* dynamic link library name          */
  586.                  'VIOGETCURTYPE',   /* Video Input Output GET CURsor TYPE */
  587.                  selector(string)|| /* string selector                    */
  588.                  offset(string)||   /* string offset                      */
  589.                  atoi(0))           /* Vio Handle                         */
  590.  compile if HOST_SUPPORT = 'EMUL'
  591.   compile if USING = 'IBM'
  592. ;; quietshell 'RECEIVE' vTEMP_PATH'MSGS.TMP 'host_LT':MSGS >nul'  -- This turns cursor back on.
  593.    rc = EHLLAPI_SEND_RECEIVE(91, vTEMP_PATH'MSGS.TMP 'host_LT':MSGS')
  594.   compile elseif USING = 'CM'
  595.    compile if EVERSION >= 5
  596.    call send_HLLAPI_string('@CLAMPDQ MSGS@E')
  597.    compile else
  598.    if host_lt then
  599.       lt='/'host_lt' '
  600.    else
  601.       lt=''
  602.    endif
  603.    quietshell hostcmd lt'@CLAMPDQ MSGS'
  604.    compile endif
  605.    call dynalink('DOSCALLS', '#32', atol_swap(2000))  /* 2 second DOSSLEEP */
  606.    quietshell hostcopy HOSTCOPYDRIVE || host_LT':MSGS CMSUT1 * 'vTEMP_PATH'MSGS.TMP /q /ascii'
  607.   compile endif
  608.  compile else
  609.    quietshell 'CP78CMD LAMPDQ MSGS>nul'
  610.    quietshell 'CP78COPY H:MSGS CMSUT1 *' vTEMP_PATH'MSGS.TMP /q'
  611.  compile endif
  612.    status_=rc
  613.    if substr(string,7,2)==atoi(-1) then
  614.       call cursoroff()  -- turn off cursor
  615.    endif
  616.    if status_ then sayerror '(CHKMSGS) Status =' status_; return 0; endif
  617.    'xcom e /d /q' vTEMP_PATH'MSGS.TMP'
  618. compile endif
  619.    msgflag=0                /* No messages seen yet. */
  620.    if textline(1)<>'' or .last>1 then  -- Some messages
  621.       do i=1 to .last
  622.          call parsehostmessage(textline(i))
  623.       end
  624.    endif
  625.    .modify = 0
  626.    'xcom q'
  627. compile if HOST_SUPPORT = 'SRPI'
  628.    activatefile startfile            -- Restore non-hidden ring.
  629. ;  display 1
  630. compile else                         -- If not using SRPI, erase temp file.
  631.    call erasetemp(vTEMP_PATH'MSGS.TMP')
  632. compile endif
  633.    return msgflag
  634.  
  635.  
  636. defproc ParseHostMessage(msgline)   /* Tailor for yourself. */
  637.    universal new_mail,msgflag
  638. ;  Values for MSGFLAG are:
  639. ;     0 - line not added
  640. ;     1 - line added, low priority (e.g. RSCS progress message)
  641. ;     2 - line added, normal priority (e.g., message from a real user)
  642. ;     3 - line added, high priority (e.g., message from director!)
  643.  
  644.    universal host_msg_file
  645.    lclmsgflag=2          /* Default:  Add line; normal priority. */
  646.    node=''; uid=''
  647.    parse value msgline with f id ':' rest
  648.    if upcase(f)='FROM' then                /* It's a message! */
  649.       uid=id
  650.       if id=RSCS then
  651.          parse value rest with w1 rest2
  652.          if leftstr(w1,5)='YKTVM' then rest=rest2 endif  -- Local YKT-ism
  653.          parse value rest with f id ':' rest2
  654.          if upcase(f)='FROM' then          /* Remote message */
  655.             if pos('(',id)>0 then  /*   from a user */
  656.                parse value id with node '(' uid ')'
  657.                msgline=rest
  658.             else                   /*   from another RSCS mschine */
  659.                node=id
  660.                msgline='From' node'('RSCS'):' rest2
  661.             endif
  662.          else
  663.             parse value upcase(rest) with w1 w2 w3 w4 w5 w6 w7 w8 w9 .
  664. ;  w1   w2     w3      w4 w5   w6 w7  w8    w9
  665. ;  File (5570) spooled to MYID -- ORG RNODE (RUSER)  2/03/88 17:00:32 EST
  666.             if w1='FILE' & w3='SPOOLED' & w4='TO' & w7='ORG' & leftstr(w9,1)='(' then
  667.                node=w8
  668.                parse value w9 with '(' uid ')'
  669.             endif
  670.          endif
  671.       endif
  672.       call setprior(uid,node,lclmsgflag,'MSG',rest)
  673.    else
  674.       lclmsgflag=1  -- CP response - give low priority, but display it.
  675.       parse value upcase(msgline) with w1 w2 w3 w4 w5 w6 w7 .
  676. ;        PUN FILE 3262 FROM IBMPC    COPY 001   NOHOLD
  677. ;        RDR FILE 3334 TRANSFERRED FROM USER RSCS
  678. ; Or, in XA,
  679. ;        RDR FILE 1234 SENT FROM IBMPC  PUN WAS 4321 RECS 0006 CPY 001 B NOHOLD NOKEEP
  680.       if w2='FILE' then
  681.          if w4='FROM' then uid=w5
  682.          elseif w4='TRANSFERRED' then uid=w7
  683.          elseif w4 w5='SENT FROM' then uid=w6
  684.          endif
  685.       endif
  686.       if uid<>'' then new_mail = 1; endif
  687.       call setprior(uid,node,lclmsgflag,'CP',msgline)
  688.    endif
  689.    if lclmsgflag then   /* Insert the line into the message file. */
  690.       insertline msgline,host_msg_file.last+1,host_msg_file
  691. ;  else  -- For debugging...
  692. ;     insertline '(?)' msgline,host_msg_file.last+1,host_msg_file
  693.    endif
  694.    msgflag=max(msgflag,lclmsgflag)
  695.  
  696.  
  697. ;*********** Priorities are set below:                  **********************
  698. defproc setprior(uid,node,var msgflag,how,text)
  699.      if uid=RSCS then     -- From some RSCS machine.  Ignore RSCS messages, but
  700.       if how='MSG' then                   -- not FILE TRANSFERRED FROM RSCS msg.
  701.          if pos('CPQ:',text) then         -- Something we asked RSCS?
  702.             msgflag=2                     -- If so, display it
  703.          else
  704.             msgflag=0                     -- otherwise, discard it.
  705.          endif
  706.       endif
  707. /*  My personal setup; not for product.
  708.    elseif ((uid='WALDBAU' | uid='SERENSO' | uid='CONNORS' |
  709.             uid='CONNELL' | uid='ARMSTRN') &
  710.            (node='' | leftstr(node,5)='YKTVM')) |
  711.           ((uid='RICH' | uid='RON') & (node='THORNVM'))
  712.       then msgflag=3
  713. */
  714.    endif
  715.  
  716. definit
  717.    universal host_msg_file,msg_file_size
  718.    getfileid fileid
  719.    msg_file_size = 0
  720.    host_msg_file = ''
  721.  
  722. ;******************* Following stuff adds the Speaker and Play support *****
  723.  
  724. defproc pplay(prior)
  725.    if     prior=1 then strng='3000 100 2400 100'
  726.    elseif prior=2 then strng='2000 100 2200 100 2400 150'
  727.    elseif prior=3 then strng='800 150 800 150 1000 150 1000 150 1600 180 800 150 900 150'
  728.    else strng=''
  729.    endif
  730.    do forever
  731.       parse value strng with pitch duration strng
  732.       if duration='' then leave; endif
  733.       call beep(pitch,duration)
  734.    end
  735. ;display 1; messageNwait('hostrc=' hostrc'; result="'result'"')
  736.  
  737. compile if EVERSION >= 5 & HOST_SUPPORT = 'EMUL'
  738. defproc send_HLLAPI_string(host_string)     -- Send a string to the  host screen
  739.    universal host_lt
  740.    lt = host_lt
  741.    if lt='' then lt='A'; endif
  742.    result=simple_HLLAPI_call(1, lt)  -- *** Connect to host PS ***
  743.    if result & result<>4 & result<>5 then  -- 4=Busy; 5=Locked
  744.       sayerror 'Error' result 'trying to connect to host session' lt
  745.       stop
  746.    endif
  747.    result=simple_HLLAPI_call(6, 'LaMail Interface Screen')  -- *** Search PS ***
  748.    if result=24 then
  749.       if 'Y' = askyesno('LAMPDQ appears to not be running.  Would you like it started?',1) then
  750.          result=simple_HLLAPI_call(3, '@CLAMPDQ@E')  -- *** Send key sequence to host ***
  751.          if result then
  752.             sayerror 'Error' result 'trying to send LAMPDQ command.'
  753.             stop
  754.          endif
  755.       endif
  756.    endif
  757.    result=simple_HLLAPI_call(3, host_string)  -- *** Send key sequence to host ***
  758.    if result then
  759.       sayerror 'Error' result 'trying to send host command.'
  760.       stop
  761.    endif
  762.    call simple_HLLAPI_call(2, '')  -- *** Disconnect from host presentation space ***
  763. compile endif
  764.