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