2001-11-30 18:46:42 +00:00
|
|
|
/*
|
2004-09-08 01:25:05 +00:00
|
|
|
* Win32 console functions
|
2001-11-30 18:46:42 +00:00
|
|
|
*
|
|
|
|
* Copyright 1995 Martin von Loewis and Cameron Heide
|
|
|
|
* Copyright 1997 Karl Garrison
|
|
|
|
* Copyright 1998 John Richardson
|
|
|
|
* Copyright 1998 Marcus Meissner
|
2011-01-18 21:02:37 +00:00
|
|
|
* Copyright 2001,2002,2004,2005,2010 Eric Pouech
|
2001-11-30 18:46:42 +00:00
|
|
|
* Copyright 2001 Alexandre Julliard
|
2002-03-09 23:29:33 +00: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 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2001-11-30 18:46:42 +00: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 19:20:28 +00:00
|
|
|
#include "wine/port.h"
|
2001-11-30 18:46:42 +00:00
|
|
|
|
2003-09-05 23:08:26 +00:00
|
|
|
#include <stdarg.h>
|
2001-11-30 18:46:42 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2014-04-16 08:09:02 +00:00
|
|
|
#include <limits.h>
|
2002-08-17 00:43:16 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2001-11-30 18:46:42 +00:00
|
|
|
#include <assert.h>
|
2010-08-30 20:19:24 +00:00
|
|
|
#ifdef HAVE_TERMIOS_H
|
|
|
|
# include <termios.h>
|
|
|
|
#endif
|
2010-12-12 21:31:32 +00:00
|
|
|
#ifdef HAVE_SYS_POLL_H
|
|
|
|
# include <sys/poll.h>
|
|
|
|
#endif
|
2001-11-30 18:46:42 +00:00
|
|
|
|
2011-08-03 16:07:09 +00:00
|
|
|
#define NONAMELESSUNION
|
2010-09-10 19:50:19 +00:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2003-09-05 23:08:26 +00:00
|
|
|
#include "windef.h"
|
2001-11-30 18:46:42 +00:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "wincon.h"
|
2020-07-06 17:28:57 +00:00
|
|
|
#include "wine/condrv.h"
|
2001-11-30 18:46:42 +00:00
|
|
|
#include "wine/server.h"
|
|
|
|
#include "wine/exception.h"
|
|
|
|
#include "wine/unicode.h"
|
2002-03-09 23:29:33 +00:00
|
|
|
#include "wine/debug.h"
|
2002-12-12 23:34:01 +00:00
|
|
|
#include "excpt.h"
|
2002-09-04 18:41:03 +00:00
|
|
|
#include "console_private.h"
|
2003-06-21 02:07:10 +00:00
|
|
|
#include "kernel_private.h"
|
2001-11-30 18:46:42 +00:00
|
|
|
|
2002-03-09 23:29:33 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(console);
|
2001-11-30 18:46:42 +00:00
|
|
|
|
2007-12-02 21:12:19 +00: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 09:54:09 +00: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 02:07:10 +00:00
|
|
|
|
2019-12-12 11:03:47 +00: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 19:50:19 +00: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 20:57:38 +00:00
|
|
|
if (is_console_handle(hin) &&
|
|
|
|
wine_server_handle_to_fd(wine_server_ptr_handle(console_handle_unmap(hin)),
|
2010-11-11 21:30:11 +00:00
|
|
|
0, &fd, NULL) == STATUS_SUCCESS)
|
2010-09-10 19:50:19 +00: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 18:14:46 +00:00
|
|
|
static BOOL put_console_into_raw_mode(int fd)
|
2010-09-10 19:50:19 +00: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 11:38:43 +00: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 19:50:19 +00:00
|
|
|
*/
|
|
|
|
static BOOL restore_console_mode(HANDLE hin)
|
|
|
|
{
|
|
|
|
int fd;
|
2015-11-17 15:41:43 +00: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 19:50:19 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-04-02 19:18:51 +00:00
|
|
|
/******************************************************************************
|
2007-01-18 07:53:39 +00:00
|
|
|
* GetConsoleWindow [KERNEL32.@] Get hwnd of the console window.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: hwnd of the console window.
|
|
|
|
* Failure: NULL
|
2004-04-02 19:18:51 +00:00
|
|
|
*/
|
|
|
|
HWND WINAPI GetConsoleWindow(VOID)
|
|
|
|
{
|
2007-08-23 15:17:17 +00:00
|
|
|
HWND hWnd = NULL;
|
|
|
|
|
|
|
|
SERVER_START_REQ(get_console_input_info)
|
|
|
|
{
|
|
|
|
req->handle = 0;
|
2008-12-08 15:58:20 +00:00
|
|
|
if (!wine_server_call_err(req)) hWnd = wine_server_ptr_handle( reply->win );
|
2007-08-23 15:17:17 +00:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
|
|
|
|
return hWnd;
|
2004-04-02 19:18:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-08 04:24:49 +00: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 04:10:52 +00:00
|
|
|
/******************************************************************
|
|
|
|
* OpenConsoleW (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Undocumented
|
|
|
|
* Open a handle to the current process console.
|
|
|
|
* Returns INVALID_HANDLE_VALUE on failure.
|
|
|
|
*/
|
2004-03-11 22:46:27 +00:00
|
|
|
HANDLE WINAPI OpenConsoleW(LPCWSTR name, DWORD access, BOOL inherit, DWORD creation)
|
2003-12-12 04:10:52 +00:00
|
|
|
{
|
2020-06-25 20:27:51 +00:00
|
|
|
SECURITY_ATTRIBUTES sa;
|
2003-12-12 04:10:52 +00:00
|
|
|
|
2010-04-01 00:53:59 +00:00
|
|
|
TRACE("(%s, 0x%08x, %d, %u)\n", debugstr_w(name), access, inherit, creation);
|
|
|
|
|
2020-06-25 20:27:51 +00:00
|
|
|
if (!name || (strcmpiW( coninW, name ) && strcmpiW( conoutW, name )) || creation != OPEN_EXISTING)
|
2003-12-12 04:10:52 +00:00
|
|
|
{
|
2020-06-25 20:27:51 +00:00
|
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
2003-12-12 04:10:52 +00:00
|
|
|
return INVALID_HANDLE_VALUE;
|
2010-04-01 00:53:59 +00:00
|
|
|
}
|
2003-12-12 04:10:52 +00:00
|
|
|
|
2020-06-25 20:27:51 +00:00
|
|
|
sa.nLength = sizeof(sa);
|
|
|
|
sa.lpSecurityDescriptor = NULL;
|
|
|
|
sa.bInheritHandle = inherit;
|
2010-08-30 20:19:39 +00:00
|
|
|
|
2020-06-25 20:27:51 +00:00
|
|
|
return CreateFileW( name, access, FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, creation, 0, NULL );
|
2003-12-12 04:10:52 +00: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 17:54:36 +00:00
|
|
|
ret = !wine_server_call( req );
|
2003-12-12 04:10:52 +00: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 15:05:17 +00:00
|
|
|
!DuplicateHandle(GetCurrentProcess(), wine_server_ptr_handle(console_handle_unmap(handle)),
|
2003-12-12 04:10:52 +00: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 15:05:17 +00:00
|
|
|
return CloseHandle(wine_server_ptr_handle(console_handle_unmap(handle)));
|
2003-12-12 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* GetConsoleInputWaitHandle (KERNEL32.@)
|
|
|
|
*
|
|
|
|
* Undocumented
|
|
|
|
*/
|
|
|
|
HANDLE WINAPI GetConsoleInputWaitHandle(void)
|
|
|
|
{
|
2020-07-01 14:27:22 +00:00
|
|
|
return GetStdHandle( STD_INPUT_HANDLE );
|
2003-12-12 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-21 02:07:10 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* read_console_input
|
|
|
|
*
|
|
|
|
* Helper function for ReadConsole, ReadConsoleInput and FlushConsoleInputBuffer
|
|
|
|
*
|
2010-08-30 20:19:24 +00:00
|
|
|
* Returns
|
2003-06-21 02:07:10 +00:00
|
|
|
* 0 for error, 1 for no INPUT_RECORD ready, 2 with INPUT_RECORD ready
|
2001-11-30 18:46:42 +00:00
|
|
|
*/
|
2003-06-21 02:07:10 +00:00
|
|
|
enum read_console_input_return {rci_error = 0, rci_timeout = 1, rci_gotone = 2};
|
2010-08-30 20:19:24 +00:00
|
|
|
|
2010-12-12 21:31:32 +00:00
|
|
|
static enum read_console_input_return bare_console_fetch_input(HANDLE handle, int fd, DWORD timeout)
|
2010-08-30 20:19:24 +00:00
|
|
|
{
|
2011-01-18 21:02:37 +00:00
|
|
|
enum read_console_input_return ret;
|
|
|
|
char input[8];
|
2011-01-24 21:13:32 +00:00
|
|
|
WCHAR inputw[8];
|
2011-01-18 21:02:37 +00:00
|
|
|
int i;
|
2011-01-24 21:13:32 +00:00
|
|
|
size_t idx = 0, idxw;
|
2011-01-18 21:02:37 +00:00
|
|
|
unsigned numEvent;
|
|
|
|
INPUT_RECORD ir[8];
|
|
|
|
DWORD written;
|
|
|
|
struct pollfd pollfd;
|
|
|
|
BOOL locked = FALSE, next_char;
|
|
|
|
|
|
|
|
do
|
2010-08-30 20:19:24 +00:00
|
|
|
{
|
2011-01-18 21:02:37 +00: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 21:31:32 +00:00
|
|
|
{
|
2011-01-18 21:02:31 +00:00
|
|
|
case 1:
|
2011-01-18 21:02:37 +00: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 19:18:09 +00:00
|
|
|
idxw = MultiByteToWideChar(CP_UNIXCP, 0, input, idx, inputw, ARRAY_SIZE(inputw));
|
2011-01-24 21:13:32 +00: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 21:02:37 +00:00
|
|
|
{
|
2011-01-24 21:13:32 +00:00
|
|
|
numEvent = TERM_FillSimpleChar(inputw[i], ir);
|
2011-01-18 21:02:37 +00:00
|
|
|
WriteConsoleInputW(handle, ir, numEvent, &written);
|
|
|
|
}
|
2011-01-24 21:13:32 +00:00
|
|
|
ret = rci_gotone;
|
2011-01-18 21:02:37 +00: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 21:02:31 +00:00
|
|
|
break;
|
2011-01-18 21:02:37 +00:00
|
|
|
case 0: ret = rci_timeout; break;
|
2010-12-12 21:31:32 +00:00
|
|
|
default: ret = rci_error; break;
|
|
|
|
}
|
2011-01-18 21:02:37 +00:00
|
|
|
} while (next_char);
|
|
|
|
if (locked) RtlLeaveCriticalSection(&CONSOLE_CritSect);
|
|
|
|
|
|
|
|
return ret;
|
2010-08-30 20:19:24 +00:00
|
|
|
}
|
|
|
|
|
2004-05-05 05:54:44 +00:00
|
|
|
static enum read_console_input_return read_console_input(HANDLE handle, PINPUT_RECORD ir, DWORD timeout)
|
2001-11-30 18:46:42 +00:00
|
|
|
{
|
2010-11-07 18:14:46 +00:00
|
|
|
int fd;
|
2003-06-21 02:07:10 +00:00
|
|
|
enum read_console_input_return ret;
|
2020-07-06 17:28:57 +00:00
|
|
|
int blocking = timeout != 0;
|
|
|
|
DWORD read_bytes;
|
2003-06-21 02:07:10 +00:00
|
|
|
|
2010-11-07 18:14:46 +00:00
|
|
|
if ((fd = get_console_bare_fd(handle)) != -1)
|
2010-08-30 20:19:24 +00:00
|
|
|
{
|
2010-11-07 18:14:46 +00:00
|
|
|
put_console_into_raw_mode(fd);
|
2020-07-01 14:27:14 +00:00
|
|
|
if (WaitForSingleObject(handle, 0) != WAIT_OBJECT_0)
|
2010-08-30 20:19:24 +00:00
|
|
|
{
|
2010-12-12 21:31:32 +00:00
|
|
|
ret = bare_console_fetch_input(handle, fd, timeout);
|
2010-08-30 20:19:24 +00:00
|
|
|
}
|
2010-12-12 21:31:32 +00:00
|
|
|
else ret = rci_gotone;
|
|
|
|
close(fd);
|
|
|
|
if (ret != rci_gotone) return ret;
|
2010-08-30 20:19:24 +00:00
|
|
|
}
|
|
|
|
|
2020-07-06 17:28:57 +00:00
|
|
|
if (!DeviceIoControl( handle, IOCTL_CONDRV_READ_INPUT, &blocking, sizeof(blocking), ir, sizeof(*ir), &read_bytes, NULL ))
|
|
|
|
return rci_error;
|
|
|
|
return read_bytes ? rci_gotone : rci_timeout;
|
2001-11-30 18:46:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-21 02:07:10 +00: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 18:46:42 +00: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 18:28:00 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* GetConsoleKeyboardLayoutNameA (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetConsoleKeyboardLayoutNameA(LPSTR layoutName)
|
|
|
|
{
|
|
|
|
FIXME( "stub %p\n", layoutName);
|
2019-09-09 20:17:58 +00:00
|
|
|
return TRUE;
|
2001-11-30 18:46:42 +00:00
|
|
|
}
|
|
|
|
|
2019-09-09 20:17:58 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* GetConsoleKeyboardLayoutNameW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI GetConsoleKeyboardLayoutNameW(LPWSTR layoutName)
|
2016-01-05 07:59:32 +00:00
|
|
|
{
|
2019-09-09 20:17:58 +00:00
|
|
|
static int once;
|
|
|
|
if (!once++)
|
|
|
|
FIXME( "stub %p\n", layoutName);
|
|
|
|
return TRUE;
|
2016-01-05 07:59:32 +00:00
|
|
|
}
|
2001-11-30 18:46:42 +00:00
|
|
|
|
|
|
|
/***********************************************************************
|
2019-09-09 20:17:58 +00:00
|
|
|
* GetConsoleTitleA (KERNEL32.@)
|
2001-11-30 18:46:42 +00:00
|
|
|
*
|
2019-09-09 20:17:58 +00:00
|
|
|
* See GetConsoleTitleW.
|
2001-11-30 18:46:42 +00:00
|
|
|
*/
|
2019-09-09 20:17:58 +00:00
|
|
|
DWORD WINAPI GetConsoleTitleA(LPSTR title, DWORD size)
|
2001-11-30 18:46:42 +00:00
|
|
|
{
|
2019-09-09 20:17:58 +00:00
|
|
|
WCHAR *ptr = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * size);
|
|
|
|
DWORD ret;
|
2001-11-30 18:46:42 +00:00
|
|
|
|
2019-09-09 20:17:58 +00: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 18:46:42 +00:00
|
|
|
}
|
2019-09-09 20:17:58 +00:00
|
|
|
|
2002-07-31 19:20:28 +00:00
|
|
|
|
|
|
|
static WCHAR* S_EditString /* = NULL */;
|
|
|
|
static unsigned S_EditStrPos /* = 0 */;
|
|
|
|
|
|
|
|
|
2019-12-12 11:03:47 +00: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 19:20:28 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* ReadConsoleW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI ReadConsoleW(HANDLE hConsoleInput, LPVOID lpBuffer,
|
|
|
|
DWORD nNumberOfCharsToRead, LPDWORD lpNumberOfCharsRead, LPVOID lpReserved)
|
|
|
|
{
|
|
|
|
DWORD charsread;
|
2009-03-11 08:39:16 +00:00
|
|
|
LPWSTR xbuf = lpBuffer;
|
2002-07-31 19:20:28 +00:00
|
|
|
DWORD mode;
|
2010-11-07 18:14:46 +00:00
|
|
|
BOOL is_bare = FALSE;
|
|
|
|
int fd;
|
2002-07-31 19:20:28 +00:00
|
|
|
|
2006-10-12 20:56:29 +00:00
|
|
|
TRACE("(%p,%p,%d,%p,%p)\n",
|
2002-07-31 19:20:28 +00:00
|
|
|
hConsoleInput, lpBuffer, nNumberOfCharsToRead, lpNumberOfCharsRead, lpReserved);
|
|
|
|
|
2014-04-16 08:09:02 +00:00
|
|
|
if (nNumberOfCharsToRead > INT_MAX)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-11-07 18:14:46 +00:00
|
|
|
if (!GetConsoleMode(hConsoleInput, &mode))
|
2002-07-31 19:20:28 +00:00
|
|
|
return FALSE;
|
2010-11-11 21:30:11 +00:00
|
|
|
if ((fd = get_console_bare_fd(hConsoleInput)) != -1)
|
2010-11-07 18:14:46 +00:00
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
is_bare = TRUE;
|
|
|
|
}
|
2002-07-31 19:20:28 +00:00
|
|
|
if (mode & ENABLE_LINE_INPUT)
|
|
|
|
{
|
|
|
|
if (!S_EditString || S_EditString[S_EditStrPos] == 0)
|
|
|
|
{
|
2004-12-23 17:06:43 +00:00
|
|
|
HeapFree(GetProcessHeap(), 0, S_EditString);
|
2010-08-30 20:19:31 +00:00
|
|
|
if (!(S_EditString = CONSOLE_Readline(hConsoleInput, !is_bare)))
|
2002-07-31 19:20:28 +00: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 02:07:10 +00:00
|
|
|
DWORD timeout = INFINITE;
|
2002-07-31 19:20:28 +00: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 02:07:10 +00:00
|
|
|
* chars stored in xbuf...)
|
2007-12-18 16:38:50 +00: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 19:20:28 +00:00
|
|
|
*/
|
2003-06-21 02:07:10 +00:00
|
|
|
charsread = 0;
|
|
|
|
do
|
2002-07-31 19:20:28 +00:00
|
|
|
{
|
2003-06-21 02:07:10 +00:00
|
|
|
if (read_console_input(hConsoleInput, &ir, timeout) != rci_gotone) break;
|
|
|
|
if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown &&
|
2008-10-27 11:14:28 +00:00
|
|
|
ir.Event.KeyEvent.uChar.UnicodeChar)
|
2002-07-31 19:20:28 +00:00
|
|
|
{
|
|
|
|
xbuf[charsread++] = ir.Event.KeyEvent.uChar.UnicodeChar;
|
2007-12-18 16:38:50 +00:00
|
|
|
timeout = 0;
|
2002-07-31 19:20:28 +00:00
|
|
|
}
|
2003-06-21 02:07:10 +00:00
|
|
|
} while (charsread < nNumberOfCharsToRead);
|
|
|
|
/* nothing has been read */
|
|
|
|
if (timeout == INFINITE) return FALSE;
|
2002-07-31 19:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (lpNumberOfCharsRead) *lpNumberOfCharsRead = charsread;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-12 11:03:47 +00: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 19:20:28 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* ReadConsoleInputW (KERNEL32.@)
|
|
|
|
*/
|
2004-05-05 05:54:44 +00:00
|
|
|
BOOL WINAPI ReadConsoleInputW(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer,
|
2002-07-31 19:20:28 +00:00
|
|
|
DWORD nLength, LPDWORD lpNumberOfEventsRead)
|
|
|
|
{
|
2003-06-21 02:07:10 +00:00
|
|
|
DWORD idx = 0;
|
|
|
|
DWORD timeout = INFINITE;
|
2002-07-31 19:20:28 +00:00
|
|
|
|
|
|
|
if (!nLength)
|
|
|
|
{
|
|
|
|
if (lpNumberOfEventsRead) *lpNumberOfEventsRead = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* loop until we get at least one event */
|
2003-06-21 02:07:10 +00: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 19:20:28 +00: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 14:43:48 +00:00
|
|
|
LONG CALLBACK CONSOLE_HandleCtrlC( EXCEPTION_POINTERS *eptr )
|
2002-07-31 19:20:28 +00:00
|
|
|
{
|
2020-06-03 08:20:09 +00:00
|
|
|
extern DWORD WINAPI CtrlRoutine( void *arg );
|
2011-12-30 20:54:31 +00:00
|
|
|
HANDLE thread;
|
|
|
|
|
2020-06-06 14:43:48 +00:00
|
|
|
if (eptr->ExceptionRecord->ExceptionCode != CONTROL_C_EXIT) return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
|
2002-07-31 19:20:28 +00:00
|
|
|
/* FIXME: better test whether a console is attached to this process ??? */
|
2020-06-06 14:43:48 +00:00
|
|
|
if (CONSOLE_GetNumHistoryEntries() == (unsigned)-1) return EXCEPTION_CONTINUE_SEARCH;
|
2002-07-31 19:20:28 +00:00
|
|
|
|
2004-09-08 01:25:05 +00:00
|
|
|
/* check if we have to ignore ctrl-C events */
|
|
|
|
if (!(NtCurrentTeb()->Peb->ProcessParameters->ConsoleFlags & 1))
|
2002-07-31 19:20:28 +00:00
|
|
|
{
|
2004-09-08 01:25:05 +00: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 19:20:28 +00:00
|
|
|
*/
|
2020-06-03 08:20:09 +00:00
|
|
|
thread = CreateThread(NULL, 0, CtrlRoutine, (void*)CTRL_C_EVENT, 0, NULL);
|
2020-06-06 14:43:48 +00:00
|
|
|
if (thread) CloseHandle(thread);
|
2002-07-31 19:20:28 +00:00
|
|
|
}
|
2020-06-06 14:43:48 +00:00
|
|
|
return EXCEPTION_CONTINUE_EXECUTION;
|
2002-07-31 19:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2003-05-13 04:46:24 +00:00
|
|
|
* CONSOLE_WriteChars
|
2002-07-31 19:20:28 +00:00
|
|
|
*
|
|
|
|
* WriteConsoleOutput helper: hides server call semantics
|
2003-05-13 04:46:24 +00:00
|
|
|
* writes a string at a given pos with standard attribute
|
2002-07-31 19:20:28 +00:00
|
|
|
*/
|
2005-06-14 11:42:34 +00:00
|
|
|
static int CONSOLE_WriteChars(HANDLE hCon, LPCWSTR lpBuffer, int nc, COORD* pos)
|
2002-07-31 19:20:28 +00:00
|
|
|
{
|
|
|
|
int written = -1;
|
|
|
|
|
|
|
|
if (!nc) return 0;
|
|
|
|
|
|
|
|
SERVER_START_REQ( write_console_output )
|
|
|
|
{
|
2003-06-21 02:07:10 +00:00
|
|
|
req->handle = console_handle_unmap(hCon);
|
2002-07-31 19:20:28 +00: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-23 22:40:22 +00:00
|
|
|
static BOOL next_line(HANDLE hCon, CONSOLE_SCREEN_BUFFER_INFO* csbi)
|
2002-07-31 19:20:28 +00:00
|
|
|
{
|
|
|
|
SMALL_RECT src;
|
|
|
|
CHAR_INFO ci;
|
|
|
|
COORD dst;
|
|
|
|
|
|
|
|
csbi->dwCursorPosition.X = 0;
|
|
|
|
csbi->dwCursorPosition.Y++;
|
|
|
|
|
2013-10-23 22:40:22 +00:00
|
|
|
if (csbi->dwCursorPosition.Y < csbi->dwSize.Y) return TRUE;
|
2002-07-31 19:20:28 +00: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-23 22:40:22 +00:00
|
|
|
return FALSE;
|
|
|
|
return TRUE;
|
2002-07-31 19:20:28 +00: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-23 22:40:22 +00:00
|
|
|
static BOOL write_block(HANDLE hCon, CONSOLE_SCREEN_BUFFER_INFO* csbi,
|
|
|
|
DWORD mode, LPCWSTR ptr, int len)
|
2002-07-31 19:20:28 +00:00
|
|
|
{
|
|
|
|
int blk; /* number of chars to write on current line */
|
2003-05-13 04:46:24 +00:00
|
|
|
int done; /* number of chars already written */
|
2002-07-31 19:20:28 +00:00
|
|
|
|
2013-10-23 22:40:22 +00:00
|
|
|
if (len <= 0) return TRUE;
|
2002-07-31 19:20:28 +00: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 04:46:24 +00:00
|
|
|
if (CONSOLE_WriteChars(hCon, ptr + done, blk, &csbi->dwCursorPosition) != blk)
|
2013-10-23 22:40:22 +00:00
|
|
|
return FALSE;
|
2002-07-31 19:20:28 +00:00
|
|
|
if (csbi->dwCursorPosition.X == csbi->dwSize.X && !next_line(hCon, csbi))
|
2013-10-23 22:40:22 +00:00
|
|
|
return FALSE;
|
2002-07-31 19:20:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-05-13 04:46:24 +00: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 13:26:05 +00:00
|
|
|
for (done = 0; done < len; done += blk)
|
2002-07-31 19:20:28 +00:00
|
|
|
{
|
2003-05-13 04:46:24 +00: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-23 22:40:22 +00:00
|
|
|
return FALSE;
|
2002-07-31 19:20:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-23 22:40:22 +00:00
|
|
|
return TRUE;
|
2002-07-31 19:20:28 +00:00
|
|
|
}
|
|
|
|
|
2019-12-12 11:03:47 +00: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 19:20:28 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* WriteConsoleW (KERNEL32.@)
|
|
|
|
*/
|
|
|
|
BOOL WINAPI WriteConsoleW(HANDLE hConsoleOutput, LPCVOID lpBuffer, DWORD nNumberOfCharsToWrite,
|
|
|
|
LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
|
|
|
|
{
|
|
|
|
DWORD mode;
|
|
|
|
DWORD nw = 0;
|
2004-06-14 17:04:34 +00:00
|
|
|
const WCHAR* psz = lpBuffer;
|
2002-07-31 19:20:28 +00:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
2010-11-07 18:14:46 +00:00
|
|
|
int k, first = 0, fd;
|
2002-07-31 19:20:28 +00:00
|
|
|
|
2006-10-12 20:56:29 +00:00
|
|
|
TRACE("%p %s %d %p %p\n",
|
2002-07-31 19:20:28 +00:00
|
|
|
hConsoleOutput, debugstr_wn(lpBuffer, nNumberOfCharsToWrite),
|
|
|
|
nNumberOfCharsToWrite, lpNumberOfCharsWritten, lpReserved);
|
|
|
|
|
|
|
|
if (lpNumberOfCharsWritten) *lpNumberOfCharsWritten = 0;
|
|
|
|
|
2010-11-07 18:14:46 +00:00
|
|
|
if ((fd = get_console_bare_fd(hConsoleOutput)) != -1)
|
2010-08-30 20:19:24 +00:00
|
|
|
{
|
|
|
|
char* ptr;
|
|
|
|
unsigned len;
|
2011-08-03 16:07:09 +00:00
|
|
|
HANDLE hFile;
|
|
|
|
NTSTATUS status;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
2010-08-30 20:19:24 +00:00
|
|
|
|
2010-11-07 18:14:46 +00:00
|
|
|
close(fd);
|
2010-08-30 20:19:24 +00: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 16:07:09 +00: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 20:19:24 +00:00
|
|
|
{
|
2011-08-03 16:07:09 +00:00
|
|
|
WaitForSingleObject(hFile, INFINITE);
|
|
|
|
status = iosb.u.Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != STATUS_PENDING && lpNumberOfCharsWritten)
|
|
|
|
{
|
|
|
|
if (iosb.Information == len)
|
2010-08-30 20:19:24 +00:00
|
|
|
*lpNumberOfCharsWritten = nNumberOfCharsToWrite;
|
|
|
|
else
|
|
|
|
FIXME("Conversion not supported yet\n");
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, ptr);
|
2020-05-26 10:29:06 +00:00
|
|
|
return set_ntstatus( status );
|
2010-08-30 20:19:24 +00:00
|
|
|
}
|
|
|
|
|
2010-11-07 18:14:46 +00:00
|
|
|
if (!GetConsoleMode(hConsoleOutput, &mode) || !GetConsoleScreenBufferInfo(hConsoleOutput, &csbi))
|
2002-07-31 19:20:28 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2009-01-19 05:52:11 +00:00
|
|
|
if (!nNumberOfCharsToWrite) return TRUE;
|
|
|
|
|
2002-07-31 19:20:28 +00:00
|
|
|
if (mode & ENABLE_PROCESSED_OUTPUT)
|
|
|
|
{
|
2004-08-10 23:43:21 +00:00
|
|
|
unsigned int i;
|
2002-07-31 19:20:28 +00: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 12:08:23 +00:00
|
|
|
static const WCHAR tmp[] = {' ',' ',' ',' ',' ',' ',' ',' '};
|
2002-07-31 19:20:28 +00: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 02:07:10 +00:00
|
|
|
req->handle = console_handle_unmap(hConsoleOutput);
|
2002-07-31 19:20:28 +00: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 17:14:41 +00: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 19:20:28 +00: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 10:55:43 +00:00
|
|
|
if (!len) return FALSE;
|
2002-07-31 19:20:28 +00: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 06:01:32 +00:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* CONSOLE_GetEditionMode
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL CONSOLE_GetEditionMode(HANDLE hConIn, int* mode)
|
|
|
|
{
|
2020-07-07 14:07:15 +00:00
|
|
|
struct condrv_input_info info;
|
|
|
|
return DeviceIoControl( hConIn, IOCTL_CONDRV_GET_INPUT_INFO, NULL, 0, &info, sizeof(info), NULL, NULL )
|
|
|
|
? info.edition_mode : 0;
|
2003-01-09 06:01:32 +00:00
|
|
|
}
|
2008-12-07 19:41:06 +00: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 17:03:53 +00:00
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return 0;
|
2008-12-07 19:41:06 +00:00
|
|
|
}
|
2010-01-05 08:32:36 +00: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 20:19:18 +00:00
|
|
|
|
|
|
|
BOOL CONSOLE_Init(RTL_USER_PROCESS_PARAMETERS *params)
|
|
|
|
{
|
2010-09-10 19:50:19 +00:00
|
|
|
memset(&S_termios, 0, sizeof(S_termios));
|
2010-08-30 20:19:18 +00: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 21:02:24 +00:00
|
|
|
TERM_Init();
|
2010-08-30 20:19:24 +00:00
|
|
|
wine_server_send_fd(0);
|
2010-08-30 20:19:18 +00:00
|
|
|
SERVER_START_REQ( alloc_console )
|
|
|
|
{
|
|
|
|
req->access = GENERIC_READ | GENERIC_WRITE;
|
|
|
|
req->attributes = OBJ_INHERIT;
|
|
|
|
req->pid = 0xffffffff;
|
2010-08-30 20:19:24 +00:00
|
|
|
req->input_fd = 0;
|
2010-08-30 20:19:18 +00: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 20:19:24 +00: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 20:19:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* convert value from server:
|
2015-01-04 06:37:42 +00:00
|
|
|
* + INVALID_HANDLE_VALUE => TEB: 0, STARTUPINFO: INVALID_HANDLE_VALUE
|
|
|
|
* + 0 => TEB: 0, STARTUPINFO: INVALID_HANDLE_VALUE
|
2010-08-30 20:19:18 +00:00
|
|
|
* + console handle needs to be mapped
|
|
|
|
*/
|
2015-01-04 06:37:42 +00:00
|
|
|
if (!params->hStdInput || params->hStdInput == INVALID_HANDLE_VALUE)
|
|
|
|
params->hStdInput = 0;
|
2010-08-30 20:19:18 +00:00
|
|
|
else if (VerifyConsoleIoHandle(console_handle_map(params->hStdInput)))
|
2010-09-10 19:50:19 +00:00
|
|
|
{
|
2010-08-30 20:19:18 +00:00
|
|
|
params->hStdInput = console_handle_map(params->hStdInput);
|
2010-09-10 19:50:19 +00:00
|
|
|
save_console_mode(params->hStdInput);
|
|
|
|
}
|
2010-08-30 20:19:18 +00:00
|
|
|
|
2015-01-04 06:37:42 +00:00
|
|
|
if (!params->hStdOutput || params->hStdOutput == INVALID_HANDLE_VALUE)
|
|
|
|
params->hStdOutput = 0;
|
2010-08-30 20:19:18 +00:00
|
|
|
else if (VerifyConsoleIoHandle(console_handle_map(params->hStdOutput)))
|
|
|
|
params->hStdOutput = console_handle_map(params->hStdOutput);
|
|
|
|
|
2015-01-04 06:37:42 +00:00
|
|
|
if (!params->hStdError || params->hStdError == INVALID_HANDLE_VALUE)
|
|
|
|
params->hStdError = 0;
|
2010-08-30 20:19:18 +00:00
|
|
|
else if (VerifyConsoleIoHandle(console_handle_map(params->hStdError)))
|
|
|
|
params->hStdError = console_handle_map(params->hStdError);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-09-10 19:50:19 +00: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 08:27:33 +00: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 21:48:51 +00: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 21:49:08 +00: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 21:51:45 +00:00
|
|
|
|
2016-04-01 02:38:36 +00: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 21:51:45 +00: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 00:11:52 +00: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 07:59:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
BOOL WINAPI SetConsoleIcon(HICON icon)
|
|
|
|
{
|
|
|
|
FIXME(": (%p) stub!\n", icon);
|
|
|
|
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2012-08-20 04:20:16 +00:00
|
|
|
|
2015-10-29 12:17:20 +00:00
|
|
|
DWORD WINAPI GetNumberOfConsoleFonts(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-01-05 07:59:33 +00:00
|
|
|
BOOL WINAPI SetConsoleFont(HANDLE hConsole, DWORD index)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %u): stub!\n", hConsole, index);
|
2019-11-13 23:29:58 +00:00
|
|
|
SetLastError(LOWORD(E_NOTIMPL) /* win10 1709+ */);
|
2016-01-05 07:59:33 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2015-11-02 17:29:47 +00: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 10:45:29 +00:00
|
|
|
BOOL WINAPI GetCurrentConsoleFontEx(HANDLE hConsole, BOOL maxwindow, CONSOLE_FONT_INFOEX *fontinfo)
|
2012-08-20 04:20:16 +00:00
|
|
|
{
|
2020-07-09 17:28:32 +00:00
|
|
|
DWORD size;
|
2019-11-20 10:45:29 +00:00
|
|
|
struct
|
|
|
|
{
|
2020-07-09 17:28:32 +00:00
|
|
|
struct condrv_output_info info;
|
|
|
|
WCHAR face_name[LF_FACESIZE - 1];
|
2019-11-20 10:45:29 +00:00
|
|
|
} data;
|
2015-10-26 06:42:13 +00:00
|
|
|
|
2019-11-20 10:45:29 +00:00
|
|
|
if (fontinfo->cbSize != sizeof(CONSOLE_FONT_INFOEX))
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2015-10-26 06:42:13 +00:00
|
|
|
|
2020-07-09 17:28:32 +00:00
|
|
|
if (!DeviceIoControl( hConsole, IOCTL_CONDRV_GET_OUTPUT_INFO, NULL, 0,
|
|
|
|
&data, sizeof(data), &size, NULL ))
|
2015-10-26 06:42:13 +00:00
|
|
|
{
|
2020-07-09 17:28:32 +00:00
|
|
|
SetLastError( ERROR_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
2015-10-26 06:42:13 +00:00
|
|
|
}
|
2020-07-09 17:28:32 +00:00
|
|
|
|
|
|
|
fontinfo->nFont = 0;
|
|
|
|
if (maxwindow)
|
|
|
|
{
|
|
|
|
fontinfo->dwFontSize.X = min( data.info.width, data.info.max_width );
|
|
|
|
fontinfo->dwFontSize.Y = min( data.info.height, data.info.max_height );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fontinfo->dwFontSize.X = data.info.win_right - data.info.win_left + 1;
|
|
|
|
fontinfo->dwFontSize.Y = data.info.win_bottom - data.info.win_top + 1;
|
|
|
|
}
|
|
|
|
size -= sizeof(data.info);
|
|
|
|
if (size) memcpy( fontinfo->FaceName, data.face_name, size );
|
|
|
|
fontinfo->FaceName[size / sizeof(WCHAR)] = 0;
|
|
|
|
fontinfo->FontFamily = data.info.font_pitch_family;
|
|
|
|
fontinfo->FontWeight = data.info.font_weight;
|
|
|
|
return TRUE;
|
2012-08-20 04:45:03 +00:00
|
|
|
}
|
|
|
|
|
2019-11-20 10:45:29 +00: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 12:17:21 +00:00
|
|
|
static COORD get_console_font_size(HANDLE hConsole, DWORD index)
|
|
|
|
{
|
2020-07-09 17:28:20 +00:00
|
|
|
struct condrv_output_info info;
|
2015-10-29 12:17:21 +00:00
|
|
|
COORD c = {0,0};
|
|
|
|
|
|
|
|
if (index >= GetNumberOfConsoleFonts())
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2020-07-09 17:28:20 +00:00
|
|
|
if (DeviceIoControl( hConsole, IOCTL_CONDRV_GET_OUTPUT_INFO, NULL, 0, &info, sizeof(info), NULL, NULL ))
|
2015-10-29 12:17:21 +00:00
|
|
|
{
|
2020-07-09 17:28:20 +00:00
|
|
|
c.X = info.font_width;
|
|
|
|
c.Y = info.font_height;
|
2015-10-29 12:17:21 +00:00
|
|
|
}
|
2020-07-09 17:28:20 +00:00
|
|
|
else SetLastError( ERROR_INVALID_HANDLE );
|
2015-10-29 12:17:21 +00:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2020-04-26 23:19:00 +00:00
|
|
|
#if defined(__i386__) && !defined(__MINGW32__) && !defined(_MSC_VER)
|
2012-08-20 04:45:03 +00:00
|
|
|
#undef GetConsoleFontSize
|
2015-10-29 12:17:21 +00:00
|
|
|
DWORD WINAPI GetConsoleFontSize(HANDLE hConsole, DWORD index)
|
2012-08-20 04:45:03 +00:00
|
|
|
{
|
|
|
|
union {
|
|
|
|
COORD c;
|
|
|
|
DWORD w;
|
|
|
|
} x;
|
|
|
|
|
2015-10-29 12:17:21 +00:00
|
|
|
x.c = get_console_font_size(hConsole, index);
|
2012-08-20 04:45:03 +00:00
|
|
|
return x.w;
|
|
|
|
}
|
2019-09-09 20:17:58 +00:00
|
|
|
#else
|
2015-10-29 12:17:21 +00:00
|
|
|
COORD WINAPI GetConsoleFontSize(HANDLE hConsole, DWORD index)
|
2012-08-20 04:45:03 +00:00
|
|
|
{
|
2015-10-29 12:17:21 +00:00
|
|
|
return get_console_font_size(hConsole, index);
|
2012-08-20 04:20:16 +00:00
|
|
|
}
|
2015-10-29 12:17:21 +00:00
|
|
|
#endif /* !defined(__i386__) */
|
2015-12-27 03:56:10 +00:00
|
|
|
|
2016-04-19 01:20:50 +00: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 15:46:09 +00:00
|
|
|
SetLastError(LOWORD(E_NOTIMPL) /* win10 1709+ */);
|
2016-04-19 01:20:50 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-03-21 07:53:57 +00: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;
|
|
|
|
}
|