home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmmac.zip / EPMSHELL.E < prev    next >
Text File  |  1995-04-07  |  15KB  |  371 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' & not defined(STD_MENU_NAME)
  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 EPM32
  26.       buildmenuitem defaultmenu, 1, 104, SHELL_BREAK_MENU__MSG,        'shell_break'SHELL_BREAK_MENUP__MSG,  0, mpfrom2short(HP_COMMAND_SHELL, 16384)
  27.  compile endif
  28.  compile if RING_OPTIONAL  -- if not ring_enabled then ring_toggle will do the showmenu.
  29.       if activemenu = defaultmenu & ring_enabled then
  30.          call showmenu_activemenu()  -- show the updated EPM menu
  31.       endif
  32.  compile else
  33.       call maybe_show_menu()
  34.  compile endif
  35.    endif
  36. compile endif
  37. compile if RING_OPTIONAL
  38.    if not ring_enabled then
  39.       'ring_toggle'
  40.    endif
  41. compile endif
  42.    shell_index = shell_index + 1
  43.    ShellHandle  = '????'
  44.    retval = SUE_new(ShellHandle, shell_index)
  45.    if retval then
  46.       sayerror ERROR__MSG retval SHELL_ERROR1__MSG
  47.    else
  48.       'xcom e /c .command_shell_'shell_index
  49.       if rc<>sayerror('New file') then
  50.          sayerror ERROR__MSG rc SHELL_ERROR2__MSG
  51.          stop
  52.       endif
  53.       getfileid shellfid
  54.       .filename = '.command_shell_'shell_index
  55.       .autosave = 0
  56.       do_array 2, EPM_utility_array_ID, 'Shell_f'shell_index, shellfid
  57.       do_array 2, EPM_utility_array_ID, 'Shell_h'shell_index, shellHandle
  58.       'postme monofont'
  59.    endif
  60. ;; sayerror "shellhandle=0x" || ltoa(ShellHandle, 16) || "  newObject.retval="retval;
  61. compile if EPM_SHELL_PROMPT<>''
  62.    'shell_write' shell_index EPM_SHELL_PROMPT
  63. compile endif
  64.    if arg(1) then
  65.       'shell_write' shell_index arg(1)
  66.    endif
  67.  
  68. -------------------------------------------------------------Shell_Kill------------------
  69. defc shell_kill   -- destroys a shell object
  70.    universal EPM_utility_array_ID
  71.    parse arg shellnum .
  72.    if shellnum='' & leftstr(.filename, 15) = ".command_shell_" then
  73.       shellnum=substr(.filename,16)
  74.    endif
  75.    if shellnum='' then
  76.       sayerror NOT_IN_SHELL__MSG
  77.       return
  78.    endif
  79.    do_array 3, EPM_utility_array_ID, 'Shell_f'shellnum, shellfid
  80.    do_array 3, EPM_utility_array_ID, 'Shell_h'shellnum, shellHandle
  81.    null=''
  82.    if shellhandle<>'' then
  83.       retval = SUE_free(ShellHandle);
  84.       if retval then sayerror ERROR__MSG retval SHELL_ERROR3__MSG; endif
  85.       do_array 2, EPM_utility_array_ID, 'Shell_h'shellnum, null
  86.    endif
  87.    if shellfid<>'' then
  88.       getfileid curfid
  89.       activatefile shellfid
  90.       .modify=0
  91. compile if INCLUDING_FILE = 'E.E'
  92.       'xcom quit'
  93. compile else   -- Force activation of main .ex file, in case is last file in ring
  94.       'xcom_quit'
  95. compile endif -- INCLUDING_FILE = 'E.E'
  96.       do_array 2, EPM_utility_array_ID, 'Shell_f'shellnum, null
  97.       if curfid<>shellfid then
  98.          activatefile curfid
  99.       endif
  100.    endif
  101.  
  102. -------------------------------------------------------------Shell_Write-----------------
  103. defc Shell_Write
  104.    universal ShellHandle
  105.    universal EPM_utility_array_ID
  106.    universal Shell_lastwrite
  107.    parse arg shellnum text
  108.    if shellnum='' & leftstr(.filename, 15) = ".command_shell_" then
  109.       shellnum=substr(.filename,16)
  110.    endif
  111.    if shellnum='' then
  112.       sayerror NOT_IN_SHELL__MSG
  113.       return
  114.    endif
  115.    do_array 3, EPM_utility_array_ID, 'Shell_h'shellnum, shellHandle
  116.    if shellhandle<>'' then
  117.       if text='' then
  118. compile if EVERSION < 5.21
  119.          text=entrybox(SHELL_PROMPT__MSG shellnum)
  120. compile else
  121.          shell_title = strip(WRITE_SHELL_MENU__MSG, 'T', '.')  -- '~Write to shell...'
  122.          tilde = pos('~', shell_title)
  123.          if tilde then
  124.             shell_title = delstr(shell_title, tilde, 1)
  125.          endif
  126.          do forever
  127.             parse value entrybox(shell_title,               -- Title,
  128.  compile if EPM_SHELL_PROMPT = '@prompt epm: $p $g' | EPM_SHELL_PROMPT = '@prompt [epm: $p ]'
  129.                    '/'OK__MSG'/'LIST__MSG'/'Cancel__MSG'/', -- Buttons
  130.  compile else
  131.                    '/'OK__MSG'/'Cancel__MSG'/', -- Buttons
  132.  compile endif
  133.                    Shell_lastwrite, '', 254,                -- Entrytext, cols, maxchars
  134.                    atoi(1) || atoi(0000) || gethwndc(APP_HANDLE) ||
  135.                    SHELL_PROMPT__MSG shellnum) with button 2 text \0
  136.  compile if EPM_SHELL_PROMPT = '@prompt epm: $p $g' | EPM_SHELL_PROMPT = '@prompt [epm: $p ]'
  137.             if button=\2 then -- User asked for a list
  138.                getfileid shell_fileid
  139.                call psave_pos(save_pos)
  140.                'xcom e /c cmdslist'
  141.                if rc<>-282 then  -- -282 = sayerror("New file")
  142.                   sayerror ERROR__MSG rc BAD_TMP_FILE__MSG sayerrortext(rc)
  143.                   return
  144.                endif
  145.                browse_mode = browse()     -- query current state
  146.                if browse_mode then call browse(0); endif
  147.                .autosave = 0
  148.                getfileid lb_fid
  149.                activatefile shell_fileid
  150.                display -2
  151.                getsearch oldsearch
  152.                0
  153.   compile if EPM_SHELL_PROMPT = '@prompt epm: $p $g'
  154.    compile if EPM32
  155.                'xcom l /^epm\: .*>:o./x'
  156.    compile else
  157.                'xcom l /^epm: .*> *[^ ]/g'
  158.    compile endif -- EPM32
  159.   compile else  -- else EPM_SHELL_PROMPT = '@prompt [epm: $p ]'
  160.    compile if EPM32
  161.                'xcom l /^\[epm\: .*\]:o./x'
  162.    compile else
  163.                'xcom l /^\[epm: .*\] *[^ ]/g'
  164.    compile endif -- EPM32
  165.   compile endif -- EPM_SHELL_PROMPT
  166.                do while rc = 0
  167.   compile if EPM_SHELL_PROMPT = '@prompt epm: $p $g'
  168.                   parse value textline(.line) with '>' cmd
  169.   compile else
  170.                   parse value textline(.line) with ']' cmd
  171.   compile endif -- EPM_SHELL_PROMPT
  172.                   insertline strip(cmd, 'L'), lb_fid.last+1, lb_fid
  173.                   repeatfind
  174.                enddo
  175.                setsearch oldsearch
  176.                call prestore_pos(save_pos)
  177.                if browse_mode then call browse(1); endif  -- restore browse state
  178.                activatefile lb_fid
  179.                display 2
  180.                if not .modify then  -- Nothing added?
  181.                   'xcom quit'
  182.                   activatefile shell_fileid
  183.                   sayerror -273 -- String not found
  184.                   return
  185.                endif
  186.                if listbox_buffer_from_file(shell_fileid, bufhndl, noflines, usedsize) then return; endif
  187.                parse value listbox(shell_title,
  188.   compile if 0 --POWERPC
  189.                                    \0 || atol(usedsize) || atol(bufhndl+32),
  190.   compile elseif EPM32
  191.                                    \0 || atol(usedsize) || atoi(32) || atoi(bufhndl),
  192.   compile else
  193.                                    \0 || atoi(usedsize) || atoi(bufhndl) || atoi(32),
  194.   compile endif -- EPM32
  195.                                    '/'OK__MSG'/'EDIT__MSG'/'Cancel__MSG, 1, 35, min(noflines,12), 0,
  196.   compile if EVERSION >= 5.60
  197.                                    gethwndc(APP_HANDLE) || atoi(1) || atoi(1) || atoi(0000)) with button 2 text \0
  198.   compile else
  199.                                    atoi(1) || atoi(1) || atoi(0000) || gethwndc(APP_HANDLE)) with button 2 text \0
  200.   compile endif
  201.                call buffer(FREEBUF, bufhndl)
  202.                if button=\2 then -- 'Edit' selected
  203.                   Shell_lastwrite = text
  204.                   iterate
  205.                endif
  206.             endif
  207.  compile endif
  208.             if button<>\1 then return; endif
  209.             leave
  210.          enddo
  211. compile endif  -- EVERSION < 5.21
  212.       endif  -- text = ''
  213. ;     if text='' then return; endif
  214.       if text<>'' then Shell_lastwrite = text; endif
  215.       writebuf = text\13\10
  216.       retval   = SUE_write(ShellHandle, writebuf, bytesmoved);
  217.       if retval or bytesmoved<>length(writebuf) then
  218.          sayerror "write.retval="retval || "  byteswritten=" bytesmoved "of" length(writebuf)
  219.       endif
  220.    endif
  221.    --
  222.    -- the above code is not really complete.  It should also deal with situations
  223.    --   where only part of the data to be written is written.  It needs to keep the
  224.    --   unwritten data around and put it out again during the "NowCanWriteShell"
  225.    --   comand processing. (todo)
  226.  
  227. -------------------------------------------------------------NowCanWriteShell------------
  228. defc NowCanWriteShell
  229.    -- Shell object sends this command to inform the editor that there is
  230.    --    room for additional data to be written.
  231.    sayerror SHELL_OBJECT__MSG arg(1) SHELL_READY__MSG -- Use Shell_Write with argumentstring'
  232.  
  233. -------------------------------------------------------------NowCanReadShell-------------
  234. defc NowCanReadShell
  235.    -- Shell object sends this command to inform the editor that there is
  236.    --    additional data to be read.
  237.    universal EPM_utility_array_ID
  238.    parse arg shellnum .
  239.    if not isnum(shellnum) then
  240.       sayerror 'NowCanReadShell:  'INVALID_ARG__MSG '"'arg(1)'"'
  241.       return
  242.    endif
  243.    do_array 3, EPM_utility_array_ID, 'Shell_f'shellnum, shellfid
  244.    do_array 3, EPM_utility_array_ID, 'Shell_h'shellnum, shellhandle
  245.    bytesmoved = 1;
  246.    while bytesmoved do
  247.       readbuf = copies(' ',MAXCOL)
  248.       retval = SUE_readln(ShellHandle, readbuf, bytesmoved);
  249.       readbuf = leftstr(readbuf, bytesmoved)
  250.       if readbuf=\13 then iterate
  251.       elseif leftstr(readbuf,1)=\10 then
  252.          insertline substr(readbuf,2), shellfid.last+1, shellfid
  253.       else
  254.          getline oldline, shellfid.last, shellfid
  255.          if length(oldline)+length(readbuf)>MAXCOL then
  256.             insertline readbuf, shellfid.last+1, shellfid
  257.          else
  258.             replaceline oldline || readbuf, shellfid.last, shellfid
  259.          endif
  260.       endif
  261.       getline lastline, shellfid.last, shellfid
  262.       shellfid.line = shellfid.last
  263.       shellfid.col = min(MAXCOL,length(lastline)+1)
  264.    endwhile
  265.  
  266. -------------------------------------------------------------SUE_new---------------------
  267. defproc SUE_new(var shell_handle, shellnum)     -- Called from Shell command
  268.    thandle = '????';
  269. ;; sayerror "address=0x" || ltoa(taddr, 16) || "  hwnd=0x"ltoa(hwnd, 16);
  270. compile if EPM32
  271.    result  = dynalink32(ERES_DLL,
  272.                        'SUE_new',
  273.                        address(thandle)             ||
  274.                        gethwndc(EPMINFO_EDITCLIENT) ||
  275.                        atol(shellnum) );
  276. compile else
  277.    result  = dynalink(ERES_DLL,
  278.                       'SUE_NEW',
  279.                       address(thandle) ||
  280.                       gethwnd(EPMINFO_EDITCLIENT) ||
  281.                       atol_swap(shellnum) );
  282. compile endif
  283.    shell_handle = thandle;
  284.    return result;
  285.  
  286. -------------------------------------------------------------SUE_free--------------------
  287. defproc SUE_free(var shell_handle)     -- Called from Shell_Kill command
  288.    thandle = shell_handle;
  289. compile if EPM32
  290.    result  = dynalink32(ERES_DLL,
  291.                        'SUE_free',
  292.                        address(thandle) )
  293. compile else
  294.    result  = dynalink(ERES_DLL,
  295.                       'SUE_FREE',
  296.                       address(thandle) )
  297. compile endif
  298.    shell_handle = thandle;
  299.    return result;
  300.  
  301. -------------------------------------------------------------SUE_readln------------------
  302. defproc SUE_readln(shell_handle, var buffe, var bytesmoved)  -- Called from NowCanReadShell cmd
  303.    bufstring = buffe;  -- just to insure the same amount of space is available
  304.    bm        = "??"
  305. compile if EPM32
  306.    result  = dynalink32(ERES_DLL,
  307.                         'SUE_readln',
  308.                         shell_handle               ||
  309.                         address(bufstring)         ||
  310.                         atol(length(bufstring))    ||
  311.                         address(bm))
  312. compile else
  313.    result  = dynalink(ERES_DLL,
  314.                       'SUE_READLN',
  315.                       substr(shell_handle, 3, 2) ||
  316.                       substr(shell_handle, 1, 2) ||
  317.                       address(bufstring)         ||
  318.                       atoi(length(bufstring))    ||
  319.                       address(bm) );
  320. compile endif
  321.    bytesmoved = itoa(bm,10);
  322.    buffe     = bufstring;
  323.    return result;
  324.  
  325. -------------------------------------------------------------SUE_write-------------------
  326. defproc SUE_write(shell_handle, buffe, var bytesmoved)   -- Called from Shell_Write command
  327.    bm        = "??"
  328. compile if EPM32
  329.    result  = dynalink32(ERES_DLL,
  330.                         'SUE_write',
  331.                         shell_handle                     ||
  332.                         address(buffe)                   ||
  333.                         atol(length(buffe))              ||
  334.                         address(bm))
  335. compile else
  336.    result  = dynalink(ERES_DLL,
  337.                       'SUE_WRITE',
  338.                       substr(shell_handle, 3, 2) || substr(shell_handle, 1, 2) ||
  339.                       address(buffe) ||
  340.                       atoi(length(buffe)) ||
  341.                       address(bm) );
  342. compile endif
  343.    bytesmoved = itoa(bm, 10);
  344.    return result;
  345.  
  346. compile if EPM32 & not POWERPC
  347. -------------------------------------------------------------Shell_Break-----------------
  348. defc shell_break  -- Sends a Break to a shell object
  349.    universal EPM_utility_array_ID
  350.    parse arg shellnum .
  351.    if shellnum='' & leftstr(.filename, 15) = ".command_shell_" then
  352.       shellnum=substr(.filename,16)
  353.    endif
  354.    if shellnum='' then
  355.       sayerror NOT_IN_SHELL__MSG
  356.       return
  357.    endif
  358.    do_array 3, EPM_utility_array_ID, 'Shell_f'shellnum, shellfid
  359.    do_array 3, EPM_utility_array_ID, 'Shell_h'shellnum, shellHandle
  360.    if shellhandle<>'' then
  361.       retval = SUE_break(ShellHandle);
  362.       if retval then sayerror ERROR_NUMBER__MSG retval; endif
  363.    endif
  364.  
  365. -------------------------------------------------------------SUE_break-------------------
  366. defproc SUE_break(shell_handle)
  367.    return dynalink32(ERES_DLL,
  368.                      'SUE_break',
  369.                      shell_handle )
  370. compile endif
  371.