4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
12 #ifndef LYX_ENVIRONMENT_H
13 #define LYX_ENVIRONMENT_H
21 /// @returns true if the environment variable @c name exists.
22 bool hasEnv(std::string const & name);
24 /// @returns the contents of the environment variable @c name encoded in utf8.
25 std::string const getEnv(std::string const & name);
27 /** @returns the contents of the environment variable @c name,
28 * split into path elements using the OS-dependent separator token
29 * and encoded in utf8.
30 * Each element is then passed through os::internal_path() to
31 * guarantee that it is in the form of a unix-style path.
32 * If the environment variable is not set, then the function returns
35 std::vector<std::string> const getEnvPath(std::string const & name);
37 /** Set the contents of the environment variable @c name to @c value.
38 * \p value is encoded in utf8.
39 * @returns true if the variable was set successfully.
41 bool setEnv(std::string const & name, std::string const & value);
43 /** Set the contents of the environment variable @c name
44 * using the paths stored in the @c env vector (encoded in utf8).
45 * Each element is passed through os::external_path().
46 * Multiple elements are concatenated into a single string using
47 * os::path_separator().
49 void setEnvPath(std::string const & name, std::vector<std::string> const & env);
51 /** Prepend a list of paths to that returned by the environment variable.
52 * Identical paths occurring later in the list are removed.
53 * @param name the name of the environment variable (encoded in utf8).
54 * @prefix the list of paths in OS-native syntax (encoded in utf8).
55 * Eg "/foo/bar:/usr/bin:/usr/local/bin" on *nix,
56 * "C:\foo\bar;C:\windows" on Windows.
58 void prependEnvPath(std::string const & name, std::string const & prefix);
60 /** Remove the variable @c name from the environment.
61 * @returns true if the variable was unset successfully.
63 bool unsetEnv(std::string const & name);
66 /** Utility class to change temporarily an environment variable. The
67 * variable is reset to its original state when the dummy EnvChanger
68 * variable is deleted.
73 EnvChanger(std::string const & name, std::string const & value)
74 : name_(name), set_(hasEnv(name)), value_(getEnv(name))
82 setEnv(name_, value_);
88 /// the name of the variable
90 /// was the variable set?
96 } // namespace support
99 #endif // LYX_ENVIRONMENT_H