]> git.lyx.org Git - lyx.git/blob - src/support/os.h
25176729fd76e6908b3b526247b2269e6ffa459e
[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 io_channel {
31         STDIN = 0,
32         STDOUT,
33         STDERR
34 };
35
36 enum path_case {
37         CASE_UNCHANGED,
38         CASE_ADJUSTED
39 };
40
41 /// Do some work just once.
42 void init(int argc, char * argv[]);
43
44 /// Returns the name of the NULL device (/dev/null, null).
45 std::string const & nulldev();
46
47 /// Tells whether \p channel is connected to a terminal or not. 
48 bool is_terminal(io_channel channel);
49
50 /// Returns "/" on *nix, "C:/", etc on Windows.
51 std::string current_root();
52
53 ///
54 shell_type shell();
55
56 /// Name of the python interpreter
57 std::string const python();
58
59 ///
60 bool isFilesystemCaseSensitive();
61
62 /// Extract the path common to both @c p1 and @c p2. DBCS aware!
63 /// \p p1 and \p p2 are encoded in ucs4, \returns the index to the end of
64 /// the last matching path component (the index may be pointing after the
65 /// end of @c p1 or @c p2 if their last char is not the path separator).
66 std::size_t common_path(docstring const & p1, docstring const & p2);
67
68 /// Converts a unix style path to host OS style.
69 /// \p p and the return value are encoded in utf8.
70 std::string external_path(std::string const & p);
71
72 /// Converts a host OS style path to unix style.
73 /// \p p and the return value are encoded in utf8.
74 std::string internal_path(std::string const & p);
75
76 /// Converts a host OS style path to a unicode safe unix style.
77 /// On Windows, this is achieved by using the short form of the path,
78 /// which can be safely passed to standard I/O functions expecting narrow
79 /// char paths even when the path contains non-ascii chars.
80 /// \p p and the return value are encoded in utf8.
81 std::string safe_internal_path(std::string const & p);
82
83 /// Converts a unix style path list to host OS style.
84 /// \p p and the return value are encoded in utf8.
85 std::string external_path_list(std::string const & p);
86
87 /// Converts a host OS style path list to unix style.
88 /// \p p and the return value are encoded in utf8.
89 std::string internal_path_list(std::string const & p);
90
91 /**
92  * Converts a unix style path into a form suitable for inclusion in a LaTeX
93  * document.
94  * \p p is encoded in utf8.
95  * Caution: This function handles only the OS specific part of that task.
96  * Never use it directly, use lyx::support::latex_path instead.
97  */
98 std::string latex_path(std::string const & p);
99
100 /// Checks if the format string is suitable on the OS
101 bool is_valid_strftime(std::string const & p);
102
103 /** Returns a string suitable to be passed to popen when
104  *  reading a file.
105  */
106 char const * popen_read_mode();
107
108 /** The character used to separate paths returned by the
109  *  PATH environment variable.
110  */
111 char path_separator();
112
113 /** If @c use_windows_paths is true, LyX will output Windows-style paths to
114  *  latex files rather than posix ones. Obviously, this option is used only
115  *  under Windows.
116  */
117 void windows_style_tex_paths(bool use_windows_paths);
118
119 enum auto_open_mode {
120         VIEW,
121         EDIT
122 };
123
124 /** Check whether or not a file can be opened by a default viewer or editor.
125  *  \param extension (without leading .)
126  *  \param mode can be opened in VIEW or EDIT mode
127  *  \returns whether or not the format can be opened according to \p mode
128  */
129 bool canAutoOpenFile(std::string const & ext, auto_open_mode const mode = VIEW);
130
131 /** View or edit a file with the default viewer or editor.
132  *  \param filename file to open (encoded in utf8)
133  *  \param mode open in VIEW or EDIT mode
134  *  \returns whether or not the file is viewed (or edited) successfully.
135  */
136 bool autoOpenFile(std::string const & filename, auto_open_mode const mode = VIEW);
137
138 /** Resolves a path such that it does not contain '.', '..', or symbolic links.
139   * \p path and the return value are encoded in utf8.
140   */
141 std::string real_path(std::string const & path);
142
143 /** Checks whether \param path starts with \param pre, accounting for case
144   * insensitive file systems.
145   */
146 bool path_prefix_is(std::string const & path, std::string const & pre);
147
148 /** Checks whether \param path starts with \param pre, accounting for case
149   * insensitive file systems. If true, the file system is case insensitive,
150   * and \param how == CASE_ADJUSTED, the case of the matching prefix in
151   * @c path is made equal to that of @c pre.
152   */
153 bool path_prefix_is(std::string & path, std::string const & pre, path_case how = CASE_UNCHANGED);
154
155 } // namespace os
156 } // namespace support
157 } // namespace lyx
158
159 #endif