/[eiffelstudio]/FreeELKS/trunk/library/support/execution_environment.e
ViewVC logotype

Contents of /FreeELKS/trunk/library/support/execution_environment.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91469 - (show annotations)
Tue Feb 21 14:54:50 2006 UTC (13 years, 11 months ago) by ericb
File size: 4761 byte(s)
Synchronized with ISE 5.7.0414.
Implemented BOOL_STRING in pure Eiffel.

1 indexing
2
3 description:
4 "The objects available from the environment at time of execution"
5
6 library: "Free implementation of ELKS library"
7 copyright: "Copyright (c) 2005, Eiffel Software and others"
8 license: "Eiffel Forum License v2 (see forum.txt)"
9 date: "$Date$"
10 revision: "$Revision$"
11
12
13 class EXECUTION_ENVIRONMENT
14
15 feature -- Access
16
17 command_line: ARGUMENTS is
18 -- Command line that was used to start current execution
19 once
20 create Result
21 end
22
23 current_working_directory: STRING is
24 -- Directory of current execution
25 external
26 "C use %"eif_dir.h%""
27 alias
28 "dir_current"
29 ensure
30 result_not_void: Result /= Void
31 end
32
33 default_shell: STRING is
34 -- Default shell
35 once
36 Result := get ("SHELL")
37 if Result = Void then
38 Result := ""
39 end
40 end
41
42 get (s: STRING): STRING is
43 -- Value of `s' if it is an environment variable and has been set;
44 -- void otherwise.
45 require
46 s_exists: s /= Void
47 not_has_null_character: not s.has ('%U')
48 local
49 ext: ANY
50 c_string: POINTER
51 void_pointer: POINTER
52 do
53 ext := s.to_c
54 c_string := eif_getenv ($ext)
55 if c_string /= void_pointer then
56 create Result.make_from_c (c_string)
57 end
58 end
59
60 home_directory_name: STRING is
61 -- Directory name corresponding to the home directory.
62 require
63 home_directory_supported: Operating_environment.home_directory_supported
64 do
65 Result := eif_home_directory_name
66 end
67
68 root_directory_name: STRING is
69 -- Directory name corresponding to the root directory.
70 require
71 root_directory_supported: Operating_environment.root_directory_supported
72 do
73 Result := eif_root_directory_name
74 ensure
75 result_not_void: Result /= Void
76 end
77
78 feature -- Status
79
80 return_code: INTEGER
81 -- Status code set by last call to `system' or `put'
82
83 feature -- Status setting
84
85 change_working_directory (path: STRING) is
86 -- Set the current directory to `path'
87 local
88 ext: ANY
89 do
90 ext := path.to_c
91 return_code := eif_chdir ($ext)
92 end
93
94 put (value, key: STRING) is
95 -- Set the environment variable `key' to `value'.
96 require
97 key_exists: key /= Void
98 key_meaningful: not key.is_empty
99 not_key_has_null_character: not key.has ('%U')
100 value_exists: value /= Void
101 not_value_has_null_character: not value.has ('%U')
102 local
103 l_env: STRING
104 l_c_env: C_STRING
105 do
106 create l_env.make (value.count + key.count + 1)
107 l_env.append (key)
108 l_env.append_character ('=')
109 l_env.append (value)
110 create l_c_env.make (l_env)
111
112 environ.force (l_c_env, key)
113 return_code := eif_putenv (l_c_env.item)
114 ensure
115 variable_set: (return_code = 0) implies (value.is_equal (get (key)))
116 end
117
118 system (s: STRING) is
119 -- Pass to the operating system a request to execute `s'.
120 -- If `s' is empty, use the default shell as command.
121 require
122 s_exists: s /= Void
123 local
124 ext: ANY
125 do
126 if s.is_empty then
127 ext := default_shell.to_c
128 else
129 ext := s.to_c
130 end
131 return_code := system_call ($ext)
132 end
133
134 launch (s: STRING) is
135 -- Pass to the operating system an asynchronous request to
136 -- execute `s'.
137 -- If `s' is empty, use the default shell as command.
138 require
139 s_not_void: s /= Void
140 local
141 ext: ANY
142 do
143 if s.is_empty then
144 ext := default_shell.to_c
145 else
146 ext := s.to_c
147 end
148 asynchronous_system_call ($ext)
149 end
150
151 feature {NONE} -- Implementation
152
153 environ: HASH_TABLE [C_STRING, STRING] is
154 -- Environment variable memory set by current execution,
155 -- indexed by environment variable name. Needed otherwise
156 -- we would corrupt memory after freeing memory used by
157 -- C_STRING instance since not referenced anywhere else.
158 once
159 create Result.make (10)
160 end
161
162 feature {NONE} -- External
163
164 eif_getenv (s: POINTER): POINTER is
165 -- Value of environment variable `s'
166 external
167 "C use %"eif_misc.h%""
168 end
169
170 eif_putenv (v: POINTER): INTEGER is
171 -- Set `v' in environment.
172 external
173 "C use <stdlib.h>"
174 alias
175 "putenv"
176 end
177
178 eif_chdir (path: POINTER): INTEGER is
179 -- Set the current directory to `path'
180 external
181 "C use %"eif_dir.h%""
182 end
183
184 system_call (s: POINTER): INTEGER is
185 -- Pass to the operating system a request to execute `s'.
186 external
187 "C blocking use %"eif_misc.h%""
188 alias
189 "eif_system"
190 end
191
192 asynchronous_system_call (s: POINTER) is
193 -- Pass to the operating system an asynchronous request to execute `s'.
194 external
195 "C blocking use %"eif_misc.h%""
196 alias
197 "eif_system_asynchronous"
198 end
199
200 eif_home_directory_name: STRING is
201 -- Directory name corresponding to the home directory
202 external
203 "C use %"eif_path_name.h%""
204 end
205
206 eif_root_directory_name: STRING is
207 -- Directory name corresponding to the root directory
208 external
209 "C use %"eif_path_name.h%""
210 end
211
212 end

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23