annotate system/Init.cpp @ 622:43b0bfd07bd3

* Fix potential static initialiser race (FileFinder vs InteractiveFileFinder instance pointers)
author Chris Cannam
date Fri, 12 Mar 2010 14:53:44 +0000
parents 4884fba80e00
children 29efe322ab47
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@404 18 #ifdef Q_WS_X11
Chris@404 19 #include <X11/Xlib.h>
Chris@404 20 #include <X11/Xutil.h>
Chris@404 21 #include <X11/Xatom.h>
Chris@404 22 #include <X11/SM/SMlib.h>
Chris@404 23
Chris@404 24 static int handle_x11_error(Display *dpy, XErrorEvent *err)
Chris@404 25 {
Chris@404 26 char errstr[256];
Chris@404 27 XGetErrorText(dpy, err->error_code, errstr, 256);
Chris@404 28 if (err->error_code != BadWindow) {
Chris@404 29 std::cerr << "Sonic Visualiser: X Error: "
Chris@404 30 << errstr << " " << int(err->error_code)
Chris@404 31 << "\nin major opcode: "
Chris@404 32 << int(err->request_code) << std::endl;
Chris@404 33 }
Chris@404 34 return 0;
Chris@404 35 }
Chris@404 36 #endif
Chris@404 37
Chris@404 38 #ifdef Q_WS_WIN32
Chris@404 39
Chris@404 40 #include <fcntl.h>
Chris@404 41 #include <windows.h>
Chris@404 42
Chris@404 43 // Set default file open mode to binary
Chris@404 44 //#undef _fmode
Chris@404 45 //int _fmode = _O_BINARY;
Chris@404 46
Chris@404 47 void redirectStderr()
Chris@404 48 {
Chris@404 49 HANDLE stderrHandle = GetStdHandle(STD_ERROR_HANDLE);
Chris@404 50 if (!stderrHandle) return;
Chris@404 51
Chris@404 52 AllocConsole();
Chris@404 53
Chris@404 54 CONSOLE_SCREEN_BUFFER_INFO info;
Chris@404 55 GetConsoleScreenBufferInfo(stderrHandle, &info);
Chris@404 56 info.dwSize.Y = 1000;
Chris@404 57 SetConsoleScreenBufferSize(stderrHandle, info.dwSize);
Chris@404 58
Chris@404 59 int h = _open_osfhandle((long)stderrHandle, _O_TEXT);
Chris@404 60 if (h) {
Chris@404 61 FILE *fd = _fdopen(h, "w");
Chris@404 62 if (fd) {
Chris@404 63 *stderr = *fd;
Chris@404 64 setvbuf(stderr, NULL, _IONBF, 0);
Chris@404 65 }
Chris@404 66 }
Chris@404 67 }
Chris@404 68
Chris@404 69 #endif
Chris@404 70
Chris@404 71 extern void svSystemSpecificInitialisation()
Chris@404 72 {
Chris@404 73 #ifdef Q_WS_X11
Chris@404 74 XSetErrorHandler(handle_x11_error);
Chris@404 75 #endif
Chris@404 76
Chris@404 77 #ifdef Q_WS_WIN32
Chris@404 78 redirectStderr();
Chris@404 79 #else
Chris@404 80 #endif
Chris@404 81 }
Chris@404 82
Chris@404 83
Chris@404 84