home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / e / epmmac2.zip / EPMSHELL.E < prev    next >
Text File  |  1993-01-07  |  10KB  |  247 lines

  1. compile if WANT_EPM_SHELL='HIDDEN' & not defined(HP_COMMAND_SHELL)
  2.    include 'MENUHELP.H'
  3. compile endif
  4.  
  5. defc sendshell =
  6.    if leftstr(.filename, 15) <> ".command_shell_" then
  7.       sayerror NOT_IN_SHELL__MSG
  8.       return
  9.    endif
  10.    'shell_write' substr(.filename,16) substr(textline(.line), .col)
  11.  
  12. -------------------------------------------------------------Shell-----------------------
  13. defc shell   -- starts a shell object
  14.    universal Shell_index, EPM_utility_array_ID
  15. compile if RING_OPTIONAL
  16.    universal ring_enabled
  17. compile endif
  18. compile if WANT_EPM_SHELL='HIDDEN'
  19.    universal activemenu,defaultmenu
  20.    if not shell_index then
  21.       buildmenuitem defaultmenu, 1, 101, \0,                      '',            4, 0
  22.       buildmenuitem defaultmenu, 1, 102, CREATE_SHELL_MENU__MSG,       'shell'CREATE_SHELL_MENUP__MSG,       0, mpfrom2short(HP_COMMAND_SHELL, 0)
  23.       buildmenuitem defaultmenu, 1, 103, WRITE_SHELL_MENU__MSG,        'shell_write'WRITE_SHELL_MENUP__MSG, 0, mpfrom2short(HP_COMMAND_SHELL, 16384)
  24. ;     buildmenuitem defaultmenu, 1, 104, KILL_SHELL_MENU__MSG,         'shell_kill'KILL_SHELL_MENUP__MSG,  0, mpfrom2short(HP_COMMAND_SHELL, 16384)
  25.  compile if RING_OPTIONAL  -- if not ring_enabled then ring_toggle will do the showmenu.
  26.       if activemenu = defaultmenu & ring_enabled then
  27.  compile else
  28.       if activemenu = defaultmenu then
  29.  compile endif
  30.          showmenu activemenu
  31.       endif
  32.    endif
  33. compile endif
  34. compile if RING_OPTIONAL
  35.    if not ring_enabled then
  36.       'ring_toggle'
  37.    endif
  38. compile endif
  39.    shell_index = shell_index + 1
  40.    ShellHandle  = '????'
  41.    retval = SUE_new(ShellHandle, shell_index)
  42.    if retval then
  43.       sayerror ERROR__MSG retval SHELL_ERROR1__MSG
  44.    else
  45.       'xcom e /c .command_shell_'shell_index
  46.       if rc<>sayerror('New file') then
  47.          sayerror ERROR__MSG rc SHELL_ERROR2__MSG
  48.          stop
  49.       endif
  50.       getfileid shellfid
  51.       .filename = '.command_shell_'shell_index
  52.       .autosave = 0
  53.       do_array 2, EPM_utility_array_ID, 'Shell_f'shell_index, shellfid
  54.       do_array 2, EPM_utility_array_ID, 'Shell_h'shell_index, shellHandle
  55.    endif
  56. ;; sayerror "shellhandle=0x" || ltoa(ShellHandle, 16) || "  newObject.retval="retval;
  57. compile if EPM_SHELL_PROMPT<>''
  58.    'shell_write' shell_index EPM_SHELL_PROMPT
  59. compile endif
  60.  
  61. -------------------------------------------------------------Shell_Kill------------------
  62. defc shell_kill   -- destroys a shell object
  63.    universal EPM_utility_array_ID
  64.    parse arg shellnum .
  65.    if shellnum='' & leftstr(.filename, 15) = ".command_shell_" then
  66.       shellnum=substr(.filename,16)
  67.    endif
  68.    if shellnum='' then
  69.       sayerror NOT_IN_SHELL__MSG
  70.       return
  71.    endif
  72.    do_array 3, EPM_utility_array_ID, 'Shell_f'shellnum, shellfid
  73.    do_array 3, EPM_utility_array_ID, 'Shell_h'shellnum, shellHandle
  74.    null=''
  75.    if shellhandle<>'' then
  76.       retval = SUE_free(ShellHandle);
  77.       if retval then sayerror ERROR__MSG retval SHELL_ERROR3__MSG; endif
  78.       do_array 2, EPM_utility_array_ID, 'Shell_h'shellnum, null
  79.    endif
  80.    if shellfid<>'' then
  81.       getfileid curfid
  82.       activatefile shellfid
  83.       .modify=0
  84.       'xcom quit'
  85.       do_array 2, EPM_utility_array_ID, 'Shell_f'shellnum, null
  86.       if curfid<>shellfid then
  87.          activatefile curfid
  88.       endif
  89.    endif
  90.  
  91. -------------------------------------------------------------Shell_Write-----------------
  92. defc Shell_Write
  93.    universal ShellHandle
  94.    universal EPM_utility_array_ID
  95.    parse arg shellnum text
  96.    if shellnum='' & leftstr(.filename, 15) = ".command_shell_" then
  97.       shellnum=substr(.filename,16)
  98.    endif
  99.    if shellnum='' then
  100.       sayerror NOT_IN_SHELL__MSG
  101.       return
  102.    endif
  103.    do_array 3, EPM_utility_array_ID, 'Shell_h'shellnum, shellHandle
  104.    if shellhandle<>'' then
  105.       if text='' then
  106.          text=entrybox(SHELL_PROMPT__MSG shellnum)
  107.       endif
  108.       if text='' then return; endif
  109.       writebuf = text\13\10
  110.       retval   = SUE_write(ShellHandle, writebuf, bytesmoved);
  111.       if retval or bytesmoved<>length(writebuf) then
  112.          sayerror "write.retval="retval || "  byteswritten=" bytesmoved "of" length(writebuf)
  113.       endif
  114.    endif
  115.    --
  116.    -- the above code is not really complete.  It should also deal with situations
  117.    --   where only part of the data to be written is written.  It needs to keep the
  118.    --   unwritten data around and put it out again during the "NowCanWriteShell"
  119.    --   comand processing. (todo)
  120.  
  121. -------------------------------------------------------------NowCanWriteShell------------
  122. defc NowCanWriteShell
  123.    -- Shell object sends this command to inform the editor that there is
  124.    --    room for additional data to be written.
  125.    sayerror SHELL_OBJECT__MSG arg(1) SHELL_READY__MSG -- Use Shell_Write with argumentstring'
  126.  
  127. -------------------------------------------------------------NowCanReadShell-------------
  128. defc NowCanReadShell
  129.    -- Shell object sends this command to inform the editor that there is
  130.    --    additional data to be read.
  131.    universal EPM_utility_array_ID
  132.    parse arg shellnum .
  133.    if not isnum(shellnum) then
  134.       sayerror 'NowCanReadShell:  'INVALID_ARG__MSG '"'arg(1)'"'
  135.       return
  136.    endif
  137.    do_array 3, EPM_utility_array_ID, 'Shell_f'shellnum, shellfid
  138.    do_array 3, EPM_utility_array_ID, 'Shell_h'shellnum, shellhandle
  139.    bytesmoved = 1;
  140.    while bytesmoved do
  141.       readbuf = copies(' ',MAXCOL)
  142.       retval = SUE_readln(ShellHandle, readbuf, bytesmoved);
  143.       readbuf = leftstr(readbuf, bytesmoved)
  144.       if readbuf=\13 then iterate
  145.       elseif leftstr(readbuf,1)=\10 then
  146.          insertline substr(readbuf,2), shellfid.last+1, shellfid
  147.       else
  148.          getline oldline, shellfid.last, shellfid
  149.          if length(oldline)+length(readbuf)>MAXCOL then
  150.             insertline readbuf, shellfid.last+1, shellfid
  151.          else
  152.             replaceline oldline || readbuf, shellfid.last, shellfid
  153.          endif
  154.       endif
  155.       getline lastline, shellfid.last, shellfid
  156.       shellfid.line = shellfid.last
  157.       shellfid.col = min(MAXCOL,length(lastline)+1)
  158.    endwhile
  159.  
  160. -------------------------------------------------------------SUE_new---------------------
  161. defproc SUE_new(var shell_handle, shellnum)     -- Called from Shell command
  162.    thandle = '????';
  163. ;; sayerror "address=0x" || ltoa(taddr, 16) || "  hwnd=0x"ltoa(hwnd, 16);
  164. compile if EPM32
  165.    result  = dynalinkc(ERES_DLL,
  166.                       'SUE_new',
  167.                       offset(thandle)              ||
  168.                       selector(thandle)            ||
  169.                       gethwndc(EPMINFO_EDITCLIENT) ||
  170.                       atol(shellnum) );
  171. compile else
  172.    result  = dynalink(ERES_DLL,
  173.                       'SUE_NEW',
  174.                       selector(thandle) || offset(thandle) ||
  175.                       gethwnd(EPMINFO_EDITCLIENT) ||
  176.                       atol_swap(shellnum) );
  177. compile endif
  178.    shell_handle = thandle;
  179.    return result;
  180.  
  181. -------------------------------------------------------------SUE_free--------------------
  182. defproc SUE_free(var shell_handle)     -- Called from Shell_Kill command
  183.    thandle = shell_handle;
  184. compile if EPM32
  185.    result  = dynalinkc(ERES_DLL,
  186.                       'SUE_free',
  187.                       offset(thandle)  ||
  188.                       selector(thandle) )
  189. compile else
  190.    result  = dynalink(ERES_DLL,
  191.                       'SUE_FREE',
  192.                       selector(thandle) || offset(thandle) )
  193. compile endif
  194.    shell_handle = thandle;
  195.    return result;
  196.  
  197. -------------------------------------------------------------SUE_readln------------------
  198. defproc SUE_readln(shell_handle, var buffe, var bytesmoved)  -- Called from NowCanReadShell cmd
  199.    bufstring = buffe;  -- just to insure the same amount of space is available
  200.    bm        = "??"
  201. compile if EPM32
  202.    result  = dynalinkc(ERES_DLL,
  203.                       'SUE_readln',
  204.                       shell_handle               ||
  205.                       offset(bufstring)          ||
  206.                       selector(bufstring)        ||
  207.                       atol(length(bufstring))    ||
  208.                       offset(bm)                 ||
  209.                       selector(bm))
  210. compile else
  211.    result  = dynalink(ERES_DLL,
  212.                       'SUE_READLN',
  213.                       substr(shell_handle, 3, 2) ||
  214.                       substr(shell_handle, 1, 2) ||
  215.                       selector(bufstring)        ||
  216.                       offset(bufstring)          ||
  217.                       atoi(length(bufstring))    ||
  218.                       selector(bm) || offset(bm) );
  219. compile endif
  220.    bytesmoved = itoa(bm,10);
  221.    buffe     = bufstring;
  222.    return result;
  223.  
  224. -------------------------------------------------------------SUE_write-------------------
  225. defproc SUE_write(shell_handle, buffe, var bytesmoved)   -- Called from Shell_Write command
  226.    bm        = "??"
  227. compile if EPM32
  228.    result  = dynalinkc(ERES_DLL,
  229.                       'SUE_write',
  230.                       shell_handle                     ||
  231.                       offset(buffe)                    ||
  232.                       selector(buffe)                  ||
  233.                       atol(length(buffe))              ||
  234.                       offset(bm)                       ||
  235.                       selector(bm),
  236.                       2)
  237. compile else
  238.    result  = dynalink(ERES_DLL,
  239.                       'SUE_WRITE',
  240.                       substr(shell_handle, 3, 2) || substr(shell_handle, 1, 2) ||
  241.                       selector(buffe) || offset(buffe) ||
  242.                       atoi(length(buffe)) ||
  243.                       selector(bm) || offset(bm) );
  244. compile endif
  245.    bytesmoved = itoa(bm, 10);
  246.    return result;
  247.