]> git.lyx.org Git - lyx.git/blob - src/support/os.h
1644ef4bf001eac42a13bae957aa28999736e720
[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 /// Do some work just once.
37 void init(int argc, char * argv[]);
38
39 /// Returns the name of the NULL device (/dev/null, null).
40 std::string const & nulldev();
41
42 /// Returns the name of the stdout device (/dev/stdout, /dev/tty, conout$).
43 std::string const & stdoutdev();
44
45 /// Returns the name of the stderr device (/dev/stderr, /dev/tty, conout$).
46 std::string const & stderrdev();
47
48 /// Tells whether \p channel is connected to a terminal or not. 
49 bool is_terminal(io_channel channel);
50
51 /// Returns "/" on *nix, "C:/", etc on Windows.
52 std::string current_root();
53
54 ///
55 shell_type shell();
56
57 /// Name of the python interpreter
58 std::string const python();
59
60 ///
61 bool isFilesystemCaseSensitive();
62
63 /// Extract the path common to both @c p1 and @c p2. DBCS aware!
64 /// \p p1, \p p2 and the return value are encoded in utf8.
65 std::size_t common_path(docstring const & p1, docstring const & p2);
66
67 /// Converts a unix style path to host OS style.
68 /// \p p and the return value are encoded in utf8.
69 std::string external_path(std::string const & p);
70
71 /// Converts a host OS style path to unix style.
72 /// \p p and the return value are encoded in utf8.
73 std::string internal_path(std::string const & p);
74
75 /// Converts a unix style path list to host OS style.
76 /// \p p and the return value are encoded in utf8.
77 std::string external_path_list(std::string const & p);
78
79 /// Converts a host OS style path list to unix style.
80 /// \p p and the return value are encoded in utf8.
81 std::string internal_path_list(std::string const & p);
82
83 /**
84  * Converts a unix style path into a form suitable for inclusion in a LaTeX
85  * document.
86  * \p p is encoded in utf8.
87  * Caution: This function handles only the OS specific part of that task.
88  * Never use it directly, use lyx::support::latex_path instead.
89  */
90 std::string latex_path(std::string const & p);
91
92 /// Checks if the format string is suitable on the OS
93 bool is_valid_strftime(std::string const & p);
94
95 /** Returns a string suitable to be passed to popen when
96  *  reading a file.
97  */
98 char const * popen_read_mode();
99
100 /** The character used to separate paths returned by the
101  *  PATH environment variable.
102  */
103 char path_separator();
104
105 /** If @c use_windows_paths is true, LyX will output Windows-style paths to
106  *  latex files rather than posix ones. Obviously, this option is used only
107  *  under Windows.
108  */
109 void windows_style_tex_paths(bool use_windows_paths);
110
111 enum auto_open_mode {
112         VIEW,
113         EDIT
114 };
115
116 /** Check whether or not a file can be opened by a default viewer or editor.
117  *  \param extension (without leading .)
118  *  \param mode can be opened in VIEW or EDIT mode
119  *  \returns whether or not the format can be opened according to \p mode
120  */
121 bool canAutoOpenFile(std::string const & ext, auto_open_mode const mode = VIEW);
122
123 /** View or edit a file with the default viewer or editor.
124  *  \param filename file to open (encoded in utf8)
125  *  \param mode open in VIEW or EDIT mode
126  *  \returns whether or not the file is viewed (or edited) successfully.
127  */
128 bool autoOpenFile(std::string const & filename, auto_open_mode const mode = VIEW);
129
130 /** Resolves a path such that it does not contain '.', '..', or symbolic links.
131   * \warning the path must already be in the filesystem encoding.
132   * \returns the resolved path in utf8 encoding.
133   */
134 std::string real_path(std::string const & path);
135
136 } // namespace os
137 } // namespace support
138 } // namespace lyx
139
140 #endif