]> git.lyx.org Git - lyx.git/blob - src/support/environment.h
Fix several filename and environment variable encoding problems
[lyx.git] / src / support / environment.h
1 // -*- C++ -*-
2 /**
3  * \file environment.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef LYX_ENVIRONMENT_H
13 #define LYX_ENVIRONMENT_H
14
15 #include <string>
16 #include <vector>
17
18 namespace lyx {
19 namespace support {
20
21 /// @returns the contents of the environment variable @c name encoded in utf8.
22 std::string const getEnv(std::string const & envname);
23
24 /** @returns the contents of the environment variable @c name,
25  *  split into path elements using the OS-dependent separator token
26  *  and encoded in utf8.
27  *  Each element is then passed through os::internal_path() to
28  *  guarantee that it is in the form of a unix-style path.
29  *  If the environment variable is not set, then the function returns
30  *  an empty vector.
31  */
32 std::vector<std::string> const getEnvPath(std::string const & name);
33
34 /** Set the contents of the environment variable @c name to @c value.
35  *  \p value is encoded in utf8.
36  *  @returns true if the variable was set successfully.
37  */
38 bool setEnv(std::string const & name, std::string const & value);
39
40 /** Set the contents of the environment variable @c name
41  *  using the paths stored in the @c env vector (encoded in utf8).
42  *  Each element is passed through os::external_path().
43  *  Multiple elements are concatenated into a single string using
44  *  os::path_separator().
45  */
46 void setEnvPath(std::string const & name, std::vector<std::string> const & env);
47
48 /** Prepend a list of paths to that returned by the environment variable.
49  *  Identical paths occurring later in the list are removed.
50  *  @param name the name of the environment variable (encoded in utf8).
51  *  @prefix the list of paths in OS-native syntax (encoded in utf8).
52  *  Eg "/foo/bar:/usr/bin:/usr/local/bin" on *nix,
53  *     "C:\foo\bar;C:\windows" on Windows.
54  */
55 void prependEnvPath(std::string const & name, std::string const & prefix);
56
57 } // namespace support
58 } // namespace lyx
59
60 #endif // LYX_ENVIRONMENT_H