annotate system/Init.cpp @ 394:44d1e22918f3

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