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