home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / wps / editor / epmtools / epmmac / epmshell.e < prev    next >
Text File  |  1993-03-22  |  9KB  |  240 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  = dynalink32(ERES_DLL,
  166.                        'SUE_new',
  167.                        address(thandle)             ||
  168.                        gethwndc(EPMINFO_EDITCLIENT) ||
  169.                        atol(shellnum) );
  170. compile else
  171.    result  = dynalink(ERES_DLL,
  172.                       'SUE_NEW',
  173.                       address(thandle) || 
  174.                       gethwnd(EPMINFO_EDITCLIENT) ||
  175.                       atol_swap(shellnum) );
  176. compile endif
  177.    shell_handle = thandle;
  178.    return result;
  179.  
  180. -------------------------------------------------------------SUE_free--------------------
  181. defproc SUE_free(var shell_handle)     -- Called from Shell_Kill command
  182.    thandle = shell_handle;
  183. compile if EPM32
  184.    result  = dynalink32(ERES_DLL,
  185.                        'SUE_free',
  186.                        address(thandle) )
  187. compile else
  188.    result  = dynalink(ERES_DLL,
  189.                       'SUE_FREE',
  190.                       address(thandle) )
  191. compile endif
  192.    shell_handle = thandle;
  193.    return result;
  194.  
  195. -------------------------------------------------------------SUE_readln------------------
  196. defproc SUE_readln(shell_handle, var buffe, var bytesmoved)  -- Called from NowCanReadShell cmd
  197.    bufstring = buffe;  -- just to insure the same amount of space is available
  198.    bm        = "??"
  199. compile if EPM32
  200.    result  = dynalink32(ERES_DLL,
  201.                         'SUE_readln',
  202.                         shell_handle               ||
  203.                         address(bufstring)         ||
  204.                         atol(length(bufstring))    ||
  205.                         address(bm))
  206. compile else
  207.    result  = dynalink(ERES_DLL,
  208.                       'SUE_READLN',
  209.                       substr(shell_handle, 3, 2) ||
  210.                       substr(shell_handle, 1, 2) ||
  211.                       address(bufstring)         ||
  212.                       atoi(length(bufstring))    ||
  213.                       address(bm) );
  214. compile endif
  215.    bytesmoved = itoa(bm,10);
  216.    buffe     = bufstring;
  217.    return result;
  218.  
  219. -------------------------------------------------------------SUE_write-------------------
  220. defproc SUE_write(shell_handle, buffe, var bytesmoved)   -- Called from Shell_Write command
  221.    bm        = "??"
  222. compile if EPM32
  223.    result  = dynalink32(ERES_DLL,
  224.                         'SUE_write',
  225.                         shell_handle                     ||
  226.                         address(buffe)                   ||
  227.                         atol(length(buffe))              ||
  228.                         address(bm),
  229.                         2)
  230. compile else
  231.    result  = dynalink(ERES_DLL,
  232.                       'SUE_WRITE',
  233.                       substr(shell_handle, 3, 2) || substr(shell_handle, 1, 2) ||
  234.                       address(buffe) || 
  235.                       atoi(length(buffe)) ||
  236.                       address(bm) );
  237. compile endif
  238.    bytesmoved = itoa(bm, 10);
  239.    return result;
  240.