]> git.lyx.org Git - lyx.git/blob - src/support/os.h
Fix bug 3904
[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/docstring.h"
18
19
20 namespace lyx {
21 namespace support {
22 namespace os {
23
24 enum shell_type {
25         UNIX,   // Do we have to distinguish sh and csh?
26         CMD_EXE
27 };
28
29 /// Do some work just once.
30 void init(int argc, char * argv[]);
31
32 /// Returns the name of the NULL device (/dev/null, null).
33 std::string const & nulldev();
34
35 /// Returns "/" on *nix, "C:/", etc on Windows.
36 std::string current_root();
37
38 ///
39 shell_type shell();
40
41 /// Name of the python interpreter
42 std::string const python();
43
44 /// Extract the path common to both @c p1 and @c p2. DBCS aware!
45 /// \p p1, \p p2 and the return value are encoded in utf8.
46 docstring::size_type common_path(docstring const & p1, docstring const & p2);
47
48 /// Converts a unix style path to host OS style.
49 /// \p p and the return value are encoded in utf8.
50 std::string external_path(std::string const & p);
51
52 /// Converts a host OS style path to unix style.
53 /// \p p and the return value are encoded in utf8.
54 std::string internal_path(std::string const & p);
55
56 /// Converts a unix style path list to host OS style.
57 /// \p p and the return value are encoded in utf8.
58 std::string external_path_list(std::string const & p);
59
60 /// Converts a host OS style path list to unix style.
61 /// \p p and the return value are encoded in utf8.
62 std::string internal_path_list(std::string const & p);
63
64 /**
65  * Converts a unix style path into a form suitable for inclusion in a LaTeX
66  * document.
67  * \p p is encoded in utf8.
68  * Caution: This function handles only the OS specific part of that task.
69  * Never use it directly, use lyx::support::latex_path instead.
70  */
71 std::string latex_path(std::string const & p);
72
73 /// Is the path absolute?
74 /// \p p is encoded in utf8.
75 bool is_absolute_path(std::string const & p);
76
77 /** Returns a string suitable to be passed to popen when
78  *  reading a file.
79  */
80 char const * popen_read_mode();
81
82 /** The character used to separate paths returned by the
83  *  PATH environment variable.
84  */
85 char path_separator();
86
87 /** If @c use_windows_paths is true, LyX will output Windows-style paths to
88  *  latex files rather than posix ones. Obviously, this option is used only
89  *  under Windows.
90  */
91 void windows_style_tex_paths(bool use_windows_paths);
92
93 enum auto_open_mode {
94         VIEW,
95         EDIT
96 };
97
98 /** Check whether or not a file can be opened by a default viewer or editor.
99  *  \param extension (without leading .)
100  *  \param mode can be opened in VIEW or EDIT mode
101  *  \returns whether or not the format can be opened according to \p mode
102  */
103 bool canAutoOpenFile(std::string const & ext, auto_open_mode const mode = VIEW);
104
105 /** View or edit a file with the default viewer or editor.
106  *  \param filename file to open (encoded in utf8)
107  *  \param mode open in VIEW or EDIT mode
108  *  \returns whether or not the file is viewed (or edited) successfully.
109  */
110 bool autoOpenFile(std::string const & filename, auto_open_mode const mode = VIEW);
111
112 /** General font utilities.
113  *  FIXME: only MAC and WIN32 for now but it would be nice to convince
114  *  fontconfig to do the same for linux.
115  */
116
117 /// Add fonts to the font subsystem, must be called before Application
118 /// is initialized.
119 void addFontResources();
120
121 /// Restore original font resources, must be called after Application
122 /// is destroyed.
123 void restoreFontResources();
124
125 } // namespace os
126 } // namespace support
127 } // namespace lyx
128
129 #endif