home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / texec.seq < prev    next >
Text File  |  1989-11-20  |  2KB  |  55 lines

  1. \ TEXEC.SEQ     Shell command library function          by Tom Zimmer
  2.  
  3. comment:
  4.  
  5.   This file along with "EXECF" in LIBRARY.SEQ provides an interface to
  6. DOS allowing commands to be shelled out.
  7.  
  8.   An example definition of MAIN is provided at the end of this file.
  9. Place it in SAMPLE.SEQ and compile with this library file to make a
  10. simple example of "shelling out" to DOS.
  11.  
  12. comment;
  13.  
  14. FORTH DECIMAL TARGET >LIBRARY       \ A Library file
  15.  
  16. $80 ARRAY EXEC.BUF
  17. $10 ARRAY EXEC.PARAM
  18. $30 ARRAY CMDPATH
  19.  
  20. : EXEC.BUF+/c+$ ( a1 -- )
  21.                 " /C "   exec.buf  place
  22.                 count    exec.buf +place
  23.                 exec.buf count + off ;
  24.  
  25. : $sys          ( command_line --- f1 )         \ spawn a shell
  26.                 cmdpath c@ 0= abort" COMSPEC not initialized"
  27.                 exec.param 16 erase
  28.                 dup c@
  29.         if      exec.buf+/c+$
  30.         else    drop exec.buf off
  31.         then    ?CS: 44 @L  exec.param      !   \ environment segmnt
  32.                 ?ds:        exec.param  4 + !   \ command line seg
  33.                 exec.buf    exec.param  2 + !   \ and offset
  34.                 $0D exec.buf count + c!         \ append a carraige return
  35.                 cmdpath count + off
  36.                 cmdpath 1+ exec.param execf ;
  37.  
  38. : ?syserror     ( n1 --- )      \ handle ONLY error codes 2 and 8 from $sys
  39.                 dup  2 = abort" Can't find COMMAND.COM"
  40.                 dup  8 = abort" Not enough memory"
  41.                 drop ;
  42.  
  43. >FORTH FORTH TARGET >TARGET
  44.  
  45. \S      Stop loading HERE!
  46. \ ***************************************************************************
  47. \  Put the following into SAMPLE.SEQ, and you can spawn a simple DOS shell.
  48.  
  49. : MAIN          ( -- )
  50.                 ." Enter a command line->"
  51.                 PAD 1+ 80 EXPECT SPAN @ PAD C!
  52.                 CR
  53.                 PAD $SYS DROP BYE ;
  54.  
  55.