]> git.lyx.org Git - lyx.git/blob - src/support/os.h
New auto-open feature from Bo Peng (with help from Jean-Marc and Enrico)
[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 <string>
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 /// Extract the path common to both @c p1 and @c p2. DBCS aware!
42 std::string::size_type common_path(std::string const & p1, std::string const & p2);
43
44 /// Converts a unix style path to host OS style.
45 std::string external_path(std::string const & p);
46
47 /// Converts a host OS style path to unix style.
48 std::string internal_path(std::string const & p);
49
50 /// Converts a unix style path list to host OS style.
51 std::string external_path_list(std::string const & p);
52
53 /// Converts a host OS style path list to unix style.
54 std::string internal_path_list(std::string const & p);
55
56 /**
57  * Converts a unix style path into a form suitable for inclusion in a LaTeX
58  * document.
59  * Caution: This function handles only the OS specific part of that task.
60  * Never use it directly, use lyx::support::latex_path instead.
61  */
62 std::string latex_path(std::string const & p);
63
64 /// Is the path absolute?
65 bool is_absolute_path(std::string const & p);
66
67 /** Returns a string suitable to be passed to popen when
68  *  reading a file.
69  */
70 char const * popen_read_mode();
71
72 /** The character used to separate paths returned by the
73  *  PATH environment variable.
74  */
75 char path_separator();
76
77 /** If @c use_cygwin_paths is true, LyX will output cygwin style paths
78  *  rather than native Win32 ones. Obviously, this option is used only
79  *  under Cygwin.
80  */
81 void cygwin_path_fix(bool use_cygwin_paths);
82
83 enum auto_open_mode {
84         VIEW,
85         EDIT
86 };
87
88 /** Check whether or not a file can be viewed by a default viewer 
89  *  \param extension (without leading .)
90  *  \mode can be opened in VIEW or EDIT mode
91  *  \returns whether or not the format can be viewed
92  */
93 bool canAutoOpenFile(std::string const & ext, auto_open_mode const mode=VIEW);
94
95 /** view a file, with given command and parameter.
96  *  \param filename
97  *  \param mode open in VIEW or EDIT mode
98  *  \returns whether or not the file is viewed (or edited) successfully.
99  */
100 bool autoOpenFile(std::string const & filename, auto_open_mode const mode=VIEW);
101
102 } // namespace os
103 } // namespace support
104 } // namespace lyx
105
106 #endif