]> git.lyx.org Git - lyx.git/blob - src/support/os.h
Amend 207eaeee9071cb
[lyx.git] / src / support / os.h
1 // -*- C++ -*-
2 /**
3  * \file os.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Ruurd A. Reitsma
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * wrap OS-specific stuff
12  */
13
14 #ifndef OS_H
15 #define OS_H
16
17 #include "support/strfwd.h"
18 #include <cstddef>
19
20
21 namespace lyx {
22 namespace support {
23 namespace os {
24
25 enum shell_type {
26         UNIX,   // Do we have to distinguish sh and csh?
27         CMD_EXE
28 };
29
30 enum path_case {
31         CASE_UNCHANGED,
32         CASE_ADJUSTED
33 };
34
35 enum file_access {
36         EXISTING,
37         CREATE
38 };
39
40 /// Do some work just once.
41 void init(int argc, char ** argv[]);
42
43 /// Returns the i-th program argument in utf8 encoding.
44 std::string utf8_argv(int i);
45
46 /// Removes from the internal copy \p num program arguments starting from \p i.
47 void remove_internal_args(int i, int num);
48
49 /// Returns the name of the NULL device (/dev/null, null).
50 std::string const & nulldev();
51
52 /// Returns "/" on *nix, "C:/", etc on Windows.
53 std::string current_root();
54
55 ///
56 shell_type shell();
57
58 /// Returns no. of milliseconds allowed for a command to complete.
59 int timeout_ms();
60
61 /// Name of the python interpreter
62 /// @param reset True if the python path should be recomputed
63 std::string const python(bool reset = false);
64
65 /// Check for availability of the python interpreter
66 bool hasPython();
67
68 /// Return information about the python interperter (version and path)
69 std::string const python_info();
70
71 ///
72 bool isFilesystemCaseSensitive();
73
74 /// Extract the path common to both @c p1 and @c p2. DBCS aware!
75 /// \p p1 and \p p2 are encoded in ucs4, \returns the index to the end of
76 /// the last matching path component (the index may be pointing after the
77 /// end of @c p1 or @c p2 if their last char is not the path separator).
78 std::size_t common_path(docstring const & p1, docstring const & p2);
79
80 /// Converts a unix style path to host OS style.
81 /// \p p and the return value are encoded in utf8.
82 std::string external_path(std::string const & p);
83
84 /// Converts a host OS style path to unix style.
85 /// \p p and the return value are encoded in utf8.
86 std::string internal_path(std::string const & p);
87
88 /// Converts a host OS style path to a unicode safe unix style.
89 /// On Windows, this is achieved by using the short form of the path,
90 /// which can be safely passed to standard I/O functions expecting narrow
91 /// char paths even when the path contains non-ascii chars.
92 /// As the short form is only available for existing files, if the file is
93 /// to be accessed for writing, \param how should be set to CREATE.
94 /// \p p and the return value are encoded in utf8.
95 std::string safe_internal_path(std::string const & p, file_access how = EXISTING);
96
97 /// Converts a unix style path list to host OS style.
98 /// \p p and the return value are encoded in utf8.
99 std::string external_path_list(std::string const & p);
100
101 /// Converts a host OS style path list to unix style.
102 /// \p p and the return value are encoded in utf8.
103 std::string internal_path_list(std::string const & p);
104
105 /**
106  * Converts a unix style path into a form suitable for inclusion in a LaTeX
107  * document.
108  * \p p is encoded in utf8.
109  * Caution: This function handles only the OS specific part of that task.
110  * Never use it directly, use lyx::support::latex_path instead.
111  */
112 std::string latex_path(std::string const & p);
113
114 /**
115  * Converts a platform style path list into a form suitable for the TeX engine.
116  * \p p is encoded in utf8.
117  */
118 std::string latex_path_list(std::string const & p);
119
120 /** Returns a string suitable to be passed to popen when
121  *  reading a file.
122  */
123 char const * popen_read_mode();
124
125 enum path_type {
126         PLATFORM,
127         TEXENGINE
128 };
129
130 /** The character used to separate paths for platform environment variables
131  *  (such as PATH) or for the TeX engine.
132  */
133 char path_separator(path_type type = PLATFORM);
134
135 /** If @c use_windows_paths is true, LyX will output Windows-style paths to
136  *  latex files rather than posix ones. Obviously, this option is used only
137  *  under Windows.
138  */
139 void windows_style_tex_paths(bool use_windows_paths);
140
141 enum auto_open_mode {
142         VIEW,
143         EDIT
144 };
145
146 /** Check whether or not a file can be opened by a default viewer or editor.
147  *  \param extension (without leading .)
148  *  \param mode can be opened in VIEW or EDIT mode
149  *  \returns whether or not the format can be opened according to \p mode
150  */
151 bool canAutoOpenFile(std::string const & ext, auto_open_mode const mode);
152
153 /** View or edit a file with the default viewer or editor.
154  *  \param filename file to open (encoded in utf8)
155  *  \param mode open in VIEW or EDIT mode
156  *  \returns whether or not the file is viewed (or edited) successfully.
157  */
158 bool autoOpenFile(std::string const & filename, auto_open_mode const mode,
159                   std::string const & path = empty_string());
160
161 /** Resolves a path such that it does not contain '.', '..', or symbolic links.
162   * \p path and the return value are encoded in utf8.
163   */
164 std::string real_path(std::string const & path);
165
166 /** Checks whether \param path starts with \param pre, accounting for case
167   * insensitive file systems.
168   */
169 bool path_prefix_is(std::string const & path, std::string const & pre);
170
171 /** Checks whether \param path starts with \param pre, accounting for case
172   * insensitive file systems. If true, the file system is case insensitive,
173   * and \param how == CASE_ADJUSTED, the case of the matching prefix in
174   * @c path is made equal to that of @c pre.
175   */
176 bool path_prefix_is(std::string & path, std::string const & pre, path_case how = CASE_UNCHANGED);
177
178 } // namespace os
179 } // namespace support
180 } // namespace lyx
181
182 #endif