annotate system/Init.cpp @ 659:cd1fa6387cb9

* Fix csv-one-file option
author Chris Cannam
date Mon, 18 Oct 2010 14:14:26 +0100
parents 29efe322ab47
children b0fde2a60188
rev   line source
Chris@404 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@404 2
Chris@404 3 /*
Chris@404 4 Sonic Visualiser
Chris@404 5 An audio file viewer and annotation editor.
Chris@404 6 Centre for Digital Music, Queen Mary, University of London.
Chris@404 7 This file copyright 2006 Chris Cannam.
Chris@404 8
Chris@404 9 This program is free software; you can redistribute it and/or
Chris@404 10 modify it under the terms of the GNU General Public License as
Chris@404 11 published by the Free Software Foundation; either version 2 of the
Chris@404 12 License, or (at your option) any later version. See the file
Chris@404 13 COPYING included with this distribution for more information.
Chris@404 14 */
Chris@404 15
Chris@404 16 #include <iostream>
Chris@404 17
Chris@658 18 #include <qglobal.h>
Chris@658 19
Chris@404 20 #ifdef Q_WS_X11
Chris@404 21 #include <X11/Xlib.h>
Chris@404 22 #include <X11/Xutil.h>
Chris@404 23 #include <X11/Xatom.h>
Chris@404 24 #include <X11/SM/SMlib.h>
Chris@404 25
Chris@404 26 static int handle_x11_error(Display *dpy, XErrorEvent *err)
Chris@404 27 {
Chris@404 28 char errstr[256];
Chris@404 29 XGetErrorText(dpy, err->error_code, errstr, 256);
Chris@404 30 if (err->error_code != BadWindow) {
Chris@404 31 std::cerr << "Sonic Visualiser: X Error: "
Chris@404 32 << errstr << " " << int(err->error_code)
Chris@404 33 << "\nin major opcode: "
Chris@404 34 << int(err->request_code) << std::endl;
Chris@404 35 }
Chris@404 36 return 0;
Chris@404 37 }
Chris@404 38 #endif
Chris@404 39
Chris@404 40 #ifdef Q_WS_WIN32
Chris@404 41
Chris@404 42 #include <fcntl.h>
Chris@658 43
Chris@658 44 // required for SetDllDirectory
Chris@658 45 #define _WIN32_WINNT 0x0502
Chris@404 46 #include <windows.h>
Chris@404 47
Chris@404 48 // Set default file open mode to binary
Chris@404 49 //#undef _fmode
Chris@404 50 //int _fmode = _O_BINARY;
Chris@404 51
Chris@404 52 void redirectStderr()
Chris@404 53 {
Chris@658 54 #ifdef NO_PROBABLY_NOT
Chris@404 55 HANDLE stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
Chris@404 56 if (!stderrHandle) return;
Chris@404 57
Chris@404 58 AllocConsole();
Chris@404 59
Chris@404 60 CONSOLE_SCREEN_BUFFER_INFO info;
Chris@404 61 GetConsoleScreenBufferInfo(stderrHandle, &info);
Chris@404 62 info.dwSize.Y = 1000;
Chris@404 63 SetConsoleScreenBufferSize(stderrHandle, info.dwSize);
Chris@404 64
Chris@404 65 int h = _open_osfhandle((long)stderrHandle, _O_TEXT);
Chris@404 66 if (h) {
Chris@404 67 FILE *fd = _fdopen(h, "w");
Chris@404 68 if (fd) {
Chris@404 69 *stderr = *fd;
Chris@404 70 setvbuf(stderr, NULL, _IONBF, 0);
Chris@404 71 }
Chris@404 72 }
Chris@658 73 #endif
Chris@404 74 }
Chris@404 75
Chris@404 76 #endif
Chris@404 77
Chris@404 78 extern void svSystemSpecificInitialisation()
Chris@404 79 {
Chris@404 80 #ifdef Q_WS_X11
Chris@404 81 XSetErrorHandler(handle_x11_error);
Chris@404 82 #endif
Chris@404 83
Chris@404 84 #ifdef Q_WS_WIN32
Chris@404 85 redirectStderr();
Chris@658 86
Chris@658 87 // Remove the CWD from the DLL search path, just in case
Chris@658 88 SetDllDirectory(L"");
Chris@658 89 putenv("PATH=");
Chris@404 90 #else
Chris@404 91 #endif
Chris@404 92 }
Chris@404 93
Chris@404 94
Chris@404 95