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 >
Wrap
Text File
|
1988-11-01
|
4KB
|
109 lines
The Environment 1
The Environment
---------------
The OS-9 Shell supports a data structure called the environment. It is
used to store some information about the process' operational environment,
such as user name, terminal type, home directory path and so on. The
concept of the environment has been taken from the UNIX Operating system
without any modifications from the user's and C-programmerts point of
view. However, accessing the environment on assembly language level is not
quite easy, because the current implementation has been made compatible to
older versions of the shell (and os9exec() resp.). This lead to a somewhat
not-transparent structure, that is hard to understand without any
documentation. This description is based on a source listing of the
os9exec() C-Function I got from Microware when I asked them for
documentation.
The Parameter Area
------------------
The environment is passed together with the command line parameters in the
parameter area (see OS9/68000 Technical Manual, description of the F$Fork
System call). The following list shows the structure of the parameter
area:
(A5) Command line parameters
(character strings, separated by single spaces)
Command line parameter terminator
($000D, in early V2.0 shells sometimes only $00, due to an
error in os9exec())
ALIGN (zero fill byte if address is odd)
Environment variables
(each variable is represented by a character string in the
Form:
"VarName=VarContents". The variables are separated by
single spaces.
Environment variable terminator
($00 byte)
ALIGN (zero fill byte if address is odd)
$FC01 "special sync code"
This is used by cstart to find the argv[0] pointer. If
this "sync code" cannot be found, no argv[0] pointer and
string is available.
argv[0] longword pointer (relative to the parameter area
beginning)
argv[0] string (C-type string: terminated by $00 byte)
(program name or program file pathlist)
ALIGN (zero fill byte if address is odd)
$000D word
$00000000 longword (argv[] pointer list beginning)
The Environment 2
argv[1] .. argv[n] longword pointers
(pointers to each of the command line parameters, relative
to the parameter area beginning)
If no parameters are passed, there are no argv[] pointers.
$00000000 longword (separator between argv[] and envp[]
pointers)
envp[0] .. envp[n] longword pointers
(pointers to each of the environment variables, relative
to the parameter area beginning)
If no parameters are passed, there are no envp[] pointers.
(A5+D5.L-4) $00000000 longword (envp[] pointer list terminator)
This longword (the last 4 bytes of the parameter area) is
also used to identify older parameter areas that have no
argv[] and envp[] pointers: in this case this longword
contains a non-zero value.
(A5+D5.L)
Notes
-----
- Command line parameters as well as environment variable contents may
contain spaces. Therefore, if only the command line (or environment
variable, resp) strings are examined, it is impossible to find the
separating spaces, because every space could be a separator as well
as a part of a string. The only way to separate the strings safely is
accessing them using the argv[] (or envp[] resp.) pointers.
- The OS-9 V1.2 Shell does not pass the argv[0] parameter, so there is
no "special sync code" in a V1.2 Shell parameter area. For C
Programs, cstart will assign the program's module name to argv[0] in
this case.
- Due to an error in early V2.0 Shells, the parameter string is not
always terminated by a $0D (or $000D): Sometimes there is only a $00
terminator.