home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / EFFO / forum7.lzh / INFO / the_environment < prev    next >
Text File  |  1988-11-01  |  4KB  |  109 lines

  1. The Environment                                                          1
  2.  
  3. The Environment
  4. ---------------
  5.  
  6. The OS-9 Shell supports a data structure called  the  environment.  It  is
  7. used to store some information about the process' operational environment,
  8. such as user name, terminal type, home  directory  path  and  so  on.  The
  9. concept of the environment has been taken from the UNIX  Operating  system
  10. without any modifications from the  user's  and  C-programmerts  point  of
  11. view. However, accessing the environment on assembly language level is not
  12. quite easy, because the current implementation has been made compatible to
  13. older versions of the shell (and os9exec() resp.). This lead to a somewhat
  14. not-transparent  structure,  that  is  hard  to  understand  without   any
  15. documentation. This description is  based  on  a  source  listing  of  the
  16. os9exec()  C-Function  I  got  from  Microware  when  I  asked  them   for
  17. documentation.
  18.  
  19. The Parameter Area
  20. ------------------
  21.  
  22. The environment is passed together with the command line parameters in the
  23. parameter area (see OS9/68000 Technical Manual, description of the  F$Fork
  24. System call). The following list shows  the  structure  of  the  parameter
  25. area:
  26.  
  27.  (A5)         Command line parameters
  28.               (character strings, separated by single spaces)
  29.  
  30.               Command line parameter terminator
  31.               ($000D, in early V2.0 shells sometimes only $00, due to an
  32.               error in os9exec())
  33.  
  34.               ALIGN (zero fill byte if address is odd)
  35.  
  36.               Environment variables
  37.               (each variable is represented by a character string in the
  38.               Form:
  39.               "VarName=VarContents". The variables are separated by
  40.               single spaces.
  41.  
  42.               Environment variable terminator
  43.               ($00 byte)
  44.  
  45.               ALIGN (zero fill byte if address is odd)
  46.  
  47.               $FC01 "special sync code"
  48.               This is used by cstart to find the argv[0] pointer. If
  49.               this "sync code" cannot be found, no argv[0] pointer and
  50.               string is available.
  51.  
  52.               argv[0] longword pointer (relative to the parameter area
  53.               beginning)
  54.  
  55.               argv[0] string (C-type string: terminated by $00 byte)
  56.               (program name or program file pathlist)
  57.  
  58.               ALIGN (zero fill byte if address is odd)
  59.  
  60.               $000D word
  61.  
  62.               $00000000 longword (argv[] pointer list beginning)
  63.  
  64.  
  65.  
  66. The Environment                                                          2
  67.  
  68.               argv[1] .. argv[n] longword pointers
  69.               (pointers to each of the command line parameters, relative
  70.               to the parameter area beginning)
  71.               If no parameters are passed, there are no argv[] pointers.
  72.  
  73.               $00000000 longword (separator between argv[] and envp[]
  74.               pointers)
  75.  
  76.               envp[0] .. envp[n] longword pointers
  77.               (pointers to each of the environment variables, relative
  78.               to the parameter area beginning)
  79.               If no parameters are passed, there are no envp[] pointers.
  80.  
  81.  (A5+D5.L-4)  $00000000 longword (envp[] pointer list terminator)
  82.               This longword (the last 4 bytes of the parameter area) is
  83.               also used to identify older parameter areas that have no
  84.               argv[] and envp[] pointers: in this case this longword
  85.               contains a non-zero value.
  86.  
  87.  (A5+D5.L)
  88.  
  89.  
  90. Notes
  91. -----
  92.  
  93.   -  Command line parameters as well as environment variable contents  may
  94.      contain spaces. Therefore, if only the command line  (or  environment
  95.      variable, resp) strings are examined, it is impossible  to  find  the
  96.      separating spaces, because every space could be a separator  as  well
  97.      as a part of a string. The only way to separate the strings safely is
  98.      accessing them using the argv[] (or envp[] resp.) pointers.
  99.  
  100.   -  The OS-9 V1.2 Shell does not pass the argv[0] parameter, so there  is
  101.      no "special sync  code"  in  a  V1.2  Shell  parameter  area.  For  C
  102.      Programs, cstart will assign the program's module name to argv[0]  in
  103.      this case.
  104.  
  105.   -  Due to an error in early V2.0 Shells, the  parameter  string  is  not
  106.      always terminated by a $0D (or $000D): Sometimes there is only a  $00
  107.      terminator.
  108.  
  109.