2001-11-30 19:46:42 +01:00
|
|
|
/*
|
2004-09-08 03:25:05 +02:00
|
|
|
* Win32 console functions
|
2001-11-30 19:46:42 +01:00
|
|
|
*
|
|
|
|
* Copyright 1995 Martin von Loewis and Cameron Heide
|
|
|
|
* Copyright 1997 Karl Garrison
|
|
|
|
* Copyright 1998 John Richardson
|
|
|
|
* Copyright 1998 Marcus Meissner
|
2011-01-18 22:02:37 +01:00
|
|
|
* Copyright 2001,2002,2004,2005,2010 Eric Pouech
|
2001-11-30 19:46:42 +01:00
|
|
|
* Copyright 2001 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-11-30 19:46:42 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Reference applications:
|
|
|
|
* - IDA (interactive disassembler) full version 3.75. Works.
|
|
|
|
* - LYNX/W32. Works mostly, some keys crash it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2002-07-31 21:20:28 +02:00
|
|
|
#include "wine/port.h"
|
2001-11-30 19:46:42 +01:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2001-11-30 19:46:42 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2014-04-16 10:09:02 +02:00
|
|
|
#include <limits.h>
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2001-11-30 19:46:42 +01:00
|
|
|
#include <assert.h>
|
2010-08-30 22:19:24 +02:00
|
|
|
#ifdef HAVE_TERMIOS_H
|
|
|
|
# include <termios.h>
|
|
|
|
#endif
|
2010-12-12 22:31:32 +01:00
|
|
|
#ifdef HAVE_SYS_POLL_H
|
|
|
|
# include <sys/poll.h>
|
|
|
|
#endif
|
2001-11-30 19:46:42 +01:00
|
|
|
|
2011-08-03 18:07:09 +02:00
|
|
|
#define NONAMELESSUNION
|
2010-09-10 21:50:19 +02:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2001-11-30 19:46:42 +01:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wincon.h"
|
|
|
|
#include "wine/server.h"
|
|
|
|
#include "wine/exception.h"
|
|
|
|
#include "wine/unicode.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2002-12-13 00:34:01 +01:00
|
|
|
#include "excpt.h"
|
2002-09-04 20:41:03 +02:00
|
|
|
#include "console_private.h"
|
2003-06-21 04:07:10 +02:00
|
|
|
#include "kernel_private.h"
|
2001-11-30 19:46:42 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(console);
|
2001-11-30 19:46:42 +01:00
|
|
|
|
2007-12-02 22:12:19 +01:00
|
|
|
static CRITICAL_SECTION CONSOLE_CritSect;
|
|
|
|
static CRITICAL_SECTION_DEBUG critsect_debug =
|
|
|
|
{
|
|
|
|
0, 0, &CONSOLE_CritSect,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": CONSOLE_CritSect") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION CONSOLE_CritSect = { &critsect_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2005-06-27 11:54:09 +02:00
|
|
|
static const WCHAR coninW[] = {'C','O','N','I','N','$',0};
|
|
|
|
static const WCHAR conoutW[] = {'C','O','N','O','U','T','$',0};
|
2003-06-21 04:07:10 +02:00
|
|
|
|
2007-12-20 13:19:10 +01:00
|
|
|
/* FIXME: this is not thread safe */
|
|
|
|
static HANDLE console_wait_event;
|
|
|
|
|
2019-12-12 12:03:47 +01:00
|
|
|
/* map input records to ASCII */
|
|
|
|
static void input_records_WtoA( INPUT_RECORD *buffer, int count )
|
|
|
|
{
|
|
|
|
UINT cp = GetConsoleCP();
|
|
|
|
int i;
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (buffer[i].EventType != KEY_EVENT) continue;
|
|
|
|
WideCharToMultiByte( cp, 0, &buffer[i].Event.KeyEvent.uChar.UnicodeChar, 1, &ch, 1, NULL, NULL );
|
|
|
|
buffer[i].Event.KeyEvent.uChar.AsciiChar = ch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-10 21:50:19 +02:00
|
|
|
static struct termios S_termios; /* saved termios for bare consoles */
|
|
|
|
static BOOL S_termios_raw /* = FALSE */;
|
|
|
|
|
|
|
|
/* The scheme for bare consoles for managing raw/cooked settings is as follows:
|
|
|
|
* - a bare console is created for all CUI programs started from command line (without
|
|
|
|
* wineconsole) (let's call those PS)
|
|
|
|
* - of course, every child of a PS which requires console inheritance will get it
|
|
|
|
* - the console termios attributes are saved at the start of program which is attached to be
|
|
|
|
* bare console
|
|
|
|
* - if any program attached to a bare console requests input from console, the console is
|
|
|
|
* turned into raw mode
|
|
|
|
* - when the program which created the bare console (the program started from command line)
|
|
|
|
* exits, it will restore the console termios attributes it saved at startup (this
|
|
|
|
* will put back the console into cooked mode if it had been put in raw mode)
|
|
|
|
* - if any other program attached to this bare console is still alive, the Unix shell will put
|
|
|
|
* it in the background, hence forbidding access to the console. Therefore, reading console
|
|
|
|
* input will not be available when the bare console creator has died.
|
|
|
|
* FIXME: This is a limitation of current implementation
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* returns the fd for a bare console (-1 otherwise) */
|
|
|
|
static int get_console_bare_fd(HANDLE hin)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
2012-02-17 21:57:38 +01:00
|
|
|
if (is_console_handle(hin) &&
|
|
|
|
wine_server_handle_to_fd(wine_server_ptr_handle(console_handle_unmap(hin)),
|
2010-11-11 22:30:11 +01:00
|
|
|
0, &fd, NULL) == STATUS_SUCCESS)
|
2010-09-10 21:50:19 +02:00
|
|
|
return fd;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL save_console_mode(HANDLE hin)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if ((fd = get_console_bare_fd(hin)) == -1) return FALSE;
|
|
|
|
ret = tcgetattr(fd, &S_termios) >= 0;
|
|
|
|
close(fd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-07 19:14:46 +01:00
|
|
|
static BOOL put_console_into_raw_mode(int fd)
|
2010-09-10 21:50:19 +02:00
|
|
|
{
|
|
|
|
RtlEnterCriticalSection(&CONSOLE_CritSect);
|
|
|
|
if (!S_termios_raw)
|
|
|
|
{
|
|
|
|
struct termios term = S_termios;
|
|
|
|
|
|
|
|
term.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
|
|
|
|
term.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
|
|
|
|
term.c_cflag &= ~(CSIZE | PARENB);
|
|
|
|
term.c_cflag |= CS8;
|
|
|
|
/* FIXME: we should actually disable output processing here
|
|
|
|
* and let kernel32/console.c do the job (with support of enable/disable of
|
|
|
|
* processed output)
|
|
|
|
*/
|
|
|
|
/* term.c_oflag &= ~(OPOST); */
|
|
|
|
term.c_cc[VMIN] = 1;
|
|
|
|
term.c_cc[VTIME] = 0;
|
|
|
|
S_termios_raw = tcsetattr(fd, TCSANOW, &term) >= 0;
|
|
|
|
}
|
|
|
|
RtlLeaveCriticalSection(&CONSOLE_CritSect);
|
|
|
|
|
|
|
|
return S_termios_raw;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* put back the console in cooked mode iff we're the process which created the bare console
|
2011-07-27 13:38:43 +02:00
|
|
|
* we don't test if this process has set the console in raw mode as it could be one of its
|
|
|
|
* children who did it
|
2010-09-10 21:50:19 +02:00
|
|
|
*/
|
|
|
|
static BOOL restore_console_mode(HANDLE hin)
|
|
|
|
{
|
|
|
|
int fd;
|
2015-11-17 16:41:43 +01:00
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
|
|
|
if (S_termios_raw)
|
|
|
|
{
|
|
|
|
if ((fd = get_console_bare_fd(hin)) == -1) return FALSE;
|
|
|
|
ret = tcsetattr(fd, TCSANOW, &S_termios) >= 0;
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RtlGetCurrentPeb()->ProcessParameters->ConsoleHandle == KERNEL32_CONSOLE_SHELL)
|
|
|
|
TERM_Exit();
|
2010-09-10 21:50:19 +02:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-04-02 21:18:51 +02:00
|
|
|
/******************************************************************************
|
2007-01-18 08:53:39 +01:00
|
|
|
* GetConsoleWindow [KERNEL32.@] Get hwnd of the console window.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: hwnd of the console window.
|
|
|
|
* Failure: NULL
|
2004-04-02 21:18:51 +02:00
|
|
|
*/
|
|
|
|
HWND WINAPI GetConsoleWindow(VOID)
|
|
|
|
{
|
2007-08-23 17:17:17 +02:00
|
|
|
HWND hWnd = NULL;
|
|
|
|
|
|
|
|
SERVER_START_REQ(get_console_input_info)
|
|
|
|
{
|
|
|
|
req->handle = 0;
|
2008-12-08 16:58:20 +01:00
|
|
|
if (!wine_server_call_err(req)) hWnd = wine_server_ptr_handle( reply->win );
|
2007-08-23 17:17:17 +02:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
return hWnd;
|
2004-04-02 21:18:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 06:24:49 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* Beep (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI Beep( DWORD dwFreq, DWORD dwDur )
|
|
|
|
{
|
|
|
|
static const char beep = '\a';
|
|
|
|
/* dwFreq and dwDur are ignored by Win95 */
|
|
|
|
if (isatty(2)) write( 2, &beep, 1 );
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-12-12 05:10:52 +01:00
|
|
|
/******************************************************************
|
|
|
|
* OpenConsoleW (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Undocumented
|
|
|
|
* Open a handle to the current process console.
|
|
|
|
* Returns INVALID_HANDLE_VALUE on failure.
|
|
|
|
*/
|
2004-03-11 23:46:27 +01:00
|
|
|
HANDLE WINAPI OpenConsoleW(LPCWSTR name, DWORD access, BOOL inherit, DWORD creation)
|
2003-12-12 05:10:52 +01:00
|
|
|
{
|
2020-06-25 22:27:51 +02:00
|
|
|
SECURITY_ATTRIBUTES sa;
|
2003-12-12 05:10:52 +01:00
|
|
|
|
2010-04-01 02:53:59 +02:00
|
|
|
TRACE("(%s, 0x%08x, %d, %u)\n", debugstr_w(name), access, inherit, creation);
|
|
|
|
|
2020-06-25 22:27:51 +02:00
|
|
|
if (!name || (strcmpiW( coninW, name ) && strcmpiW( conoutW, name )) || creation != OPEN_EXISTING)
|
2003-12-12 05:10:52 +01:00
|
|
|
{
|
2020-06-25 22:27:51 +02:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2003-12-12 05:10:52 +01:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2010-04-01 02:53:59 +02:00
|
|
|
}
|
2003-12-12 05:10:52 +01:00
|
|
|
|
2020-06-25 22:27:51 +02:00
|
|
|
sa.nLength = sizeof(sa);
|
|
|
|
sa.lpSecurityDescriptor = NULL;
|
|
|
|
sa.bInheritHandle = inherit;
|
2010-08-30 22:19:39 +02:00
|
|
|
|
2020-06-25 22:27:51 +02:00
|
|
|
return CreateFileW( name, access, FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, creation, 0, NULL );
|
2003-12-12 05:10:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* VerifyConsoleIoHandle (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Undocumented
|
|
|
|
*/
|
|
|
|
BOOL WINAPI VerifyConsoleIoHandle(HANDLE handle)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!is_console_handle(handle)) return FALSE;
|
|
|
|
SERVER_START_REQ(get_console_mode)
|
|
|
|
{
|
|
|
|
req->handle = console_handle_unmap(handle);
|
2010-09-22 19:54:36 +02:00
|
|
|
ret = !wine_server_call( req );
|
2003-12-12 05:10:52 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* DuplicateConsoleHandle (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Undocumented
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI DuplicateConsoleHandle(HANDLE handle, DWORD access, BOOL inherit,
|
|
|
|
DWORD options)
|
|
|
|
{
|
|
|
|
HANDLE ret;
|
|
|
|
|
|
|
|
if (!is_console_handle(handle) ||
|
2008-12-08 16:05:17 +01:00
|
|
|
!DuplicateHandle(GetCurrentProcess(), wine_server_ptr_handle(console_handle_unmap(handle)),
|
2003-12-12 05:10:52 +01:00
|
|
|
GetCurrentProcess(), &ret, access, inherit, options))
|
|
|
|
return INVALID_HANDLE_VALUE;
|
|
|
|
return console_handle_map(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* CloseConsoleHandle (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Undocumented
|
|
|
|
*/
|
|
|
|
BOOL WINAPI CloseConsoleHandle(HANDLE handle)
|
|
|
|
{
|
|
|
|
if (!is_console_handle(handle))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-12-08 16:05:17 +01:00
|
|
|
return CloseHandle(wine_server_ptr_handle(console_handle_unmap(handle)));
|
2003-12-12 05:10:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetConsoleInputWaitHandle (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Undocumented
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI GetConsoleInputWaitHandle(void)
|
|
|
|
{
|
|
|
|
if (!console_wait_event)
|
|
|
|
{
|
|
|
|
SERVER_START_REQ(get_console_wait_event)
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
if (!wine_server_call_err( req ))
|
2019-12-12 11:46:39 +01:00
|
|
|
console_wait_event = wine_server_ptr_handle( reply->event );
|
2003-12-12 05:10:52 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
|
|
|
return console_wait_event;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-21 04:07:10 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* read_console_input
|
|
|
|
*
|
|
|
|
* Helper function for ReadConsole, ReadConsoleInput and FlushConsoleInputBuffer
|
|
|
|
*
|
2010-08-30 22:19:24 +02:00
|
|
|
* Returns
|
2003-06-21 04:07:10 +02:00
|
|
|
* 0 for error, 1 for no INPUT_RECORD ready, 2 with INPUT_RECORD ready
|
2001-11-30 19:46:42 +01:00
|
|
|
*/
|
2003-06-21 04:07:10 +02:00
|
|
|
enum read_console_input_return {rci_error = 0, rci_timeout = 1, rci_gotone = 2};
|
2010-08-30 22:19:24 +02:00
|
|
|
|
2010-12-12 22:31:32 +01:00
|
|
|
static enum read_console_input_return bare_console_fetch_input(HANDLE handle, int fd, DWORD timeout)
|
2010-08-30 22:19:24 +02:00
|
|
|
{
|
2011-01-18 22:02:37 +01:00
|
|
|
enum read_console_input_return ret;
|
|
|
|
char input[8];
|
2011-01-24 22:13:32 +01:00
|
|
|
WCHAR inputw[8];
|
2011-01-18 22:02:37 +01:00
|
|
|
int i;
|
2011-01-24 22:13:32 +01:00
|
|
|
size_t idx = 0, idxw;
|
2011-01-18 22:02:37 +01:00
|
|
|
unsigned numEvent;
|
|
|
|
INPUT_RECORD ir[8];
|
|
|
|
DWORD written;
|
|
|
|
struct pollfd pollfd;
|
|
|
|
BOOL locked = FALSE, next_char;
|
|
|
|
|
|
|
|
do
|
2010-08-30 22:19:24 +02:00
|
|
|
{
|
2011-01-18 22:02:37 +01:00
|
|
|
if (idx == sizeof(input))
|
|
|
|
{
|
|
|
|
FIXME("buffer too small (%s)\n", wine_dbgstr_an(input, idx));
|
|
|
|
ret = rci_error;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pollfd.fd = fd;
|
|
|
|
pollfd.events = POLLIN;
|
|
|
|
pollfd.revents = 0;
|
|
|
|
next_char = FALSE;
|
|
|
|
|
|
|
|
switch (poll(&pollfd, 1, timeout))
|
2010-12-12 22:31:32 +01:00
|
|
|
{
|
2011-01-18 22:02:31 +01:00
|
|
|
case 1:
|
2011-01-18 22:02:37 +01:00
|
|
|
if (!locked)
|
|
|
|
{
|
|
|
|
RtlEnterCriticalSection(&CONSOLE_CritSect);
|
|
|
|
locked = TRUE;
|
|
|
|
}
|
|
|
|
i = read(fd, &input[idx], 1);
|
|
|
|
if (i < 0)
|
|
|
|
{
|
|
|
|
ret = rci_error;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
/* actually another thread likely beat us to reading the char
|
|
|
|
* return rci_gotone, while not perfect, it should work in most of the cases (as the new event
|
|
|
|
* should be now in the queue, fed from the other thread)
|
|
|
|
*/
|
|
|
|
ret = rci_gotone;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
idx++;
|
|
|
|
numEvent = TERM_FillInputRecord(input, idx, ir);
|
|
|
|
switch (numEvent)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
/* we need more char(s) to tell if it matches a key-db entry. wait 1/2s for next char */
|
|
|
|
timeout = 500;
|
|
|
|
next_char = TRUE;
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
/* we haven't found the string into key-db, push full input string into server */
|
2018-07-30 21:18:09 +02:00
|
|
|
idxw = MultiByteToWideChar(CP_UNIXCP, 0, input, idx, inputw, ARRAY_SIZE(inputw));
|
2011-01-24 22:13:32 +01:00
|
|
|
|
|
|
|
/* we cannot translate yet... likely we need more chars (wait max 1/2s for next char) */
|
|
|
|
if (idxw == 0)
|
|
|
|
{
|
|
|
|
timeout = 500;
|
|
|
|
next_char = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (i = 0; i < idxw; i++)
|
2011-01-18 22:02:37 +01:00
|
|
|
{
|
2011-01-24 22:13:32 +01:00
|
|
|
numEvent = TERM_FillSimpleChar(inputw[i], ir);
|
2011-01-18 22:02:37 +01:00
|
|
|
WriteConsoleInputW(handle, ir, numEvent, &written);
|
|
|
|
}
|
2011-01-24 22:13:32 +01:00
|
|
|
ret = rci_gotone;
|
2011-01-18 22:02:37 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* we got a transformation from key-db... push this into server */
|
|
|
|
ret = WriteConsoleInputW(handle, ir, numEvent, &written) ? rci_gotone : rci_error;
|
|
|
|
break;
|
|
|
|
}
|
2011-01-18 22:02:31 +01:00
|
|
|
break;
|
2011-01-18 22:02:37 +01:00
|
|
|
case 0: ret = rci_timeout; break;
|
2010-12-12 22:31:32 +01:00
|
|
|
default: ret = rci_error; break;
|
|
|
|
}
|
2011-01-18 22:02:37 +01:00
|
|
|
} while (next_char);
|
|
|
|
if (locked) RtlLeaveCriticalSection(&CONSOLE_CritSect);
|
|
|
|
|
|
|
|
return ret;
|
2010-08-30 22:19:24 +02:00
|
|
|
}
|
|
|
|
|
2004-05-05 07:54:44 +02:00
|
|
|
static enum read_console_input_return read_console_input(HANDLE handle, PINPUT_RECORD ir, DWORD timeout)
|
2001-11-30 19:46:42 +01:00
|
|
|
{
|
2010-11-07 19:14:46 +01:00
|
|
|
int fd;
|
2003-06-21 04:07:10 +02:00
|
|
|
enum read_console_input_return ret;
|
|
|
|
|
2010-11-07 19:14:46 +01:00
|
|
|
if ((fd = get_console_bare_fd(handle)) != -1)
|
2010-08-30 22:19:24 +02:00
|
|
|
{
|
2010-11-07 19:14:46 +01:00
|
|
|
put_console_into_raw_mode(fd);
|
2010-08-30 22:19:24 +02:00
|
|
|
if (WaitForSingleObject(GetConsoleInputWaitHandle(), 0) != WAIT_OBJECT_0)
|
|
|
|
{
|
2010-12-12 22:31:32 +01:00
|
|
|
ret = bare_console_fetch_input(handle, fd, timeout);
|
2010-08-30 22:19:24 +02:00
|
|
|
}
|
2010-12-12 22:31:32 +01:00
|
|
|
else ret = rci_gotone;
|
|
|
|
close(fd);
|
|
|
|
if (ret != rci_gotone) return ret;
|
2010-08-30 22:19:24 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-11-07 19:15:01 +01:00
|
|
|
if (!VerifyConsoleIoHandle(handle)) return rci_error;
|
2010-11-07 19:14:46 +01:00
|
|
|
|
2010-08-30 22:19:24 +02:00
|
|
|
if (WaitForSingleObject(GetConsoleInputWaitHandle(), timeout) != WAIT_OBJECT_0)
|
|
|
|
return rci_timeout;
|
|
|
|
}
|
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
SERVER_START_REQ( read_console_input )
|
|
|
|
{
|
2003-06-21 04:07:10 +02:00
|
|
|
req->handle = console_handle_unmap(handle);
|
|
|
|
req->flush = TRUE;
|
|
|
|
wine_server_set_reply( req, ir, sizeof(INPUT_RECORD) );
|
|
|
|
if (wine_server_call_err( req ) || !reply->read) ret = rci_error;
|
|
|
|
else ret = rci_gotone;
|
2001-11-30 19:46:42 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
2003-06-21 04:07:10 +02:00
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-21 04:07:10 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* FlushConsoleInputBuffer (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI FlushConsoleInputBuffer( HANDLE handle )
|
|
|
|
{
|
|
|
|
enum read_console_input_return last;
|
|
|
|
INPUT_RECORD ir;
|
|
|
|
|
|
|
|
while ((last = read_console_input(handle, &ir, 0)) == rci_gotone);
|
|
|
|
|
|
|
|
return last == rci_timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-30 19:46:42 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* SetConsoleTitleA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetConsoleTitleA( LPCSTR title )
|
|
|
|
{
|
|
|
|
LPWSTR titleW;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
DWORD len = MultiByteToWideChar( GetConsoleOutputCP(), 0, title, -1, NULL, 0 );
|
|
|
|
if (!(titleW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)))) return FALSE;
|
|
|
|
MultiByteToWideChar( GetConsoleOutputCP(), 0, title, -1, titleW, len );
|
|
|
|
ret = SetConsoleTitleW(titleW);
|
|
|
|
HeapFree(GetProcessHeap(), 0, titleW);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-11-11 19:28:00 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetConsoleKeyboardLayoutNameA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetConsoleKeyboardLayoutNameA(LPSTR layoutName)
|
|
|
|
{
|
|
|
|
FIXME( "stub %p\n", layoutName);
|
2019-09-09 22:17:58 +02:00
|
|
|
return TRUE;
|
2001-11-30 19:46:42 +01:00
|
|
|
}
|
|
|
|
|
2019-09-09 22:17:58 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* GetConsoleKeyboardLayoutNameW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetConsoleKeyboardLayoutNameW(LPWSTR layoutName)
|
2016-01-05 08:59:32 +01:00
|
|
|
{
|
2019-09-09 22:17:58 +02:00
|
|
|
static int once;
|
|
|
|
if (!once++)
|
|
|
|
FIXME( "stub %p\n", layoutName);
|
|
|
|
return TRUE;
|
2016-01-05 08:59:32 +01:00
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
2019-09-09 22:17:58 +02:00
|
|
|
* GetConsoleTitleA (KERNEL32.@)
|
2001-11-30 19:46:42 +01:00
|
|
|
*
|
2019-09-09 22:17:58 +02:00
|
|
|
* See GetConsoleTitleW.
|
2001-11-30 19:46:42 +01:00
|
|
|
*/
|
2019-09-09 22:17:58 +02:00
|
|
|
DWORD WINAPI GetConsoleTitleA(LPSTR title, DWORD size)
|
2001-11-30 19:46:42 +01:00
|
|
|
{
|
2019-09-09 22:17:58 +02:00
|
|
|
WCHAR *ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * size);
|
|
|
|
DWORD ret;
|
2001-11-30 19:46:42 +01:00
|
|
|
|
2019-09-09 22:17:58 +02:00
|
|
|
if (!ptr) return 0;
|
|
|
|
ret = GetConsoleTitleW( ptr, size );
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
WideCharToMultiByte( GetConsoleOutputCP(), 0, ptr, ret + 1, title, size, NULL, NULL);
|
|
|
|
ret = strlen(title);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
|
|
|
return ret;
|
2001-11-30 19:46:42 +01:00
|
|
|
}
|
2019-09-09 22:17:58 +02:00
|
|
|
|
2002-07-31 21:20:28 +02:00
|
|
|
|
|
|
|
static WCHAR* S_EditString /* = NULL */;
|
|
|
|
static unsigned S_EditStrPos /* = 0 */;
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FreeConsole (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI FreeConsole(VOID)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
|
2007-12-20 13:19:10 +01:00
|
|
|
/* invalidate local copy of input event handle */
|
|
|
|
console_wait_event = 0;
|
|
|
|
|
2002-07-31 21:20:28 +02:00
|
|
|
SERVER_START_REQ(free_console)
|
|
|
|
{
|
|
|
|
ret = !wine_server_call_err( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* start_console_renderer
|
|
|
|
*
|
|
|
|
* helper for AllocConsole
|
|
|
|
* starts the renderer process
|
|
|
|
*/
|
2002-09-04 20:41:03 +02:00
|
|
|
static BOOL start_console_renderer_helper(const char* appname, STARTUPINFOA* si,
|
|
|
|
HANDLE hEvent)
|
2002-07-31 21:20:28 +02:00
|
|
|
{
|
2002-09-04 20:41:03 +02:00
|
|
|
char buffer[1024];
|
|
|
|
int ret;
|
2002-07-31 21:20:28 +02:00
|
|
|
PROCESS_INFORMATION pi;
|
2002-09-04 20:41:03 +02:00
|
|
|
|
|
|
|
/* FIXME: use dynamic allocation for most of the buffers below */
|
2006-05-25 06:46:32 +02:00
|
|
|
ret = snprintf(buffer, sizeof(buffer), "%s --use-event=%ld", appname, (DWORD_PTR)hEvent);
|
2002-09-04 20:41:03 +02:00
|
|
|
if ((ret > -1) && (ret < sizeof(buffer)) &&
|
|
|
|
CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS,
|
|
|
|
NULL, NULL, si, &pi))
|
|
|
|
{
|
2009-08-29 14:42:13 +02:00
|
|
|
HANDLE wh[2];
|
2011-10-21 08:18:21 +02:00
|
|
|
DWORD res;
|
2009-08-29 14:42:13 +02:00
|
|
|
|
|
|
|
wh[0] = hEvent;
|
|
|
|
wh[1] = pi.hProcess;
|
2011-10-21 08:18:21 +02:00
|
|
|
res = WaitForMultipleObjects(2, wh, FALSE, INFINITE);
|
2009-08-29 14:42:13 +02:00
|
|
|
|
2008-02-16 16:35:48 +01:00
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
|
2011-10-21 08:18:21 +02:00
|
|
|
if (res != WAIT_OBJECT_0) return FALSE;
|
2002-09-04 20:41:03 +02:00
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("Started wineconsole pid=%08x tid=%08x\n",
|
2002-09-04 20:41:03 +02:00
|
|
|
pi.dwProcessId, pi.dwThreadId);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL start_console_renderer(STARTUPINFOA* si)
|
|
|
|
{
|
2002-07-31 21:20:28 +02:00
|
|
|
HANDLE hEvent = 0;
|
|
|
|
LPSTR p;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
2002-09-04 20:41:03 +02:00
|
|
|
BOOL ret = FALSE;
|
2002-07-31 21:20:28 +02:00
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.Attributes = OBJ_INHERIT;
|
|
|
|
attr.ObjectName = NULL;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
|
|
|
|
2010-01-18 20:34:54 +01:00
|
|
|
NtCreateEvent(&hEvent, EVENT_ALL_ACCESS, &attr, NotificationEvent, FALSE);
|
2002-07-31 21:20:28 +02:00
|
|
|
if (!hEvent) return FALSE;
|
|
|
|
|
|
|
|
/* first try environment variable */
|
|
|
|
if ((p = getenv("WINECONSOLE")) != NULL)
|
|
|
|
{
|
2002-09-04 20:41:03 +02:00
|
|
|
ret = start_console_renderer_helper(p, si, hEvent);
|
|
|
|
if (!ret)
|
|
|
|
ERR("Couldn't launch Wine console from WINECONSOLE env var (%s)... "
|
|
|
|
"trying default access\n", p);
|
2002-07-31 21:20:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* then try the regular PATH */
|
2002-09-04 20:41:03 +02:00
|
|
|
if (!ret)
|
|
|
|
ret = start_console_renderer_helper("wineconsole", si, hEvent);
|
2002-07-31 21:20:28 +02:00
|
|
|
|
|
|
|
CloseHandle(hEvent);
|
2002-09-04 20:41:03 +02:00
|
|
|
return ret;
|
2002-07-31 21:20:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* AllocConsole (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* creates an xterm with a pty to our program
|
|
|
|
*/
|
|
|
|
BOOL WINAPI AllocConsole(void)
|
|
|
|
{
|
|
|
|
HANDLE handle_in = INVALID_HANDLE_VALUE;
|
|
|
|
HANDLE handle_out = INVALID_HANDLE_VALUE;
|
|
|
|
HANDLE handle_err = INVALID_HANDLE_VALUE;
|
2002-09-04 20:41:03 +02:00
|
|
|
STARTUPINFOA siCurrent;
|
|
|
|
STARTUPINFOA siConsole;
|
|
|
|
char buffer[1024];
|
2002-07-31 21:20:28 +02:00
|
|
|
|
|
|
|
TRACE("()\n");
|
|
|
|
|
2005-06-27 11:54:09 +02:00
|
|
|
handle_in = OpenConsoleW( coninW, GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE,
|
|
|
|
FALSE, OPEN_EXISTING );
|
2002-07-31 21:20:28 +02:00
|
|
|
|
2005-06-27 11:54:09 +02:00
|
|
|
if (VerifyConsoleIoHandle(handle_in))
|
2002-07-31 21:20:28 +02:00
|
|
|
{
|
|
|
|
/* we already have a console opened on this process, don't create a new one */
|
|
|
|
CloseHandle(handle_in);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-12-20 13:19:10 +01:00
|
|
|
/* invalidate local copy of input event handle */
|
|
|
|
console_wait_event = 0;
|
|
|
|
|
2002-09-04 20:41:03 +02:00
|
|
|
GetStartupInfoA(&siCurrent);
|
|
|
|
|
|
|
|
memset(&siConsole, 0, sizeof(siConsole));
|
|
|
|
siConsole.cb = sizeof(siConsole);
|
|
|
|
/* setup a view arguments for wineconsole (it'll use them as default values) */
|
|
|
|
if (siCurrent.dwFlags & STARTF_USECOUNTCHARS)
|
|
|
|
{
|
|
|
|
siConsole.dwFlags |= STARTF_USECOUNTCHARS;
|
|
|
|
siConsole.dwXCountChars = siCurrent.dwXCountChars;
|
|
|
|
siConsole.dwYCountChars = siCurrent.dwYCountChars;
|
|
|
|
}
|
|
|
|
if (siCurrent.dwFlags & STARTF_USEFILLATTRIBUTE)
|
|
|
|
{
|
|
|
|
siConsole.dwFlags |= STARTF_USEFILLATTRIBUTE;
|
|
|
|
siConsole.dwFillAttribute = siCurrent.dwFillAttribute;
|
|
|
|
}
|
2005-04-14 13:30:09 +02:00
|
|
|
if (siCurrent.dwFlags & STARTF_USESHOWWINDOW)
|
|
|
|
{
|
|
|
|
siConsole.dwFlags |= STARTF_USESHOWWINDOW;
|
|
|
|
siConsole.wShowWindow = siCurrent.wShowWindow;
|
|
|
|
}
|
2002-09-04 20:41:03 +02:00
|
|
|
/* FIXME (should pass the unicode form) */
|
|
|
|
if (siCurrent.lpTitle)
|
|
|
|
siConsole.lpTitle = siCurrent.lpTitle;
|
|
|
|
else if (GetModuleFileNameA(0, buffer, sizeof(buffer)))
|
2004-05-19 05:22:55 +02:00
|
|
|
{
|
|
|
|
buffer[sizeof(buffer) - 1] = '\0';
|
2002-09-04 20:41:03 +02:00
|
|
|
siConsole.lpTitle = buffer;
|
2004-05-19 05:22:55 +02:00
|
|
|
}
|
2002-09-04 20:41:03 +02:00
|
|
|
|
|
|
|
if (!start_console_renderer(&siConsole))
|
2002-07-31 21:20:28 +02:00
|
|
|
goto the_end;
|
|
|
|
|
2004-12-15 11:47:23 +01:00
|
|
|
if( !(siCurrent.dwFlags & STARTF_USESTDHANDLES) ) {
|
|
|
|
/* all std I/O handles are inheritable by default */
|
2005-06-27 11:54:09 +02:00
|
|
|
handle_in = OpenConsoleW( coninW, GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE,
|
|
|
|
TRUE, OPEN_EXISTING );
|
2004-12-15 11:47:23 +01:00
|
|
|
if (handle_in == INVALID_HANDLE_VALUE) goto the_end;
|
|
|
|
|
2005-06-27 11:54:09 +02:00
|
|
|
handle_out = OpenConsoleW( conoutW, GENERIC_READ|GENERIC_WRITE,
|
|
|
|
TRUE, OPEN_EXISTING );
|
2004-12-15 11:47:23 +01:00
|
|
|
if (handle_out == INVALID_HANDLE_VALUE) goto the_end;
|
|
|
|
|
|
|
|
if (!DuplicateHandle(GetCurrentProcess(), handle_out, GetCurrentProcess(),
|
|
|
|
&handle_err, 0, TRUE, DUPLICATE_SAME_ACCESS))
|
|
|
|
goto the_end;
|
|
|
|
} else {
|
|
|
|
/* STARTF_USESTDHANDLES flag: use handles from StartupInfo */
|
|
|
|
handle_in = siCurrent.hStdInput;
|
|
|
|
handle_out = siCurrent.hStdOutput;
|
|
|
|
handle_err = siCurrent.hStdError;
|
|
|
|
}
|
2002-07-31 21:20:28 +02:00
|
|
|
|
|
|
|
/* NT resets the STD_*_HANDLEs on console alloc */
|
|
|
|
SetStdHandle(STD_INPUT_HANDLE, handle_in);
|
|
|
|
SetStdHandle(STD_OUTPUT_HANDLE, handle_out);
|
|
|
|
SetStdHandle(STD_ERROR_HANDLE, handle_err);
|
|
|
|
|
|
|
|
SetLastError(ERROR_SUCCESS);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
the_end:
|
|
|
|
ERR("Can't allocate console\n");
|
|
|
|
if (handle_in != INVALID_HANDLE_VALUE) CloseHandle(handle_in);
|
|
|
|
if (handle_out != INVALID_HANDLE_VALUE) CloseHandle(handle_out);
|
|
|
|
if (handle_err != INVALID_HANDLE_VALUE) CloseHandle(handle_err);
|
|
|
|
FreeConsole();
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-12 12:03:47 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ReadConsoleA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI ReadConsoleA( HANDLE handle, LPVOID buffer, DWORD length, DWORD *ret_count, void *reserved )
|
|
|
|
{
|
|
|
|
LPWSTR strW = HeapAlloc( GetProcessHeap(), 0, length * sizeof(WCHAR) );
|
|
|
|
DWORD count = 0;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (!strW)
|
|
|
|
{
|
|
|
|
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if ((ret = ReadConsoleW( handle, strW, length, &count, NULL )))
|
|
|
|
{
|
|
|
|
count = WideCharToMultiByte( GetConsoleCP(), 0, strW, count, buffer, length, NULL, NULL );
|
|
|
|
if (ret_count) *ret_count = count;
|
|
|
|
}
|
|
|
|
HeapFree( GetProcessHeap(), 0, strW );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-31 21:20:28 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ReadConsoleW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI ReadConsoleW(HANDLE hConsoleInput, LPVOID lpBuffer,
|
|
|
|
DWORD nNumberOfCharsToRead, LPDWORD lpNumberOfCharsRead, LPVOID lpReserved)
|
|
|
|
{
|
|
|
|
DWORD charsread;
|
2009-03-11 09:39:16 +01:00
|
|
|
LPWSTR xbuf = lpBuffer;
|
2002-07-31 21:20:28 +02:00
|
|
|
DWORD mode;
|
2010-11-07 19:14:46 +01:00
|
|
|
BOOL is_bare = FALSE;
|
|
|
|
int fd;
|
2002-07-31 21:20:28 +02:00
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("(%p,%p,%d,%p,%p)\n",
|
2002-07-31 21:20:28 +02:00
|
|
|
hConsoleInput, lpBuffer, nNumberOfCharsToRead, lpNumberOfCharsRead, lpReserved);
|
|
|
|
|
2014-04-16 10:09:02 +02:00
|
|
|
if (nNumberOfCharsToRead > INT_MAX)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-11-07 19:14:46 +01:00
|
|
|
if (!GetConsoleMode(hConsoleInput, &mode))
|
2002-07-31 21:20:28 +02:00
|
|
|
return FALSE;
|
2010-11-11 22:30:11 +01:00
|
|
|
if ((fd = get_console_bare_fd(hConsoleInput)) != -1)
|
2010-11-07 19:14:46 +01:00
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
is_bare = TRUE;
|
|
|
|
}
|
2002-07-31 21:20:28 +02:00
|
|
|
if (mode & ENABLE_LINE_INPUT)
|
|
|
|
{
|
|
|
|
if (!S_EditString || S_EditString[S_EditStrPos] == 0)
|
|
|
|
{
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, S_EditString);
|
2010-08-30 22:19:31 +02:00
|
|
|
if (!(S_EditString = CONSOLE_Readline(hConsoleInput, !is_bare)))
|
2002-07-31 21:20:28 +02:00
|
|
|
return FALSE;
|
|
|
|
S_EditStrPos = 0;
|
|
|
|
}
|
|
|
|
charsread = lstrlenW(&S_EditString[S_EditStrPos]);
|
|
|
|
if (charsread > nNumberOfCharsToRead) charsread = nNumberOfCharsToRead;
|
|
|
|
memcpy(xbuf, &S_EditString[S_EditStrPos], charsread * sizeof(WCHAR));
|
|
|
|
S_EditStrPos += charsread;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
INPUT_RECORD ir;
|
2003-06-21 04:07:10 +02:00
|
|
|
DWORD timeout = INFINITE;
|
2002-07-31 21:20:28 +02:00
|
|
|
|
|
|
|
/* FIXME: should we read at least 1 char? The SDK does not say */
|
|
|
|
/* wait for at least one available input record (it doesn't mean we'll have
|
2003-06-21 04:07:10 +02:00
|
|
|
* chars stored in xbuf...)
|
2007-12-18 17:38:50 +01:00
|
|
|
*
|
|
|
|
* Although SDK doc keeps silence about 1 char, SDK examples assume
|
|
|
|
* that we should wait for at least one character (not key). --KS
|
2002-07-31 21:20:28 +02:00
|
|
|
*/
|
2003-06-21 04:07:10 +02:00
|
|
|
charsread = 0;
|
|
|
|
do
|
2002-07-31 21:20:28 +02:00
|
|
|
{
|
2003-06-21 04:07:10 +02:00
|
|
|
if (read_console_input(hConsoleInput, &ir, timeout) != rci_gotone) break;
|
|
|
|
if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown &&
|
2008-10-27 12:14:28 +01:00
|
|
|
ir.Event.KeyEvent.uChar.UnicodeChar)
|
2002-07-31 21:20:28 +02:00
|
|
|
{
|
|
|
|
xbuf[charsread++] = ir.Event.KeyEvent.uChar.UnicodeChar;
|
2007-12-18 17:38:50 +01:00
|
|
|
timeout = 0;
|
2002-07-31 21:20:28 +02:00
|
|
|
}
|
2003-06-21 04:07:10 +02:00
|
|
|
} while (charsread < nNumberOfCharsToRead);
|
|
|
|
/* nothing has been read */
|
|
|
|
if (timeout == INFINITE) return FALSE;
|
2002-07-31 21:20:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lpNumberOfCharsRead) *lpNumberOfCharsRead = charsread;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-12 12:03:47 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ReadConsoleInputA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI ReadConsoleInputA( HANDLE handle, INPUT_RECORD *buffer, DWORD length, DWORD *count )
|
|
|
|
{
|
|
|
|
DWORD read;
|
|
|
|
|
|
|
|
if (!ReadConsoleInputW( handle, buffer, length, &read )) return FALSE;
|
|
|
|
input_records_WtoA( buffer, read );
|
|
|
|
if (count) *count = read;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-31 21:20:28 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* ReadConsoleInputW (KERNEL32.@)
|
|
|
|
*/
|
2004-05-05 07:54:44 +02:00
|
|
|
BOOL WINAPI ReadConsoleInputW(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer,
|
2002-07-31 21:20:28 +02:00
|
|
|
DWORD nLength, LPDWORD lpNumberOfEventsRead)
|
|
|
|
{
|
2003-06-21 04:07:10 +02:00
|
|
|
DWORD idx = 0;
|
|
|
|
DWORD timeout = INFINITE;
|
2002-07-31 21:20:28 +02:00
|
|
|
|
|
|
|
if (!nLength)
|
|
|
|
{
|
|
|
|
if (lpNumberOfEventsRead) *lpNumberOfEventsRead = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* loop until we get at least one event */
|
2003-06-21 04:07:10 +02:00
|
|
|
while (read_console_input(hConsoleInput, &lpBuffer[idx], timeout) == rci_gotone &&
|
|
|
|
++idx < nLength)
|
|
|
|
timeout = 0;
|
|
|
|
|
|
|
|
if (lpNumberOfEventsRead) *lpNumberOfEventsRead = idx;
|
|
|
|
return idx != 0;
|
2002-07-31 21:20:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetNumberOfConsoleMouseButtons (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons)
|
|
|
|
{
|
|
|
|
FIXME("(%p): stub\n", nrofbuttons);
|
|
|
|
*nrofbuttons = 2;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* CONSOLE_HandleCtrlC
|
|
|
|
*
|
|
|
|
* Check whether the shall manipulate CtrlC events
|
|
|
|
*/
|
2020-06-06 16:43:48 +02:00
|
|
|
LONG CALLBACK CONSOLE_HandleCtrlC( EXCEPTION_POINTERS *eptr )
|
2002-07-31 21:20:28 +02:00
|
|
|
{
|
2020-06-03 10:20:09 +02:00
|
|
|
extern DWORD WINAPI CtrlRoutine( void *arg );
|
2011-12-30 21:54:31 +01:00
|
|
|
HANDLE thread;
|
|
|
|
|
2020-06-06 16:43:48 +02:00
|
|
|
if (eptr->ExceptionRecord->ExceptionCode != CONTROL_C_EXIT) return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
|
2002-07-31 21:20:28 +02:00
|
|
|
/* FIXME: better test whether a console is attached to this process ??? */
|
2020-06-06 16:43:48 +02:00
|
|
|
if (CONSOLE_GetNumHistoryEntries() == (unsigned)-1) return EXCEPTION_CONTINUE_SEARCH;
|
2002-07-31 21:20:28 +02:00
|
|
|
|
2004-09-08 03:25:05 +02:00
|
|
|
/* check if we have to ignore ctrl-C events */
|
|
|
|
if (!(NtCurrentTeb()->Peb->ProcessParameters->ConsoleFlags & 1))
|
2002-07-31 21:20:28 +02:00
|
|
|
{
|
2004-09-08 03:25:05 +02:00
|
|
|
/* Create a separate thread to signal all the events.
|
|
|
|
* This is needed because:
|
|
|
|
* - this function can be called in an Unix signal handler (hence on an
|
|
|
|
* different stack than the thread that's running). This breaks the
|
|
|
|
* Win32 exception mechanisms (where the thread's stack is checked).
|
|
|
|
* - since the current thread, while processing the signal, can hold the
|
|
|
|
* console critical section, we need another execution environment where
|
|
|
|
* we can wait on this critical section
|
2002-07-31 21:20:28 +02:00
|
|
|
*/
|
2020-06-03 10:20:09 +02:00
|
|
|
thread = CreateThread(NULL, 0, CtrlRoutine, (void*)CTRL_C_EVENT, 0, NULL);
|
2020-06-06 16:43:48 +02:00
|
|
|
if (thread) CloseHandle(thread);
|
2002-07-31 21:20:28 +02:00
|
|
|
}
|
2020-06-06 16:43:48 +02:00
|
|
|
return EXCEPTION_CONTINUE_EXECUTION;
|
2002-07-31 21:20:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2003-05-13 06:46:24 +02:00
|
|
|
* CONSOLE_WriteChars
|
2002-07-31 21:20:28 +02:00
|
|
|
*
|
|
|
|
* WriteConsoleOutput helper: hides server call semantics
|
2003-05-13 06:46:24 +02:00
|
|
|
* writes a string at a given pos with standard attribute
|
2002-07-31 21:20:28 +02:00
|
|
|
*/
|
2005-06-14 13:42:34 +02:00
|
|
|
static int CONSOLE_WriteChars(HANDLE hCon, LPCWSTR lpBuffer, int nc, COORD* pos)
|
2002-07-31 21:20:28 +02:00
|
|
|
{
|
|
|
|
int written = -1;
|
|
|
|
|
|
|
|
if (!nc) return 0;
|
|
|
|
|
|
|
|
SERVER_START_REQ( write_console_output )
|
|
|
|
{
|
2003-06-21 04:07:10 +02:00
|
|
|
req->handle = console_handle_unmap(hCon);
|
2002-07-31 21:20:28 +02:00
|
|
|
req->x = pos->X;
|
|
|
|
req->y = pos->Y;
|
|
|
|
req->mode = CHAR_INFO_MODE_TEXTSTDATTR;
|
|
|
|
req->wrap = FALSE;
|
|
|
|
wine_server_add_data( req, lpBuffer, nc * sizeof(WCHAR) );
|
|
|
|
if (!wine_server_call_err( req )) written = reply->written;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (written > 0) pos->X += written;
|
|
|
|
return written;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* next_line
|
|
|
|
*
|
|
|
|
* WriteConsoleOutput helper: handles passing to next line (+scrolling if necessary)
|
|
|
|
*
|
|
|
|
*/
|
2013-10-24 00:40:22 +02:00
|
|
|
static BOOL next_line(HANDLE hCon, CONSOLE_SCREEN_BUFFER_INFO* csbi)
|
2002-07-31 21:20:28 +02:00
|
|
|
{
|
|
|
|
SMALL_RECT src;
|
|
|
|
CHAR_INFO ci;
|
|
|
|
COORD dst;
|
|
|
|
|
|
|
|
csbi->dwCursorPosition.X = 0;
|
|
|
|
csbi->dwCursorPosition.Y++;
|
|
|
|
|
2013-10-24 00:40:22 +02:00
|
|
|
if (csbi->dwCursorPosition.Y < csbi->dwSize.Y) return TRUE;
|
2002-07-31 21:20:28 +02:00
|
|
|
|
|
|
|
src.Top = 1;
|
|
|
|
src.Bottom = csbi->dwSize.Y - 1;
|
|
|
|
src.Left = 0;
|
|
|
|
src.Right = csbi->dwSize.X - 1;
|
|
|
|
|
|
|
|
dst.X = 0;
|
|
|
|
dst.Y = 0;
|
|
|
|
|
|
|
|
ci.Attributes = csbi->wAttributes;
|
|
|
|
ci.Char.UnicodeChar = ' ';
|
|
|
|
|
|
|
|
csbi->dwCursorPosition.Y--;
|
|
|
|
if (!ScrollConsoleScreenBufferW(hCon, &src, NULL, dst, &ci))
|
2013-10-24 00:40:22 +02:00
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2002-07-31 21:20:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* write_block
|
|
|
|
*
|
|
|
|
* WriteConsoleOutput helper: writes a block of non special characters
|
|
|
|
* Block can spread on several lines, and wrapping, if needed, is
|
|
|
|
* handled
|
|
|
|
*
|
|
|
|
*/
|
2013-10-24 00:40:22 +02:00
|
|
|
static BOOL write_block(HANDLE hCon, CONSOLE_SCREEN_BUFFER_INFO* csbi,
|
|
|
|
DWORD mode, LPCWSTR ptr, int len)
|
2002-07-31 21:20:28 +02:00
|
|
|
{
|
|
|
|
int blk; /* number of chars to write on current line */
|
2003-05-13 06:46:24 +02:00
|
|
|
int done; /* number of chars already written */
|
2002-07-31 21:20:28 +02:00
|
|
|
|
2013-10-24 00:40:22 +02:00
|
|
|
if (len <= 0) return TRUE;
|
2002-07-31 21:20:28 +02:00
|
|
|
|
|
|
|
if (mode & ENABLE_WRAP_AT_EOL_OUTPUT) /* writes remaining on next line */
|
|
|
|
{
|
|
|
|
for (done = 0; done < len; done += blk)
|
|
|
|
{
|
|
|
|
blk = min(len - done, csbi->dwSize.X - csbi->dwCursorPosition.X);
|
|
|
|
|
2003-05-13 06:46:24 +02:00
|
|
|
if (CONSOLE_WriteChars(hCon, ptr + done, blk, &csbi->dwCursorPosition) != blk)
|
2013-10-24 00:40:22 +02:00
|
|
|
return FALSE;
|
2002-07-31 21:20:28 +02:00
|
|
|
if (csbi->dwCursorPosition.X == csbi->dwSize.X && !next_line(hCon, csbi))
|
2013-10-24 00:40:22 +02:00
|
|
|
return FALSE;
|
2002-07-31 21:20:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-05-13 06:46:24 +02:00
|
|
|
int pos = csbi->dwCursorPosition.X;
|
|
|
|
/* FIXME: we could reduce the number of loops
|
|
|
|
* but, in most cases we wouldn't gain lots of time (it would only
|
|
|
|
* happen if we're asked to overwrite more than twice the part of the line,
|
|
|
|
* which is unlikely
|
|
|
|
*/
|
2010-09-18 15:26:05 +02:00
|
|
|
for (done = 0; done < len; done += blk)
|
2002-07-31 21:20:28 +02:00
|
|
|
{
|
2003-05-13 06:46:24 +02:00
|
|
|
blk = min(len - done, csbi->dwSize.X - csbi->dwCursorPosition.X);
|
|
|
|
|
|
|
|
csbi->dwCursorPosition.X = pos;
|
|
|
|
if (CONSOLE_WriteChars(hCon, ptr + done, blk, &csbi->dwCursorPosition) != blk)
|
2013-10-24 00:40:22 +02:00
|
|
|
return FALSE;
|
2002-07-31 21:20:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-24 00:40:22 +02:00
|
|
|
return TRUE;
|
2002-07-31 21:20:28 +02:00
|
|
|
}
|
|
|
|
|
2019-12-12 12:03:47 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* WriteConsoleA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DECLSPEC_HOTPATCH WriteConsoleA( HANDLE handle, LPCVOID buffer, DWORD length,
|
|
|
|
DWORD *written, void *reserved )
|
|
|
|
{
|
|
|
|
UINT cp = GetConsoleOutputCP();
|
|
|
|
LPWSTR strW;
|
|
|
|
DWORD lenW;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
if (written) *written = 0;
|
|
|
|
lenW = MultiByteToWideChar( cp, 0, buffer, length, NULL, 0 );
|
|
|
|
if (!(strW = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) ))) return FALSE;
|
|
|
|
MultiByteToWideChar( cp, 0, buffer, length, strW, lenW );
|
|
|
|
ret = WriteConsoleW( handle, strW, lenW, written, 0 );
|
|
|
|
HeapFree( GetProcessHeap(), 0, strW );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-31 21:20:28 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* WriteConsoleW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WriteConsoleW(HANDLE hConsoleOutput, LPCVOID lpBuffer, DWORD nNumberOfCharsToWrite,
|
|
|
|
LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
|
|
|
|
{
|
|
|
|
DWORD mode;
|
|
|
|
DWORD nw = 0;
|
2004-06-14 19:04:34 +02:00
|
|
|
const WCHAR* psz = lpBuffer;
|
2002-07-31 21:20:28 +02:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
2010-11-07 19:14:46 +01:00
|
|
|
int k, first = 0, fd;
|
2002-07-31 21:20:28 +02:00
|
|
|
|
2006-10-12 22:56:29 +02:00
|
|
|
TRACE("%p %s %d %p %p\n",
|
2002-07-31 21:20:28 +02:00
|
|
|
hConsoleOutput, debugstr_wn(lpBuffer, nNumberOfCharsToWrite),
|
|
|
|
nNumberOfCharsToWrite, lpNumberOfCharsWritten, lpReserved);
|
|
|
|
|
|
|
|
if (lpNumberOfCharsWritten) *lpNumberOfCharsWritten = 0;
|
|
|
|
|
2010-11-07 19:14:46 +01:00
|
|
|
if ((fd = get_console_bare_fd(hConsoleOutput)) != -1)
|
2010-08-30 22:19:24 +02:00
|
|
|
{
|
|
|
|
char* ptr;
|
|
|
|
unsigned len;
|
2011-08-03 18:07:09 +02:00
|
|
|
HANDLE hFile;
|
|
|
|
NTSTATUS status;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
2010-08-30 22:19:24 +02:00
|
|
|
|
2010-11-07 19:14:46 +01:00
|
|
|
close(fd);
|
2010-08-30 22:19:24 +02:00
|
|
|
/* FIXME: mode ENABLED_OUTPUT is not processed (or actually we rely on underlying Unix/TTY fd
|
|
|
|
* to do the job
|
|
|
|
*/
|
|
|
|
len = WideCharToMultiByte(CP_UNIXCP, 0, lpBuffer, nNumberOfCharsToWrite, NULL, 0, NULL, NULL);
|
|
|
|
if ((ptr = HeapAlloc(GetProcessHeap(), 0, len)) == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, lpBuffer, nNumberOfCharsToWrite, ptr, len, NULL, NULL);
|
2011-08-03 18:07:09 +02:00
|
|
|
hFile = wine_server_ptr_handle(console_handle_unmap(hConsoleOutput));
|
|
|
|
status = NtWriteFile(hFile, NULL, NULL, NULL, &iosb, ptr, len, 0, NULL);
|
|
|
|
if (status == STATUS_PENDING)
|
2010-08-30 22:19:24 +02:00
|
|
|
{
|
2011-08-03 18:07:09 +02:00
|
|
|
WaitForSingleObject(hFile, INFINITE);
|
|
|
|
status = iosb.u.Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != STATUS_PENDING && lpNumberOfCharsWritten)
|
|
|
|
{
|
|
|
|
if (iosb.Information == len)
|
2010-08-30 22:19:24 +02:00
|
|
|
*lpNumberOfCharsWritten = nNumberOfCharsToWrite;
|
|
|
|
else
|
|
|
|
FIXME("Conversion not supported yet\n");
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
2020-05-26 12:29:06 +02:00
|
|
|
return set_ntstatus( status );
|
2010-08-30 22:19:24 +02:00
|
|
|
}
|
|
|
|
|
2010-11-07 19:14:46 +01:00
|
|
|
if (!GetConsoleMode(hConsoleOutput, &mode) || !GetConsoleScreenBufferInfo(hConsoleOutput, &csbi))
|
2002-07-31 21:20:28 +02:00
|
|
|
return FALSE;
|
|
|
|
|
2009-01-19 06:52:11 +01:00
|
|
|
if (!nNumberOfCharsToWrite) return TRUE;
|
|
|
|
|
2002-07-31 21:20:28 +02:00
|
|
|
if (mode & ENABLE_PROCESSED_OUTPUT)
|
|
|
|
{
|
2004-08-11 01:43:21 +02:00
|
|
|
unsigned int i;
|
2002-07-31 21:20:28 +02:00
|
|
|
|
|
|
|
for (i = 0; i < nNumberOfCharsToWrite; i++)
|
|
|
|
{
|
|
|
|
switch (psz[i])
|
|
|
|
{
|
|
|
|
case '\b': case '\t': case '\n': case '\a': case '\r':
|
|
|
|
/* don't handle here the i-th char... done below */
|
|
|
|
if ((k = i - first) > 0)
|
|
|
|
{
|
|
|
|
if (!write_block(hConsoleOutput, &csbi, mode, &psz[first], k))
|
|
|
|
goto the_end;
|
|
|
|
nw += k;
|
|
|
|
}
|
|
|
|
first = i + 1;
|
|
|
|
nw++;
|
|
|
|
}
|
|
|
|
switch (psz[i])
|
|
|
|
{
|
|
|
|
case '\b':
|
|
|
|
if (csbi.dwCursorPosition.X > 0) csbi.dwCursorPosition.X--;
|
|
|
|
break;
|
|
|
|
case '\t':
|
|
|
|
{
|
2011-12-16 13:08:23 +01:00
|
|
|
static const WCHAR tmp[] = {' ',' ',' ',' ',' ',' ',' ',' '};
|
2002-07-31 21:20:28 +02:00
|
|
|
if (!write_block(hConsoleOutput, &csbi, mode, tmp,
|
|
|
|
((csbi.dwCursorPosition.X + 8) & ~7) - csbi.dwCursorPosition.X))
|
|
|
|
goto the_end;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
next_line(hConsoleOutput, &csbi);
|
|
|
|
break;
|
|
|
|
case '\a':
|
|
|
|
Beep(400, 300);
|
|
|
|
break;
|
|
|
|
case '\r':
|
|
|
|
csbi.dwCursorPosition.X = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* write the remaining block (if any) if processed output is enabled, or the
|
|
|
|
* entire buffer otherwise
|
|
|
|
*/
|
|
|
|
if ((k = nNumberOfCharsToWrite - first) > 0)
|
|
|
|
{
|
|
|
|
if (!write_block(hConsoleOutput, &csbi, mode, &psz[first], k))
|
|
|
|
goto the_end;
|
|
|
|
nw += k;
|
|
|
|
}
|
|
|
|
|
|
|
|
the_end:
|
|
|
|
SetConsoleCursorPosition(hConsoleOutput, csbi.dwCursorPosition);
|
|
|
|
if (lpNumberOfCharsWritten) *lpNumberOfCharsWritten = nw;
|
|
|
|
return nw != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* CONSOLE_FillLineUniform
|
|
|
|
*
|
|
|
|
* Helper function for ScrollConsoleScreenBufferW
|
|
|
|
* Fills a part of a line with a constant character info
|
|
|
|
*/
|
|
|
|
void CONSOLE_FillLineUniform(HANDLE hConsoleOutput, int i, int j, int len, LPCHAR_INFO lpFill)
|
|
|
|
{
|
|
|
|
SERVER_START_REQ( fill_console_output )
|
|
|
|
{
|
2003-06-21 04:07:10 +02:00
|
|
|
req->handle = console_handle_unmap(hConsoleOutput);
|
2002-07-31 21:20:28 +02:00
|
|
|
req->mode = CHAR_INFO_MODE_TEXTATTR;
|
|
|
|
req->x = i;
|
|
|
|
req->y = j;
|
|
|
|
req->count = len;
|
|
|
|
req->wrap = FALSE;
|
|
|
|
req->data.ch = lpFill->Char.UnicodeChar;
|
|
|
|
req->data.attr = lpFill->Attributes;
|
|
|
|
wine_server_call_err( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
|
|
|
|
2008-06-26 19:14:41 +02:00
|
|
|
/******************************************************************
|
|
|
|
* GetConsoleDisplayMode (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetConsoleDisplayMode(LPDWORD lpModeFlags)
|
|
|
|
{
|
|
|
|
TRACE("semi-stub: %p\n", lpModeFlags);
|
|
|
|
/* It is safe to successfully report windowed mode */
|
|
|
|
*lpModeFlags = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* SetConsoleDisplayMode (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI SetConsoleDisplayMode(HANDLE hConsoleOutput, DWORD dwFlags,
|
|
|
|
COORD *lpNewScreenBufferDimensions)
|
|
|
|
{
|
|
|
|
TRACE("(%p, %x, (%d, %d))\n", hConsoleOutput, dwFlags,
|
|
|
|
lpNewScreenBufferDimensions->X, lpNewScreenBufferDimensions->Y);
|
|
|
|
if (dwFlags == 1)
|
|
|
|
{
|
|
|
|
/* We cannot switch to fullscreen */
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-07-31 21:20:28 +02:00
|
|
|
|
|
|
|
/* ====================================================================
|
|
|
|
*
|
|
|
|
* Console manipulation functions
|
|
|
|
*
|
|
|
|
* ====================================================================*/
|
|
|
|
|
|
|
|
/* some missing functions...
|
|
|
|
* FIXME: those are likely to be defined as undocumented function in kernel32 (or part of them)
|
|
|
|
* should get the right API and implement them
|
|
|
|
* SetConsoleCommandHistoryMode
|
|
|
|
* SetConsoleNumberOfCommands[AW]
|
|
|
|
*/
|
|
|
|
int CONSOLE_GetHistory(int idx, WCHAR* buf, int buf_len)
|
|
|
|
{
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
SERVER_START_REQ( get_console_input_history )
|
|
|
|
{
|
|
|
|
req->handle = 0;
|
|
|
|
req->index = idx;
|
|
|
|
if (buf && buf_len > 1)
|
|
|
|
{
|
|
|
|
wine_server_set_reply( req, buf, (buf_len - 1) * sizeof(WCHAR) );
|
|
|
|
}
|
|
|
|
if (!wine_server_call_err( req ))
|
|
|
|
{
|
|
|
|
if (buf) buf[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
|
|
|
|
len = reply->total / sizeof(WCHAR) + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* CONSOLE_AppendHistory
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL CONSOLE_AppendHistory(const WCHAR* ptr)
|
|
|
|
{
|
|
|
|
size_t len = strlenW(ptr);
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
while (len && (ptr[len - 1] == '\n' || ptr[len - 1] == '\r')) len--;
|
2007-08-08 12:55:43 +02:00
|
|
|
if (!len) return FALSE;
|
2002-07-31 21:20:28 +02:00
|
|
|
|
|
|
|
SERVER_START_REQ( append_console_input_history )
|
|
|
|
{
|
|
|
|
req->handle = 0;
|
|
|
|
wine_server_add_data( req, ptr, len * sizeof(WCHAR) );
|
|
|
|
ret = !wine_server_call_err( req );
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* CONSOLE_GetNumHistoryEntries
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
unsigned CONSOLE_GetNumHistoryEntries(void)
|
|
|
|
{
|
|
|
|
unsigned ret = -1;
|
|
|
|
SERVER_START_REQ(get_console_input_info)
|
|
|
|
{
|
|
|
|
req->handle = 0;
|
|
|
|
if (!wine_server_call_err( req )) ret = reply->history_index;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
2003-01-09 07:01:32 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* CONSOLE_GetEditionMode
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL CONSOLE_GetEditionMode(HANDLE hConIn, int* mode)
|
|
|
|
{
|
2013-10-24 00:40:22 +02:00
|
|
|
unsigned ret = 0;
|
2003-01-09 07:01:32 +01:00
|
|
|
SERVER_START_REQ(get_console_input_info)
|
|
|
|
{
|
2003-06-21 04:07:10 +02:00
|
|
|
req->handle = console_handle_unmap(hConIn);
|
2003-01-09 07:01:32 +01:00
|
|
|
if ((ret = !wine_server_call_err( req )))
|
|
|
|
*mode = reply->edition_mode;
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-12-07 20:41:06 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetConsoleAliasW
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* 0 if an error occurred, non-zero for success
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetConsoleAliasW(LPWSTR lpSource, LPWSTR lpTargetBuffer,
|
|
|
|
DWORD TargetBufferLength, LPWSTR lpExename)
|
|
|
|
{
|
|
|
|
FIXME("(%s,%p,%d,%s): stub\n", debugstr_w(lpSource), lpTargetBuffer, TargetBufferLength, debugstr_w(lpExename));
|
2009-06-12 19:03:53 +02:00
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
2008-12-07 20:41:06 +01:00
|
|
|
}
|
2010-01-05 09:32:36 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetConsoleProcessList (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetConsoleProcessList(LPDWORD processlist, DWORD processcount)
|
|
|
|
{
|
|
|
|
FIXME("(%p,%d): stub\n", processlist, processcount);
|
|
|
|
|
|
|
|
if (!processlist || processcount < 1)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-08-30 22:19:18 +02:00
|
|
|
|
|
|
|
BOOL CONSOLE_Init(RTL_USER_PROCESS_PARAMETERS *params)
|
|
|
|
{
|
2010-09-10 21:50:19 +02:00
|
|
|
memset(&S_termios, 0, sizeof(S_termios));
|
2010-08-30 22:19:18 +02:00
|
|
|
if (params->ConsoleHandle == KERNEL32_CONSOLE_SHELL)
|
|
|
|
{
|
|
|
|
HANDLE conin;
|
|
|
|
|
|
|
|
/* FIXME: to be done even if program is a GUI ? */
|
|
|
|
/* This is wine specific: we have no parent (we're started from unix)
|
|
|
|
* so, create a simple console with bare handles
|
|
|
|
*/
|
2011-01-18 22:02:24 +01:00
|
|
|
TERM_Init();
|
2010-08-30 22:19:24 +02:00
|
|
|
wine_server_send_fd(0);
|
2010-08-30 22:19:18 +02:00
|
|
|
SERVER_START_REQ( alloc_console )
|
|
|
|
{
|
|
|
|
req->access = GENERIC_READ | GENERIC_WRITE;
|
|
|
|
req->attributes = OBJ_INHERIT;
|
|
|
|
req->pid = 0xffffffff;
|
2010-08-30 22:19:24 +02:00
|
|
|
req->input_fd = 0;
|
2010-08-30 22:19:18 +02:00
|
|
|
wine_server_call( req );
|
|
|
|
conin = wine_server_ptr_handle( reply->handle_in );
|
|
|
|
/* reply->event shouldn't be created by server */
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
if (!params->hStdInput)
|
|
|
|
params->hStdInput = conin;
|
2010-08-30 22:19:24 +02:00
|
|
|
|
|
|
|
if (!params->hStdOutput)
|
|
|
|
{
|
|
|
|
wine_server_send_fd(1);
|
|
|
|
SERVER_START_REQ( create_console_output )
|
|
|
|
{
|
|
|
|
req->handle_in = wine_server_obj_handle(conin);
|
|
|
|
req->access = GENERIC_WRITE|GENERIC_READ;
|
|
|
|
req->attributes = OBJ_INHERIT;
|
|
|
|
req->share = FILE_SHARE_READ|FILE_SHARE_WRITE;
|
|
|
|
req->fd = 1;
|
|
|
|
wine_server_call(req);
|
|
|
|
params->hStdOutput = wine_server_ptr_handle(reply->handle_out);
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
|
|
|
if (!params->hStdError)
|
|
|
|
{
|
|
|
|
wine_server_send_fd(2);
|
|
|
|
SERVER_START_REQ( create_console_output )
|
|
|
|
{
|
|
|
|
req->handle_in = wine_server_obj_handle(conin);
|
|
|
|
req->access = GENERIC_WRITE|GENERIC_READ;
|
|
|
|
req->attributes = OBJ_INHERIT;
|
|
|
|
req->share = FILE_SHARE_READ|FILE_SHARE_WRITE;
|
|
|
|
req->fd = 2;
|
|
|
|
wine_server_call(req);
|
|
|
|
params->hStdError = wine_server_ptr_handle(reply->handle_out);
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
2010-08-30 22:19:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* convert value from server:
|
2015-01-04 07:37:42 +01:00
|
|
|
* + INVALID_HANDLE_VALUE => TEB: 0, STARTUPINFO: INVALID_HANDLE_VALUE
|
|
|
|
* + 0 => TEB: 0, STARTUPINFO: INVALID_HANDLE_VALUE
|
2010-08-30 22:19:18 +02:00
|
|
|
* + console handle needs to be mapped
|
|
|
|
*/
|
2015-01-04 07:37:42 +01:00
|
|
|
if (!params->hStdInput || params->hStdInput == INVALID_HANDLE_VALUE)
|
|
|
|
params->hStdInput = 0;
|
2010-08-30 22:19:18 +02:00
|
|
|
else if (VerifyConsoleIoHandle(console_handle_map(params->hStdInput)))
|
2010-09-10 21:50:19 +02:00
|
|
|
{
|
2010-08-30 22:19:18 +02:00
|
|
|
params->hStdInput = console_handle_map(params->hStdInput);
|
2010-09-10 21:50:19 +02:00
|
|
|
save_console_mode(params->hStdInput);
|
|
|
|
}
|
2010-08-30 22:19:18 +02:00
|
|
|
|
2015-01-04 07:37:42 +01:00
|
|
|
if (!params->hStdOutput || params->hStdOutput == INVALID_HANDLE_VALUE)
|
|
|
|
params->hStdOutput = 0;
|
2010-08-30 22:19:18 +02:00
|
|
|
else if (VerifyConsoleIoHandle(console_handle_map(params->hStdOutput)))
|
|
|
|
params->hStdOutput = console_handle_map(params->hStdOutput);
|
|
|
|
|
2015-01-04 07:37:42 +01:00
|
|
|
if (!params->hStdError || params->hStdError == INVALID_HANDLE_VALUE)
|
|
|
|
params->hStdError = 0;
|
2010-08-30 22:19:18 +02:00
|
|
|
else if (VerifyConsoleIoHandle(console_handle_map(params->hStdError)))
|
|
|
|
params->hStdError = console_handle_map(params->hStdError);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-09-10 21:50:19 +02:00
|
|
|
|
|
|
|
BOOL CONSOLE_Exit(void)
|
|
|
|
{
|
|
|
|
/* the console is in raw mode, put it back in cooked mode */
|
|
|
|
return restore_console_mode(GetStdHandle(STD_INPUT_HANDLE));
|
|
|
|
}
|
2012-01-18 09:27:33 +01:00
|
|
|
|
|
|
|
/* Undocumented, called by native doskey.exe */
|
|
|
|
/* FIXME: Should use CONSOLE_GetHistory() above for full implementation */
|
|
|
|
DWORD WINAPI GetConsoleCommandHistoryA(DWORD unknown1, DWORD unknown2, DWORD unknown3)
|
|
|
|
{
|
|
|
|
FIXME(": (0x%x, 0x%x, 0x%x) stub!\n", unknown1, unknown2, unknown3);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Undocumented, called by native doskey.exe */
|
|
|
|
/* FIXME: Should use CONSOLE_GetHistory() above for full implementation */
|
|
|
|
DWORD WINAPI GetConsoleCommandHistoryW(DWORD unknown1, DWORD unknown2, DWORD unknown3)
|
|
|
|
{
|
|
|
|
FIXME(": (0x%x, 0x%x, 0x%x) stub!\n", unknown1, unknown2, unknown3);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-19 22:48:51 +01:00
|
|
|
|
|
|
|
/* Undocumented, called by native doskey.exe */
|
|
|
|
/* FIXME: Should use CONSOLE_GetHistory() above for full implementation */
|
|
|
|
DWORD WINAPI GetConsoleCommandHistoryLengthA(LPCSTR unknown)
|
|
|
|
{
|
|
|
|
FIXME(": (%s) stub!\n", debugstr_a(unknown));
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Undocumented, called by native doskey.exe */
|
|
|
|
/* FIXME: Should use CONSOLE_GetHistory() above for full implementation */
|
|
|
|
DWORD WINAPI GetConsoleCommandHistoryLengthW(LPCWSTR unknown)
|
|
|
|
{
|
|
|
|
FIXME(": (%s) stub!\n", debugstr_w(unknown));
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-19 22:49:08 +01:00
|
|
|
|
|
|
|
DWORD WINAPI GetConsoleAliasesLengthA(LPSTR unknown)
|
|
|
|
{
|
|
|
|
FIXME(": (%s) stub!\n", debugstr_a(unknown));
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI GetConsoleAliasesLengthW(LPWSTR unknown)
|
|
|
|
{
|
|
|
|
FIXME(": (%s) stub!\n", debugstr_w(unknown));
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
2012-01-19 22:51:45 +01:00
|
|
|
|
2016-04-01 04:38:36 +02:00
|
|
|
DWORD WINAPI GetConsoleAliasExesLengthA(void)
|
|
|
|
{
|
|
|
|
FIXME(": stub!\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD WINAPI GetConsoleAliasExesLengthW(void)
|
|
|
|
{
|
|
|
|
FIXME(": stub!\n");
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-19 22:51:45 +01:00
|
|
|
VOID WINAPI ExpungeConsoleCommandHistoryA(LPCSTR unknown)
|
|
|
|
{
|
|
|
|
FIXME(": (%s) stub!\n", debugstr_a(unknown));
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID WINAPI ExpungeConsoleCommandHistoryW(LPCWSTR unknown)
|
|
|
|
{
|
|
|
|
FIXME(": (%s) stub!\n", debugstr_w(unknown));
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
}
|
2012-01-25 01:11:52 +01:00
|
|
|
|
|
|
|
BOOL WINAPI AddConsoleAliasA(LPSTR source, LPSTR target, LPSTR exename)
|
|
|
|
{
|
|
|
|
FIXME(": (%s, %s, %s) stub!\n", debugstr_a(source), debugstr_a(target), debugstr_a(exename));
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI AddConsoleAliasW(LPWSTR source, LPWSTR target, LPWSTR exename)
|
|
|
|
{
|
|
|
|
FIXME(": (%s, %s, %s) stub!\n", debugstr_w(source), debugstr_w(target), debugstr_w(exename));
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-06-05 09:59:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
BOOL WINAPI SetConsoleIcon(HICON icon)
|
|
|
|
{
|
|
|
|
FIXME(": (%p) stub!\n", icon);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-08-20 06:20:16 +02:00
|
|
|
|
2015-10-29 13:17:20 +01:00
|
|
|
DWORD WINAPI GetNumberOfConsoleFonts(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-01-05 08:59:33 +01:00
|
|
|
BOOL WINAPI SetConsoleFont(HANDLE hConsole, DWORD index)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %u): stub!\n", hConsole, index);
|
2019-11-14 00:29:58 +01:00
|
|
|
SetLastError(LOWORD(E_NOTIMPL) /* win10 1709+ */);
|
2016-01-05 08:59:33 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-11-02 18:29:47 +01:00
|
|
|
|
|
|
|
BOOL WINAPI SetConsoleKeyShortcuts(BOOL set, BYTE keys, VOID *a, DWORD b)
|
|
|
|
{
|
|
|
|
FIXME(": (%u %u %p %u) stub!\n", set, keys, a, b);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-11-20 11:45:29 +01:00
|
|
|
BOOL WINAPI GetCurrentConsoleFontEx(HANDLE hConsole, BOOL maxwindow, CONSOLE_FONT_INFOEX *fontinfo)
|
2012-08-20 06:20:16 +02:00
|
|
|
{
|
2015-10-26 07:42:13 +01:00
|
|
|
BOOL ret;
|
2019-11-20 11:45:29 +01:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
unsigned int color_map[16];
|
|
|
|
WCHAR face_name[LF_FACESIZE];
|
|
|
|
} data;
|
2015-10-26 07:42:13 +01:00
|
|
|
|
2019-11-20 11:45:29 +01:00
|
|
|
if (fontinfo->cbSize != sizeof(CONSOLE_FONT_INFOEX))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-10-26 07:42:13 +01:00
|
|
|
|
|
|
|
SERVER_START_REQ(get_console_output_info)
|
|
|
|
{
|
|
|
|
req->handle = console_handle_unmap(hConsole);
|
2019-11-20 11:45:29 +01:00
|
|
|
wine_server_set_reply( req, &data, sizeof(data) - sizeof(WCHAR) );
|
2015-10-26 07:42:13 +01:00
|
|
|
if ((ret = !wine_server_call_err(req)))
|
|
|
|
{
|
2019-11-20 11:45:29 +01:00
|
|
|
fontinfo->nFont = 0;
|
2016-01-27 04:55:16 +01:00
|
|
|
if (maxwindow)
|
|
|
|
{
|
|
|
|
fontinfo->dwFontSize.X = min(reply->width, reply->max_width);
|
|
|
|
fontinfo->dwFontSize.Y = min(reply->height, reply->max_height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fontinfo->dwFontSize.X = reply->win_right - reply->win_left + 1;
|
|
|
|
fontinfo->dwFontSize.Y = reply->win_bottom - reply->win_top + 1;
|
|
|
|
}
|
2019-11-20 11:45:29 +01:00
|
|
|
if (wine_server_reply_size( reply ) > sizeof(data.color_map))
|
|
|
|
{
|
|
|
|
data_size_t len = wine_server_reply_size( reply ) - sizeof(data.color_map);
|
|
|
|
memcpy( fontinfo->FaceName, data.face_name, len );
|
|
|
|
fontinfo->FaceName[len / sizeof(WCHAR)] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fontinfo->FaceName[0] = 0;
|
|
|
|
fontinfo->FontFamily = reply->font_pitch_family;
|
|
|
|
fontinfo->FontWeight = reply->font_weight;
|
2015-10-26 07:42:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return ret;
|
2012-08-20 06:45:03 +02:00
|
|
|
}
|
|
|
|
|
2019-11-20 11:45:29 +01:00
|
|
|
BOOL WINAPI GetCurrentConsoleFont(HANDLE hConsole, BOOL maxwindow, CONSOLE_FONT_INFO *fontinfo)
|
|
|
|
{
|
|
|
|
BOOL ret;
|
|
|
|
CONSOLE_FONT_INFOEX res;
|
|
|
|
|
|
|
|
res.cbSize = sizeof(CONSOLE_FONT_INFOEX);
|
|
|
|
|
|
|
|
ret = GetCurrentConsoleFontEx(hConsole, maxwindow, &res);
|
|
|
|
if(ret)
|
|
|
|
{
|
|
|
|
fontinfo->nFont = res.nFont;
|
|
|
|
fontinfo->dwFontSize.X = res.dwFontSize.X;
|
|
|
|
fontinfo->dwFontSize.Y = res.dwFontSize.Y;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-29 13:17:21 +01:00
|
|
|
static COORD get_console_font_size(HANDLE hConsole, DWORD index)
|
|
|
|
{
|
|
|
|
COORD c = {0,0};
|
|
|
|
|
|
|
|
if (index >= GetNumberOfConsoleFonts())
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
SERVER_START_REQ(get_console_output_info)
|
|
|
|
{
|
|
|
|
req->handle = console_handle_unmap(hConsole);
|
|
|
|
if (!wine_server_call_err(req))
|
|
|
|
{
|
|
|
|
c.X = reply->font_width;
|
|
|
|
c.Y = reply->font_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2020-04-27 01:19:00 +02:00
|
|
|
#if defined(__i386__) && !defined(__MINGW32__) && !defined(_MSC_VER)
|
2012-08-20 06:45:03 +02:00
|
|
|
#undef GetConsoleFontSize
|
2015-10-29 13:17:21 +01:00
|
|
|
DWORD WINAPI GetConsoleFontSize(HANDLE hConsole, DWORD index)
|
2012-08-20 06:45:03 +02:00
|
|
|
{
|
|
|
|
union {
|
|
|
|
COORD c;
|
|
|
|
DWORD w;
|
|
|
|
} x;
|
|
|
|
|
2015-10-29 13:17:21 +01:00
|
|
|
x.c = get_console_font_size(hConsole, index);
|
2012-08-20 06:45:03 +02:00
|
|
|
return x.w;
|
|
|
|
}
|
2019-09-09 22:17:58 +02:00
|
|
|
#else
|
2015-10-29 13:17:21 +01:00
|
|
|
COORD WINAPI GetConsoleFontSize(HANDLE hConsole, DWORD index)
|
2012-08-20 06:45:03 +02:00
|
|
|
{
|
2015-10-29 13:17:21 +01:00
|
|
|
return get_console_font_size(hConsole, index);
|
2012-08-20 06:20:16 +02:00
|
|
|
}
|
2015-10-29 13:17:21 +01:00
|
|
|
#endif /* !defined(__i386__) */
|
2015-12-27 04:56:10 +01:00
|
|
|
|
2016-04-19 03:20:50 +02:00
|
|
|
BOOL WINAPI GetConsoleFontInfo(HANDLE hConsole, BOOL maximize, DWORD numfonts, CONSOLE_FONT_INFO *info)
|
|
|
|
{
|
|
|
|
FIXME("(%p %d %u %p): stub!\n", hConsole, maximize, numfonts, info);
|
2019-11-06 16:46:09 +01:00
|
|
|
SetLastError(LOWORD(E_NOTIMPL) /* win10 1709+ */);
|
2016-04-19 03:20:50 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-03-21 08:53:57 +01:00
|
|
|
BOOL WINAPI SetCurrentConsoleFontEx(HANDLE hConsole, BOOL maxwindow, CONSOLE_FONT_INFOEX *cfix)
|
|
|
|
{
|
|
|
|
FIXME("(%p %d %p): stub!\n", hConsole, maxwindow, cfix);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|