Add debug console window when debug mode is enabled to get any text messages on Windows.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2137 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2007-12-30 15:54:00 +00:00
parent 7746eee602
commit 347c1da00c
4 changed files with 74 additions and 1 deletions

View File

@ -4,6 +4,11 @@
Don't parse in comments and fix wrong creation of tags including
non-tag characters(e.g. '=' sign).
* src/document.c: Avoid crash on Windows with enabled debug messages.
* src/main.c, src/win32.c, src/win32.h:
Add debug console window when debug mode is enabled to get any text
messages on Windows.
Fix wrong argument in win32_check_write_permission()
(reported by Jeff Pohlmeyer, thanks).
2007-12-28 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>

View File

@ -471,6 +471,10 @@ static void parse_command_line_options(gint *argc, gchar ***argv)
app->debug_mode = debug_mode;
#endif
#ifdef G_OS_WIN32
win32_init_debug_code();
#endif
if (alternate_config)
{
geany_debug("alternate config: %s", alternate_config);

View File

@ -35,6 +35,7 @@
#include <commdlg.h>
#include <shlobj.h>
#include <io.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
@ -559,7 +560,8 @@ gboolean win32_message_dialog(GtkWidget *parent, GtkMessageType type, const gcha
gint win32_check_write_permission(const gchar *dir)
{
static wchar_t w_dir[512];
MultiByteToWideChar(CP_UTF8, 0, app->configdir, -1, w_dir, sizeof w_dir);
errno = 0; // to get sure it is clean
MultiByteToWideChar(CP_UTF8, 0, dir, -1, w_dir, sizeof w_dir);
_waccess(w_dir, R_OK | W_OK);
return errno;
}
@ -597,4 +599,63 @@ void win32_open_browser(const gchar *uri)
ShellExecute(NULL, "open", uri, NULL, NULL, SW_SHOWNORMAL);
}
static void debug_setup_console()
{
static const WORD MAX_CONSOLE_LINES = 500;
gint hConHandle;
glong lStdHandle;
CONSOLE_SCREEN_BUFFER_INFO coninfo;
FILE *fp;
// allocate a console for this app
AllocConsole();
// set the screen buffer to be big enough to let us scroll text
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
coninfo.dwSize.Y = MAX_CONSOLE_LINES;
SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
// redirect unbuffered STDOUT to the console
lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
fp = _fdopen(hConHandle, "w");
*stdout = *fp;
setvbuf(stdout, NULL, _IONBF, 0);
// redirect unbuffered STDERR to the console
lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
fp = _fdopen(hConHandle, "w");
*stderr = *fp;
setvbuf(stderr, NULL, _IONBF, 0);
}
static void debug_log_handler(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message,
gpointer user_data)
{
if (log_domain != NULL)
fprintf(stderr, "%s: %s\n", log_domain, message);
else
fprintf(stderr, "%s\n", message);
}
void win32_init_debug_code()
{
#ifndef GEANY_DEBUG
if (app->debug_mode)
#endif
{ // create a console window to get log messages on Windows
debug_setup_console();
// change the log handlers to output log messages in ther created console window
g_log_set_handler("GLib",
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, debug_log_handler, NULL);
g_log_set_default_handler(debug_log_handler, NULL);
}
}
#endif

View File

@ -55,4 +55,7 @@ gchar *win32_show_project_folder_dialog(GtkWidget *parent, const gchar *title,
gint win32_check_write_permission(const gchar *dir);
void win32_init_debug_code();
#endif