- Added f8 (history retrieval from partial command) support
[wine/multimedia.git] / win32 / console.c
blob274f71b5457938ce2c4fbd66d1dd12af7ca0749a
1 /*
2 * Win32 kernel 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 Eric Pouech
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 /* Reference applications:
26 * - IDA (interactive disassembler) full version 3.75. Works.
27 * - LYNX/W32. Works mostly, some keys crash it.
30 #include "config.h"
31 #include "wine/port.h"
33 #include <stdio.h>
34 #include <string.h>
35 #include <unistd.h>
36 #include <assert.h>
38 #include "winbase.h"
39 #include "winnls.h"
40 #include "winerror.h"
41 #include "wincon.h"
42 #include "heap.h"
43 #include "wine/server.h"
44 #include "wine/exception.h"
45 #include "wine/debug.h"
46 #include "options.h"
47 #include "msvcrt/excpt.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(console);
51 /* editline.c */
52 extern WCHAR* CONSOLE_Readline(HANDLE, int);
54 static WCHAR* S_EditString /* = NULL */;
55 static unsigned S_EditStrPos /* = 0 */;
57 /***********************************************************************
58 * FreeConsole (KERNEL32.@)
60 BOOL WINAPI FreeConsole(VOID)
62 BOOL ret;
64 SERVER_START_REQ(free_console)
66 ret = !wine_server_call_err( req );
68 SERVER_END_REQ;
69 return ret;
72 /******************************************************************
73 * start_console_renderer
75 * helper for AllocConsole
76 * starts the renderer process
78 static BOOL start_console_renderer(void)
80 char buffer[256];
81 int ret;
82 STARTUPINFOA si;
83 PROCESS_INFORMATION pi;
84 HANDLE hEvent = 0;
85 LPSTR p, path = NULL;
86 OBJECT_ATTRIBUTES attr;
88 attr.Length = sizeof(attr);
89 attr.RootDirectory = 0;
90 attr.Attributes = OBJ_INHERIT;
91 attr.ObjectName = NULL;
92 attr.SecurityDescriptor = NULL;
93 attr.SecurityQualityOfService = NULL;
95 NtCreateEvent(&hEvent, EVENT_ALL_ACCESS, &attr, TRUE, FALSE);
96 if (!hEvent) return FALSE;
98 memset(&si, 0, sizeof(si));
99 si.cb = sizeof(si);
101 /* FIXME: use dynamic allocation for most of the buffers below */
102 /* first try environment variable */
103 if ((p = getenv("WINECONSOLE")) != NULL)
105 ret = snprintf(buffer, sizeof(buffer), "%s --use-event=%d", p, hEvent);
106 if ((ret > -1) && (ret < sizeof(buffer)) &&
107 CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi))
108 goto succeed;
109 ERR("Couldn't launch Wine console from WINECONSOLE env var... trying default access\n");
112 /* then the regular installation dir */
113 ret = snprintf(buffer, sizeof(buffer), "%s --use-event=%d", BINDIR "/wineconsole", hEvent);
114 if ((ret > -1) && (ret < sizeof(buffer)) &&
115 CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi))
116 goto succeed;
118 /* then try the dir where we were started from */
119 if ((path = HeapAlloc(GetProcessHeap(), 0, strlen(full_argv0) + sizeof(buffer))))
121 int n;
123 if ((p = strrchr(strcpy( path, full_argv0 ), '/')))
125 p++;
126 sprintf(p, "wineconsole --use-event=%d", hEvent);
127 if (CreateProcessA(NULL, path, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi))
128 goto succeed;
129 sprintf(p, "programs/wineconsole/wineconsole --use-event=%d", hEvent);
130 if (CreateProcessA(NULL, path, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi))
131 goto succeed;
134 n = readlink(full_argv0, buffer, sizeof(buffer));
135 if (n != -1 && n < sizeof(buffer))
137 buffer[n] = 0;
138 if (buffer[0] == '/') /* absolute path ? */
139 strcpy(path, buffer);
140 else if ((p = strrchr(strcpy( path, full_argv0 ), '/')))
142 strcpy(p + 1, buffer);
144 else *path = 0;
146 if ((p = strrchr(path, '/')))
148 p++;
149 sprintf(p, "wineconsole --use-event=%d", hEvent);
150 if (CreateProcessA(NULL, path, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi))
151 goto succeed;
152 sprintf(p, "programs/wineconsole/wineconsole --use-event=%d", hEvent);
153 if (CreateProcessA(NULL, path, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi))
154 goto succeed;
156 } else perror("readlink");
158 HeapFree(GetProcessHeap(), 0, path); path = NULL;
161 /* then try the regular PATH */
162 sprintf(buffer, "wineconsole --use-event=%d\n", hEvent);
163 if (CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi))
164 goto succeed;
166 goto the_end;
168 succeed:
169 if (path) HeapFree(GetProcessHeap(), 0, path);
170 if (WaitForSingleObject(hEvent, INFINITE) != WAIT_OBJECT_0) goto the_end;
171 CloseHandle(hEvent);
173 TRACE("Started wineconsole pid=%08lx tid=%08lx\n", pi.dwProcessId, pi.dwThreadId);
175 return TRUE;
177 the_end:
178 ERR("Can't allocate console\n");
179 if (path) HeapFree(GetProcessHeap(), 0, path);
180 CloseHandle(hEvent);
181 return FALSE;
184 /***********************************************************************
185 * AllocConsole (KERNEL32.@)
187 * creates an xterm with a pty to our program
189 BOOL WINAPI AllocConsole(void)
191 HANDLE handle_in = INVALID_HANDLE_VALUE;
192 HANDLE handle_out = INVALID_HANDLE_VALUE;
193 HANDLE handle_err = INVALID_HANDLE_VALUE;
194 STARTUPINFOW si;
196 TRACE("()\n");
198 handle_in = CreateFileA( "CONIN$", GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE,
199 0, NULL, OPEN_EXISTING, 0, 0 );
201 if (handle_in != INVALID_HANDLE_VALUE)
203 /* we already have a console opened on this process, don't create a new one */
204 CloseHandle(handle_in);
205 return FALSE;
208 if (!start_console_renderer())
209 goto the_end;
211 handle_in = CreateFileA( "CONIN$", GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE,
212 0, NULL, OPEN_EXISTING, 0, 0 );
213 if (handle_in == INVALID_HANDLE_VALUE) goto the_end;
215 handle_out = CreateFileA( "CONOUT$", GENERIC_READ|GENERIC_WRITE,
216 0, NULL, OPEN_EXISTING, 0, 0 );
217 if (handle_out == INVALID_HANDLE_VALUE) goto the_end;
219 if (!DuplicateHandle(GetCurrentProcess(), handle_out, GetCurrentProcess(), &handle_err,
220 0, TRUE, DUPLICATE_SAME_ACCESS))
221 goto the_end;
223 /* NT resets the STD_*_HANDLEs on console alloc */
224 SetStdHandle(STD_INPUT_HANDLE, handle_in);
225 SetStdHandle(STD_OUTPUT_HANDLE, handle_out);
226 SetStdHandle(STD_ERROR_HANDLE, handle_err);
228 GetStartupInfoW(&si);
229 if (si.dwFlags & STARTF_USECOUNTCHARS)
231 COORD c;
232 c.X = si.dwXCountChars;
233 c.Y = si.dwYCountChars;
234 SetConsoleScreenBufferSize(handle_out, c);
236 if (si.dwFlags & STARTF_USEFILLATTRIBUTE)
237 SetConsoleTextAttribute(handle_out, si.dwFillAttribute);
238 if (si.lpTitle)
239 SetConsoleTitleW(si.lpTitle);
241 SetLastError(ERROR_SUCCESS);
243 return TRUE;
245 the_end:
246 ERR("Can't allocate console\n");
247 if (handle_in != INVALID_HANDLE_VALUE) CloseHandle(handle_in);
248 if (handle_out != INVALID_HANDLE_VALUE) CloseHandle(handle_out);
249 if (handle_err != INVALID_HANDLE_VALUE) CloseHandle(handle_err);
250 FreeConsole();
251 return FALSE;
255 /******************************************************************************
256 * read_console_input
258 * Helper function for ReadConsole, ReadConsoleInput and PeekConsoleInput
260 static BOOL read_console_input(HANDLE handle, LPINPUT_RECORD buffer, DWORD count,
261 LPDWORD pRead, BOOL flush)
263 BOOL ret;
264 unsigned read = 0;
265 DWORD mode;
267 SERVER_START_REQ( read_console_input )
269 req->handle = handle;
270 req->flush = flush;
271 wine_server_set_reply( req, buffer, count * sizeof(INPUT_RECORD) );
272 if ((ret = !wine_server_call_err( req ))) read = reply->read;
274 SERVER_END_REQ;
275 if (count && flush && GetConsoleMode(handle, &mode) && (mode & ENABLE_PROCESSED_INPUT))
277 int i;
279 for (i = 0; i < read; i++)
281 if (buffer[i].EventType == KEY_EVENT && buffer[i].Event.KeyEvent.bKeyDown &&
282 buffer[i].Event.KeyEvent.uChar.UnicodeChar == 'C' - 64 &&
283 !(buffer[i].Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
285 GenerateConsoleCtrlEvent(CTRL_C_EVENT, GetCurrentProcessId());
286 /* FIXME: this is hackish, but it easily disables IR handling afterwards */
287 buffer[i].Event.KeyEvent.uChar.UnicodeChar = 0;
291 if (pRead) *pRead = read;
292 return ret;
296 /***********************************************************************
297 * ReadConsoleA (KERNEL32.@)
299 BOOL WINAPI ReadConsoleA(HANDLE hConsoleInput, LPVOID lpBuffer, DWORD nNumberOfCharsToRead,
300 LPDWORD lpNumberOfCharsRead, LPVOID lpReserved)
302 LPWSTR ptr = HeapAlloc(GetProcessHeap(), 0, nNumberOfCharsToRead * sizeof(WCHAR));
303 DWORD ncr = 0;
304 BOOL ret;
306 if ((ret = ReadConsoleW(hConsoleInput, ptr, nNumberOfCharsToRead, &ncr, 0)))
307 ncr = WideCharToMultiByte(CP_ACP, 0, ptr, ncr, lpBuffer, nNumberOfCharsToRead, NULL, NULL);
309 if (lpNumberOfCharsRead) *lpNumberOfCharsRead = ncr;
310 HeapFree(GetProcessHeap(), 0, ptr);
312 return ret;
315 /***********************************************************************
316 * ReadConsoleW (KERNEL32.@)
318 BOOL WINAPI ReadConsoleW(HANDLE hConsoleInput, LPVOID lpBuffer,
319 DWORD nNumberOfCharsToRead, LPDWORD lpNumberOfCharsRead, LPVOID lpReserved)
321 DWORD charsread;
322 LPWSTR xbuf = (LPWSTR)lpBuffer;
323 DWORD mode;
325 TRACE("(%d,%p,%ld,%p,%p)\n",
326 hConsoleInput, lpBuffer, nNumberOfCharsToRead, lpNumberOfCharsRead, lpReserved);
328 if (!GetConsoleMode(hConsoleInput, &mode))
329 return FALSE;
331 if (mode & ENABLE_LINE_INPUT)
333 if (!S_EditString || S_EditString[S_EditStrPos] == 0)
335 if (S_EditString) HeapFree(GetProcessHeap(), 0, S_EditString);
336 if (!(S_EditString = CONSOLE_Readline(hConsoleInput, mode & WINE_ENABLE_LINE_INPUT_EMACS)))
337 return FALSE;
338 S_EditStrPos = 0;
340 charsread = lstrlenW(&S_EditString[S_EditStrPos]);
341 if (charsread > nNumberOfCharsToRead) charsread = nNumberOfCharsToRead;
342 memcpy(xbuf, &S_EditString[S_EditStrPos], charsread * sizeof(WCHAR));
343 S_EditStrPos += charsread;
345 else
347 INPUT_RECORD ir;
348 DWORD count;
350 /* FIXME: should we read at least 1 char? The SDK does not say */
351 /* wait for at least one available input record (it doesn't mean we'll have
352 * chars stored in xbuf...
354 WaitForSingleObject(hConsoleInput, INFINITE);
355 for (charsread = 0; charsread < nNumberOfCharsToRead;)
357 if (!read_console_input(hConsoleInput, &ir, 1, &count, TRUE)) return FALSE;
358 if (count && ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown &&
359 ir.Event.KeyEvent.uChar.UnicodeChar &&
360 !(ir.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
362 xbuf[charsread++] = ir.Event.KeyEvent.uChar.UnicodeChar;
367 if (lpNumberOfCharsRead) *lpNumberOfCharsRead = charsread;
369 return TRUE;
373 /***********************************************************************
374 * ReadConsoleInputW (KERNEL32.@)
376 BOOL WINAPI ReadConsoleInputW(HANDLE hConsoleInput, LPINPUT_RECORD lpBuffer,
377 DWORD nLength, LPDWORD lpNumberOfEventsRead)
379 DWORD count;
381 if (!nLength)
383 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = 0;
384 return TRUE;
387 /* loop until we get at least one event */
388 for (;;)
390 WaitForSingleObject(hConsoleInput, INFINITE);
391 if (!read_console_input(hConsoleInput, lpBuffer, nLength, &count, TRUE))
392 return FALSE;
393 if (count)
395 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = count;
396 return TRUE;
402 /******************************************************************************
403 * WriteConsoleOutputCharacterW [KERNEL32.@] Copies character to consecutive
404 * cells in the console screen buffer
406 * PARAMS
407 * hConsoleOutput [I] Handle to screen buffer
408 * str [I] Pointer to buffer with chars to write
409 * length [I] Number of cells to write to
410 * coord [I] Coords of first cell
411 * lpNumCharsWritten [O] Pointer to number of cells written
413 * RETURNS
414 * Success: TRUE
415 * Failure: FALSE
418 BOOL WINAPI WriteConsoleOutputCharacterW( HANDLE hConsoleOutput, LPCWSTR str, DWORD length,
419 COORD coord, LPDWORD lpNumCharsWritten )
421 BOOL ret;
423 TRACE("(%d,%s,%ld,%dx%d,%p)\n", hConsoleOutput,
424 debugstr_wn(str, length), length, coord.X, coord.Y, lpNumCharsWritten);
426 SERVER_START_REQ( write_console_output )
428 req->handle = hConsoleOutput;
429 req->x = coord.X;
430 req->y = coord.Y;
431 req->mode = CHAR_INFO_MODE_TEXT;
432 req->wrap = TRUE;
433 wine_server_add_data( req, str, length * sizeof(WCHAR) );
434 if ((ret = !wine_server_call_err( req )))
436 if (lpNumCharsWritten) *lpNumCharsWritten = reply->written;
439 SERVER_END_REQ;
440 return ret;
444 /******************************************************************************
445 * SetConsoleTitleW [KERNEL32.@] Sets title bar string for console
447 * PARAMS
448 * title [I] Address of new title
450 * RETURNS
451 * Success: TRUE
452 * Failure: FALSE
454 BOOL WINAPI SetConsoleTitleW(LPCWSTR title)
456 BOOL ret;
458 SERVER_START_REQ( set_console_input_info )
460 req->handle = 0;
461 req->mask = SET_CONSOLE_INPUT_INFO_TITLE;
462 wine_server_add_data( req, title, strlenW(title) * sizeof(WCHAR) );
463 ret = !wine_server_call_err( req );
465 SERVER_END_REQ;
466 return ret;
470 /***********************************************************************
471 * GetNumberOfConsoleMouseButtons (KERNEL32.@)
473 BOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons)
475 FIXME("(%p): stub\n", nrofbuttons);
476 *nrofbuttons = 2;
477 return TRUE;
480 /******************************************************************************
481 * SetConsoleInputExeNameW [KERNEL32.@]
483 * BUGS
484 * Unimplemented
486 BOOL WINAPI SetConsoleInputExeNameW(LPCWSTR name)
488 FIXME("(%s): stub!\n", debugstr_w(name));
490 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
491 return TRUE;
494 /******************************************************************************
495 * SetConsoleInputExeNameA [KERNEL32.@]
497 * BUGS
498 * Unimplemented
500 BOOL WINAPI SetConsoleInputExeNameA(LPCSTR name)
502 int len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
503 LPWSTR xptr = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
504 BOOL ret;
506 if (!xptr) return FALSE;
508 MultiByteToWideChar(CP_ACP, 0, name, -1, xptr, len);
509 ret = SetConsoleInputExeNameW(xptr);
510 HeapFree(GetProcessHeap(), 0, xptr);
512 return ret;
515 static BOOL WINAPI CONSOLE_DefaultHandler(DWORD dwCtrlType)
517 FIXME("Terminating process %lx on event %lx\n", GetCurrentProcessId(), dwCtrlType);
518 ExitProcess(0);
519 /* should never go here */
520 return TRUE;
523 /******************************************************************************
524 * SetConsoleCtrlHandler [KERNEL32.@] Adds function to calling process list
526 * PARAMS
527 * func [I] Address of handler function
528 * add [I] Handler to add or remove
530 * RETURNS
531 * Success: TRUE
532 * Failure: FALSE
534 * CHANGED
535 * James Sutherland (JamesSutherland@gmx.de)
536 * Added global variables console_ignore_ctrl_c and handlers[]
537 * Does not yet do any error checking, or set LastError if failed.
538 * This doesn't yet matter, since these handlers are not yet called...!
541 static unsigned int console_ignore_ctrl_c = 0; /* FIXME: this should be inherited somehow */
542 static PHANDLER_ROUTINE handlers[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,CONSOLE_DefaultHandler};
544 /*****************************************************************************/
546 BOOL WINAPI SetConsoleCtrlHandler(PHANDLER_ROUTINE func, BOOL add)
548 int alloc_loop = sizeof(handlers)/sizeof(handlers[0]) - 1;
550 FIXME("(%p,%i) - no error checking or testing yet\n", func, add);
552 if (!func)
554 console_ignore_ctrl_c = add;
555 return TRUE;
557 if (add)
559 for (; alloc_loop >= 0 && handlers[alloc_loop]; alloc_loop--);
560 if (alloc_loop <= 0)
562 FIXME("Out of space on CtrlHandler table\n");
563 return FALSE;
565 handlers[alloc_loop] = func;
567 else
569 for (; alloc_loop >= 0 && handlers[alloc_loop] != func; alloc_loop--);
570 if (alloc_loop <= 0)
572 WARN("Attempt to remove non-installed CtrlHandler %p\n", func);
573 return FALSE;
575 /* sanity check */
576 if (alloc_loop == sizeof(handlers)/sizeof(handlers[0]) - 1)
578 ERR("Who's trying to remove default handler???\n");
579 return FALSE;
581 if (alloc_loop)
582 memmove(&handlers[1], &handlers[0], alloc_loop * sizeof(handlers[0]));
583 handlers[0] = 0;
585 return TRUE;
588 static WINE_EXCEPTION_FILTER(CONSOLE_CtrlEventHandler)
590 TRACE("(%lx)\n", GetExceptionCode());
591 return EXCEPTION_EXECUTE_HANDLER;
594 /******************************************************************************
595 * GenerateConsoleCtrlEvent [KERNEL32.@] Simulate a CTRL-C or CTRL-BREAK
597 * PARAMS
598 * dwCtrlEvent [I] Type of event
599 * dwProcessGroupID [I] Process group ID to send event to
601 * NOTES
602 * Doesn't yet work...!
604 * RETURNS
605 * Success: True
606 * Failure: False (and *should* [but doesn't] set LastError)
608 BOOL WINAPI GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,
609 DWORD dwProcessGroupID)
611 if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
613 ERR("invalid event %ld for PGID %ld\n", dwCtrlEvent, dwProcessGroupID);
614 return FALSE;
617 if (dwProcessGroupID == GetCurrentProcessId() || dwProcessGroupID == 0)
619 int i;
621 FIXME("Attempt to send event %ld to self groupID, doing locally only\n", dwCtrlEvent);
623 /* this is only meaningfull when done locally, otherwise it will have to be done on
624 * the 'receive' side of the event generation
626 if (dwCtrlEvent == CTRL_C_EVENT && console_ignore_ctrl_c)
627 return TRUE;
629 /* try to pass the exception to the debugger
630 * if it continues, there's nothing more to do
631 * otherwise, we need to send the ctrl-event to the handlers
633 __TRY
635 RaiseException( (dwCtrlEvent == CTRL_C_EVENT) ? DBG_CONTROL_C : DBG_CONTROL_BREAK,
636 0, 0, NULL);
638 __EXCEPT(CONSOLE_CtrlEventHandler)
640 /* the debugger didn't continue... so, pass to ctrl handlers */
641 for (i = 0; i < sizeof(handlers)/sizeof(handlers[0]); i++)
643 if (handlers[i] && (handlers[i])(dwCtrlEvent)) break;
646 __ENDTRY;
647 return TRUE;
649 FIXME("event %ld to external PGID %ld - not implemented yet\n", dwCtrlEvent, dwProcessGroupID);
650 return FALSE;
654 /******************************************************************************
655 * CreateConsoleScreenBuffer [KERNEL32.@] Creates a console screen buffer
657 * PARAMS
658 * dwDesiredAccess [I] Access flag
659 * dwShareMode [I] Buffer share mode
660 * sa [I] Security attributes
661 * dwFlags [I] Type of buffer to create
662 * lpScreenBufferData [I] Reserved
664 * NOTES
665 * Should call SetLastError
667 * RETURNS
668 * Success: Handle to new console screen buffer
669 * Failure: INVALID_HANDLE_VALUE
671 HANDLE WINAPI CreateConsoleScreenBuffer(DWORD dwDesiredAccess, DWORD dwShareMode,
672 LPSECURITY_ATTRIBUTES sa, DWORD dwFlags,
673 LPVOID lpScreenBufferData)
675 HANDLE ret = INVALID_HANDLE_VALUE;
677 TRACE("(%ld,%ld,%p,%ld,%p)\n",
678 dwDesiredAccess, dwShareMode, sa, dwFlags, lpScreenBufferData);
680 if (dwFlags != CONSOLE_TEXTMODE_BUFFER || lpScreenBufferData != NULL)
682 SetLastError(ERROR_INVALID_PARAMETER);
683 return INVALID_HANDLE_VALUE;
686 SERVER_START_REQ(create_console_output)
688 req->handle_in = 0;
689 req->access = dwDesiredAccess;
690 req->share = dwShareMode;
691 req->inherit = (sa && sa->bInheritHandle);
692 if (!wine_server_call_err( req )) ret = reply->handle_out;
694 SERVER_END_REQ;
696 return ret;
700 /***********************************************************************
701 * GetConsoleScreenBufferInfo (KERNEL32.@)
703 BOOL WINAPI GetConsoleScreenBufferInfo(HANDLE hConsoleOutput, LPCONSOLE_SCREEN_BUFFER_INFO csbi)
705 BOOL ret;
707 SERVER_START_REQ(get_console_output_info)
709 req->handle = hConsoleOutput;
710 if ((ret = !wine_server_call_err( req )))
712 csbi->dwSize.X = reply->width;
713 csbi->dwSize.Y = reply->height;
714 csbi->dwCursorPosition.X = reply->cursor_x;
715 csbi->dwCursorPosition.Y = reply->cursor_y;
716 csbi->wAttributes = reply->attr;
717 csbi->srWindow.Left = reply->win_left;
718 csbi->srWindow.Right = reply->win_right;
719 csbi->srWindow.Top = reply->win_top;
720 csbi->srWindow.Bottom = reply->win_bottom;
721 csbi->dwMaximumWindowSize.X = reply->max_width;
722 csbi->dwMaximumWindowSize.Y = reply->max_height;
725 SERVER_END_REQ;
727 return ret;
731 /******************************************************************************
732 * SetConsoleActiveScreenBuffer [KERNEL32.@] Sets buffer to current console
734 * RETURNS
735 * Success: TRUE
736 * Failure: FALSE
738 BOOL WINAPI SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput)
740 BOOL ret;
742 TRACE("(%x)\n", hConsoleOutput);
744 SERVER_START_REQ( set_console_input_info )
746 req->handle = 0;
747 req->mask = SET_CONSOLE_INPUT_INFO_ACTIVE_SB;
748 req->active_sb = hConsoleOutput;
749 ret = !wine_server_call_err( req );
751 SERVER_END_REQ;
752 return ret;
756 /***********************************************************************
757 * GetConsoleMode (KERNEL32.@)
759 BOOL WINAPI GetConsoleMode(HANDLE hcon, LPDWORD mode)
761 BOOL ret;
763 SERVER_START_REQ(get_console_mode)
765 req->handle = hcon;
766 ret = !wine_server_call_err( req );
767 if (ret && mode) *mode = reply->mode;
769 SERVER_END_REQ;
770 return ret;
774 /******************************************************************************
775 * SetConsoleMode [KERNEL32.@] Sets input mode of console's input buffer
777 * PARAMS
778 * hcon [I] Handle to console input or screen buffer
779 * mode [I] Input or output mode to set
781 * RETURNS
782 * Success: TRUE
783 * Failure: FALSE
785 BOOL WINAPI SetConsoleMode(HANDLE hcon, DWORD mode)
787 BOOL ret;
789 TRACE("(%x,%lx)\n", hcon, mode);
791 SERVER_START_REQ(set_console_mode)
793 req->handle = hcon;
794 req->mode = mode;
795 ret = !wine_server_call_err( req );
797 SERVER_END_REQ;
798 /* FIXME: when resetting a console input to editline mode, I think we should
799 * empty the S_EditString buffer
801 return ret;
805 /******************************************************************
806 * write_char
808 * WriteConsoleOutput helper: hides server call semantics
810 static int write_char(HANDLE hCon, LPCWSTR lpBuffer, int nc, COORD* pos)
812 int written = -1;
814 if (!nc) return 0;
816 SERVER_START_REQ( write_console_output )
818 req->handle = hCon;
819 req->x = pos->X;
820 req->y = pos->Y;
821 req->mode = CHAR_INFO_MODE_TEXTSTDATTR;
822 req->wrap = FALSE;
823 wine_server_add_data( req, lpBuffer, nc * sizeof(WCHAR) );
824 if (!wine_server_call_err( req )) written = reply->written;
826 SERVER_END_REQ;
828 if (written > 0) pos->X += written;
829 return written;
832 /******************************************************************
833 * next_line
835 * WriteConsoleOutput helper: handles passing to next line (+scrolling if necessary)
838 static int next_line(HANDLE hCon, CONSOLE_SCREEN_BUFFER_INFO* csbi)
840 SMALL_RECT src;
841 CHAR_INFO ci;
842 COORD dst;
844 csbi->dwCursorPosition.X = 0;
845 csbi->dwCursorPosition.Y++;
847 if (csbi->dwCursorPosition.Y < csbi->dwSize.Y) return 1;
849 src.Top = 1;
850 src.Bottom = csbi->dwSize.Y - 1;
851 src.Left = 0;
852 src.Right = csbi->dwSize.X - 1;
854 dst.X = 0;
855 dst.Y = 0;
857 ci.Attributes = csbi->wAttributes;
858 ci.Char.UnicodeChar = ' ';
860 csbi->dwCursorPosition.Y--;
861 if (!ScrollConsoleScreenBufferW(hCon, &src, NULL, dst, &ci))
862 return 0;
863 return 1;
866 /******************************************************************
867 * write_block
869 * WriteConsoleOutput helper: writes a block of non special characters
870 * Block can spread on several lines, and wrapping, if needed, is
871 * handled
874 static int write_block(HANDLE hCon, CONSOLE_SCREEN_BUFFER_INFO* csbi,
875 DWORD mode, LPWSTR ptr, int len)
877 int blk; /* number of chars to write on current line */
879 if (len <= 0) return 1;
881 if (mode & ENABLE_WRAP_AT_EOL_OUTPUT) /* writes remaining on next line */
883 int done;
885 for (done = 0; done < len; done += blk)
887 blk = min(len - done, csbi->dwSize.X - csbi->dwCursorPosition.X);
889 if (write_char(hCon, ptr + done, blk, &csbi->dwCursorPosition) != blk)
890 return 0;
891 if (csbi->dwCursorPosition.X == csbi->dwSize.X && !next_line(hCon, csbi))
892 return 0;
895 else
897 blk = min(len, csbi->dwSize.X - csbi->dwCursorPosition.X);
899 if (write_char(hCon, ptr, blk, &csbi->dwCursorPosition) != blk)
900 return 0;
901 if (blk < len)
903 csbi->dwCursorPosition.X = csbi->dwSize.X - 1;
904 /* all remaining chars should be written on last column,
905 * so only overwrite the last column with last char in block
907 if (write_char(hCon, ptr + len - 1, 1, &csbi->dwCursorPosition) != 1)
908 return 0;
909 csbi->dwCursorPosition.X = csbi->dwSize.X - 1;
913 return 1;
916 /***********************************************************************
917 * WriteConsoleW (KERNEL32.@)
919 BOOL WINAPI WriteConsoleW(HANDLE hConsoleOutput, LPCVOID lpBuffer, DWORD nNumberOfCharsToWrite,
920 LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
922 DWORD mode;
923 DWORD nw = 0;
924 WCHAR* psz = (WCHAR*)lpBuffer;
925 CONSOLE_SCREEN_BUFFER_INFO csbi;
926 int k, first = 0;
928 TRACE("%d %s %ld %p %p\n",
929 hConsoleOutput, debugstr_wn(lpBuffer, nNumberOfCharsToWrite),
930 nNumberOfCharsToWrite, lpNumberOfCharsWritten, lpReserved);
932 if (lpNumberOfCharsWritten) *lpNumberOfCharsWritten = 0;
934 if (!GetConsoleMode(hConsoleOutput, &mode) ||
935 !GetConsoleScreenBufferInfo(hConsoleOutput, &csbi))
936 return FALSE;
938 if (mode & ENABLE_PROCESSED_OUTPUT)
940 int i;
942 for (i = 0; i < nNumberOfCharsToWrite; i++)
944 switch (psz[i])
946 case '\b': case '\t': case '\n': case '\a': case '\r':
947 /* don't handle here the i-th char... done below */
948 if ((k = i - first) > 0)
950 if (!write_block(hConsoleOutput, &csbi, mode, &psz[first], k))
951 goto the_end;
952 nw += k;
954 first = i + 1;
955 nw++;
957 switch (psz[i])
959 case '\b':
960 if (csbi.dwCursorPosition.X > 0) csbi.dwCursorPosition.X--;
961 break;
962 case '\t':
964 WCHAR tmp[8] = {' ',' ',' ',' ',' ',' ',' ',' '};
966 if (!write_block(hConsoleOutput, &csbi, mode, tmp,
967 ((csbi.dwCursorPosition.X + 8) & ~7) - csbi.dwCursorPosition.X))
968 goto the_end;
970 break;
971 case '\n':
972 next_line(hConsoleOutput, &csbi);
973 break;
974 case '\a':
975 Beep(400, 300);
976 break;
977 case '\r':
978 csbi.dwCursorPosition.X = 0;
979 break;
980 default:
981 break;
986 /* write the remaining block (if any) if processed output is enabled, or the
987 * entire buffer otherwise
989 if ((k = nNumberOfCharsToWrite - first) > 0)
991 if (!write_block(hConsoleOutput, &csbi, mode, &psz[first], k))
992 goto the_end;
993 nw += k;
996 the_end:
997 SetConsoleCursorPosition(hConsoleOutput, csbi.dwCursorPosition);
998 if (lpNumberOfCharsWritten) *lpNumberOfCharsWritten = nw;
999 return nw != 0;
1003 /***********************************************************************
1004 * WriteConsoleA (KERNEL32.@)
1006 BOOL WINAPI WriteConsoleA(HANDLE hConsoleOutput, LPCVOID lpBuffer, DWORD nNumberOfCharsToWrite,
1007 LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
1009 BOOL ret;
1010 LPWSTR xstring;
1011 DWORD n;
1013 n = MultiByteToWideChar(CP_ACP, 0, lpBuffer, nNumberOfCharsToWrite, NULL, 0);
1015 if (lpNumberOfCharsWritten) *lpNumberOfCharsWritten = 0;
1016 xstring = HeapAlloc(GetProcessHeap(), 0, n * sizeof(WCHAR));
1017 if (!xstring) return 0;
1019 MultiByteToWideChar(CP_ACP, 0, lpBuffer, nNumberOfCharsToWrite, xstring, n);
1021 ret = WriteConsoleW(hConsoleOutput, xstring, n, lpNumberOfCharsWritten, 0);
1023 HeapFree(GetProcessHeap(), 0, xstring);
1025 return ret;
1028 /******************************************************************************
1029 * SetConsoleCursorPosition [KERNEL32.@]
1030 * Sets the cursor position in console
1032 * PARAMS
1033 * hConsoleOutput [I] Handle of console screen buffer
1034 * dwCursorPosition [I] New cursor position coordinates
1036 * RETURNS STD
1038 BOOL WINAPI SetConsoleCursorPosition(HANDLE hcon, COORD pos)
1040 BOOL ret;
1041 CONSOLE_SCREEN_BUFFER_INFO csbi;
1042 int do_move = 0;
1043 int w, h;
1045 TRACE("%x %d %d\n", hcon, pos.X, pos.Y);
1047 SERVER_START_REQ(set_console_output_info)
1049 req->handle = hcon;
1050 req->cursor_x = pos.X;
1051 req->cursor_y = pos.Y;
1052 req->mask = SET_CONSOLE_OUTPUT_INFO_CURSOR_POS;
1053 ret = !wine_server_call_err( req );
1055 SERVER_END_REQ;
1057 if (!ret || !GetConsoleScreenBufferInfo(hcon, &csbi))
1058 return FALSE;
1060 /* if cursor is no longer visible, scroll the visible window... */
1061 w = csbi.srWindow.Right - csbi.srWindow.Left + 1;
1062 h = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
1063 if (pos.X < csbi.srWindow.Left)
1065 csbi.srWindow.Left = min(pos.X, csbi.dwSize.X - w);
1066 do_move++;
1068 else if (pos.X > csbi.srWindow.Right)
1070 csbi.srWindow.Left = max(pos.X, w) - w + 1;
1071 do_move++;
1073 csbi.srWindow.Right = csbi.srWindow.Left + w - 1;
1075 if (pos.Y < csbi.srWindow.Top)
1077 csbi.srWindow.Top = min(pos.Y, csbi.dwSize.Y - h);
1078 do_move++;
1080 else if (pos.Y > csbi.srWindow.Bottom)
1082 csbi.srWindow.Top = max(pos.Y, h) - h + 1;
1083 do_move++;
1085 csbi.srWindow.Bottom = csbi.srWindow.Top + h - 1;
1087 ret = (do_move) ? SetConsoleWindowInfo(hcon, TRUE, &csbi.srWindow) : TRUE;
1089 return ret;
1092 /******************************************************************************
1093 * GetConsoleCursorInfo [KERNEL32.@] Gets size and visibility of console
1095 * PARAMS
1096 * hcon [I] Handle to console screen buffer
1097 * cinfo [O] Address of cursor information
1099 * RETURNS
1100 * Success: TRUE
1101 * Failure: FALSE
1103 BOOL WINAPI GetConsoleCursorInfo(HANDLE hcon, LPCONSOLE_CURSOR_INFO cinfo)
1105 BOOL ret;
1107 SERVER_START_REQ(get_console_output_info)
1109 req->handle = hcon;
1110 ret = !wine_server_call_err( req );
1111 if (ret && cinfo)
1113 cinfo->dwSize = reply->cursor_size;
1114 cinfo->bVisible = reply->cursor_visible;
1117 SERVER_END_REQ;
1118 return ret;
1122 /******************************************************************************
1123 * SetConsoleCursorInfo [KERNEL32.@] Sets size and visibility of cursor
1125 * PARAMS
1126 * hcon [I] Handle to console screen buffer
1127 * cinfo [I] Address of cursor information
1128 * RETURNS
1129 * Success: TRUE
1130 * Failure: FALSE
1132 BOOL WINAPI SetConsoleCursorInfo(HANDLE hCon, LPCONSOLE_CURSOR_INFO cinfo)
1134 BOOL ret;
1136 SERVER_START_REQ(set_console_output_info)
1138 req->handle = hCon;
1139 req->cursor_size = cinfo->dwSize;
1140 req->cursor_visible = cinfo->bVisible;
1141 req->mask = SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM;
1142 ret = !wine_server_call_err( req );
1144 SERVER_END_REQ;
1145 return ret;
1149 /******************************************************************************
1150 * SetConsoleWindowInfo [KERNEL32.@] Sets size and position of console
1152 * PARAMS
1153 * hcon [I] Handle to console screen buffer
1154 * bAbsolute [I] Coordinate type flag
1155 * window [I] Address of new window rectangle
1156 * RETURNS
1157 * Success: TRUE
1158 * Failure: FALSE
1160 BOOL WINAPI SetConsoleWindowInfo(HANDLE hCon, BOOL bAbsolute, LPSMALL_RECT window)
1162 SMALL_RECT p = *window;
1163 BOOL ret;
1165 if (!bAbsolute)
1167 CONSOLE_SCREEN_BUFFER_INFO csbi;
1168 if (!GetConsoleScreenBufferInfo(hCon, &csbi))
1169 return FALSE;
1170 p.Left += csbi.srWindow.Left;
1171 p.Top += csbi.srWindow.Top;
1172 p.Right += csbi.srWindow.Left;
1173 p.Bottom += csbi.srWindow.Top;
1175 SERVER_START_REQ(set_console_output_info)
1177 req->handle = hCon;
1178 req->win_left = p.Left;
1179 req->win_top = p.Top;
1180 req->win_right = p.Right;
1181 req->win_bottom = p.Bottom;
1182 req->mask = SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW;
1183 ret = !wine_server_call_err( req );
1185 SERVER_END_REQ;
1187 return ret;
1191 /******************************************************************************
1192 * SetConsoleTextAttribute [KERNEL32.@] Sets colors for text
1194 * Sets the foreground and background color attributes of characters
1195 * written to the screen buffer.
1197 * RETURNS
1198 * Success: TRUE
1199 * Failure: FALSE
1201 BOOL WINAPI SetConsoleTextAttribute(HANDLE hConsoleOutput, WORD wAttr)
1203 BOOL ret;
1205 SERVER_START_REQ(set_console_output_info)
1207 req->handle = hConsoleOutput;
1208 req->attr = wAttr;
1209 req->mask = SET_CONSOLE_OUTPUT_INFO_ATTR;
1210 ret = !wine_server_call_err( req );
1212 SERVER_END_REQ;
1213 return ret;
1217 /******************************************************************************
1218 * SetConsoleScreenBufferSize [KERNEL32.@] Changes size of console
1220 * PARAMS
1221 * hConsoleOutput [I] Handle to console screen buffer
1222 * dwSize [I] New size in character rows and cols
1224 * RETURNS
1225 * Success: TRUE
1226 * Failure: FALSE
1228 BOOL WINAPI SetConsoleScreenBufferSize(HANDLE hConsoleOutput, COORD dwSize)
1230 BOOL ret;
1232 SERVER_START_REQ(set_console_output_info)
1234 req->handle = hConsoleOutput;
1235 req->width = dwSize.X;
1236 req->height = dwSize.Y;
1237 req->mask = SET_CONSOLE_OUTPUT_INFO_SIZE;
1238 ret = !wine_server_call_err( req );
1240 SERVER_END_REQ;
1241 return ret;
1245 /******************************************************************************
1246 * ScrollConsoleScreenBufferA [KERNEL32.@]
1249 BOOL WINAPI ScrollConsoleScreenBufferA(HANDLE hConsoleOutput, LPSMALL_RECT lpScrollRect,
1250 LPSMALL_RECT lpClipRect, COORD dwDestOrigin,
1251 LPCHAR_INFO lpFill)
1253 CHAR_INFO ciw;
1255 ciw.Attributes = lpFill->Attributes;
1256 MultiByteToWideChar(CP_ACP, 0, &lpFill->Char.AsciiChar, 1, &ciw.Char.UnicodeChar, 1);
1258 return ScrollConsoleScreenBufferW(hConsoleOutput, lpScrollRect, lpClipRect,
1259 dwDestOrigin, &ciw);
1262 /******************************************************************
1263 * fill_line_uniform
1265 * Helper function for ScrollConsoleScreenBufferW
1266 * Fills a part of a line with a constant character info
1268 static void fill_line_uniform(HANDLE hConsoleOutput, int i, int j, int len, LPCHAR_INFO lpFill)
1270 SERVER_START_REQ( fill_console_output )
1272 req->handle = hConsoleOutput;
1273 req->mode = CHAR_INFO_MODE_TEXTATTR;
1274 req->x = i;
1275 req->y = j;
1276 req->count = len;
1277 req->wrap = FALSE;
1278 req->data.ch = lpFill->Char.UnicodeChar;
1279 req->data.attr = lpFill->Attributes;
1280 wine_server_call_err( req );
1282 SERVER_END_REQ;
1285 /******************************************************************************
1286 * ScrollConsoleScreenBufferW [KERNEL32.@]
1290 BOOL WINAPI ScrollConsoleScreenBufferW(HANDLE hConsoleOutput, LPSMALL_RECT lpScrollRect,
1291 LPSMALL_RECT lpClipRect, COORD dwDestOrigin,
1292 LPCHAR_INFO lpFill)
1294 SMALL_RECT dst;
1295 DWORD ret;
1296 int i, j;
1297 int start = -1;
1298 SMALL_RECT clip;
1299 CONSOLE_SCREEN_BUFFER_INFO csbi;
1300 BOOL inside;
1302 if (lpClipRect)
1303 TRACE("(%d,(%d,%d-%d,%d),(%d,%d-%d,%d),%d-%d,%p)\n", hConsoleOutput,
1304 lpScrollRect->Left, lpScrollRect->Top,
1305 lpScrollRect->Right, lpScrollRect->Bottom,
1306 lpClipRect->Left, lpClipRect->Top,
1307 lpClipRect->Right, lpClipRect->Bottom,
1308 dwDestOrigin.X, dwDestOrigin.Y, lpFill);
1309 else
1310 TRACE("(%d,(%d,%d-%d,%d),(nil),%d-%d,%p)\n", hConsoleOutput,
1311 lpScrollRect->Left, lpScrollRect->Top,
1312 lpScrollRect->Right, lpScrollRect->Bottom,
1313 dwDestOrigin.X, dwDestOrigin.Y, lpFill);
1315 if (!GetConsoleScreenBufferInfo(hConsoleOutput, &csbi))
1316 return FALSE;
1318 /* step 1: get dst rect */
1319 dst.Left = dwDestOrigin.X;
1320 dst.Top = dwDestOrigin.Y;
1321 dst.Right = dst.Left + (lpScrollRect->Right - lpScrollRect->Left);
1322 dst.Bottom = dst.Top + (lpScrollRect->Bottom - lpScrollRect->Top);
1324 /* step 2a: compute the final clip rect (optional passed clip and screen buffer limits */
1325 if (lpClipRect)
1327 clip.Left = max(0, lpClipRect->Left);
1328 clip.Right = min(csbi.dwSize.X - 1, lpClipRect->Right);
1329 clip.Top = max(0, lpClipRect->Top);
1330 clip.Bottom = min(csbi.dwSize.Y - 1, lpClipRect->Bottom);
1332 else
1334 clip.Left = 0;
1335 clip.Right = csbi.dwSize.X - 1;
1336 clip.Top = 0;
1337 clip.Bottom = csbi.dwSize.Y - 1;
1339 if (clip.Left > clip.Right || clip.Top > clip.Bottom) return FALSE;
1341 /* step 2b: clip dst rect */
1342 if (dst.Left < clip.Left ) dst.Left = clip.Left;
1343 if (dst.Top < clip.Top ) dst.Top = clip.Top;
1344 if (dst.Right > clip.Right ) dst.Right = clip.Right;
1345 if (dst.Bottom > clip.Bottom) dst.Bottom = clip.Bottom;
1347 /* step 3: transfer the bits */
1348 SERVER_START_REQ(move_console_output)
1350 req->handle = hConsoleOutput;
1351 req->x_src = lpScrollRect->Left;
1352 req->y_src = lpScrollRect->Top;
1353 req->x_dst = dst.Left;
1354 req->y_dst = dst.Top;
1355 req->w = dst.Right - dst.Left + 1;
1356 req->h = dst.Bottom - dst.Top + 1;
1357 ret = !wine_server_call_err( req );
1359 SERVER_END_REQ;
1361 if (!ret) return FALSE;
1363 /* step 4: clean out the exposed part */
1365 /* have to write celll [i,j] if it is not in dst rect (because it has already
1366 * been written to by the scroll) and is in clip (we shall not write
1367 * outside of clip)
1369 for (j = max(lpScrollRect->Top, clip.Top); j <= min(lpScrollRect->Bottom, clip.Bottom); j++)
1371 inside = dst.Top <= j && j <= dst.Bottom;
1372 start = -1;
1373 for (i = max(lpScrollRect->Left, clip.Left); i <= min(lpScrollRect->Right, clip.Right); i++)
1375 if (inside && dst.Left <= i && i <= dst.Right)
1377 if (start != -1)
1379 fill_line_uniform(hConsoleOutput, start, j, i - start, lpFill);
1380 start = -1;
1383 else
1385 if (start == -1) start = i;
1388 if (start != -1)
1389 fill_line_uniform(hConsoleOutput, start, j, i - start, lpFill);
1392 return TRUE;
1396 /* ====================================================================
1398 * Console manipulation functions
1400 * ====================================================================*/
1401 /* some missing functions...
1402 * FIXME: those are likely to be defined as undocumented function in kernel32 (or part of them)
1403 * should get the right API and implement them
1404 * GetConsoleCommandHistory[AW] (dword dword dword)
1405 * GetConsoleCommandHistoryLength[AW]
1406 * SetConsoleCommandHistoryMode
1407 * SetConsoleNumberOfCommands[AW]
1409 int CONSOLE_GetHistory(int idx, WCHAR* buf, int buf_len)
1411 int len = 0;
1413 SERVER_START_REQ( get_console_input_history )
1415 req->handle = 0;
1416 req->index = idx;
1417 if (buf && buf_len > 1)
1419 wine_server_set_reply( req, buf, (buf_len - 1) * sizeof(WCHAR) );
1421 if (!wine_server_call_err( req ))
1423 if (buf) buf[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
1424 len = reply->total / sizeof(WCHAR) + 1;
1427 SERVER_END_REQ;
1428 return len;
1431 /******************************************************************
1432 * CONSOLE_AppendHistory
1436 BOOL CONSOLE_AppendHistory(const WCHAR* ptr)
1438 size_t len = strlenW(ptr);
1439 BOOL ret;
1441 while (len && (ptr[len - 1] == '\n' || ptr[len - 1] == '\r')) len--;
1443 SERVER_START_REQ( append_console_input_history )
1445 req->handle = 0;
1446 wine_server_add_data( req, ptr, len * sizeof(WCHAR) );
1447 ret = !wine_server_call_err( req );
1449 SERVER_END_REQ;
1450 return ret;
1453 /******************************************************************
1454 * CONSOLE_GetNumHistoryEntries
1458 unsigned CONSOLE_GetNumHistoryEntries(void)
1460 unsigned ret = 0;
1461 SERVER_START_REQ(get_console_input_info)
1463 req->handle = 0;
1464 if (!wine_server_call_err( req )) ret = reply->history_index;
1466 SERVER_END_REQ;
1467 return ret;