Implement SET INDIVIDUAL DAC REGISTER and SET BLOCK OF DAC REGISTERS.
[wine/hacks.git] / win32 / console.c
blob6fb0c9b2f00c32062ce0180db259e38cdd4f2d1f
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"
32 #include <stdio.h>
33 #include <string.h>
34 #include <unistd.h>
35 #include <assert.h>
37 #include "winbase.h"
38 #include "winnls.h"
39 #include "winerror.h"
40 #include "wincon.h"
41 #include "heap.h"
42 #include "wine/server.h"
43 #include "wine/exception.h"
44 #include "wine/debug.h"
45 #include "options.h"
46 #include "msvcrt/excpt.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(console);
50 /* editline.c */
51 extern WCHAR* CONSOLE_Readline(HANDLE, int);
53 static WCHAR* S_EditString /* = NULL */;
54 static unsigned S_EditStrPos /* = 0 */;
56 /***********************************************************************
57 * FreeConsole (KERNEL32.@)
59 BOOL WINAPI FreeConsole(VOID)
61 BOOL ret;
63 SERVER_START_REQ(free_console)
65 ret = !wine_server_call_err( req );
67 SERVER_END_REQ;
68 return ret;
71 /******************************************************************
72 * start_console_renderer
74 * helper for AllocConsole
75 * starts the renderer process
77 static BOOL start_console_renderer(void)
79 char buffer[256];
80 int ret;
81 STARTUPINFOA si;
82 PROCESS_INFORMATION pi;
83 HANDLE hEvent = 0;
84 LPSTR p, path = NULL;
85 OBJECT_ATTRIBUTES attr;
87 attr.Length = sizeof(attr);
88 attr.RootDirectory = 0;
89 attr.Attributes = OBJ_INHERIT;
90 attr.ObjectName = NULL;
91 attr.SecurityDescriptor = NULL;
92 attr.SecurityQualityOfService = NULL;
94 NtCreateEvent(&hEvent, EVENT_ALL_ACCESS, &attr, TRUE, FALSE);
95 if (!hEvent) return FALSE;
97 memset(&si, 0, sizeof(si));
98 si.cb = sizeof(si);
100 /* FIXME: use dynamic allocation for most of the buffers below */
101 /* first try environment variable */
102 if ((p = getenv("WINECONSOLE")) != NULL)
104 ret = snprintf(buffer, sizeof(buffer), "%s --use-event=%d", p, hEvent);
105 if ((ret > -1) && (ret < sizeof(buffer)) &&
106 CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi))
107 goto succeed;
108 ERR("Couldn't launch Wine console from WINECONSOLE env var... trying default access\n");
111 /* then the regular installation dir */
112 ret = snprintf(buffer, sizeof(buffer), "%s --use-event=%d", BINDIR "/wineconsole", hEvent);
113 if ((ret > -1) && (ret < sizeof(buffer)) &&
114 CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi))
115 goto succeed;
117 /* then try the dir where we were started from */
118 if ((path = HeapAlloc(GetProcessHeap(), 0, strlen(full_argv0) + sizeof(buffer))))
120 int n;
122 if ((p = strrchr(strcpy( path, full_argv0 ), '/')))
124 p++;
125 sprintf(p, "wineconsole --use-event=%d", hEvent);
126 if (CreateProcessA(NULL, path, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi))
127 goto succeed;
128 sprintf(p, "programs/wineconsole/wineconsole --use-event=%d", hEvent);
129 if (CreateProcessA(NULL, path, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi))
130 goto succeed;
133 n = readlink(full_argv0, buffer, sizeof(buffer));
134 if (n != -1 && n < sizeof(buffer))
136 buffer[n] = 0;
137 if (buffer[0] == '/') /* absolute path ? */
138 strcpy(path, buffer);
139 else if ((p = strrchr(strcpy( path, full_argv0 ), '/')))
141 strcpy(p + 1, buffer);
143 else *path = 0;
145 if ((p = strrchr(path, '/')))
147 p++;
148 sprintf(p, "wineconsole --use-event=%d", hEvent);
149 if (CreateProcessA(NULL, path, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi))
150 goto succeed;
151 sprintf(p, "programs/wineconsole/wineconsole --use-event=%d", hEvent);
152 if (CreateProcessA(NULL, path, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi))
153 goto succeed;
155 } else perror("readlink");
157 HeapFree(GetProcessHeap(), 0, path); path = NULL;
160 /* then try the regular PATH */
161 sprintf(buffer, "wineconsole --use-event=%d\n", hEvent);
162 if (CreateProcessA(NULL, buffer, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, NULL, &si, &pi))
163 goto succeed;
165 goto the_end;
167 succeed:
168 if (path) HeapFree(GetProcessHeap(), 0, path);
169 if (WaitForSingleObject(hEvent, INFINITE) != WAIT_OBJECT_0) goto the_end;
170 CloseHandle(hEvent);
172 TRACE("Started wineconsole pid=%08lx tid=%08lx\n", pi.dwProcessId, pi.dwThreadId);
174 return TRUE;
176 the_end:
177 ERR("Can't allocate console\n");
178 if (path) HeapFree(GetProcessHeap(), 0, path);
179 CloseHandle(hEvent);
180 return FALSE;
183 /***********************************************************************
184 * AllocConsole (KERNEL32.@)
186 * creates an xterm with a pty to our program
188 BOOL WINAPI AllocConsole(void)
190 HANDLE handle_in = INVALID_HANDLE_VALUE;
191 HANDLE handle_out = INVALID_HANDLE_VALUE;
192 HANDLE handle_err = INVALID_HANDLE_VALUE;
193 STARTUPINFOW si;
195 TRACE("()\n");
197 handle_in = CreateFileA( "CONIN$", GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE,
198 0, NULL, OPEN_EXISTING, 0, 0 );
200 if (handle_in != INVALID_HANDLE_VALUE)
202 /* we already have a console opened on this process, don't create a new one */
203 CloseHandle(handle_in);
204 return FALSE;
207 if (!start_console_renderer())
208 goto the_end;
210 handle_in = CreateFileA( "CONIN$", GENERIC_READ|GENERIC_WRITE|SYNCHRONIZE,
211 0, NULL, OPEN_EXISTING, 0, 0 );
212 if (handle_in == INVALID_HANDLE_VALUE) goto the_end;
214 handle_out = CreateFileA( "CONOUT$", GENERIC_READ|GENERIC_WRITE,
215 0, NULL, OPEN_EXISTING, 0, 0 );
216 if (handle_out == INVALID_HANDLE_VALUE) goto the_end;
218 if (!DuplicateHandle(GetCurrentProcess(), handle_out, GetCurrentProcess(), &handle_err,
219 0, TRUE, DUPLICATE_SAME_ACCESS))
220 goto the_end;
222 /* NT resets the STD_*_HANDLEs on console alloc */
223 SetStdHandle(STD_INPUT_HANDLE, handle_in);
224 SetStdHandle(STD_OUTPUT_HANDLE, handle_out);
225 SetStdHandle(STD_ERROR_HANDLE, handle_err);
227 GetStartupInfoW(&si);
228 if (si.dwFlags & STARTF_USECOUNTCHARS)
230 COORD c;
231 c.X = si.dwXCountChars;
232 c.Y = si.dwYCountChars;
233 SetConsoleScreenBufferSize(handle_out, c);
235 if (si.dwFlags & STARTF_USEFILLATTRIBUTE)
236 SetConsoleTextAttribute(handle_out, si.dwFillAttribute);
237 if (si.lpTitle)
238 SetConsoleTitleW(si.lpTitle);
240 SetLastError(ERROR_SUCCESS);
242 return TRUE;
244 the_end:
245 ERR("Can't allocate console\n");
246 if (handle_in != INVALID_HANDLE_VALUE) CloseHandle(handle_in);
247 if (handle_out != INVALID_HANDLE_VALUE) CloseHandle(handle_out);
248 if (handle_err != INVALID_HANDLE_VALUE) CloseHandle(handle_err);
249 FreeConsole();
250 return FALSE;
254 /******************************************************************************
255 * read_console_input
257 * Helper function for ReadConsole, ReadConsoleInput and PeekConsoleInput
259 static BOOL read_console_input(HANDLE handle, LPINPUT_RECORD buffer, DWORD count,
260 LPDWORD pRead, BOOL flush)
262 BOOL ret;
263 unsigned read = 0;
264 DWORD mode;
266 SERVER_START_REQ( read_console_input )
268 req->handle = handle;
269 req->flush = flush;
270 wine_server_set_reply( req, buffer, count * sizeof(INPUT_RECORD) );
271 if ((ret = !wine_server_call_err( req ))) read = reply->read;
273 SERVER_END_REQ;
274 if (count && flush && GetConsoleMode(handle, &mode) && (mode & ENABLE_PROCESSED_INPUT))
276 int i;
278 for (i = 0; i < read; i++)
280 if (buffer[i].EventType == KEY_EVENT && buffer[i].Event.KeyEvent.bKeyDown &&
281 buffer[i].Event.KeyEvent.uChar.UnicodeChar == 'C' - 64 &&
282 !(buffer[i].Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
284 GenerateConsoleCtrlEvent(CTRL_C_EVENT, GetCurrentProcessId());
285 /* FIXME: this is hackish, but it easily disables IR handling afterwards */
286 buffer[i].Event.KeyEvent.uChar.UnicodeChar = 0;
290 if (pRead) *pRead = read;
291 return ret;
295 /***********************************************************************
296 * ReadConsoleA (KERNEL32.@)
298 BOOL WINAPI ReadConsoleA(HANDLE hConsoleInput, LPVOID lpBuffer, DWORD nNumberOfCharsToRead,
299 LPDWORD lpNumberOfCharsRead, LPVOID lpReserved)
301 LPWSTR ptr = HeapAlloc(GetProcessHeap(), 0, nNumberOfCharsToRead * sizeof(WCHAR));
302 DWORD ncr = 0;
303 BOOL ret;
305 if ((ret = ReadConsoleW(hConsoleInput, ptr, nNumberOfCharsToRead, &ncr, 0)))
306 ncr = WideCharToMultiByte(CP_ACP, 0, ptr, ncr, lpBuffer, nNumberOfCharsToRead, NULL, NULL);
308 if (lpNumberOfCharsRead) *lpNumberOfCharsRead = ncr;
309 HeapFree(GetProcessHeap(), 0, ptr);
311 return ret;
314 /***********************************************************************
315 * ReadConsoleW (KERNEL32.@)
317 BOOL WINAPI ReadConsoleW(HANDLE hConsoleInput, LPVOID lpBuffer,
318 DWORD nNumberOfCharsToRead, LPDWORD lpNumberOfCharsRead, LPVOID lpReserved)
320 DWORD charsread;
321 LPWSTR xbuf = (LPWSTR)lpBuffer;
322 DWORD mode;
324 TRACE("(%d,%p,%ld,%p,%p)\n",
325 hConsoleInput, lpBuffer, nNumberOfCharsToRead, lpNumberOfCharsRead, lpReserved);
327 if (!GetConsoleMode(hConsoleInput, &mode))
328 return FALSE;
330 if (mode & ENABLE_LINE_INPUT)
332 if (!S_EditString || S_EditString[S_EditStrPos] == 0)
334 if (S_EditString) HeapFree(GetProcessHeap(), 0, S_EditString);
335 if (!(S_EditString = CONSOLE_Readline(hConsoleInput, mode & WINE_ENABLE_LINE_INPUT_EMACS)))
336 return FALSE;
337 S_EditStrPos = 0;
339 charsread = lstrlenW(&S_EditString[S_EditStrPos]);
340 if (charsread > nNumberOfCharsToRead) charsread = nNumberOfCharsToRead;
341 memcpy(xbuf, &S_EditString[S_EditStrPos], charsread * sizeof(WCHAR));
342 S_EditStrPos += charsread;
344 else
346 INPUT_RECORD ir;
347 DWORD count;
349 /* FIXME: should we read at least 1 char? The SDK does not say */
350 /* wait for at least one available input record (it doesn't mean we'll have
351 * chars stored in xbuf...
353 WaitForSingleObject(hConsoleInput, INFINITE);
354 for (charsread = 0; charsread < nNumberOfCharsToRead;)
356 if (!read_console_input(hConsoleInput, &ir, 1, &count, TRUE)) return FALSE;
357 if (count && ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown &&
358 ir.Event.KeyEvent.uChar.UnicodeChar &&
359 !(ir.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
361 xbuf[charsread++] = ir.Event.KeyEvent.uChar.UnicodeChar;
366 if (lpNumberOfCharsRead) *lpNumberOfCharsRead = charsread;
368 return TRUE;
372 /***********************************************************************
373 * ReadConsoleInputW (KERNEL32.@)
375 BOOL WINAPI ReadConsoleInputW(HANDLE hConsoleInput, LPINPUT_RECORD lpBuffer,
376 DWORD nLength, LPDWORD lpNumberOfEventsRead)
378 DWORD count;
380 if (!nLength)
382 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = 0;
383 return TRUE;
386 /* loop until we get at least one event */
387 for (;;)
389 WaitForSingleObject(hConsoleInput, INFINITE);
390 if (!read_console_input(hConsoleInput, lpBuffer, nLength, &count, TRUE))
391 return FALSE;
392 if (count)
394 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = count;
395 return TRUE;
401 /******************************************************************************
402 * WriteConsoleOutputCharacterW [KERNEL32.@] Copies character to consecutive
403 * cells in the console screen buffer
405 * PARAMS
406 * hConsoleOutput [I] Handle to screen buffer
407 * str [I] Pointer to buffer with chars to write
408 * length [I] Number of cells to write to
409 * coord [I] Coords of first cell
410 * lpNumCharsWritten [O] Pointer to number of cells written
412 * RETURNS
413 * Success: TRUE
414 * Failure: FALSE
417 BOOL WINAPI WriteConsoleOutputCharacterW( HANDLE hConsoleOutput, LPCWSTR str, DWORD length,
418 COORD coord, LPDWORD lpNumCharsWritten )
420 BOOL ret;
422 TRACE("(%d,%s,%ld,%dx%d,%p)\n", hConsoleOutput,
423 debugstr_wn(str, length), length, coord.X, coord.Y, lpNumCharsWritten);
425 SERVER_START_REQ( write_console_output )
427 req->handle = hConsoleOutput;
428 req->x = coord.X;
429 req->y = coord.Y;
430 req->mode = CHAR_INFO_MODE_TEXT;
431 req->wrap = TRUE;
432 wine_server_add_data( req, str, length * sizeof(WCHAR) );
433 if ((ret = !wine_server_call_err( req )))
435 if (lpNumCharsWritten) *lpNumCharsWritten = reply->written;
438 SERVER_END_REQ;
439 return ret;
443 /******************************************************************************
444 * SetConsoleTitleW [KERNEL32.@] Sets title bar string for console
446 * PARAMS
447 * title [I] Address of new title
449 * RETURNS
450 * Success: TRUE
451 * Failure: FALSE
453 BOOL WINAPI SetConsoleTitleW(LPCWSTR title)
455 BOOL ret;
457 SERVER_START_REQ( set_console_input_info )
459 req->handle = 0;
460 req->mask = SET_CONSOLE_INPUT_INFO_TITLE;
461 wine_server_add_data( req, title, strlenW(title) * sizeof(WCHAR) );
462 ret = !wine_server_call_err( req );
464 SERVER_END_REQ;
465 return ret;
469 /***********************************************************************
470 * GetNumberOfConsoleMouseButtons (KERNEL32.@)
472 BOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons)
474 FIXME("(%p): stub\n", nrofbuttons);
475 *nrofbuttons = 2;
476 return TRUE;
479 /******************************************************************************
480 * SetConsoleInputExeNameW [KERNEL32.@]
482 * BUGS
483 * Unimplemented
485 BOOL WINAPI SetConsoleInputExeNameW(LPCWSTR name)
487 FIXME("(%s): stub!\n", debugstr_w(name));
489 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
490 return TRUE;
493 /******************************************************************************
494 * SetConsoleInputExeNameA [KERNEL32.@]
496 * BUGS
497 * Unimplemented
499 BOOL WINAPI SetConsoleInputExeNameA(LPCSTR name)
501 int len = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
502 LPWSTR xptr = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
503 BOOL ret;
505 if (!xptr) return FALSE;
507 MultiByteToWideChar(CP_ACP, 0, name, -1, xptr, len);
508 ret = SetConsoleInputExeNameW(xptr);
509 HeapFree(GetProcessHeap(), 0, xptr);
511 return ret;
514 static BOOL WINAPI CONSOLE_DefaultHandler(DWORD dwCtrlType)
516 FIXME("Terminating process %lx on event %lx\n", GetCurrentProcessId(), dwCtrlType);
517 ExitProcess(0);
518 /* should never go here */
519 return TRUE;
522 /******************************************************************************
523 * SetConsoleCtrlHandler [KERNEL32.@] Adds function to calling process list
525 * PARAMS
526 * func [I] Address of handler function
527 * add [I] Handler to add or remove
529 * RETURNS
530 * Success: TRUE
531 * Failure: FALSE
533 * CHANGED
534 * James Sutherland (JamesSutherland@gmx.de)
535 * Added global variables console_ignore_ctrl_c and handlers[]
536 * Does not yet do any error checking, or set LastError if failed.
537 * This doesn't yet matter, since these handlers are not yet called...!
540 static unsigned int console_ignore_ctrl_c = 0; /* FIXME: this should be inherited somehow */
541 static PHANDLER_ROUTINE handlers[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,CONSOLE_DefaultHandler};
543 /*****************************************************************************/
545 BOOL WINAPI SetConsoleCtrlHandler(PHANDLER_ROUTINE func, BOOL add)
547 int alloc_loop = sizeof(handlers)/sizeof(handlers[0]) - 1;
549 FIXME("(%p,%i) - no error checking or testing yet\n", func, add);
551 if (!func)
553 console_ignore_ctrl_c = add;
554 return TRUE;
556 if (add)
558 for (; alloc_loop >= 0 && handlers[alloc_loop]; alloc_loop--);
559 if (alloc_loop <= 0)
561 FIXME("Out of space on CtrlHandler table\n");
562 return FALSE;
564 handlers[alloc_loop] = func;
566 else
568 for (; alloc_loop >= 0 && handlers[alloc_loop] != func; alloc_loop--);
569 if (alloc_loop <= 0)
571 WARN("Attempt to remove non-installed CtrlHandler %p\n", func);
572 return FALSE;
574 /* sanity check */
575 if (alloc_loop == sizeof(handlers)/sizeof(handlers[0]) - 1)
577 ERR("Who's trying to remove default handler???\n");
578 return FALSE;
580 if (alloc_loop)
581 memmove(&handlers[1], &handlers[0], alloc_loop * sizeof(handlers[0]));
582 handlers[0] = 0;
584 return TRUE;
587 static WINE_EXCEPTION_FILTER(CONSOLE_CtrlEventHandler)
589 TRACE("(%lx)\n", GetExceptionCode());
590 return EXCEPTION_EXECUTE_HANDLER;
593 /******************************************************************************
594 * GenerateConsoleCtrlEvent [KERNEL32.@] Simulate a CTRL-C or CTRL-BREAK
596 * PARAMS
597 * dwCtrlEvent [I] Type of event
598 * dwProcessGroupID [I] Process group ID to send event to
600 * NOTES
601 * Doesn't yet work...!
603 * RETURNS
604 * Success: True
605 * Failure: False (and *should* [but doesn't] set LastError)
607 BOOL WINAPI GenerateConsoleCtrlEvent(DWORD dwCtrlEvent,
608 DWORD dwProcessGroupID)
610 if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
612 ERR("invalid event %ld for PGID %ld\n", dwCtrlEvent, dwProcessGroupID);
613 return FALSE;
616 if (dwProcessGroupID == GetCurrentProcessId() || dwProcessGroupID == 0)
618 int i;
620 FIXME("Attempt to send event %ld to self groupID, doing locally only\n", dwCtrlEvent);
622 /* this is only meaningfull when done locally, otherwise it will have to be done on
623 * the 'receive' side of the event generation
625 if (dwCtrlEvent == CTRL_C_EVENT && console_ignore_ctrl_c)
626 return TRUE;
628 /* try to pass the exception to the debugger
629 * if it continues, there's nothing more to do
630 * otherwise, we need to send the ctrl-event to the handlers
632 __TRY
634 RaiseException( (dwCtrlEvent == CTRL_C_EVENT) ? DBG_CONTROL_C : DBG_CONTROL_BREAK,
635 0, 0, NULL);
637 __EXCEPT(CONSOLE_CtrlEventHandler)
639 /* the debugger didn't continue... so, pass to ctrl handlers */
640 for (i = 0; i < sizeof(handlers)/sizeof(handlers[0]); i++)
642 if (handlers[i] && (handlers[i])(dwCtrlEvent)) break;
645 __ENDTRY;
646 return TRUE;
648 FIXME("event %ld to external PGID %ld - not implemented yet\n", dwCtrlEvent, dwProcessGroupID);
649 return FALSE;
653 /******************************************************************************
654 * CreateConsoleScreenBuffer [KERNEL32.@] Creates a console screen buffer
656 * PARAMS
657 * dwDesiredAccess [I] Access flag
658 * dwShareMode [I] Buffer share mode
659 * sa [I] Security attributes
660 * dwFlags [I] Type of buffer to create
661 * lpScreenBufferData [I] Reserved
663 * NOTES
664 * Should call SetLastError
666 * RETURNS
667 * Success: Handle to new console screen buffer
668 * Failure: INVALID_HANDLE_VALUE
670 HANDLE WINAPI CreateConsoleScreenBuffer(DWORD dwDesiredAccess, DWORD dwShareMode,
671 LPSECURITY_ATTRIBUTES sa, DWORD dwFlags,
672 LPVOID lpScreenBufferData)
674 HANDLE ret = INVALID_HANDLE_VALUE;
676 TRACE("(%ld,%ld,%p,%ld,%p)\n",
677 dwDesiredAccess, dwShareMode, sa, dwFlags, lpScreenBufferData);
679 if (dwFlags != CONSOLE_TEXTMODE_BUFFER || lpScreenBufferData != NULL)
681 SetLastError(ERROR_INVALID_PARAMETER);
682 return INVALID_HANDLE_VALUE;
685 SERVER_START_REQ(create_console_output)
687 req->handle_in = 0;
688 req->access = dwDesiredAccess;
689 req->share = dwShareMode;
690 req->inherit = (sa && sa->bInheritHandle);
691 if (!wine_server_call_err( req )) ret = reply->handle_out;
693 SERVER_END_REQ;
695 return ret;
699 /***********************************************************************
700 * GetConsoleScreenBufferInfo (KERNEL32.@)
702 BOOL WINAPI GetConsoleScreenBufferInfo(HANDLE hConsoleOutput, LPCONSOLE_SCREEN_BUFFER_INFO csbi)
704 BOOL ret;
706 SERVER_START_REQ(get_console_output_info)
708 req->handle = hConsoleOutput;
709 if ((ret = !wine_server_call_err( req )))
711 csbi->dwSize.X = reply->width;
712 csbi->dwSize.Y = reply->height;
713 csbi->dwCursorPosition.X = reply->cursor_x;
714 csbi->dwCursorPosition.Y = reply->cursor_y;
715 csbi->wAttributes = reply->attr;
716 csbi->srWindow.Left = reply->win_left;
717 csbi->srWindow.Right = reply->win_right;
718 csbi->srWindow.Top = reply->win_top;
719 csbi->srWindow.Bottom = reply->win_bottom;
720 csbi->dwMaximumWindowSize.X = reply->max_width;
721 csbi->dwMaximumWindowSize.Y = reply->max_height;
724 SERVER_END_REQ;
726 return ret;
730 /******************************************************************************
731 * SetConsoleActiveScreenBuffer [KERNEL32.@] Sets buffer to current console
733 * RETURNS
734 * Success: TRUE
735 * Failure: FALSE
737 BOOL WINAPI SetConsoleActiveScreenBuffer(HANDLE hConsoleOutput)
739 BOOL ret;
741 TRACE("(%x)\n", hConsoleOutput);
743 SERVER_START_REQ( set_console_input_info )
745 req->handle = 0;
746 req->mask = SET_CONSOLE_INPUT_INFO_ACTIVE_SB;
747 req->active_sb = hConsoleOutput;
748 ret = !wine_server_call_err( req );
750 SERVER_END_REQ;
751 return ret;
755 /***********************************************************************
756 * GetConsoleMode (KERNEL32.@)
758 BOOL WINAPI GetConsoleMode(HANDLE hcon, LPDWORD mode)
760 BOOL ret;
762 SERVER_START_REQ(get_console_mode)
764 req->handle = hcon;
765 ret = !wine_server_call_err( req );
766 if (ret && mode) *mode = reply->mode;
768 SERVER_END_REQ;
769 return ret;
773 /******************************************************************************
774 * SetConsoleMode [KERNEL32.@] Sets input mode of console's input buffer
776 * PARAMS
777 * hcon [I] Handle to console input or screen buffer
778 * mode [I] Input or output mode to set
780 * RETURNS
781 * Success: TRUE
782 * Failure: FALSE
784 BOOL WINAPI SetConsoleMode(HANDLE hcon, DWORD mode)
786 BOOL ret;
788 TRACE("(%x,%lx)\n", hcon, mode);
790 SERVER_START_REQ(set_console_mode)
792 req->handle = hcon;
793 req->mode = mode;
794 ret = !wine_server_call_err( req );
796 SERVER_END_REQ;
797 /* FIXME: when resetting a console input to editline mode, I think we should
798 * empty the S_EditString buffer
800 return ret;
804 /******************************************************************
805 * write_char
807 * WriteConsoleOutput helper: hides server call semantics
809 static int write_char(HANDLE hCon, LPCWSTR lpBuffer, int nc, COORD* pos)
811 int written = -1;
813 if (!nc) return 0;
815 SERVER_START_REQ( write_console_output )
817 req->handle = hCon;
818 req->x = pos->X;
819 req->y = pos->Y;
820 req->mode = CHAR_INFO_MODE_TEXTSTDATTR;
821 req->wrap = FALSE;
822 wine_server_add_data( req, lpBuffer, nc * sizeof(WCHAR) );
823 if (!wine_server_call_err( req )) written = reply->written;
825 SERVER_END_REQ;
827 if (written > 0) pos->X += written;
828 return written;
831 /******************************************************************
832 * next_line
834 * WriteConsoleOutput helper: handles passing to next line (+scrolling if necessary)
837 static int next_line(HANDLE hCon, CONSOLE_SCREEN_BUFFER_INFO* csbi)
839 SMALL_RECT src;
840 CHAR_INFO ci;
841 COORD dst;
843 csbi->dwCursorPosition.X = 0;
844 csbi->dwCursorPosition.Y++;
846 if (csbi->dwCursorPosition.Y < csbi->dwSize.Y) return 1;
848 src.Top = 1;
849 src.Bottom = csbi->dwSize.Y - 1;
850 src.Left = 0;
851 src.Right = csbi->dwSize.X - 1;
853 dst.X = 0;
854 dst.Y = 0;
856 ci.Attributes = csbi->wAttributes;
857 ci.Char.UnicodeChar = ' ';
859 csbi->dwCursorPosition.Y--;
860 if (!ScrollConsoleScreenBufferW(hCon, &src, NULL, dst, &ci))
861 return 0;
862 return 1;
865 /******************************************************************
866 * write_block
868 * WriteConsoleOutput helper: writes a block of non special characters
869 * Block can spread on several lines, and wrapping, if needed, is
870 * handled
873 static int write_block(HANDLE hCon, CONSOLE_SCREEN_BUFFER_INFO* csbi,
874 DWORD mode, LPWSTR ptr, int len)
876 int blk; /* number of chars to write on current line */
878 if (len <= 0) return 1;
880 if (mode & ENABLE_WRAP_AT_EOL_OUTPUT) /* writes remaining on next line */
882 int done;
884 for (done = 0; done < len; done += blk)
886 blk = min(len - done, csbi->dwSize.X - csbi->dwCursorPosition.X);
888 if (write_char(hCon, ptr + done, blk, &csbi->dwCursorPosition) != blk)
889 return 0;
890 if (csbi->dwCursorPosition.X == csbi->dwSize.X && !next_line(hCon, csbi))
891 return 0;
894 else
896 blk = min(len, csbi->dwSize.X - csbi->dwCursorPosition.X);
898 if (write_char(hCon, ptr, blk, &csbi->dwCursorPosition) != blk)
899 return 0;
900 if (blk < len)
902 csbi->dwCursorPosition.X = csbi->dwSize.X - 1;
903 /* all remaining chars should be written on last column,
904 * so only overwrite the last column with last char in block
906 if (write_char(hCon, ptr + len - 1, 1, &csbi->dwCursorPosition) != 1)
907 return 0;
908 csbi->dwCursorPosition.X = csbi->dwSize.X - 1;
912 return 1;
915 /***********************************************************************
916 * WriteConsoleW (KERNEL32.@)
918 BOOL WINAPI WriteConsoleW(HANDLE hConsoleOutput, LPCVOID lpBuffer, DWORD nNumberOfCharsToWrite,
919 LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
921 DWORD mode;
922 DWORD nw = 0;
923 WCHAR* psz = (WCHAR*)lpBuffer;
924 CONSOLE_SCREEN_BUFFER_INFO csbi;
925 int k, first = 0;
927 TRACE("%d %s %ld %p %p\n",
928 hConsoleOutput, debugstr_wn(lpBuffer, nNumberOfCharsToWrite),
929 nNumberOfCharsToWrite, lpNumberOfCharsWritten, lpReserved);
931 if (lpNumberOfCharsWritten) *lpNumberOfCharsWritten = 0;
933 if (!GetConsoleMode(hConsoleOutput, &mode) ||
934 !GetConsoleScreenBufferInfo(hConsoleOutput, &csbi))
935 return FALSE;
937 if (mode & ENABLE_PROCESSED_OUTPUT)
939 int i;
941 for (i = 0; i < nNumberOfCharsToWrite; i++)
943 switch (psz[i])
945 case '\b': case '\t': case '\n': case '\a': case '\r':
946 /* don't handle here the i-th char... done below */
947 if ((k = i - first) > 0)
949 if (!write_block(hConsoleOutput, &csbi, mode, &psz[first], k))
950 goto the_end;
951 nw += k;
953 first = i + 1;
954 nw++;
956 switch (psz[i])
958 case '\b':
959 if (csbi.dwCursorPosition.X > 0) csbi.dwCursorPosition.X--;
960 break;
961 case '\t':
963 WCHAR tmp[8] = {' ',' ',' ',' ',' ',' ',' ',' '};
965 if (!write_block(hConsoleOutput, &csbi, mode, tmp,
966 ((csbi.dwCursorPosition.X + 8) & ~7) - csbi.dwCursorPosition.X))
967 goto the_end;
969 break;
970 case '\n':
971 next_line(hConsoleOutput, &csbi);
972 break;
973 case '\a':
974 Beep(400, 300);
975 break;
976 case '\r':
977 csbi.dwCursorPosition.X = 0;
978 break;
979 default:
980 break;
985 /* write the remaining block (if any) if processed output is enabled, or the
986 * entire buffer otherwise
988 if ((k = nNumberOfCharsToWrite - first) > 0)
990 if (!write_block(hConsoleOutput, &csbi, mode, &psz[first], k))
991 goto the_end;
992 nw += k;
995 the_end:
996 SetConsoleCursorPosition(hConsoleOutput, csbi.dwCursorPosition);
997 if (lpNumberOfCharsWritten) *lpNumberOfCharsWritten = nw;
998 return nw != 0;
1002 /***********************************************************************
1003 * WriteConsoleA (KERNEL32.@)
1005 BOOL WINAPI WriteConsoleA(HANDLE hConsoleOutput, LPCVOID lpBuffer, DWORD nNumberOfCharsToWrite,
1006 LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)
1008 BOOL ret;
1009 LPWSTR xstring;
1010 DWORD n;
1012 n = MultiByteToWideChar(CP_ACP, 0, lpBuffer, nNumberOfCharsToWrite, NULL, 0);
1014 if (lpNumberOfCharsWritten) *lpNumberOfCharsWritten = 0;
1015 xstring = HeapAlloc(GetProcessHeap(), 0, n * sizeof(WCHAR));
1016 if (!xstring) return 0;
1018 MultiByteToWideChar(CP_ACP, 0, lpBuffer, nNumberOfCharsToWrite, xstring, n);
1020 ret = WriteConsoleW(hConsoleOutput, xstring, n, lpNumberOfCharsWritten, 0);
1022 HeapFree(GetProcessHeap(), 0, xstring);
1024 return ret;
1027 /******************************************************************************
1028 * SetConsoleCursorPosition [KERNEL32.@]
1029 * Sets the cursor position in console
1031 * PARAMS
1032 * hConsoleOutput [I] Handle of console screen buffer
1033 * dwCursorPosition [I] New cursor position coordinates
1035 * RETURNS STD
1037 BOOL WINAPI SetConsoleCursorPosition(HANDLE hcon, COORD pos)
1039 BOOL ret;
1040 CONSOLE_SCREEN_BUFFER_INFO csbi;
1041 int do_move = 0;
1042 int w, h;
1044 TRACE("%x %d %d\n", hcon, pos.X, pos.Y);
1046 SERVER_START_REQ(set_console_output_info)
1048 req->handle = hcon;
1049 req->cursor_x = pos.X;
1050 req->cursor_y = pos.Y;
1051 req->mask = SET_CONSOLE_OUTPUT_INFO_CURSOR_POS;
1052 ret = !wine_server_call_err( req );
1054 SERVER_END_REQ;
1056 if (!ret || !GetConsoleScreenBufferInfo(hcon, &csbi))
1057 return FALSE;
1059 /* if cursor is no longer visible, scroll the visible window... */
1060 w = csbi.srWindow.Right - csbi.srWindow.Left + 1;
1061 h = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
1062 if (pos.X < csbi.srWindow.Left)
1064 csbi.srWindow.Left = min(pos.X, csbi.dwSize.X - w);
1065 do_move++;
1067 else if (pos.X > csbi.srWindow.Right)
1069 csbi.srWindow.Left = max(pos.X, w) - w + 1;
1070 do_move++;
1072 csbi.srWindow.Right = csbi.srWindow.Left + w - 1;
1074 if (pos.Y < csbi.srWindow.Top)
1076 csbi.srWindow.Top = min(pos.Y, csbi.dwSize.Y - h);
1077 do_move++;
1079 else if (pos.Y > csbi.srWindow.Bottom)
1081 csbi.srWindow.Top = max(pos.Y, h) - h + 1;
1082 do_move++;
1084 csbi.srWindow.Bottom = csbi.srWindow.Top + h - 1;
1086 ret = (do_move) ? SetConsoleWindowInfo(hcon, TRUE, &csbi.srWindow) : TRUE;
1088 return ret;
1091 /******************************************************************************
1092 * GetConsoleCursorInfo [KERNEL32.@] Gets size and visibility of console
1094 * PARAMS
1095 * hcon [I] Handle to console screen buffer
1096 * cinfo [O] Address of cursor information
1098 * RETURNS
1099 * Success: TRUE
1100 * Failure: FALSE
1102 BOOL WINAPI GetConsoleCursorInfo(HANDLE hcon, LPCONSOLE_CURSOR_INFO cinfo)
1104 BOOL ret;
1106 SERVER_START_REQ(get_console_output_info)
1108 req->handle = hcon;
1109 ret = !wine_server_call_err( req );
1110 if (ret && cinfo)
1112 cinfo->dwSize = reply->cursor_size;
1113 cinfo->bVisible = reply->cursor_visible;
1116 SERVER_END_REQ;
1117 return ret;
1121 /******************************************************************************
1122 * SetConsoleCursorInfo [KERNEL32.@] Sets size and visibility of cursor
1124 * PARAMS
1125 * hcon [I] Handle to console screen buffer
1126 * cinfo [I] Address of cursor information
1127 * RETURNS
1128 * Success: TRUE
1129 * Failure: FALSE
1131 BOOL WINAPI SetConsoleCursorInfo(HANDLE hCon, LPCONSOLE_CURSOR_INFO cinfo)
1133 BOOL ret;
1135 SERVER_START_REQ(set_console_output_info)
1137 req->handle = hCon;
1138 req->cursor_size = cinfo->dwSize;
1139 req->cursor_visible = cinfo->bVisible;
1140 req->mask = SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM;
1141 ret = !wine_server_call_err( req );
1143 SERVER_END_REQ;
1144 return ret;
1148 /******************************************************************************
1149 * SetConsoleWindowInfo [KERNEL32.@] Sets size and position of console
1151 * PARAMS
1152 * hcon [I] Handle to console screen buffer
1153 * bAbsolute [I] Coordinate type flag
1154 * window [I] Address of new window rectangle
1155 * RETURNS
1156 * Success: TRUE
1157 * Failure: FALSE
1159 BOOL WINAPI SetConsoleWindowInfo(HANDLE hCon, BOOL bAbsolute, LPSMALL_RECT window)
1161 SMALL_RECT p = *window;
1162 BOOL ret;
1164 if (!bAbsolute)
1166 CONSOLE_SCREEN_BUFFER_INFO csbi;
1167 if (!GetConsoleScreenBufferInfo(hCon, &csbi))
1168 return FALSE;
1169 p.Left += csbi.srWindow.Left;
1170 p.Top += csbi.srWindow.Top;
1171 p.Right += csbi.srWindow.Left;
1172 p.Bottom += csbi.srWindow.Top;
1174 SERVER_START_REQ(set_console_output_info)
1176 req->handle = hCon;
1177 req->win_left = p.Left;
1178 req->win_top = p.Top;
1179 req->win_right = p.Right;
1180 req->win_bottom = p.Bottom;
1181 req->mask = SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW;
1182 ret = !wine_server_call_err( req );
1184 SERVER_END_REQ;
1186 return ret;
1190 /******************************************************************************
1191 * SetConsoleTextAttribute [KERNEL32.@] Sets colors for text
1193 * Sets the foreground and background color attributes of characters
1194 * written to the screen buffer.
1196 * RETURNS
1197 * Success: TRUE
1198 * Failure: FALSE
1200 BOOL WINAPI SetConsoleTextAttribute(HANDLE hConsoleOutput, WORD wAttr)
1202 BOOL ret;
1204 SERVER_START_REQ(set_console_output_info)
1206 req->handle = hConsoleOutput;
1207 req->attr = wAttr;
1208 req->mask = SET_CONSOLE_OUTPUT_INFO_ATTR;
1209 ret = !wine_server_call_err( req );
1211 SERVER_END_REQ;
1212 return ret;
1216 /******************************************************************************
1217 * SetConsoleScreenBufferSize [KERNEL32.@] Changes size of console
1219 * PARAMS
1220 * hConsoleOutput [I] Handle to console screen buffer
1221 * dwSize [I] New size in character rows and cols
1223 * RETURNS
1224 * Success: TRUE
1225 * Failure: FALSE
1227 BOOL WINAPI SetConsoleScreenBufferSize(HANDLE hConsoleOutput, COORD dwSize)
1229 BOOL ret;
1231 SERVER_START_REQ(set_console_output_info)
1233 req->handle = hConsoleOutput;
1234 req->width = dwSize.X;
1235 req->height = dwSize.Y;
1236 req->mask = SET_CONSOLE_OUTPUT_INFO_SIZE;
1237 ret = !wine_server_call_err( req );
1239 SERVER_END_REQ;
1240 return ret;
1244 /******************************************************************************
1245 * ScrollConsoleScreenBufferA [KERNEL32.@]
1248 BOOL WINAPI ScrollConsoleScreenBufferA(HANDLE hConsoleOutput, LPSMALL_RECT lpScrollRect,
1249 LPSMALL_RECT lpClipRect, COORD dwDestOrigin,
1250 LPCHAR_INFO lpFill)
1252 CHAR_INFO ciw;
1254 ciw.Attributes = lpFill->Attributes;
1255 MultiByteToWideChar(CP_ACP, 0, &lpFill->Char.AsciiChar, 1, &ciw.Char.UnicodeChar, 1);
1257 return ScrollConsoleScreenBufferW(hConsoleOutput, lpScrollRect, lpClipRect,
1258 dwDestOrigin, &ciw);
1261 /******************************************************************
1262 * fill_line_uniform
1264 * Helper function for ScrollConsoleScreenBufferW
1265 * Fills a part of a line with a constant character info
1267 static void fill_line_uniform(HANDLE hConsoleOutput, int i, int j, int len, LPCHAR_INFO lpFill)
1269 SERVER_START_REQ( fill_console_output )
1271 req->handle = hConsoleOutput;
1272 req->mode = CHAR_INFO_MODE_TEXTATTR;
1273 req->x = i;
1274 req->y = j;
1275 req->count = len;
1276 req->wrap = FALSE;
1277 req->data.ch = lpFill->Char.UnicodeChar;
1278 req->data.attr = lpFill->Attributes;
1279 wine_server_call_err( req );
1281 SERVER_END_REQ;
1284 /******************************************************************************
1285 * ScrollConsoleScreenBufferW [KERNEL32.@]
1289 BOOL WINAPI ScrollConsoleScreenBufferW(HANDLE hConsoleOutput, LPSMALL_RECT lpScrollRect,
1290 LPSMALL_RECT lpClipRect, COORD dwDestOrigin,
1291 LPCHAR_INFO lpFill)
1293 SMALL_RECT dst;
1294 DWORD ret;
1295 int i, j;
1296 int start = -1;
1297 SMALL_RECT clip;
1298 CONSOLE_SCREEN_BUFFER_INFO csbi;
1299 BOOL inside;
1301 if (lpClipRect)
1302 TRACE("(%d,(%d,%d-%d,%d),(%d,%d-%d,%d),%d-%d,%p)\n", hConsoleOutput,
1303 lpScrollRect->Left, lpScrollRect->Top,
1304 lpScrollRect->Right, lpScrollRect->Bottom,
1305 lpClipRect->Left, lpClipRect->Top,
1306 lpClipRect->Right, lpClipRect->Bottom,
1307 dwDestOrigin.X, dwDestOrigin.Y, lpFill);
1308 else
1309 TRACE("(%d,(%d,%d-%d,%d),(nil),%d-%d,%p)\n", hConsoleOutput,
1310 lpScrollRect->Left, lpScrollRect->Top,
1311 lpScrollRect->Right, lpScrollRect->Bottom,
1312 dwDestOrigin.X, dwDestOrigin.Y, lpFill);
1314 if (!GetConsoleScreenBufferInfo(hConsoleOutput, &csbi))
1315 return FALSE;
1317 /* step 1: get dst rect */
1318 dst.Left = dwDestOrigin.X;
1319 dst.Top = dwDestOrigin.Y;
1320 dst.Right = dst.Left + (lpScrollRect->Right - lpScrollRect->Left);
1321 dst.Bottom = dst.Top + (lpScrollRect->Bottom - lpScrollRect->Top);
1323 /* step 2a: compute the final clip rect (optional passed clip and screen buffer limits */
1324 if (lpClipRect)
1326 clip.Left = max(0, lpClipRect->Left);
1327 clip.Right = min(csbi.dwSize.X - 1, lpClipRect->Right);
1328 clip.Top = max(0, lpClipRect->Top);
1329 clip.Bottom = min(csbi.dwSize.Y - 1, lpClipRect->Bottom);
1331 else
1333 clip.Left = 0;
1334 clip.Right = csbi.dwSize.X - 1;
1335 clip.Top = 0;
1336 clip.Bottom = csbi.dwSize.Y - 1;
1338 if (clip.Left > clip.Right || clip.Top > clip.Bottom) return FALSE;
1340 /* step 2b: clip dst rect */
1341 if (dst.Left < clip.Left ) dst.Left = clip.Left;
1342 if (dst.Top < clip.Top ) dst.Top = clip.Top;
1343 if (dst.Right > clip.Right ) dst.Right = clip.Right;
1344 if (dst.Bottom > clip.Bottom) dst.Bottom = clip.Bottom;
1346 /* step 3: transfer the bits */
1347 SERVER_START_REQ(move_console_output)
1349 req->handle = hConsoleOutput;
1350 req->x_src = lpScrollRect->Left;
1351 req->y_src = lpScrollRect->Top;
1352 req->x_dst = dst.Left;
1353 req->y_dst = dst.Top;
1354 req->w = dst.Right - dst.Left + 1;
1355 req->h = dst.Bottom - dst.Top + 1;
1356 ret = !wine_server_call_err( req );
1358 SERVER_END_REQ;
1360 if (!ret) return FALSE;
1362 /* step 4: clean out the exposed part */
1364 /* have to write celll [i,j] if it is not in dst rect (because it has already
1365 * been written to by the scroll) and is in clip (we shall not write
1366 * outside of clip)
1368 for (j = max(lpScrollRect->Top, clip.Top); j <= min(lpScrollRect->Bottom, clip.Bottom); j++)
1370 inside = dst.Top <= j && j <= dst.Bottom;
1371 start = -1;
1372 for (i = max(lpScrollRect->Left, clip.Left); i <= min(lpScrollRect->Right, clip.Right); i++)
1374 if (inside && dst.Left <= i && i <= dst.Right)
1376 if (start != -1)
1378 fill_line_uniform(hConsoleOutput, start, j, i - start, lpFill);
1379 start = -1;
1382 else
1384 if (start == -1) start = i;
1387 if (start != -1)
1388 fill_line_uniform(hConsoleOutput, start, j, i - start, lpFill);
1391 return TRUE;
1395 /* ====================================================================
1397 * Console manipulation functions
1399 * ====================================================================*/
1400 /* some missing functions...
1401 * FIXME: those are likely to be defined as undocumented function in kernel32 (or part of them)
1402 * should get the right API and implement them
1403 * GetConsoleCommandHistory[AW] (dword dword dword)
1404 * GetConsoleCommandHistoryLength[AW]
1405 * SetConsoleCommandHistoryMode
1406 * SetConsoleNumberOfCommands[AW]
1408 int CONSOLE_GetHistory(int idx, WCHAR* buf, int buf_len)
1410 int len = 0;
1412 SERVER_START_REQ( get_console_input_history )
1414 req->handle = 0;
1415 req->index = idx;
1416 if (buf && buf_len > 1)
1418 wine_server_set_reply( req, buf, (buf_len - 1) * sizeof(WCHAR) );
1420 if (!wine_server_call_err( req ))
1422 if (buf) buf[wine_server_reply_size(reply) / sizeof(WCHAR)] = 0;
1423 len = reply->total / sizeof(WCHAR) + 1;
1426 SERVER_END_REQ;
1427 return len;
1430 /******************************************************************
1431 * CONSOLE_AppendHistory
1435 BOOL CONSOLE_AppendHistory(const WCHAR* ptr)
1437 size_t len = strlenW(ptr);
1438 BOOL ret;
1440 while (len && (ptr[len - 1] == '\n' || ptr[len - 1] == '\r')) len--;
1442 SERVER_START_REQ( append_console_input_history )
1444 req->handle = 0;
1445 wine_server_add_data( req, ptr, len * sizeof(WCHAR) );
1446 ret = !wine_server_call_err( req );
1448 SERVER_END_REQ;
1449 return ret;
1452 /******************************************************************
1453 * CONSOLE_GetNumHistoryEntries
1457 unsigned CONSOLE_GetNumHistoryEntries(void)
1459 unsigned ret = 0;
1460 SERVER_START_REQ(get_console_input_info)
1462 req->handle = 0;
1463 if (!wine_server_call_err( req )) ret = reply->history_index;
1465 SERVER_END_REQ;
1466 return ret;