diff options
author | Pascal Quantin <pascal.quantin@gmail.com> | 2012-10-21 19:12:18 +0000 |
---|---|---|
committer | Pascal Quantin <pascal.quantin@gmail.com> | 2012-10-21 19:12:18 +0000 |
commit | b439ae0d6a482293f4fb2f34c5ef67a91479d6fc (patch) | |
tree | ec67d9ff68b8ed79c50c5ab14e35f359289534bd /ui/win32 | |
parent | 5af3defc46eb97c75521543274705518bbc0b3f4 (diff) |
Revert r45692 and try to fix link failure another way: console_win32.[ch] definitely belong to ui/win32
Add console_win32.[ch] to Makefile.am
svn path=/trunk/; revision=45693
Diffstat (limited to 'ui/win32')
-rw-r--r-- | ui/win32/Makefile.nmake | 1 | ||||
-rw-r--r-- | ui/win32/console_win32.c | 171 | ||||
-rw-r--r-- | ui/win32/console_win32.h | 92 |
3 files changed, 264 insertions, 0 deletions
diff --git a/ui/win32/Makefile.nmake b/ui/win32/Makefile.nmake index ab51cd2286..aa55a5206e 100644 --- a/ui/win32/Makefile.nmake +++ b/ui/win32/Makefile.nmake @@ -20,6 +20,7 @@ CFLAGS=$(WARNINGS_ARE_ERRORS) $(STANDARD_CFLAGS) \ # if you add files here, be sure to include them also in Makefile.am EXTRA_DIST in the main Wireshark directory WIRESHARK_WIN32_SRC = \ + console_win32.c \ file_dlg_win32.c \ print_win32.c \ diff --git a/ui/win32/console_win32.c b/ui/win32/console_win32.c new file mode 100644 index 0000000000..700105c446 --- /dev/null +++ b/ui/win32/console_win32.c @@ -0,0 +1,171 @@ +/* console_win32.c + * Console support for MSWindows + * + * $Id: console_win32.c 45689 2012-10-21 15:04:50Z alagoutte $ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 2002, Jeffrey C. Foster <jfoste@woodward.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * + */ + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +#include <glib.h> +#include <wsutil/file_util.h> + +#include "console_win32.h" +#include "../../console_io.h" + +#ifdef _WIN32 /* Needed for console I/O */ +#if _MSC_VER < 1500 +/* AttachConsole() needs this #define! */ +#define _WIN32_WINNT 0x0501 +#endif +#include <fcntl.h> +#include <conio.h> +#include <windows.h> +#include <tchar.h> +#endif + +#ifdef _WIN32 +static gboolean has_console; /* TRUE if app has console */ +static gboolean console_wait; /* "Press any key..." */ +static gboolean stdin_capture = FALSE; /* Don't grab stdin & stdout if TRUE */ +#endif + +#ifdef _WIN32 +/* The code to create and desstroy console windows should not be necessary, + at least as I read the GLib source code, as it looks as if GLib is, on + Win32, *supposed* to create a console window into which to display its + output. + + That doesn't happen, however. I suspect there's something completely + broken about that code in GLib-for-Win32, and that it may be related + to the breakage that forces us to just call "printf()" on the message + rather than passing the message on to "g_log_default_handler()" + (which is the routine that does the aforementioned non-functional + console window creation). */ + +/* + * If this application has no console window to which its standard output + * would go, create one. + */ +void +create_console(void) +{ + if (stdin_capture) { + /* We've been handed "-i -". Don't mess with stdio. */ + return; + } + + if (!has_console) { + /* We have no console to which to print the version string, so + create one and make it the standard input, output, and error. */ + + /* + * See if we have an existing console (i.e. we were run from a + * command prompt) + */ + if (!AttachConsole(ATTACH_PARENT_PROCESS)) { + if (AllocConsole()) { + console_wait = TRUE; + SetConsoleTitle(_T("Wireshark Debug Console")); + } else { + return; /* couldn't create console */ + } + } + + ws_freopen("CONIN$", "r", stdin); + ws_freopen("CONOUT$", "w", stdout); + ws_freopen("CONOUT$", "w", stderr); + fprintf(stdout, "\n"); + fprintf(stderr, "\n"); + + /* Now register "destroy_console()" as a routine to be called just + before the application exits, so that we can destroy the console + after the user has typed a key (so that the console doesn't just + disappear out from under them, giving the user no chance to see + the message(s) we put in there). */ + atexit(destroy_console); + + /* Well, we have a console now. */ + has_console = TRUE; + } +} + +void +destroy_console(void) +{ + if (console_wait) { + printf("\n\nPress any key to exit\n"); + _getch(); + } + FreeConsole(); +} + +void +set_console_wait(gboolean set_console_wait) +{ + console_wait = set_console_wait; +} +gboolean +get_console_wait(void) +{ + return console_wait; +} + +void +set_has_console(gboolean set_has_console) +{ + has_console = has_console; +} + +gboolean +get_has_console(void) +{ + return has_console; +} + +void +set_stdin_capture(gboolean set_stdin_capture) +{ + stdin_capture = set_stdin_capture; +} + +gboolean +get_stdin_capture(void) +{ + return stdin_capture; +} +#endif /* _WIN32 */ + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 2 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=2 tabstop=8 expandtab: + * :indentSize=2:tabSize=8:noTabs=true: + */ diff --git a/ui/win32/console_win32.h b/ui/win32/console_win32.h new file mode 100644 index 0000000000..bc4c61e80e --- /dev/null +++ b/ui/win32/console_win32.h @@ -0,0 +1,92 @@ +/* console_win32.h + * Console support for MSWindows + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * Copyright 2002, Jeffrey C. Foster <jfoste@woodward.com> + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __CONSOLE_WIN32_H__ +#define __CONSOLE_WIN32_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifdef _WIN32 + +/** @file + * Win32 specific console. + */ + +/** Create Windows console. + * + */ +void create_console(void); + +/** Destroy Windows console. + * + */ +void destroy_console(void); + +/** Set console wait. + * @param console_wait set/no set console wait + */ +void set_console_wait(gboolean console_wait); +/** get console wait + * @return set/no set console wait + */ +gboolean get_console_wait(void); + +/** Set has console. + * @param has_console set/no set has_console + */ +void set_has_console(gboolean has_console); + +gboolean get_has_console(void); + +/** Set stdin capture. + * @param console_wait set/no stdin_capture + */ +void set_stdin_capture(gboolean set_stdin_capture); + +/** get stdin caputre + * @return set/no set stdin_capture + */ +gboolean get_stdin_capture(void); +#endif/* _WIN32 */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __CONSOLE_WIN32_H__ */ + +/* + * Editor modelines + * + * Local Variables: + * c-basic-offset: 2 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * ex: set shiftwidth=2 tabstop=8 expandtab: + * :indentSize=2:tabSize=8:noTabs=true: + */ |