using namespace std;
namespace lyx {
+
+void emergencyCleanup();
+
namespace support {
namespace os {
string cygdrive = "/cygdrive";
+BOOL terminate_handler(DWORD event)
+{
+ if (event == CTRL_CLOSE_EVENT
+ || event == CTRL_LOGOFF_EVENT
+ || event == CTRL_SHUTDOWN_EVENT) {
+ lyx::emergencyCleanup();
+ return TRUE;
+ }
+ return FALSE;
+}
+
} // namespace anon
void init(int /* argc */, char * argv[])
if ((retVal == ERROR_SUCCESS) && (bufSize <= MAX_PATH))
cygdrive = rtrim(string(buf), "/");
}
+
+ // Catch shutdown events.
+ SetConsoleCtrlHandler((PHANDLER_ROUTINE)terminate_handler, TRUE);
}
}
+bool path_prefix_is(string const & path, string const & pre)
+{
+ return path_prefix_is(const_cast<string &>(path), pre, CASE_UNCHANGED);
+}
+
+
+bool path_prefix_is(string & path, string const & pre, path_case how)
+{
+ docstring const p1 = from_utf8(path);
+ docstring const p2 = from_utf8(pre);
+ docstring::size_type const p1_len = p1.length();
+ docstring::size_type const p2_len = p2.length();
+ docstring::size_type common_len = common_path(p1, p2);
+
+ if (p2[p2_len - 1] == '/' && p1_len != p2_len)
+ ++common_len;
+
+ if (common_len != p2_len)
+ return false;
+
+ if (how == CASE_ADJUSTED && !prefixIs(path, pre)) {
+ if (p1_len < common_len)
+ path = to_utf8(p2.substr(0, p1_len));
+ else
+ path = to_utf8(p2 + p1.substr(common_len,
+ p1_len - common_len));
+ }
+
+ return true;
+}
+
+
string external_path(string const & p)
{
string const dos_path = subst(p, "/", "\\");
}
-string const & stdoutdev()
-{
- static string const stdoutdev_ = "conout$";
- return stdoutdev_;
-}
-
-
-string const & stderrdev()
-{
- static string const stderrdev_ = "conout$";
- return stderrdev_;
-}
-
-
-bool terminal_output()
+bool is_terminal(io_channel channel)
{
- // FIXME: Passing conout$ to Qt fails, most probably for the
- // reason explained here:
- // http://support.microsoft.com/?scid=kb%3Ben-us%3B90088&x=15&y=15
- // How to convince Qt to open conout$ in FILE_SHARE_WRITE mode?
- // For the time being, we assume we are not running in a terminal.
- return false;
+ switch (channel) {
+ case STDIN:
+ if (GetStdHandle(STD_INPUT_HANDLE) == NULL)
+ return false;
+ break;
+ case STDOUT:
+ if (GetStdHandle(STD_OUTPUT_HANDLE) == NULL)
+ return false;
+ break;
+ case STDERR:
+ if (GetStdHandle(STD_ERROR_HANDLE) == NULL)
+ return false;
+ break;
+ }
+ return true;
}