home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / editors / epm / sampmacs / epmshell.e < prev    next >
Encoding:
Text File  |  1993-12-22  |  9.4 KB  |  243 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. compile if INCLUDING_FILE = 'E.E'
  85.       'xcom quit'
  86. compile else   -- Force activation of main .ex file, in case is last file in ring
  87.       'xcom_quit'
  88. compile endif -- INCLUDING_FILE = 'E.E'
  89.       do_array 2, EPM_utility_array_ID, 'Shell_f'shellnum, null
  90.       if curfid<>shellfid then
  91.          activatefile curfid
  92.       endif
  93.    endif
  94.  
  95. -------------------------------------------------------------Shell_Write-----------------
  96. defc Shell_Write
  97.    universal ShellHandle
  98.    universal EPM_utility_array_ID
  99.    parse arg shellnum text
  100.    if shellnum='' & leftstr(.filename, 15) = ".command_shell_" then
  101.       shellnum=substr(.filename,16)
  102.    endif
  103.    if shellnum='' then
  104.       sayerror NOT_IN_SHELL__MSG
  105.       return
  106.    endif
  107.    do_array 3, EPM_utility_array_ID, 'Shell_h'shellnum, shellHandle
  108.    if shellhandle<>'' then
  109.       if text='' then
  110.          text=entrybox(SHELL_PROMPT__MSG shellnum)
  111.       endif
  112.       if text='' then return; endif
  113.       writebuf = text\13\10
  114.       retval   = SUE_write(ShellHandle, writebuf, bytesmoved);
  115.       if retval or bytesmoved<>length(writebuf) then
  116.          sayerror "write.retval="retval || "  byteswritten=" bytesmoved "of" length(writebuf)
  117.       endif
  118.    endif
  119.    --
  120.    -- the above code is not really complete.  It should also deal with situations
  121.    --   where only part of the data to be written is written.  It needs to keep the
  122.    --   unwritten data around and put it out again during the "NowCanWriteShell"
  123.    --   comand processing. (todo)
  124.  
  125. -------------------------------------------------------------NowCanWriteShell------------
  126. defc NowCanWriteShell
  127.    -- Shell object sends this command to inform the editor that there is
  128.    --    room for additional data to be written.
  129.    sayerror SHELL_OBJECT__MSG arg(1) SHELL_READY__MSG -- Use Shell_Write with argumentstring'
  130.  
  131. -------------------------------------------------------------NowCanReadShell-------------
  132. defc NowCanReadShell
  133.    -- Shell object sends this command to inform the editor that there is
  134.    --    additional data to be read.
  135.    universal EPM_utility_array_ID
  136.    parse arg shellnum .
  137.    if not isnum(shellnum) then
  138.       sayerror 'NowCanReadShell:  'INVALID_ARG__MSG '"'arg(1)'"'
  139.       return
  140.    endif
  141.    do_array 3, EPM_utility_array_ID, 'Shell_f'shellnum, shellfid
  142.    do_array 3, EPM_utility_array_ID, 'Shell_h'shellnum, shellhandle
  143.    bytesmoved = 1;
  144.    while bytesmoved do
  145.       readbuf = copies(' ',MAXCOL)
  146.       retval = SUE_readln(ShellHandle, readbuf, bytesmoved);
  147.       readbuf = leftstr(readbuf, bytesmoved)
  148.       if readbuf=\13 then iterate
  149.       elseif leftstr(readbuf,1)=\10 then
  150.          insertline substr(readbuf,2), shellfid.last+1, shellfid
  151.       else
  152.          getline oldline, shellfid.last, shellfid
  153.          if length(oldline)+length(readbuf)>MAXCOL then
  154.             insertline readbuf, shellfid.last+1, shellfid
  155.          else
  156.             replaceline oldline || readbuf, shellfid.last, shellfid
  157.          endif
  158.       endif
  159.       getline lastline, shellfid.last, shellfid
  160.       shellfid.line = shellfid.last
  161.       shellfid.col = min(MAXCOL,length(lastline)+1)
  162.    endwhile
  163.  
  164. -------------------------------------------------------------SUE_new---------------------
  165. defproc SUE_new(var shell_handle, shellnum)     -- Called from Shell command
  166.    thandle = '????';
  167. ;; sayerror "address=0x" || ltoa(taddr, 16) || "  hwnd=0x"ltoa(hwnd, 16);
  168. compile if EPM32
  169.    result  = dynalink32(ERES_DLL,
  170.                        'SUE_new',
  171.                        address(thandle)             ||
  172.                        gethwndc(EPMINFO_EDITCLIENT) ||
  173.                        atol(shellnum) );
  174. compile else
  175.    result  = dynalink(ERES_DLL,
  176.                       'SUE_NEW',
  177.                       address(thandle) ||
  178.                       gethwnd(EPMINFO_EDITCLIENT) ||
  179.                       atol_swap(shellnum) );
  180. compile endif
  181.    shell_handle = thandle;
  182.    return result;
  183.  
  184. -------------------------------------------------------------SUE_free--------------------
  185. defproc SUE_free(var shell_handle)     -- Called from Shell_Kill command
  186.    thandle = shell_handle;
  187. compile if EPM32
  188.    result  = dynalink32(ERES_DLL,
  189.                        'SUE_free',
  190.                        address(thandle) )
  191. compile else
  192.    result  = dynalink(ERES_DLL,
  193.                       'SUE_FREE',
  194.                       address(thandle) )
  195. compile endif
  196.    shell_handle = thandle;
  197.    return result;
  198.  
  199. -------------------------------------------------------------SUE_readln------------------
  200. defproc SUE_readln(shell_handle, var buffe, var bytesmoved)  -- Called from NowCanReadShell cmd
  201.    bufstring = buffe;  -- just to insure the same amount of space is available
  202.    bm        = "??"
  203. compile if EPM32
  204.    result  = dynalink32(ERES_DLL,
  205.                         'SUE_readln',
  206.                         shell_handle               ||
  207.                         address(bufstring)         ||
  208.                         atol(length(bufstring))    ||
  209.                         address(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.                       address(bufstring)         ||
  216.                       atoi(length(bufstring))    ||
  217.                       address(bm) );
  218. compile endif
  219.    bytesmoved = itoa(bm,10);
  220.    buffe     = bufstring;
  221.    return result;
  222.  
  223. -------------------------------------------------------------SUE_write-------------------
  224. defproc SUE_write(shell_handle, buffe, var bytesmoved)   -- Called from Shell_Write command
  225.    bm        = "??"
  226. compile if EPM32
  227.    result  = dynalink32(ERES_DLL,
  228.                         'SUE_write',
  229.                         shell_handle                     ||
  230.                         address(buffe)                   ||
  231.                         atol(length(buffe))              ||
  232.                         address(bm))
  233. compile else
  234.    result  = dynalink(ERES_DLL,
  235.                       'SUE_WRITE',
  236.                       substr(shell_handle, 3, 2) || substr(shell_handle, 1, 2) ||
  237.                       address(buffe) ||
  238.                       atoi(length(buffe)) ||
  239.                       address(bm) );
  240. compile endif
  241.    bytesmoved = itoa(bm, 10);
  242.    return result;
  243.