home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / editors / epm / e_macros / shell.e < prev    next >
Encoding:
Text File  |  1991-06-10  |  4.3 KB  |  132 lines

  1. /*
  2.  * Name         shell
  3.  *
  4.  * Author       Ralph Yozzo
  5.  *
  6.  * Purpose      These commands provide an interface to the internal
  7.  *              shell processor of E.
  8.  *              The shell processor allows one to execute programs
  9.  *              which use the standard input,output and error file handles
  10.  *              (known as (stdin, stdout and stderr) to "C" programmers)
  11.  *              AS IF the program interfaced directly with the E buffers.
  12.  *
  13.  *              This means that stdout and stderr direct output into
  14.  *              an E memory image of a file (also, known as an E buffer)
  15.  *              rather than an actual disk file.
  16.  *
  17.  * Application  We may wish to compile in one window and continue editing
  18.  *              in another window.  The functions provided here give us
  19.  *              this ability.
  20.  *
  21.  * Example      The following command will invoke the "C" compiler
  22.  *              asynchronously (in other words, we do not wait for the
  23.  *              command to complete before returning control to the user).
  24.  *
  25.  *              shell cl ourfile.c
  26.  *
  27.  * Example      Since we are sending our commands to the command interpreter
  28.  *              we may build any command that is valid.
  29.  *              For example,
  30.  *
  31.  *              shell dir & tree
  32.  *              is valid.
  33.  *
  34.  * Extensions   Now that we have access to the error file of a compiler
  35.  *              during the compilation process, we can extend E to
  36.  *              provide a next_error function (not shown here).
  37.  *              The next_error function would place us on the next error
  38.  *              and allow us to correct it before the compilation is
  39.  *              completed.
  40.  *
  41.  * Interface    shell
  42.  *              - is provided in order to initially send a command to
  43.  *                command interpreter.
  44.  *
  45.  *              shell_write
  46.  *              - allows us to write to the input pipe of the child process
  47.  *                - This is useful for command which require input.
  48.  *                  For example,
  49.  *
  50.  *                  shell time
  51.  *
  52.  *                   would require a
  53.  *
  54.  *                  shell_write 12:00
  55.  *
  56.  *                   in order to set the time.
  57.  *
  58.  *              shell_kill
  59.  *              - allows us to kill the child process
  60.  *
  61.  * Modifications
  62.  *  08/31/88
  63.  *   - added a windowing option
  64.  *     (The credit for this change goes to Bryan Lewis)
  65.  */
  66. defc shell
  67. compile if EVERSION < 5
  68.    savetof = top_of_file_fixed
  69.    top_of_file_fixed = 0
  70. compile endif
  71.    getfileid OriginalFileIdentification
  72.    call openshellwindow()
  73.    line=.line; .cursory=.windowheight; line     /* newtop */
  74.    refresh
  75.    getfileid ShellFileIdentification
  76.    call shell(arg(1),1,ShellFileIdentification)
  77.    sayerror 0                                /* Erase "New file" message. */
  78. compile if EVERSION < 5
  79.    top_of_file_fixed = savetof
  80. compile endif
  81.  
  82. defproc openshellwindow=
  83.    /* Snazzier:  pop a window with a dummy file, insert text into it. */
  84.    getfileid shell_fid, '.shell'   /* If already exists, reuse it. */
  85.    if shell_fid = '' then
  86.       /* jbl 12/30/88:  just edit the file, no window.
  87.        *newwindow 'E /w /n .shell'                         /* Create pop-up */
  88.        *sayerror 0                             /* Erase "New file" message. */
  89.        *call sizepopup(1,1,screenwidth(),screenheight()%2,1) /* top of screen.*/
  90.        */
  91.       'E /n .shell'
  92.       sayerror 0
  93.       call SHELL_fill()
  94.    else
  95.       activatefile shell_fid
  96.    endif
  97. -- .windowoverlap=1
  98.  
  99. defc shellprefix=
  100.    uparg=upcase(arg(1))
  101.    if uparg=ON__MSG or uparg=1 then
  102.       'xcom shellprefix 1'
  103.    elseif uparg=OFF__MSG or uparg='0' then
  104.       'xcom shellprefix 0'
  105.    else
  106.       sayerror INVALID_ARG__MSG ON_OFF__MSG')'
  107.       stop
  108.    endif
  109.  
  110.  
  111. defc shell_hidden,sh
  112.    getfileid OriginalFileIdentification
  113.    'e /n .sh'
  114.    if rc= -282 then  -- sayerror("New file")
  115.       call SHELL_fill()
  116.    endif
  117.    line=.line; .cursory=.windowheight; line      /*@ newtop */
  118.    getfileid ShellFileIdentification
  119.    call shell(arg(1),ShellFileIdentification.last,ShellFileIdentification)
  120.    activatefile OriginalFileIdentification
  121.  
  122. defc shell_write,shw
  123.    call shell_write(arg(1))
  124.  
  125. defc shell_kill,shk
  126.    call shell_kill()
  127.  
  128. defproc SHELL_fill
  129.  for i = 1 to .windowheight
  130.   insertline ''
  131.  endfor
  132.