home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / environ.seq < prev    next >
Text File  |  1988-09-19  |  4KB  |  111 lines

  1. \ ENVIRON.SEQ   Environment manipulation words          by Tom Zimmer
  2.  
  3. : evseg         ( --- n1 )      \ Return the segment of environment $.
  4.                 44 @ ;
  5.  
  6. : envsize       ( --- n1 )      \ Calculate the environment $ size.
  7.                 ?cs: evseg - 2047 min 16 * ;
  8.  
  9. : "envfind      ( a1 n1 --- n2 bool )   \ n2 is offset into environment
  10.                 false save!> caps       \  where string a1,n1 was found.
  11.                 evseg save!> SSEG       \ Set the search segment
  12.                 0 envsize search
  13.                 restore> SSEG           \ Restore the search segment
  14.                 restore> caps ;
  15.  
  16. : .env          ( --- )         \ print the environment string
  17.                 0 envsize bounds    cr
  18.                ?do      evseg i c@l 0=
  19.                         if      cr
  20.                         else    evseg i c@l emit
  21.                         then    evseg i @l 0= ?leave
  22.                 loop    ;
  23.  
  24. handle comspec$
  25.  
  26. : comspec@      ( --- )         \ extract the command spec
  27.                 " COMSPEC=" "envfind 0=
  28.                 if      ." Couldn't find Command Spec."
  29.                         drop comspec$ off
  30.                 else    8 + envsize swap
  31.                         comspec$ dup clr-hcb >nam -rot
  32.                         do      evseg i c@l 0= ?leave
  33.                                 evseg i c@l over c! 1+
  34.                                 comspec$ c@ 1+ comspec$ c!
  35.                         loop    drop
  36.                 then    ;
  37.  
  38. : .comspec      ( --- ) comspec@ comspec$ count type ;
  39.  
  40. create path$ 81 allot
  41.  
  42. : path@         ( --- )         \ extract the command spec
  43.                 " PATH=" "envfind 0=
  44.                 if      ." Couldn't find PATH."
  45.                         drop path$ off
  46.                 else    5 + envsize swap
  47.                         path$ dup clr-hcb >nam -rot
  48.                         do      evseg i c@l 0= ?leave
  49.                                 evseg i c@l over c! 1+
  50.                                 1 path$ c+!
  51.                         loop    drop
  52.                 then    ;
  53.  
  54. : .path         ( --- ) path@ path$ count type ;
  55.  
  56. handle me$
  57.  
  58. : me@           ( --- ) \ extract my own execution name string
  59.                         \ returns a null ME$ if it fails
  60.                 me$ off dosver 3 >=     \ need DOS version 3 or greater
  61.                 if      me$ 2 "envfind
  62.                         if      4 + envsize swap
  63.                                 me$ dup clr-hcb >nam -rot
  64.                                 do      evseg i c@l 0= ?leave
  65.                                         evseg i c@l over c! 1+
  66.                                         me$ c@ 1+ me$ c!
  67.                                 loop    drop
  68.                         else    drop
  69.                         then
  70.                 then            ;
  71.  
  72. : .me           ( --- ) me@ me$ count type ;
  73.  
  74. comment:
  75.  
  76. envsize       ( --- n1 )
  77.         Return the maximum size the environment can be in bytes.
  78.  
  79. .env          ( --- )
  80.         Print the environment string used by the system.
  81.  
  82. "envfind      ( a1 n1 --- n2 bool )
  83.         Find the string a1 n1 in the environment, returning
  84.         bool true if found, and n2 the offset into env$ where it
  85.         was found. N2 is the offset to the BEGINNING of the
  86.         string searched for.
  87.  
  88. comspec$
  89.         Storage space for the command spec string.
  90.  
  91. comspec@      ( --- )
  92.         Extract the command spec from the environment string.
  93.  
  94. .comspec      ( --- )
  95.         Print the command spec.
  96.  
  97. me$
  98.         Storage space for the execution string used to execute
  99.         this forth currently running.
  100.  
  101. me@           ( --- )
  102.         Extract the execution string from the environment, and
  103.         place it in the string ME$
  104.  
  105. .me           ( --- )
  106.         Print the execution string after extracting it.
  107.  
  108. comment;
  109.  
  110.  
  111.