modelize: ask that attributes in refinements are either noautoninit or have a value
[nit.git] / lib / standard / environ.nit
index 93f5b25..0abe7f3 100644 (file)
@@ -15,6 +15,7 @@
 module environ
 
 import string
+import file
 
 # TODO prevoir une structure pour recup tout un environ, le modifier et le passer a process
 
@@ -41,9 +42,29 @@ redef class String
        #     "NITis".setenv("fun")
        #     assert "NITis".environ  == "fun"
        fun setenv(v: String) do to_cstring.setenv( v.to_cstring )
+
+       # Search for the program `self` in all directories from `PATH`
+       fun program_is_in_path: Bool
+       do
+               var full_path = "PATH".environ
+               var paths = full_path.split(":")
+               for path in paths do if path.file_exists then
+                       if path.join_path(self).file_exists then return true
+               end
+
+               return false
+       end
 end
 
 redef class NativeString
        private fun get_environ: NativeString is extern "string_NativeString_NativeString_get_environ_0"
        private fun setenv( v : NativeString ) is extern "string_NativeString_NativeString_setenv_1"
 end
+
+redef class Sys
+       redef init
+       do
+               var x = "NIT_SRAND".environ
+               if x != "" then srand_from(x.to_i)
+       end
+end