X-Git-Url: http://nitlanguage.org diff --git a/lib/standard/environ.nit b/lib/standard/environ.nit index fb83040..2f6ae46 100644 --- a/lib/standard/environ.nit +++ b/lib/standard/environ.nit @@ -15,12 +15,16 @@ module environ import string +import file # TODO prevoir une structure pour recup tout un environ, le modifier et le passer a process redef class String - # Return environment value for this symbol - # If there is no such environment value, then return "" + # Return environment value for the symbol. + # If there is no such environment variable, then return "" + # + # assert "PATH".environ != "" + # assert "NIT %\n".environ == "" fun environ: String do var res = self.to_cstring.get_environ @@ -32,7 +36,24 @@ redef class String return "" end end - fun setenv( v : String ) do to_cstring.setenv( v.to_cstring ) + + # Set the enviroment value of a variable. + # + # "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