2 * Win32 console functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
5 * Copyright 1997 Karl Garrison
6 * Copyright 1998 John Richardson
7 * Copyright 1998 Marcus Meissner
8 * Copyright 2001,2002,2004,2005,2010 Eric Pouech
9 * Copyright 2001 Alexandre Julliard
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 /* Reference applications:
27 * - IDA (interactive disassembler) full version 3.75. Works.
28 * - LYNX/W32. Works mostly, some keys crash it.
32 #include "wine/port.h"
45 #ifdef HAVE_SYS_POLL_H
46 # include <sys/poll.h>
49 #define NONAMELESSUNION
51 #define WIN32_NO_STATUS
57 #include "wine/server.h"
58 #include "wine/exception.h"
59 #include "wine/unicode.h"
60 #include "wine/debug.h"
62 #include "console_private.h"
63 #include "kernel_private.h"
65 WINE_DEFAULT_DEBUG_CHANNEL(console
);
67 static CRITICAL_SECTION CONSOLE_CritSect
;
68 static CRITICAL_SECTION_DEBUG critsect_debug
=
70 0, 0, &CONSOLE_CritSect
,
71 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
72 0, 0, { (DWORD_PTR
)(__FILE__
": CONSOLE_CritSect") }
74 static CRITICAL_SECTION CONSOLE_CritSect
= { &critsect_debug
, -1, 0, 0, 0, 0 };
76 static const WCHAR coninW
[] = {'C','O','N','I','N','$',0};
77 static const WCHAR conoutW
[] = {'C','O','N','O','U','T','$',0};
79 /* FIXME: this is not thread safe */
80 static HANDLE console_wait_event
;
82 /* map input records to ASCII */
83 static void input_records_WtoA( INPUT_RECORD
*buffer
, int count
)
85 UINT cp
= GetConsoleCP();
89 for (i
= 0; i
< count
; i
++)
91 if (buffer
[i
].EventType
!= KEY_EVENT
) continue;
92 WideCharToMultiByte( cp
, 0, &buffer
[i
].Event
.KeyEvent
.uChar
.UnicodeChar
, 1, &ch
, 1, NULL
, NULL
);
93 buffer
[i
].Event
.KeyEvent
.uChar
.AsciiChar
= ch
;
97 static struct termios S_termios
; /* saved termios for bare consoles */
98 static BOOL S_termios_raw
/* = FALSE */;
100 /* The scheme for bare consoles for managing raw/cooked settings is as follows:
101 * - a bare console is created for all CUI programs started from command line (without
102 * wineconsole) (let's call those PS)
103 * - of course, every child of a PS which requires console inheritance will get it
104 * - the console termios attributes are saved at the start of program which is attached to be
106 * - if any program attached to a bare console requests input from console, the console is
107 * turned into raw mode
108 * - when the program which created the bare console (the program started from command line)
109 * exits, it will restore the console termios attributes it saved at startup (this
110 * will put back the console into cooked mode if it had been put in raw mode)
111 * - if any other program attached to this bare console is still alive, the Unix shell will put
112 * it in the background, hence forbidding access to the console. Therefore, reading console
113 * input will not be available when the bare console creator has died.
114 * FIXME: This is a limitation of current implementation
117 /* returns the fd for a bare console (-1 otherwise) */
118 static int get_console_bare_fd(HANDLE hin
)
122 if (is_console_handle(hin
) &&
123 wine_server_handle_to_fd(wine_server_ptr_handle(console_handle_unmap(hin
)),
124 0, &fd
, NULL
) == STATUS_SUCCESS
)
129 static BOOL
save_console_mode(HANDLE hin
)
134 if ((fd
= get_console_bare_fd(hin
)) == -1) return FALSE
;
135 ret
= tcgetattr(fd
, &S_termios
) >= 0;
140 static BOOL
put_console_into_raw_mode(int fd
)
142 RtlEnterCriticalSection(&CONSOLE_CritSect
);
145 struct termios term
= S_termios
;
147 term
.c_lflag
&= ~(ECHO
| ECHONL
| ICANON
| IEXTEN
);
148 term
.c_iflag
&= ~(BRKINT
| ICRNL
| INPCK
| ISTRIP
| IXON
);
149 term
.c_cflag
&= ~(CSIZE
| PARENB
);
151 /* FIXME: we should actually disable output processing here
152 * and let kernel32/console.c do the job (with support of enable/disable of
155 /* term.c_oflag &= ~(OPOST); */
157 term
.c_cc
[VTIME
] = 0;
158 S_termios_raw
= tcsetattr(fd
, TCSANOW
, &term
) >= 0;
160 RtlLeaveCriticalSection(&CONSOLE_CritSect
);
162 return S_termios_raw
;
165 /* put back the console in cooked mode iff we're the process which created the bare console
166 * we don't test if this process has set the console in raw mode as it could be one of its
167 * children who did it
169 static BOOL
restore_console_mode(HANDLE hin
)
176 if ((fd
= get_console_bare_fd(hin
)) == -1) return FALSE
;
177 ret
= tcsetattr(fd
, TCSANOW
, &S_termios
) >= 0;
181 if (RtlGetCurrentPeb()->ProcessParameters
->ConsoleHandle
== KERNEL32_CONSOLE_SHELL
)
187 /******************************************************************************
188 * GetConsoleWindow [KERNEL32.@] Get hwnd of the console window.
191 * Success: hwnd of the console window.
194 HWND WINAPI
GetConsoleWindow(VOID
)
198 SERVER_START_REQ(get_console_input_info
)
201 if (!wine_server_call_err(req
)) hWnd
= wine_server_ptr_handle( reply
->win
);
209 /***********************************************************************
212 BOOL WINAPI
Beep( DWORD dwFreq
, DWORD dwDur
)
214 static const char beep
= '\a';
215 /* dwFreq and dwDur are ignored by Win95 */
216 if (isatty(2)) write( 2, &beep
, 1 );
221 /******************************************************************
222 * OpenConsoleW (KERNEL32.@)
225 * Open a handle to the current process console.
226 * Returns INVALID_HANDLE_VALUE on failure.
228 HANDLE WINAPI
OpenConsoleW(LPCWSTR name
, DWORD access
, BOOL inherit
, DWORD creation
)
230 HANDLE output
= INVALID_HANDLE_VALUE
;
233 TRACE("(%s, 0x%08x, %d, %u)\n", debugstr_w(name
), access
, inherit
, creation
);
237 if (strcmpiW(coninW
, name
) == 0)
238 output
= (HANDLE
) FALSE
;
239 else if (strcmpiW(conoutW
, name
) == 0)
240 output
= (HANDLE
) TRUE
;
243 if (output
== INVALID_HANDLE_VALUE
|| creation
!= OPEN_EXISTING
)
245 SetLastError(ERROR_INVALID_PARAMETER
);
246 return INVALID_HANDLE_VALUE
;
249 SERVER_START_REQ( open_console
)
251 req
->from
= wine_server_obj_handle( output
);
252 req
->access
= access
;
253 req
->attributes
= inherit
? OBJ_INHERIT
: 0;
254 req
->share
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
255 wine_server_call_err( req
);
256 ret
= wine_server_ptr_handle( reply
->handle
);
260 ret
= console_handle_map(ret
);
265 /******************************************************************
266 * VerifyConsoleIoHandle (KERNEL32.@)
270 BOOL WINAPI
VerifyConsoleIoHandle(HANDLE handle
)
274 if (!is_console_handle(handle
)) return FALSE
;
275 SERVER_START_REQ(get_console_mode
)
277 req
->handle
= console_handle_unmap(handle
);
278 ret
= !wine_server_call( req
);
284 /******************************************************************
285 * DuplicateConsoleHandle (KERNEL32.@)
289 HANDLE WINAPI
DuplicateConsoleHandle(HANDLE handle
, DWORD access
, BOOL inherit
,
294 if (!is_console_handle(handle
) ||
295 !DuplicateHandle(GetCurrentProcess(), wine_server_ptr_handle(console_handle_unmap(handle
)),
296 GetCurrentProcess(), &ret
, access
, inherit
, options
))
297 return INVALID_HANDLE_VALUE
;
298 return console_handle_map(ret
);
301 /******************************************************************
302 * CloseConsoleHandle (KERNEL32.@)
306 BOOL WINAPI
CloseConsoleHandle(HANDLE handle
)
308 if (!is_console_handle(handle
))
310 SetLastError(ERROR_INVALID_PARAMETER
);
313 return CloseHandle(wine_server_ptr_handle(console_handle_unmap(handle
)));
316 /******************************************************************
317 * GetConsoleInputWaitHandle (KERNEL32.@)
321 HANDLE WINAPI
GetConsoleInputWaitHandle(void)
323 if (!console_wait_event
)
325 SERVER_START_REQ(get_console_wait_event
)
327 if (!wine_server_call_err( req
))
328 console_wait_event
= wine_server_ptr_handle( reply
->event
);
332 return console_wait_event
;
336 /******************************************************************************
339 * Helper function for ReadConsole, ReadConsoleInput and FlushConsoleInputBuffer
342 * 0 for error, 1 for no INPUT_RECORD ready, 2 with INPUT_RECORD ready
344 enum read_console_input_return
{rci_error
= 0, rci_timeout
= 1, rci_gotone
= 2};
346 static enum read_console_input_return
bare_console_fetch_input(HANDLE handle
, int fd
, DWORD timeout
)
348 enum read_console_input_return ret
;
352 size_t idx
= 0, idxw
;
356 struct pollfd pollfd
;
357 BOOL locked
= FALSE
, next_char
;
361 if (idx
== sizeof(input
))
363 FIXME("buffer too small (%s)\n", wine_dbgstr_an(input
, idx
));
368 pollfd
.events
= POLLIN
;
372 switch (poll(&pollfd
, 1, timeout
))
377 RtlEnterCriticalSection(&CONSOLE_CritSect
);
380 i
= read(fd
, &input
[idx
], 1);
388 /* actually another thread likely beat us to reading the char
389 * return rci_gotone, while not perfect, it should work in most of the cases (as the new event
390 * should be now in the queue, fed from the other thread)
397 numEvent
= TERM_FillInputRecord(input
, idx
, ir
);
401 /* we need more char(s) to tell if it matches a key-db entry. wait 1/2s for next char */
406 /* we haven't found the string into key-db, push full input string into server */
407 idxw
= MultiByteToWideChar(CP_UNIXCP
, 0, input
, idx
, inputw
, ARRAY_SIZE(inputw
));
409 /* we cannot translate yet... likely we need more chars (wait max 1/2s for next char) */
416 for (i
= 0; i
< idxw
; i
++)
418 numEvent
= TERM_FillSimpleChar(inputw
[i
], ir
);
419 WriteConsoleInputW(handle
, ir
, numEvent
, &written
);
424 /* we got a transformation from key-db... push this into server */
425 ret
= WriteConsoleInputW(handle
, ir
, numEvent
, &written
) ? rci_gotone
: rci_error
;
429 case 0: ret
= rci_timeout
; break;
430 default: ret
= rci_error
; break;
433 if (locked
) RtlLeaveCriticalSection(&CONSOLE_CritSect
);
438 static enum read_console_input_return
read_console_input(HANDLE handle
, PINPUT_RECORD ir
, DWORD timeout
)
441 enum read_console_input_return ret
;
443 if ((fd
= get_console_bare_fd(handle
)) != -1)
445 put_console_into_raw_mode(fd
);
446 if (WaitForSingleObject(GetConsoleInputWaitHandle(), 0) != WAIT_OBJECT_0
)
448 ret
= bare_console_fetch_input(handle
, fd
, timeout
);
450 else ret
= rci_gotone
;
452 if (ret
!= rci_gotone
) return ret
;
456 if (!VerifyConsoleIoHandle(handle
)) return rci_error
;
458 if (WaitForSingleObject(GetConsoleInputWaitHandle(), timeout
) != WAIT_OBJECT_0
)
462 SERVER_START_REQ( read_console_input
)
464 req
->handle
= console_handle_unmap(handle
);
466 wine_server_set_reply( req
, ir
, sizeof(INPUT_RECORD
) );
467 if (wine_server_call_err( req
) || !reply
->read
) ret
= rci_error
;
468 else ret
= rci_gotone
;
476 /***********************************************************************
477 * FlushConsoleInputBuffer (KERNEL32.@)
479 BOOL WINAPI
FlushConsoleInputBuffer( HANDLE handle
)
481 enum read_console_input_return last
;
484 while ((last
= read_console_input(handle
, &ir
, 0)) == rci_gotone
);
486 return last
== rci_timeout
;
490 /***********************************************************************
491 * SetConsoleTitleA (KERNEL32.@)
493 BOOL WINAPI
SetConsoleTitleA( LPCSTR title
)
498 DWORD len
= MultiByteToWideChar( GetConsoleOutputCP(), 0, title
, -1, NULL
, 0 );
499 if (!(titleW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
)))) return FALSE
;
500 MultiByteToWideChar( GetConsoleOutputCP(), 0, title
, -1, titleW
, len
);
501 ret
= SetConsoleTitleW(titleW
);
502 HeapFree(GetProcessHeap(), 0, titleW
);
507 /***********************************************************************
508 * GetConsoleKeyboardLayoutNameA (KERNEL32.@)
510 BOOL WINAPI
GetConsoleKeyboardLayoutNameA(LPSTR layoutName
)
512 FIXME( "stub %p\n", layoutName
);
516 /***********************************************************************
517 * GetConsoleKeyboardLayoutNameW (KERNEL32.@)
519 BOOL WINAPI
GetConsoleKeyboardLayoutNameW(LPWSTR layoutName
)
523 FIXME( "stub %p\n", layoutName
);
527 /***********************************************************************
528 * GetConsoleTitleA (KERNEL32.@)
530 * See GetConsoleTitleW.
532 DWORD WINAPI
GetConsoleTitleA(LPSTR title
, DWORD size
)
534 WCHAR
*ptr
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
) * size
);
538 ret
= GetConsoleTitleW( ptr
, size
);
541 WideCharToMultiByte( GetConsoleOutputCP(), 0, ptr
, ret
+ 1, title
, size
, NULL
, NULL
);
544 HeapFree(GetProcessHeap(), 0, ptr
);
549 static WCHAR
* S_EditString
/* = NULL */;
550 static unsigned S_EditStrPos
/* = 0 */;
552 /***********************************************************************
553 * FreeConsole (KERNEL32.@)
555 BOOL WINAPI
FreeConsole(VOID
)
559 /* invalidate local copy of input event handle */
560 console_wait_event
= 0;
562 SERVER_START_REQ(free_console
)
564 ret
= !wine_server_call_err( req
);
570 /******************************************************************
571 * start_console_renderer
573 * helper for AllocConsole
574 * starts the renderer process
576 static BOOL
start_console_renderer_helper(const char* appname
, STARTUPINFOA
* si
,
581 PROCESS_INFORMATION pi
;
583 /* FIXME: use dynamic allocation for most of the buffers below */
584 ret
= snprintf(buffer
, sizeof(buffer
), "%s --use-event=%ld", appname
, (DWORD_PTR
)hEvent
);
585 if ((ret
> -1) && (ret
< sizeof(buffer
)) &&
586 CreateProcessA(NULL
, buffer
, NULL
, NULL
, TRUE
, DETACHED_PROCESS
,
587 NULL
, NULL
, si
, &pi
))
594 res
= WaitForMultipleObjects(2, wh
, FALSE
, INFINITE
);
596 CloseHandle(pi
.hThread
);
597 CloseHandle(pi
.hProcess
);
599 if (res
!= WAIT_OBJECT_0
) return FALSE
;
601 TRACE("Started wineconsole pid=%08x tid=%08x\n",
602 pi
.dwProcessId
, pi
.dwThreadId
);
609 static BOOL
start_console_renderer(STARTUPINFOA
* si
)
613 OBJECT_ATTRIBUTES attr
;
616 attr
.Length
= sizeof(attr
);
617 attr
.RootDirectory
= 0;
618 attr
.Attributes
= OBJ_INHERIT
;
619 attr
.ObjectName
= NULL
;
620 attr
.SecurityDescriptor
= NULL
;
621 attr
.SecurityQualityOfService
= NULL
;
623 NtCreateEvent(&hEvent
, EVENT_ALL_ACCESS
, &attr
, NotificationEvent
, FALSE
);
624 if (!hEvent
) return FALSE
;
626 /* first try environment variable */
627 if ((p
= getenv("WINECONSOLE")) != NULL
)
629 ret
= start_console_renderer_helper(p
, si
, hEvent
);
631 ERR("Couldn't launch Wine console from WINECONSOLE env var (%s)... "
632 "trying default access\n", p
);
635 /* then try the regular PATH */
637 ret
= start_console_renderer_helper("wineconsole", si
, hEvent
);
643 /***********************************************************************
644 * AllocConsole (KERNEL32.@)
646 * creates an xterm with a pty to our program
648 BOOL WINAPI
AllocConsole(void)
650 HANDLE handle_in
= INVALID_HANDLE_VALUE
;
651 HANDLE handle_out
= INVALID_HANDLE_VALUE
;
652 HANDLE handle_err
= INVALID_HANDLE_VALUE
;
653 STARTUPINFOA siCurrent
;
654 STARTUPINFOA siConsole
;
659 handle_in
= OpenConsoleW( coninW
, GENERIC_READ
|GENERIC_WRITE
|SYNCHRONIZE
,
660 FALSE
, OPEN_EXISTING
);
662 if (VerifyConsoleIoHandle(handle_in
))
664 /* we already have a console opened on this process, don't create a new one */
665 CloseHandle(handle_in
);
669 /* invalidate local copy of input event handle */
670 console_wait_event
= 0;
672 GetStartupInfoA(&siCurrent
);
674 memset(&siConsole
, 0, sizeof(siConsole
));
675 siConsole
.cb
= sizeof(siConsole
);
676 /* setup a view arguments for wineconsole (it'll use them as default values) */
677 if (siCurrent
.dwFlags
& STARTF_USECOUNTCHARS
)
679 siConsole
.dwFlags
|= STARTF_USECOUNTCHARS
;
680 siConsole
.dwXCountChars
= siCurrent
.dwXCountChars
;
681 siConsole
.dwYCountChars
= siCurrent
.dwYCountChars
;
683 if (siCurrent
.dwFlags
& STARTF_USEFILLATTRIBUTE
)
685 siConsole
.dwFlags
|= STARTF_USEFILLATTRIBUTE
;
686 siConsole
.dwFillAttribute
= siCurrent
.dwFillAttribute
;
688 if (siCurrent
.dwFlags
& STARTF_USESHOWWINDOW
)
690 siConsole
.dwFlags
|= STARTF_USESHOWWINDOW
;
691 siConsole
.wShowWindow
= siCurrent
.wShowWindow
;
693 /* FIXME (should pass the unicode form) */
694 if (siCurrent
.lpTitle
)
695 siConsole
.lpTitle
= siCurrent
.lpTitle
;
696 else if (GetModuleFileNameA(0, buffer
, sizeof(buffer
)))
698 buffer
[sizeof(buffer
) - 1] = '\0';
699 siConsole
.lpTitle
= buffer
;
702 if (!start_console_renderer(&siConsole
))
705 if( !(siCurrent
.dwFlags
& STARTF_USESTDHANDLES
) ) {
706 /* all std I/O handles are inheritable by default */
707 handle_in
= OpenConsoleW( coninW
, GENERIC_READ
|GENERIC_WRITE
|SYNCHRONIZE
,
708 TRUE
, OPEN_EXISTING
);
709 if (handle_in
== INVALID_HANDLE_VALUE
) goto the_end
;
711 handle_out
= OpenConsoleW( conoutW
, GENERIC_READ
|GENERIC_WRITE
,
712 TRUE
, OPEN_EXISTING
);
713 if (handle_out
== INVALID_HANDLE_VALUE
) goto the_end
;
715 if (!DuplicateHandle(GetCurrentProcess(), handle_out
, GetCurrentProcess(),
716 &handle_err
, 0, TRUE
, DUPLICATE_SAME_ACCESS
))
719 /* STARTF_USESTDHANDLES flag: use handles from StartupInfo */
720 handle_in
= siCurrent
.hStdInput
;
721 handle_out
= siCurrent
.hStdOutput
;
722 handle_err
= siCurrent
.hStdError
;
725 /* NT resets the STD_*_HANDLEs on console alloc */
726 SetStdHandle(STD_INPUT_HANDLE
, handle_in
);
727 SetStdHandle(STD_OUTPUT_HANDLE
, handle_out
);
728 SetStdHandle(STD_ERROR_HANDLE
, handle_err
);
730 SetLastError(ERROR_SUCCESS
);
735 ERR("Can't allocate console\n");
736 if (handle_in
!= INVALID_HANDLE_VALUE
) CloseHandle(handle_in
);
737 if (handle_out
!= INVALID_HANDLE_VALUE
) CloseHandle(handle_out
);
738 if (handle_err
!= INVALID_HANDLE_VALUE
) CloseHandle(handle_err
);
744 /***********************************************************************
745 * ReadConsoleA (KERNEL32.@)
747 BOOL WINAPI
ReadConsoleA( HANDLE handle
, LPVOID buffer
, DWORD length
, DWORD
*ret_count
, void *reserved
)
749 LPWSTR strW
= HeapAlloc( GetProcessHeap(), 0, length
* sizeof(WCHAR
) );
755 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
758 if ((ret
= ReadConsoleW( handle
, strW
, length
, &count
, NULL
)))
760 count
= WideCharToMultiByte( GetConsoleCP(), 0, strW
, count
, buffer
, length
, NULL
, NULL
);
761 if (ret_count
) *ret_count
= count
;
763 HeapFree( GetProcessHeap(), 0, strW
);
768 /***********************************************************************
769 * ReadConsoleW (KERNEL32.@)
771 BOOL WINAPI
ReadConsoleW(HANDLE hConsoleInput
, LPVOID lpBuffer
,
772 DWORD nNumberOfCharsToRead
, LPDWORD lpNumberOfCharsRead
, LPVOID lpReserved
)
775 LPWSTR xbuf
= lpBuffer
;
777 BOOL is_bare
= FALSE
;
780 TRACE("(%p,%p,%d,%p,%p)\n",
781 hConsoleInput
, lpBuffer
, nNumberOfCharsToRead
, lpNumberOfCharsRead
, lpReserved
);
783 if (nNumberOfCharsToRead
> INT_MAX
)
785 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
789 if (!GetConsoleMode(hConsoleInput
, &mode
))
791 if ((fd
= get_console_bare_fd(hConsoleInput
)) != -1)
796 if (mode
& ENABLE_LINE_INPUT
)
798 if (!S_EditString
|| S_EditString
[S_EditStrPos
] == 0)
800 HeapFree(GetProcessHeap(), 0, S_EditString
);
801 if (!(S_EditString
= CONSOLE_Readline(hConsoleInput
, !is_bare
)))
805 charsread
= lstrlenW(&S_EditString
[S_EditStrPos
]);
806 if (charsread
> nNumberOfCharsToRead
) charsread
= nNumberOfCharsToRead
;
807 memcpy(xbuf
, &S_EditString
[S_EditStrPos
], charsread
* sizeof(WCHAR
));
808 S_EditStrPos
+= charsread
;
813 DWORD timeout
= INFINITE
;
815 /* FIXME: should we read at least 1 char? The SDK does not say */
816 /* wait for at least one available input record (it doesn't mean we'll have
817 * chars stored in xbuf...)
819 * Although SDK doc keeps silence about 1 char, SDK examples assume
820 * that we should wait for at least one character (not key). --KS
825 if (read_console_input(hConsoleInput
, &ir
, timeout
) != rci_gotone
) break;
826 if (ir
.EventType
== KEY_EVENT
&& ir
.Event
.KeyEvent
.bKeyDown
&&
827 ir
.Event
.KeyEvent
.uChar
.UnicodeChar
)
829 xbuf
[charsread
++] = ir
.Event
.KeyEvent
.uChar
.UnicodeChar
;
832 } while (charsread
< nNumberOfCharsToRead
);
833 /* nothing has been read */
834 if (timeout
== INFINITE
) return FALSE
;
837 if (lpNumberOfCharsRead
) *lpNumberOfCharsRead
= charsread
;
843 /***********************************************************************
844 * ReadConsoleInputA (KERNEL32.@)
846 BOOL WINAPI
ReadConsoleInputA( HANDLE handle
, INPUT_RECORD
*buffer
, DWORD length
, DWORD
*count
)
850 if (!ReadConsoleInputW( handle
, buffer
, length
, &read
)) return FALSE
;
851 input_records_WtoA( buffer
, read
);
852 if (count
) *count
= read
;
857 /***********************************************************************
858 * ReadConsoleInputW (KERNEL32.@)
860 BOOL WINAPI
ReadConsoleInputW(HANDLE hConsoleInput
, PINPUT_RECORD lpBuffer
,
861 DWORD nLength
, LPDWORD lpNumberOfEventsRead
)
864 DWORD timeout
= INFINITE
;
868 if (lpNumberOfEventsRead
) *lpNumberOfEventsRead
= 0;
872 /* loop until we get at least one event */
873 while (read_console_input(hConsoleInput
, &lpBuffer
[idx
], timeout
) == rci_gotone
&&
877 if (lpNumberOfEventsRead
) *lpNumberOfEventsRead
= idx
;
882 /***********************************************************************
883 * GetNumberOfConsoleMouseButtons (KERNEL32.@)
885 BOOL WINAPI
GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons
)
887 FIXME("(%p): stub\n", nrofbuttons
);
892 /******************************************************************
893 * CONSOLE_DefaultHandler
895 * Final control event handler
897 static BOOL WINAPI
CONSOLE_DefaultHandler(DWORD dwCtrlType
)
899 FIXME("Terminating process %x on event %x\n", GetCurrentProcessId(), dwCtrlType
);
901 /* should never go here */
905 /******************************************************************************
906 * SetConsoleCtrlHandler [KERNEL32.@] Adds function to calling process list
909 * func [I] Address of handler function
910 * add [I] Handler to add or remove
917 struct ConsoleHandler
919 PHANDLER_ROUTINE handler
;
920 struct ConsoleHandler
* next
;
923 static struct ConsoleHandler CONSOLE_DefaultConsoleHandler
= {CONSOLE_DefaultHandler
, NULL
};
924 static struct ConsoleHandler
* CONSOLE_Handlers
= &CONSOLE_DefaultConsoleHandler
;
926 /*****************************************************************************/
928 /******************************************************************
929 * SetConsoleCtrlHandler (KERNEL32.@)
931 BOOL WINAPI
SetConsoleCtrlHandler(PHANDLER_ROUTINE func
, BOOL add
)
935 TRACE("(%p,%i)\n", func
, add
);
939 RtlEnterCriticalSection(&CONSOLE_CritSect
);
941 NtCurrentTeb()->Peb
->ProcessParameters
->ConsoleFlags
|= 1;
943 NtCurrentTeb()->Peb
->ProcessParameters
->ConsoleFlags
&= ~1;
944 RtlLeaveCriticalSection(&CONSOLE_CritSect
);
948 struct ConsoleHandler
* ch
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct ConsoleHandler
));
950 if (!ch
) return FALSE
;
952 RtlEnterCriticalSection(&CONSOLE_CritSect
);
953 ch
->next
= CONSOLE_Handlers
;
954 CONSOLE_Handlers
= ch
;
955 RtlLeaveCriticalSection(&CONSOLE_CritSect
);
959 struct ConsoleHandler
** ch
;
960 RtlEnterCriticalSection(&CONSOLE_CritSect
);
961 for (ch
= &CONSOLE_Handlers
; *ch
; ch
= &(*ch
)->next
)
963 if ((*ch
)->handler
== func
) break;
967 struct ConsoleHandler
* rch
= *ch
;
970 if (rch
== &CONSOLE_DefaultConsoleHandler
)
972 ERR("Who's trying to remove default handler???\n");
973 SetLastError(ERROR_INVALID_PARAMETER
);
979 HeapFree(GetProcessHeap(), 0, rch
);
984 WARN("Attempt to remove non-installed CtrlHandler %p\n", func
);
985 SetLastError(ERROR_INVALID_PARAMETER
);
988 RtlLeaveCriticalSection(&CONSOLE_CritSect
);
993 static LONG WINAPI
CONSOLE_CtrlEventHandler(EXCEPTION_POINTERS
*eptr
)
995 TRACE("(%x)\n", eptr
->ExceptionRecord
->ExceptionCode
);
996 return EXCEPTION_EXECUTE_HANDLER
;
999 /******************************************************************
1000 * CONSOLE_SendEventThread
1002 * Internal helper to pass an event to the list on installed handlers
1004 static DWORD WINAPI
CONSOLE_SendEventThread(void* pmt
)
1006 DWORD_PTR event
= (DWORD_PTR
)pmt
;
1007 struct ConsoleHandler
* ch
;
1009 if (event
== CTRL_C_EVENT
)
1011 BOOL caught_by_dbg
= TRUE
;
1012 /* First, try to pass the ctrl-C event to the debugger (if any)
1013 * If it continues, there's nothing more to do
1014 * Otherwise, we need to send the ctrl-C event to the handlers
1018 RaiseException( DBG_CONTROL_C
, 0, 0, NULL
);
1020 __EXCEPT(CONSOLE_CtrlEventHandler
)
1022 caught_by_dbg
= FALSE
;
1025 if (caught_by_dbg
) return 0;
1026 /* the debugger didn't continue... so, pass to ctrl handlers */
1028 RtlEnterCriticalSection(&CONSOLE_CritSect
);
1029 for (ch
= CONSOLE_Handlers
; ch
; ch
= ch
->next
)
1031 if (ch
->handler(event
)) break;
1033 RtlLeaveCriticalSection(&CONSOLE_CritSect
);
1037 /******************************************************************
1038 * CONSOLE_HandleCtrlC
1040 * Check whether the shall manipulate CtrlC events
1042 int CONSOLE_HandleCtrlC(unsigned sig
)
1046 /* FIXME: better test whether a console is attached to this process ??? */
1047 extern unsigned CONSOLE_GetNumHistoryEntries(void);
1048 if (CONSOLE_GetNumHistoryEntries() == (unsigned)-1) return 0;
1050 /* check if we have to ignore ctrl-C events */
1051 if (!(NtCurrentTeb()->Peb
->ProcessParameters
->ConsoleFlags
& 1))
1053 /* Create a separate thread to signal all the events.
1054 * This is needed because:
1055 * - this function can be called in an Unix signal handler (hence on an
1056 * different stack than the thread that's running). This breaks the
1057 * Win32 exception mechanisms (where the thread's stack is checked).
1058 * - since the current thread, while processing the signal, can hold the
1059 * console critical section, we need another execution environment where
1060 * we can wait on this critical section
1062 thread
= CreateThread(NULL
, 0, CONSOLE_SendEventThread
, (void*)CTRL_C_EVENT
, 0, NULL
);
1066 CloseHandle(thread
);
1071 /******************************************************************
1072 * CONSOLE_WriteChars
1074 * WriteConsoleOutput helper: hides server call semantics
1075 * writes a string at a given pos with standard attribute
1077 static int CONSOLE_WriteChars(HANDLE hCon
, LPCWSTR lpBuffer
, int nc
, COORD
* pos
)
1083 SERVER_START_REQ( write_console_output
)
1085 req
->handle
= console_handle_unmap(hCon
);
1088 req
->mode
= CHAR_INFO_MODE_TEXTSTDATTR
;
1090 wine_server_add_data( req
, lpBuffer
, nc
* sizeof(WCHAR
) );
1091 if (!wine_server_call_err( req
)) written
= reply
->written
;
1095 if (written
> 0) pos
->X
+= written
;
1099 /******************************************************************
1102 * WriteConsoleOutput helper: handles passing to next line (+scrolling if necessary)
1105 static BOOL
next_line(HANDLE hCon
, CONSOLE_SCREEN_BUFFER_INFO
* csbi
)
1111 csbi
->dwCursorPosition
.X
= 0;
1112 csbi
->dwCursorPosition
.Y
++;
1114 if (csbi
->dwCursorPosition
.Y
< csbi
->dwSize
.Y
) return TRUE
;
1117 src
.Bottom
= csbi
->dwSize
.Y
- 1;
1119 src
.Right
= csbi
->dwSize
.X
- 1;
1124 ci
.Attributes
= csbi
->wAttributes
;
1125 ci
.Char
.UnicodeChar
= ' ';
1127 csbi
->dwCursorPosition
.Y
--;
1128 if (!ScrollConsoleScreenBufferW(hCon
, &src
, NULL
, dst
, &ci
))
1133 /******************************************************************
1136 * WriteConsoleOutput helper: writes a block of non special characters
1137 * Block can spread on several lines, and wrapping, if needed, is
1141 static BOOL
write_block(HANDLE hCon
, CONSOLE_SCREEN_BUFFER_INFO
* csbi
,
1142 DWORD mode
, LPCWSTR ptr
, int len
)
1144 int blk
; /* number of chars to write on current line */
1145 int done
; /* number of chars already written */
1147 if (len
<= 0) return TRUE
;
1149 if (mode
& ENABLE_WRAP_AT_EOL_OUTPUT
) /* writes remaining on next line */
1151 for (done
= 0; done
< len
; done
+= blk
)
1153 blk
= min(len
- done
, csbi
->dwSize
.X
- csbi
->dwCursorPosition
.X
);
1155 if (CONSOLE_WriteChars(hCon
, ptr
+ done
, blk
, &csbi
->dwCursorPosition
) != blk
)
1157 if (csbi
->dwCursorPosition
.X
== csbi
->dwSize
.X
&& !next_line(hCon
, csbi
))
1163 int pos
= csbi
->dwCursorPosition
.X
;
1164 /* FIXME: we could reduce the number of loops
1165 * but, in most cases we wouldn't gain lots of time (it would only
1166 * happen if we're asked to overwrite more than twice the part of the line,
1169 for (done
= 0; done
< len
; done
+= blk
)
1171 blk
= min(len
- done
, csbi
->dwSize
.X
- csbi
->dwCursorPosition
.X
);
1173 csbi
->dwCursorPosition
.X
= pos
;
1174 if (CONSOLE_WriteChars(hCon
, ptr
+ done
, blk
, &csbi
->dwCursorPosition
) != blk
)
1183 /***********************************************************************
1184 * WriteConsoleA (KERNEL32.@)
1186 BOOL WINAPI DECLSPEC_HOTPATCH
WriteConsoleA( HANDLE handle
, LPCVOID buffer
, DWORD length
,
1187 DWORD
*written
, void *reserved
)
1189 UINT cp
= GetConsoleOutputCP();
1194 if (written
) *written
= 0;
1195 lenW
= MultiByteToWideChar( cp
, 0, buffer
, length
, NULL
, 0 );
1196 if (!(strW
= HeapAlloc( GetProcessHeap(), 0, lenW
* sizeof(WCHAR
) ))) return FALSE
;
1197 MultiByteToWideChar( cp
, 0, buffer
, length
, strW
, lenW
);
1198 ret
= WriteConsoleW( handle
, strW
, lenW
, written
, 0 );
1199 HeapFree( GetProcessHeap(), 0, strW
);
1204 /***********************************************************************
1205 * WriteConsoleW (KERNEL32.@)
1207 BOOL WINAPI
WriteConsoleW(HANDLE hConsoleOutput
, LPCVOID lpBuffer
, DWORD nNumberOfCharsToWrite
,
1208 LPDWORD lpNumberOfCharsWritten
, LPVOID lpReserved
)
1212 const WCHAR
* psz
= lpBuffer
;
1213 CONSOLE_SCREEN_BUFFER_INFO csbi
;
1214 int k
, first
= 0, fd
;
1216 TRACE("%p %s %d %p %p\n",
1217 hConsoleOutput
, debugstr_wn(lpBuffer
, nNumberOfCharsToWrite
),
1218 nNumberOfCharsToWrite
, lpNumberOfCharsWritten
, lpReserved
);
1220 if (lpNumberOfCharsWritten
) *lpNumberOfCharsWritten
= 0;
1222 if ((fd
= get_console_bare_fd(hConsoleOutput
)) != -1)
1228 IO_STATUS_BLOCK iosb
;
1231 /* FIXME: mode ENABLED_OUTPUT is not processed (or actually we rely on underlying Unix/TTY fd
1234 len
= WideCharToMultiByte(CP_UNIXCP
, 0, lpBuffer
, nNumberOfCharsToWrite
, NULL
, 0, NULL
, NULL
);
1235 if ((ptr
= HeapAlloc(GetProcessHeap(), 0, len
)) == NULL
)
1238 WideCharToMultiByte(CP_UNIXCP
, 0, lpBuffer
, nNumberOfCharsToWrite
, ptr
, len
, NULL
, NULL
);
1239 hFile
= wine_server_ptr_handle(console_handle_unmap(hConsoleOutput
));
1240 status
= NtWriteFile(hFile
, NULL
, NULL
, NULL
, &iosb
, ptr
, len
, 0, NULL
);
1241 if (status
== STATUS_PENDING
)
1243 WaitForSingleObject(hFile
, INFINITE
);
1244 status
= iosb
.u
.Status
;
1247 if (status
!= STATUS_PENDING
&& lpNumberOfCharsWritten
)
1249 if (iosb
.Information
== len
)
1250 *lpNumberOfCharsWritten
= nNumberOfCharsToWrite
;
1252 FIXME("Conversion not supported yet\n");
1254 HeapFree(GetProcessHeap(), 0, ptr
);
1255 if (status
!= STATUS_SUCCESS
)
1257 SetLastError(RtlNtStatusToDosError(status
));
1263 if (!GetConsoleMode(hConsoleOutput
, &mode
) || !GetConsoleScreenBufferInfo(hConsoleOutput
, &csbi
))
1266 if (!nNumberOfCharsToWrite
) return TRUE
;
1268 if (mode
& ENABLE_PROCESSED_OUTPUT
)
1272 for (i
= 0; i
< nNumberOfCharsToWrite
; i
++)
1276 case '\b': case '\t': case '\n': case '\a': case '\r':
1277 /* don't handle here the i-th char... done below */
1278 if ((k
= i
- first
) > 0)
1280 if (!write_block(hConsoleOutput
, &csbi
, mode
, &psz
[first
], k
))
1290 if (csbi
.dwCursorPosition
.X
> 0) csbi
.dwCursorPosition
.X
--;
1294 static const WCHAR tmp
[] = {' ',' ',' ',' ',' ',' ',' ',' '};
1295 if (!write_block(hConsoleOutput
, &csbi
, mode
, tmp
,
1296 ((csbi
.dwCursorPosition
.X
+ 8) & ~7) - csbi
.dwCursorPosition
.X
))
1301 next_line(hConsoleOutput
, &csbi
);
1307 csbi
.dwCursorPosition
.X
= 0;
1315 /* write the remaining block (if any) if processed output is enabled, or the
1316 * entire buffer otherwise
1318 if ((k
= nNumberOfCharsToWrite
- first
) > 0)
1320 if (!write_block(hConsoleOutput
, &csbi
, mode
, &psz
[first
], k
))
1326 SetConsoleCursorPosition(hConsoleOutput
, csbi
.dwCursorPosition
);
1327 if (lpNumberOfCharsWritten
) *lpNumberOfCharsWritten
= nw
;
1332 /******************************************************************
1333 * CONSOLE_FillLineUniform
1335 * Helper function for ScrollConsoleScreenBufferW
1336 * Fills a part of a line with a constant character info
1338 void CONSOLE_FillLineUniform(HANDLE hConsoleOutput
, int i
, int j
, int len
, LPCHAR_INFO lpFill
)
1340 SERVER_START_REQ( fill_console_output
)
1342 req
->handle
= console_handle_unmap(hConsoleOutput
);
1343 req
->mode
= CHAR_INFO_MODE_TEXTATTR
;
1348 req
->data
.ch
= lpFill
->Char
.UnicodeChar
;
1349 req
->data
.attr
= lpFill
->Attributes
;
1350 wine_server_call_err( req
);
1355 /******************************************************************
1356 * GetConsoleDisplayMode (KERNEL32.@)
1358 BOOL WINAPI
GetConsoleDisplayMode(LPDWORD lpModeFlags
)
1360 TRACE("semi-stub: %p\n", lpModeFlags
);
1361 /* It is safe to successfully report windowed mode */
1366 /******************************************************************
1367 * SetConsoleDisplayMode (KERNEL32.@)
1369 BOOL WINAPI
SetConsoleDisplayMode(HANDLE hConsoleOutput
, DWORD dwFlags
,
1370 COORD
*lpNewScreenBufferDimensions
)
1372 TRACE("(%p, %x, (%d, %d))\n", hConsoleOutput
, dwFlags
,
1373 lpNewScreenBufferDimensions
->X
, lpNewScreenBufferDimensions
->Y
);
1376 /* We cannot switch to fullscreen */
1383 /* ====================================================================
1385 * Console manipulation functions
1387 * ====================================================================*/
1389 /* some missing functions...
1390 * FIXME: those are likely to be defined as undocumented function in kernel32 (or part of them)
1391 * should get the right API and implement them
1392 * SetConsoleCommandHistoryMode
1393 * SetConsoleNumberOfCommands[AW]
1395 int CONSOLE_GetHistory(int idx
, WCHAR
* buf
, int buf_len
)
1399 SERVER_START_REQ( get_console_input_history
)
1403 if (buf
&& buf_len
> 1)
1405 wine_server_set_reply( req
, buf
, (buf_len
- 1) * sizeof(WCHAR
) );
1407 if (!wine_server_call_err( req
))
1409 if (buf
) buf
[wine_server_reply_size(reply
) / sizeof(WCHAR
)] = 0;
1410 len
= reply
->total
/ sizeof(WCHAR
) + 1;
1417 /******************************************************************
1418 * CONSOLE_AppendHistory
1422 BOOL
CONSOLE_AppendHistory(const WCHAR
* ptr
)
1424 size_t len
= strlenW(ptr
);
1427 while (len
&& (ptr
[len
- 1] == '\n' || ptr
[len
- 1] == '\r')) len
--;
1428 if (!len
) return FALSE
;
1430 SERVER_START_REQ( append_console_input_history
)
1433 wine_server_add_data( req
, ptr
, len
* sizeof(WCHAR
) );
1434 ret
= !wine_server_call_err( req
);
1440 /******************************************************************
1441 * CONSOLE_GetNumHistoryEntries
1445 unsigned CONSOLE_GetNumHistoryEntries(void)
1448 SERVER_START_REQ(get_console_input_info
)
1451 if (!wine_server_call_err( req
)) ret
= reply
->history_index
;
1457 /******************************************************************
1458 * CONSOLE_GetEditionMode
1462 BOOL
CONSOLE_GetEditionMode(HANDLE hConIn
, int* mode
)
1465 SERVER_START_REQ(get_console_input_info
)
1467 req
->handle
= console_handle_unmap(hConIn
);
1468 if ((ret
= !wine_server_call_err( req
)))
1469 *mode
= reply
->edition_mode
;
1475 /******************************************************************
1480 * 0 if an error occurred, non-zero for success
1483 DWORD WINAPI
GetConsoleAliasW(LPWSTR lpSource
, LPWSTR lpTargetBuffer
,
1484 DWORD TargetBufferLength
, LPWSTR lpExename
)
1486 FIXME("(%s,%p,%d,%s): stub\n", debugstr_w(lpSource
), lpTargetBuffer
, TargetBufferLength
, debugstr_w(lpExename
));
1487 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1491 /******************************************************************
1492 * GetConsoleProcessList (KERNEL32.@)
1494 DWORD WINAPI
GetConsoleProcessList(LPDWORD processlist
, DWORD processcount
)
1496 FIXME("(%p,%d): stub\n", processlist
, processcount
);
1498 if (!processlist
|| processcount
< 1)
1500 SetLastError(ERROR_INVALID_PARAMETER
);
1507 BOOL
CONSOLE_Init(RTL_USER_PROCESS_PARAMETERS
*params
)
1509 memset(&S_termios
, 0, sizeof(S_termios
));
1510 if (params
->ConsoleHandle
== KERNEL32_CONSOLE_SHELL
)
1514 /* FIXME: to be done even if program is a GUI ? */
1515 /* This is wine specific: we have no parent (we're started from unix)
1516 * so, create a simple console with bare handles
1519 wine_server_send_fd(0);
1520 SERVER_START_REQ( alloc_console
)
1522 req
->access
= GENERIC_READ
| GENERIC_WRITE
;
1523 req
->attributes
= OBJ_INHERIT
;
1524 req
->pid
= 0xffffffff;
1526 wine_server_call( req
);
1527 conin
= wine_server_ptr_handle( reply
->handle_in
);
1528 /* reply->event shouldn't be created by server */
1532 if (!params
->hStdInput
)
1533 params
->hStdInput
= conin
;
1535 if (!params
->hStdOutput
)
1537 wine_server_send_fd(1);
1538 SERVER_START_REQ( create_console_output
)
1540 req
->handle_in
= wine_server_obj_handle(conin
);
1541 req
->access
= GENERIC_WRITE
|GENERIC_READ
;
1542 req
->attributes
= OBJ_INHERIT
;
1543 req
->share
= FILE_SHARE_READ
|FILE_SHARE_WRITE
;
1545 wine_server_call(req
);
1546 params
->hStdOutput
= wine_server_ptr_handle(reply
->handle_out
);
1550 if (!params
->hStdError
)
1552 wine_server_send_fd(2);
1553 SERVER_START_REQ( create_console_output
)
1555 req
->handle_in
= wine_server_obj_handle(conin
);
1556 req
->access
= GENERIC_WRITE
|GENERIC_READ
;
1557 req
->attributes
= OBJ_INHERIT
;
1558 req
->share
= FILE_SHARE_READ
|FILE_SHARE_WRITE
;
1560 wine_server_call(req
);
1561 params
->hStdError
= wine_server_ptr_handle(reply
->handle_out
);
1567 /* convert value from server:
1568 * + INVALID_HANDLE_VALUE => TEB: 0, STARTUPINFO: INVALID_HANDLE_VALUE
1569 * + 0 => TEB: 0, STARTUPINFO: INVALID_HANDLE_VALUE
1570 * + console handle needs to be mapped
1572 if (!params
->hStdInput
|| params
->hStdInput
== INVALID_HANDLE_VALUE
)
1573 params
->hStdInput
= 0;
1574 else if (VerifyConsoleIoHandle(console_handle_map(params
->hStdInput
)))
1576 params
->hStdInput
= console_handle_map(params
->hStdInput
);
1577 save_console_mode(params
->hStdInput
);
1580 if (!params
->hStdOutput
|| params
->hStdOutput
== INVALID_HANDLE_VALUE
)
1581 params
->hStdOutput
= 0;
1582 else if (VerifyConsoleIoHandle(console_handle_map(params
->hStdOutput
)))
1583 params
->hStdOutput
= console_handle_map(params
->hStdOutput
);
1585 if (!params
->hStdError
|| params
->hStdError
== INVALID_HANDLE_VALUE
)
1586 params
->hStdError
= 0;
1587 else if (VerifyConsoleIoHandle(console_handle_map(params
->hStdError
)))
1588 params
->hStdError
= console_handle_map(params
->hStdError
);
1593 BOOL
CONSOLE_Exit(void)
1595 /* the console is in raw mode, put it back in cooked mode */
1596 return restore_console_mode(GetStdHandle(STD_INPUT_HANDLE
));
1599 /* Undocumented, called by native doskey.exe */
1600 /* FIXME: Should use CONSOLE_GetHistory() above for full implementation */
1601 DWORD WINAPI
GetConsoleCommandHistoryA(DWORD unknown1
, DWORD unknown2
, DWORD unknown3
)
1603 FIXME(": (0x%x, 0x%x, 0x%x) stub!\n", unknown1
, unknown2
, unknown3
);
1604 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1608 /* Undocumented, called by native doskey.exe */
1609 /* FIXME: Should use CONSOLE_GetHistory() above for full implementation */
1610 DWORD WINAPI
GetConsoleCommandHistoryW(DWORD unknown1
, DWORD unknown2
, DWORD unknown3
)
1612 FIXME(": (0x%x, 0x%x, 0x%x) stub!\n", unknown1
, unknown2
, unknown3
);
1613 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1617 /* Undocumented, called by native doskey.exe */
1618 /* FIXME: Should use CONSOLE_GetHistory() above for full implementation */
1619 DWORD WINAPI
GetConsoleCommandHistoryLengthA(LPCSTR unknown
)
1621 FIXME(": (%s) stub!\n", debugstr_a(unknown
));
1622 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1626 /* Undocumented, called by native doskey.exe */
1627 /* FIXME: Should use CONSOLE_GetHistory() above for full implementation */
1628 DWORD WINAPI
GetConsoleCommandHistoryLengthW(LPCWSTR unknown
)
1630 FIXME(": (%s) stub!\n", debugstr_w(unknown
));
1631 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1635 DWORD WINAPI
GetConsoleAliasesLengthA(LPSTR unknown
)
1637 FIXME(": (%s) stub!\n", debugstr_a(unknown
));
1638 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1642 DWORD WINAPI
GetConsoleAliasesLengthW(LPWSTR unknown
)
1644 FIXME(": (%s) stub!\n", debugstr_w(unknown
));
1645 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1649 DWORD WINAPI
GetConsoleAliasExesLengthA(void)
1652 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1656 DWORD WINAPI
GetConsoleAliasExesLengthW(void)
1659 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1663 VOID WINAPI
ExpungeConsoleCommandHistoryA(LPCSTR unknown
)
1665 FIXME(": (%s) stub!\n", debugstr_a(unknown
));
1666 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1669 VOID WINAPI
ExpungeConsoleCommandHistoryW(LPCWSTR unknown
)
1671 FIXME(": (%s) stub!\n", debugstr_w(unknown
));
1672 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1675 BOOL WINAPI
AddConsoleAliasA(LPSTR source
, LPSTR target
, LPSTR exename
)
1677 FIXME(": (%s, %s, %s) stub!\n", debugstr_a(source
), debugstr_a(target
), debugstr_a(exename
));
1678 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1682 BOOL WINAPI
AddConsoleAliasW(LPWSTR source
, LPWSTR target
, LPWSTR exename
)
1684 FIXME(": (%s, %s, %s) stub!\n", debugstr_w(source
), debugstr_w(target
), debugstr_w(exename
));
1685 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1690 BOOL WINAPI
SetConsoleIcon(HICON icon
)
1692 FIXME(": (%p) stub!\n", icon
);
1693 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1697 DWORD WINAPI
GetNumberOfConsoleFonts(void)
1702 BOOL WINAPI
SetConsoleFont(HANDLE hConsole
, DWORD index
)
1704 FIXME("(%p, %u): stub!\n", hConsole
, index
);
1705 SetLastError(LOWORD(E_NOTIMPL
) /* win10 1709+ */);
1709 BOOL WINAPI
SetConsoleKeyShortcuts(BOOL set
, BYTE keys
, VOID
*a
, DWORD b
)
1711 FIXME(": (%u %u %p %u) stub!\n", set
, keys
, a
, b
);
1712 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1717 BOOL WINAPI
GetCurrentConsoleFontEx(HANDLE hConsole
, BOOL maxwindow
, CONSOLE_FONT_INFOEX
*fontinfo
)
1722 unsigned int color_map
[16];
1723 WCHAR face_name
[LF_FACESIZE
];
1726 if (fontinfo
->cbSize
!= sizeof(CONSOLE_FONT_INFOEX
))
1728 SetLastError(ERROR_INVALID_PARAMETER
);
1732 SERVER_START_REQ(get_console_output_info
)
1734 req
->handle
= console_handle_unmap(hConsole
);
1735 wine_server_set_reply( req
, &data
, sizeof(data
) - sizeof(WCHAR
) );
1736 if ((ret
= !wine_server_call_err(req
)))
1738 fontinfo
->nFont
= 0;
1741 fontinfo
->dwFontSize
.X
= min(reply
->width
, reply
->max_width
);
1742 fontinfo
->dwFontSize
.Y
= min(reply
->height
, reply
->max_height
);
1746 fontinfo
->dwFontSize
.X
= reply
->win_right
- reply
->win_left
+ 1;
1747 fontinfo
->dwFontSize
.Y
= reply
->win_bottom
- reply
->win_top
+ 1;
1749 if (wine_server_reply_size( reply
) > sizeof(data
.color_map
))
1751 data_size_t len
= wine_server_reply_size( reply
) - sizeof(data
.color_map
);
1752 memcpy( fontinfo
->FaceName
, data
.face_name
, len
);
1753 fontinfo
->FaceName
[len
/ sizeof(WCHAR
)] = 0;
1756 fontinfo
->FaceName
[0] = 0;
1757 fontinfo
->FontFamily
= reply
->font_pitch_family
;
1758 fontinfo
->FontWeight
= reply
->font_weight
;
1765 BOOL WINAPI
GetCurrentConsoleFont(HANDLE hConsole
, BOOL maxwindow
, CONSOLE_FONT_INFO
*fontinfo
)
1768 CONSOLE_FONT_INFOEX res
;
1770 res
.cbSize
= sizeof(CONSOLE_FONT_INFOEX
);
1772 ret
= GetCurrentConsoleFontEx(hConsole
, maxwindow
, &res
);
1775 fontinfo
->nFont
= res
.nFont
;
1776 fontinfo
->dwFontSize
.X
= res
.dwFontSize
.X
;
1777 fontinfo
->dwFontSize
.Y
= res
.dwFontSize
.Y
;
1782 static COORD
get_console_font_size(HANDLE hConsole
, DWORD index
)
1786 if (index
>= GetNumberOfConsoleFonts())
1788 SetLastError(ERROR_INVALID_PARAMETER
);
1792 SERVER_START_REQ(get_console_output_info
)
1794 req
->handle
= console_handle_unmap(hConsole
);
1795 if (!wine_server_call_err(req
))
1797 c
.X
= reply
->font_width
;
1798 c
.Y
= reply
->font_height
;
1805 #if defined(__i386__) && !defined(__MINGW32__)
1806 #undef GetConsoleFontSize
1807 DWORD WINAPI
GetConsoleFontSize(HANDLE hConsole
, DWORD index
)
1814 x
.c
= get_console_font_size(hConsole
, index
);
1818 COORD WINAPI
GetConsoleFontSize(HANDLE hConsole
, DWORD index
)
1820 return get_console_font_size(hConsole
, index
);
1822 #endif /* !defined(__i386__) */
1824 BOOL WINAPI
GetConsoleFontInfo(HANDLE hConsole
, BOOL maximize
, DWORD numfonts
, CONSOLE_FONT_INFO
*info
)
1826 FIXME("(%p %d %u %p): stub!\n", hConsole
, maximize
, numfonts
, info
);
1827 SetLastError(LOWORD(E_NOTIMPL
) /* win10 1709+ */);
1831 BOOL WINAPI
SetCurrentConsoleFontEx(HANDLE hConsole
, BOOL maxwindow
, CONSOLE_FONT_INFOEX
*cfix
)
1833 FIXME("(%p %d %p): stub!\n", hConsole
, maxwindow
, cfix
);
1834 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);