home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / prodtool / epm / e_macros / epmshell.e < prev    next >
Encoding:
Text File  |  1992-08-11  |  8.0 KB  |  198 lines

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