Added a few DirectInput 7 definitions and C++ fixes.
[wine.git] / win32 / console.c
blob35a67331ca8cdffb269c676e97616128f977a559
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 */
10 /* FIXME:
11 * - Completely lacks SCREENBUFFER interface.
12 * - No abstraction for something other than xterm.
13 * - Key input translation shouldn't use VkKeyScan and MapVirtualKey, since
14 * they are window (USER) driver dependend.
15 * - Output sometimes is buffered (We switched off buffering by ~ICANON ?)
17 /* Reference applications:
18 * - IDA (interactive disassembler) full version 3.75. Works.
19 * - LYNX/W32. Works mostly, some keys crash it.
22 #include "config.h"
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <unistd.h>
27 #include <termios.h>
28 #include <string.h>
29 #include <sys/ioctl.h>
30 #include <sys/types.h>
31 #include <sys/time.h>
32 #include <fcntl.h>
33 #include <errno.h>
34 #ifdef HAVE_SYS_ERRNO_H
35 #include <sys/errno.h>
36 #endif
37 #include <signal.h>
38 #include <assert.h>
40 #include "winbase.h"
41 #include "windef.h"
42 #include "wingdi.h"
43 #include "wine/winuser16.h"
44 #include "wine/keyboard16.h"
45 #include "thread.h"
46 #include "file.h"
47 #include "process.h"
48 #include "winerror.h"
49 #include "wincon.h"
50 #include "heap.h"
51 #include "server.h"
52 #include "debugtools.h"
53 #include "winnls.h"
55 DEFAULT_DEBUG_CHANNEL(console)
58 /* FIXME: Should be in an internal header file. OK, so which one?
59 Used by CONSOLE_makecomplex. */
60 int wine_openpty(int *master, int *slave, char *name,
61 struct termios *term, struct winsize *winsize);
63 /****************************************************************************
64 * CONSOLE_GetPid
66 static int CONSOLE_GetPid( HANDLE handle )
68 struct get_console_info_request *req = get_req_buffer();
69 req->handle = handle;
70 if (server_call( REQ_GET_CONSOLE_INFO )) return 0;
71 return req->pid;
74 /****************************************************************************
75 * XTERM_string_to_IR [internal]
77 * Transfers a string read from XTERM to INPUT_RECORDs and adds them to the
78 * queue. Does translation of vt100 style function keys and xterm-mouse clicks.
80 static void
81 CONSOLE_string_to_IR( HANDLE hConsoleInput,unsigned char *buf,int len) {
82 int j,k;
83 INPUT_RECORD ir;
84 DWORD junk;
86 for (j=0;j<len;j++) {
87 unsigned char inchar = buf[j];
89 if (inchar!=27) { /* no escape -> 'normal' keyboard event */
90 ir.EventType = 1; /* Key_event */
92 ir.Event.KeyEvent.bKeyDown = 1;
93 ir.Event.KeyEvent.wRepeatCount = 0;
95 ir.Event.KeyEvent.dwControlKeyState = 0;
96 if (inchar & 0x80) {
97 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
98 inchar &= ~0x80;
100 #if 0 /* FIXME: cannot call USER functions here */
101 ir.Event.KeyEvent.wVirtualKeyCode = VkKeyScan16(inchar);
102 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0100)
103 ir.Event.KeyEvent.dwControlKeyState|=SHIFT_PRESSED;
104 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0200)
105 ir.Event.KeyEvent.dwControlKeyState|=LEFT_CTRL_PRESSED;
106 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0400)
107 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
108 ir.Event.KeyEvent.wVirtualScanCode = MapVirtualKey16(
109 ir.Event.KeyEvent.wVirtualKeyCode & 0x00ff,
110 0 /* VirtualKeyCodes to ScanCode */
112 #else
113 ir.Event.KeyEvent.wVirtualKeyCode = 0;
114 ir.Event.KeyEvent.wVirtualScanCode = 0;
115 #endif
116 ir.Event.KeyEvent.uChar.AsciiChar = inchar;
118 if ((inchar==127)||(inchar=='\b')) { /* backspace */
119 ir.Event.KeyEvent.uChar.AsciiChar = '\b'; /* FIXME: hmm */
120 ir.Event.KeyEvent.wVirtualScanCode = 0x0e;
121 ir.Event.KeyEvent.wVirtualKeyCode = VK_BACK;
122 } else {
123 if ((inchar=='\n')||(inchar=='\r')) {
124 ir.Event.KeyEvent.uChar.AsciiChar = '\r';
125 ir.Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
126 ir.Event.KeyEvent.wVirtualScanCode = 0x1c;
127 ir.Event.KeyEvent.dwControlKeyState = 0;
128 } else {
129 if (inchar<' ') {
130 /* FIXME: find good values for ^X */
131 ir.Event.KeyEvent.wVirtualKeyCode = 0xdead;
132 ir.Event.KeyEvent.wVirtualScanCode = 0xbeef;
137 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
138 ir.Event.KeyEvent.bKeyDown = 0;
139 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
140 continue;
142 /* inchar is ESC */
143 if ((j==len-1) || (buf[j+1]!='[')) {/* add ESCape on its own */
144 ir.EventType = 1; /* Key_event */
145 ir.Event.KeyEvent.bKeyDown = 1;
146 ir.Event.KeyEvent.wRepeatCount = 0;
148 #if 0 /* FIXME: cannot call USER functions here */
149 ir.Event.KeyEvent.wVirtualKeyCode = VkKeyScan16(27);
150 ir.Event.KeyEvent.wVirtualScanCode = MapVirtualKey16(
151 ir.Event.KeyEvent.wVirtualKeyCode,0
153 #else
154 ir.Event.KeyEvent.wVirtualKeyCode = VK_ESCAPE;
155 ir.Event.KeyEvent.wVirtualScanCode = 1;
156 #endif
157 ir.Event.KeyEvent.dwControlKeyState = 0;
158 ir.Event.KeyEvent.uChar.AsciiChar = 27;
159 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
160 ir.Event.KeyEvent.bKeyDown = 0;
161 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
162 continue;
164 for (k=j;k<len;k++) {
165 if (((buf[k]>='A') && (buf[k]<='Z')) ||
166 ((buf[k]>='a') && (buf[k]<='z')) ||
167 (buf[k]=='~')
169 break;
171 if (k<len) {
172 int subid,scancode=0;
174 ir.EventType = 1; /* Key_event */
175 ir.Event.KeyEvent.bKeyDown = 1;
176 ir.Event.KeyEvent.wRepeatCount = 0;
177 ir.Event.KeyEvent.dwControlKeyState = 0;
179 ir.Event.KeyEvent.wVirtualKeyCode = 0xad; /* FIXME */
180 ir.Event.KeyEvent.wVirtualScanCode = 0xad; /* FIXME */
181 ir.Event.KeyEvent.uChar.AsciiChar = 0;
183 switch (buf[k]) {
184 case '~':
185 sscanf(&buf[j+2],"%d",&subid);
186 switch (subid) {
187 case 2:/*INS */scancode = 0xe052;break;
188 case 3:/*DEL */scancode = 0xe053;break;
189 case 6:/*PGDW*/scancode = 0xe051;break;
190 case 5:/*PGUP*/scancode = 0xe049;break;
191 case 11:/*F1 */scancode = 0x003b;break;
192 case 12:/*F2 */scancode = 0x003c;break;
193 case 13:/*F3 */scancode = 0x003d;break;
194 case 14:/*F4 */scancode = 0x003e;break;
195 case 15:/*F5 */scancode = 0x003f;break;
196 case 17:/*F6 */scancode = 0x0040;break;
197 case 18:/*F7 */scancode = 0x0041;break;
198 case 19:/*F8 */scancode = 0x0042;break;
199 case 20:/*F9 */scancode = 0x0043;break;
200 case 21:/*F10 */scancode = 0x0044;break;
201 case 23:/*F11 */scancode = 0x00d9;break;
202 case 24:/*F12 */scancode = 0x00da;break;
203 /* FIXME: Shift-Fx */
204 default:
205 FIXME("parse ESC[%d~\n",subid);
206 break;
208 break;
209 case 'A': /* Cursor Up */scancode = 0xe048;break;
210 case 'B': /* Cursor Down */scancode = 0xe050;break;
211 case 'D': /* Cursor Left */scancode = 0xe04b;break;
212 case 'C': /* Cursor Right */scancode = 0xe04d;break;
213 case 'F': /* End */scancode = 0xe04f;break;
214 case 'H': /* Home */scancode = 0xe047;break;
215 case 'M':
216 /* Mouse Button Press (ESCM<button+'!'><x+'!'><y+'!'>) or
217 * Release (ESCM#<x+'!'><y+'!'>
219 if (k<len-3) {
220 ir.EventType = MOUSE_EVENT;
221 ir.Event.MouseEvent.dwMousePosition.X = buf[k+2]-'!';
222 ir.Event.MouseEvent.dwMousePosition.Y = buf[k+3]-'!';
223 if (buf[k+1]=='#')
224 ir.Event.MouseEvent.dwButtonState = 0;
225 else
226 ir.Event.MouseEvent.dwButtonState = 1<<(buf[k+1]-' ');
227 ir.Event.MouseEvent.dwEventFlags = 0; /* FIXME */
228 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk));
229 j=k+3;
231 break;
232 case 'c':
233 j=k;
234 break;
236 if (scancode) {
237 ir.Event.KeyEvent.wVirtualScanCode = scancode;
238 #if 0 /* FIXME: cannot call USER functions here */
239 ir.Event.KeyEvent.wVirtualKeyCode = MapVirtualKey16(scancode,1);
240 #else
241 ir.Event.KeyEvent.wVirtualKeyCode = 0;
242 #endif
243 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
244 ir.Event.KeyEvent.bKeyDown = 0;
245 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
246 j=k;
247 continue;
253 /****************************************************************************
254 * CONSOLE_get_input (internal)
256 * Reads (nonblocking) as much input events as possible and stores them
257 * in an internal queue.
259 static void
260 CONSOLE_get_input( HANDLE handle, BOOL blockwait )
262 char *buf = HeapAlloc(GetProcessHeap(),0,1);
263 int len = 0, escape_seen = 0;
265 while (1)
267 DWORD res;
268 char inchar;
270 /* If we have at one time seen escape in this loop, we are
271 * within an Escape sequence, so wait for a bit more input for the
272 * rest of the loop.
274 if (WaitForSingleObject( handle, escape_seen*10 )) break;
275 if (!ReadFile( handle, &inchar, 1, &res, NULL )) break;
276 if (!res) /* res 0 but readable means EOF? Hmm. */
277 break;
278 buf = HeapReAlloc(GetProcessHeap(),0,buf,len+1);
279 buf[len++]=inchar;
280 if (inchar == 27) {
281 if (len>1) {
282 /* If we spot an ESC, we flush all up to it
283 * since we can be sure that we have a complete
284 * sequence.
286 CONSOLE_string_to_IR(handle,buf,len-1);
287 buf = HeapReAlloc(GetProcessHeap(),0,buf,1);
288 buf[0] = 27;
289 len = 1;
291 escape_seen = 1;
294 CONSOLE_string_to_IR(handle,buf,len);
295 HeapFree(GetProcessHeap(),0,buf);
298 /******************************************************************************
299 * SetConsoleCtrlHandler [KERNEL32.459] Adds function to calling process list
301 * PARAMS
302 * func [I] Address of handler function
303 * add [I] Handler to add or remove
305 * RETURNS
306 * Success: TRUE
307 * Failure: FALSE
309 * CHANGED
310 * James Sutherland (JamesSutherland@gmx.de)
311 * Added global variables console_ignore_ctrl_c and handlers[]
312 * Does not yet do any error checking, or set LastError if failed.
313 * This doesn't yet matter, since these handlers are not yet called...!
315 static unsigned int console_ignore_ctrl_c = 0;
316 static HANDLER_ROUTINE *handlers[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
317 BOOL WINAPI SetConsoleCtrlHandler( HANDLER_ROUTINE *func, BOOL add )
319 unsigned int alloc_loop = sizeof(handlers)/sizeof(HANDLER_ROUTINE *);
320 unsigned int done = 0;
321 FIXME("(%p,%i) - no error checking or testing yet\n", func, add);
322 if (!func)
324 console_ignore_ctrl_c = add;
325 return TRUE;
327 if (add)
329 for (;alloc_loop--;)
330 if (!handlers[alloc_loop] && !done)
332 handlers[alloc_loop] = func;
333 done++;
335 if (!done)
336 FIXME("Out of space on CtrlHandler table\n");
337 return(done);
339 else
341 for (;alloc_loop--;)
342 if (handlers[alloc_loop] == func && !done)
344 handlers[alloc_loop] = 0;
345 done++;
347 if (!done)
348 WARN("Attempt to remove non-installed CtrlHandler %p\n",
349 func);
350 return (done);
352 return (done);
356 /******************************************************************************
357 * GenerateConsoleCtrlEvent [KERNEL32.275] Simulate a CTRL-C or CTRL-BREAK
359 * PARAMS
360 * dwCtrlEvent [I] Type of event
361 * dwProcessGroupID [I] Process group ID to send event to
363 * NOTES
364 * Doesn't yet work...!
366 * RETURNS
367 * Success: True
368 * Failure: False (and *should* [but doesn't] set LastError)
370 BOOL WINAPI GenerateConsoleCtrlEvent( DWORD dwCtrlEvent,
371 DWORD dwProcessGroupID )
373 if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
375 ERR("invalid event %d for PGID %ld\n",
376 (unsigned short)dwCtrlEvent, dwProcessGroupID );
377 return FALSE;
379 if (dwProcessGroupID == GetCurrentProcessId() )
381 FIXME("Attempt to send event %d to self - stub\n",
382 (unsigned short)dwCtrlEvent );
383 return FALSE;
385 FIXME("event %d to external PGID %ld - not implemented yet\n",
386 (unsigned short)dwCtrlEvent, dwProcessGroupID );
387 return FALSE;
391 /******************************************************************************
392 * CreateConsoleScreenBuffer [KERNEL32.151] Creates a console screen buffer
394 * PARAMS
395 * dwDesiredAccess [I] Access flag
396 * dwShareMode [I] Buffer share mode
397 * sa [I] Security attributes
398 * dwFlags [I] Type of buffer to create
399 * lpScreenBufferData [I] Reserved
401 * NOTES
402 * Should call SetLastError
404 * RETURNS
405 * Success: Handle to new console screen buffer
406 * Failure: INVALID_HANDLE_VALUE
408 HANDLE WINAPI CreateConsoleScreenBuffer( DWORD dwDesiredAccess,
409 DWORD dwShareMode, LPSECURITY_ATTRIBUTES sa,
410 DWORD dwFlags, LPVOID lpScreenBufferData )
412 FIXME("(%ld,%ld,%p,%ld,%p): stub\n",dwDesiredAccess,
413 dwShareMode, sa, dwFlags, lpScreenBufferData);
414 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
415 return INVALID_HANDLE_VALUE;
419 /***********************************************************************
420 * GetConsoleScreenBufferInfo (KERNEL32.190)
422 BOOL WINAPI GetConsoleScreenBufferInfo( HANDLE hConsoleOutput,
423 LPCONSOLE_SCREEN_BUFFER_INFO csbi )
425 csbi->dwSize.X = 80;
426 csbi->dwSize.Y = 24;
427 csbi->dwCursorPosition.X = 0;
428 csbi->dwCursorPosition.Y = 0;
429 csbi->wAttributes = 0;
430 csbi->srWindow.Left = 0;
431 csbi->srWindow.Right = 79;
432 csbi->srWindow.Top = 0;
433 csbi->srWindow.Bottom = 23;
434 csbi->dwMaximumWindowSize.X = 80;
435 csbi->dwMaximumWindowSize.Y = 24;
436 return TRUE;
440 /******************************************************************************
441 * SetConsoleActiveScreenBuffer [KERNEL32.623] Sets buffer to current console
443 * RETURNS
444 * Success: TRUE
445 * Failure: FALSE
447 BOOL WINAPI SetConsoleActiveScreenBuffer(
448 HANDLE hConsoleOutput) /* [in] Handle to console screen buffer */
450 FIXME("(%x): stub\n", hConsoleOutput);
451 return FALSE;
455 /***********************************************************************
456 * GetLargestConsoleWindowSize (KERNEL32.226)
458 COORD WINAPI GetLargestConsoleWindowSize( HANDLE hConsoleOutput )
460 COORD c;
461 c.X = 80;
462 c.Y = 24;
463 return c;
466 /* gcc doesn't return structures the same way as dwords */
467 DWORD WINAPI WIN32_GetLargestConsoleWindowSize( HANDLE hConsoleOutput )
469 COORD c = GetLargestConsoleWindowSize( hConsoleOutput );
470 return *(DWORD *)&c;
473 /***********************************************************************
474 * FreeConsole (KERNEL32.267)
476 BOOL WINAPI FreeConsole(VOID)
478 return !server_call( REQ_FREE_CONSOLE );
482 /*************************************************************************
483 * CONSOLE_OpenHandle
485 * Open a handle to the current process console.
487 HANDLE CONSOLE_OpenHandle( BOOL output, DWORD access, LPSECURITY_ATTRIBUTES sa )
489 int ret = -1;
490 struct open_console_request *req = get_req_buffer();
492 req->output = output;
493 req->access = access;
494 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
495 SetLastError(0);
496 if (!server_call( REQ_OPEN_CONSOLE )) ret = req->handle;
497 return ret;
501 /*************************************************************************
502 * CONSOLE_make_complex [internal]
504 * Turns a CONSOLE kernel object into a complex one.
505 * (switches from output/input using the terminal where WINE was started to
506 * its own xterm).
508 * This makes simple commandline tools pipeable, while complex commandline
509 * tools work without getting messed up by debugoutput.
511 * All other functions should work indedependend from this call.
513 * To test for complex console: pid == 0 -> simple, otherwise complex.
515 static BOOL CONSOLE_make_complex(HANDLE handle)
517 struct set_console_fd_request *req = get_req_buffer();
518 struct termios term;
519 char buf[256];
520 char c = '\0';
521 int i,xpid,master,slave,pty_handle;
523 if (CONSOLE_GetPid( handle )) return TRUE; /* already complex */
525 MESSAGE("Console: Making console complex (creating an xterm)...\n");
527 if (tcgetattr(0, &term) < 0) {
528 /* ignore failure, or we can't run from a script */
530 term.c_lflag = ~(ECHO|ICANON);
532 if (wine_openpty(&master, &slave, NULL, &term, NULL) < 0)
533 return FALSE;
535 if ((xpid=fork()) == 0) {
536 tcsetattr(slave, TCSADRAIN, &term);
537 close( slave );
538 sprintf(buf, "-Sxx%d", master);
539 /* "-fn vga" for VGA font. Harmless if vga is not present:
540 * xterm: unable to open font "vga", trying "fixed"....
542 execlp("xterm", "xterm", buf, "-fn","vga",NULL);
543 ERR("error creating AllocConsole xterm\n");
544 exit(1);
546 pty_handle = FILE_DupUnixHandle( slave, GENERIC_READ | GENERIC_WRITE );
547 close( master );
548 close( slave );
549 if (pty_handle == -1) return FALSE;
551 /* most xterms like to print their window ID when used with -S;
552 * read it and continue before the user has a chance...
554 for (i = 0; i < 10000; i++)
556 BOOL ok = ReadFile( pty_handle, &c, 1, NULL, NULL );
557 if (!ok && !c) usleep(100); /* wait for xterm to be created */
558 else if (c == '\n') break;
560 if (i == 10000)
562 ERR("can't read xterm WID\n");
563 CloseHandle( pty_handle );
564 return FALSE;
566 req->handle = handle;
567 req->file_handle = pty_handle;
568 req->pid = xpid;
569 server_call( REQ_SET_CONSOLE_FD );
570 CloseHandle( pty_handle );
572 /* enable mouseclicks */
573 strcpy( buf, "\033[?1001s\033[?1000h" );
574 WriteFile(handle,buf,strlen(buf),NULL,NULL);
576 strcpy( buf, "\033]2;" );
577 if (GetConsoleTitleA( buf + 4, sizeof(buf) - 5 ))
579 strcat( buf, "\a" );
580 WriteFile(handle,buf,strlen(buf),NULL,NULL);
582 return TRUE;
587 /***********************************************************************
588 * AllocConsole (KERNEL32.103)
590 * creates an xterm with a pty to our program
592 BOOL WINAPI AllocConsole(VOID)
594 struct alloc_console_request *req = get_req_buffer();
595 HANDLE hStderr;
596 int handle_in, handle_out;
598 TRACE("()\n");
599 req->access = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE;
600 req->inherit = FALSE;
601 if (server_call( REQ_ALLOC_CONSOLE )) return FALSE;
602 handle_in = req->handle_in;
603 handle_out = req->handle_out;
605 if (!DuplicateHandle( GetCurrentProcess(), req->handle_out, GetCurrentProcess(), &hStderr,
606 0, TRUE, DUPLICATE_SAME_ACCESS ))
608 CloseHandle( handle_in );
609 CloseHandle( handle_out );
610 FreeConsole();
611 return FALSE;
614 /* NT resets the STD_*_HANDLEs on console alloc */
615 SetStdHandle( STD_INPUT_HANDLE, handle_in );
616 SetStdHandle( STD_OUTPUT_HANDLE, handle_out );
617 SetStdHandle( STD_ERROR_HANDLE, hStderr );
619 SetLastError(ERROR_SUCCESS);
620 SetConsoleTitleA("Wine Console");
621 return TRUE;
625 /******************************************************************************
626 * GetConsoleCP [KERNEL32.295] Returns the OEM code page for the console
628 * RETURNS
629 * Code page code
631 UINT WINAPI GetConsoleCP(VOID)
633 return GetACP();
637 /***********************************************************************
638 * GetConsoleOutputCP (KERNEL32.189)
640 UINT WINAPI GetConsoleOutputCP(VOID)
642 return GetConsoleCP();
645 /***********************************************************************
646 * GetConsoleMode (KERNEL32.188)
648 BOOL WINAPI GetConsoleMode(HANDLE hcon,LPDWORD mode)
650 BOOL ret = FALSE;
651 struct get_console_mode_request *req = get_req_buffer();
652 req->handle = hcon;
653 if (!server_call( REQ_GET_CONSOLE_MODE ))
655 if (mode) *mode = req->mode;
656 ret = TRUE;
658 return ret;
662 /******************************************************************************
663 * SetConsoleMode [KERNEL32.628] Sets input mode of console's input buffer
665 * PARAMS
666 * hcon [I] Handle to console input or screen buffer
667 * mode [I] Input or output mode to set
669 * RETURNS
670 * Success: TRUE
671 * Failure: FALSE
673 BOOL WINAPI SetConsoleMode( HANDLE hcon, DWORD mode )
675 struct set_console_mode_request *req = get_req_buffer();
676 req->handle = hcon;
677 req->mode = mode;
678 return !server_call( REQ_SET_CONSOLE_MODE );
682 /******************************************************************************
683 * SetConsoleOutputCP [KERNEL32.629] Set the output codepage used by the console
685 * PARAMS
686 * cp [I] code page to set
688 * RETURNS
689 * Success: TRUE
690 * Failure: FALSE
692 BOOL WINAPI SetConsoleOutputCP( UINT cp )
694 FIXME("stub\n");
695 return TRUE;
699 /***********************************************************************
700 * GetConsoleTitleA (KERNEL32.191)
702 DWORD WINAPI GetConsoleTitleA(LPSTR title,DWORD size)
704 struct get_console_info_request *req = get_req_buffer();
705 DWORD ret = 0;
706 HANDLE hcon;
708 if ((hcon = CreateFileA( "CONOUT$", GENERIC_READ, 0, NULL,
709 OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
710 return 0;
711 req->handle = hcon;
712 if (!server_call( REQ_GET_CONSOLE_INFO ))
714 lstrcpynA( title, req->title, size );
715 ret = strlen(req->title);
717 CloseHandle( hcon );
718 return ret;
722 /******************************************************************************
723 * GetConsoleTitleW [KERNEL32.192] Retrieves title string for console
725 * PARAMS
726 * title [O] Address of buffer for title
727 * size [I] Size of buffer
729 * RETURNS
730 * Success: Length of string copied
731 * Failure: 0
733 DWORD WINAPI GetConsoleTitleW( LPWSTR title, DWORD size )
735 char *tmp;
736 DWORD ret;
738 if (!(tmp = HeapAlloc( GetProcessHeap(), 0, size ))) return 0;
739 ret = GetConsoleTitleA( tmp, size );
740 lstrcpyAtoW( title, tmp );
741 HeapFree( GetProcessHeap(), 0, tmp );
742 return ret;
746 /***********************************************************************
747 * WriteConsoleA (KERNEL32.729)
749 BOOL WINAPI WriteConsoleA( HANDLE hConsoleOutput,
750 LPCVOID lpBuffer,
751 DWORD nNumberOfCharsToWrite,
752 LPDWORD lpNumberOfCharsWritten,
753 LPVOID lpReserved )
755 /* FIXME: should I check if this is a console handle? */
756 return WriteFile(hConsoleOutput, lpBuffer, nNumberOfCharsToWrite,
757 lpNumberOfCharsWritten, NULL);
761 #define CADD(c) \
762 if (bufused==curbufsize-1) \
763 buffer = HeapReAlloc(GetProcessHeap(),0,buffer,(curbufsize+=100));\
764 buffer[bufused++]=c;
765 #define SADD(s) { char *x=s;while (*x) {CADD(*x);x++;}}
767 /***********************************************************************
768 * WriteConsoleOutputA (KERNEL32.732)
770 BOOL WINAPI WriteConsoleOutputA( HANDLE hConsoleOutput,
771 LPCHAR_INFO lpBuffer,
772 COORD dwBufferSize,
773 COORD dwBufferCoord,
774 LPSMALL_RECT lpWriteRegion)
776 int i,j,off=0,lastattr=-1;
777 int offbase;
778 char sbuf[20],*buffer=NULL;
779 int bufused=0,curbufsize = 100;
780 DWORD res;
781 CONSOLE_SCREEN_BUFFER_INFO csbi;
782 const int colormap[8] = {
783 0,4,2,6,
784 1,5,3,7,
786 CONSOLE_make_complex(hConsoleOutput);
787 buffer = HeapAlloc(GetProcessHeap(),0,curbufsize);
788 offbase = (dwBufferCoord.Y - 1) * dwBufferSize.X +
789 (dwBufferCoord.X - lpWriteRegion->Left);
791 TRACE("orig rect top = %d, bottom=%d, left=%d, right=%d\n",
792 lpWriteRegion->Top,
793 lpWriteRegion->Bottom,
794 lpWriteRegion->Left,
795 lpWriteRegion->Right
798 GetConsoleScreenBufferInfo(hConsoleOutput, &csbi);
799 sprintf(sbuf,"%c7",27);SADD(sbuf);
801 /* Step 1. Make (Bottom,Right) offset of intersection with
802 Screen Buffer */
803 lpWriteRegion->Bottom = min(lpWriteRegion->Bottom, csbi.dwSize.Y-1) -
804 lpWriteRegion->Top;
805 lpWriteRegion->Right = min(lpWriteRegion->Right, csbi.dwSize.X-1) -
806 lpWriteRegion->Left;
808 /* Step 2. If either offset is negative, then no action
809 should be performed. (Implies that requested rectangle is
810 outside the current screen buffer rectangle.) */
811 if ((lpWriteRegion->Bottom < 0) ||
812 (lpWriteRegion->Right < 0)) {
813 /* readjust (Bottom Right) for rectangle */
814 lpWriteRegion->Bottom += lpWriteRegion->Top;
815 lpWriteRegion->Right += lpWriteRegion->Left;
817 TRACE("invisible rect top = %d, bottom=%d, left=%d, right=%d\n",
818 lpWriteRegion->Top,
819 lpWriteRegion->Bottom,
820 lpWriteRegion->Left,
821 lpWriteRegion->Right
824 HeapFree(GetProcessHeap(),0,buffer);
825 return TRUE;
828 /* Step 3. Intersect with source rectangle */
829 lpWriteRegion->Bottom = lpWriteRegion->Top - dwBufferCoord.Y +
830 min(lpWriteRegion->Bottom + dwBufferCoord.Y, dwBufferSize.Y-1);
831 lpWriteRegion->Right = lpWriteRegion->Left - dwBufferCoord.X +
832 min(lpWriteRegion->Right + dwBufferCoord.X, dwBufferSize.X-1);
834 TRACE("clipped rect top = %d, bottom=%d, left=%d,right=%d\n",
835 lpWriteRegion->Top,
836 lpWriteRegion->Bottom,
837 lpWriteRegion->Left,
838 lpWriteRegion->Right
841 /* Validate above computations made sense, if not then issue
842 error and fudge to single character rectangle */
843 if ((lpWriteRegion->Bottom < lpWriteRegion->Top) ||
844 (lpWriteRegion->Right < lpWriteRegion->Left)) {
845 ERR("Invalid clipped rectangle top = %d, bottom=%d, left=%d,right=%d\n",
846 lpWriteRegion->Top,
847 lpWriteRegion->Bottom,
848 lpWriteRegion->Left,
849 lpWriteRegion->Right
851 lpWriteRegion->Bottom = lpWriteRegion->Top;
852 lpWriteRegion->Right = lpWriteRegion->Left;
855 /* Now do the real processing and move the characters */
856 for (i=lpWriteRegion->Top;i<=lpWriteRegion->Bottom;i++) {
857 offbase += dwBufferSize.X;
858 sprintf(sbuf,"%c[%d;%dH",27,i+1,lpWriteRegion->Left+1);
859 SADD(sbuf);
860 for (j=lpWriteRegion->Left;j<=lpWriteRegion->Right;j++) {
861 off = j + offbase;
862 if (lastattr!=lpBuffer[off].Attributes) {
863 lastattr = lpBuffer[off].Attributes;
864 sprintf(sbuf,"%c[0;%s3%d;4%dm",
866 (lastattr & FOREGROUND_INTENSITY)?"1;":"",
867 colormap[lastattr&7],
868 colormap[(lastattr&0x70)>>4]
870 /* FIXME: BACKGROUND_INTENSITY */
871 SADD(sbuf);
873 CADD(lpBuffer[off].Char.AsciiChar);
876 sprintf(sbuf,"%c[0m%c8",27,27);SADD(sbuf);
877 WriteFile(hConsoleOutput,buffer,bufused,&res,NULL);
878 HeapFree(GetProcessHeap(),0,buffer);
879 return TRUE;
882 /***********************************************************************
883 * WriteConsoleOutputW (KERNEL32.734)
885 BOOL WINAPI WriteConsoleOutputW( HANDLE hConsoleOutput,
886 LPCHAR_INFO lpBuffer,
887 COORD dwBufferSize,
888 COORD dwBufferCoord,
889 LPSMALL_RECT lpWriteRegion)
891 FIXME("(%d,%p,%dx%d,%dx%d,%p): stub\n", hConsoleOutput, lpBuffer,
892 dwBufferSize.X,dwBufferSize.Y,dwBufferCoord.X,dwBufferCoord.Y,lpWriteRegion);
894 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
895 return FALSE;
898 /***********************************************************************
899 * WriteConsoleW (KERNEL32.577)
901 BOOL WINAPI WriteConsoleW( HANDLE hConsoleOutput,
902 LPCVOID lpBuffer,
903 DWORD nNumberOfCharsToWrite,
904 LPDWORD lpNumberOfCharsWritten,
905 LPVOID lpReserved )
907 BOOL ret;
908 LPSTR xstring;
909 DWORD n;
911 n = WideCharToMultiByte(CP_ACP,0,lpBuffer,nNumberOfCharsToWrite,NULL,0,NULL,NULL);
912 xstring=HeapAlloc( GetProcessHeap(), 0, n );
914 n = WideCharToMultiByte(CP_ACP,0,lpBuffer,nNumberOfCharsToWrite,xstring,n,NULL,NULL);
916 /* FIXME: should I check if this is a console handle? */
917 ret= WriteFile(hConsoleOutput, xstring, n,
918 lpNumberOfCharsWritten, NULL);
919 /* FIXME: lpNumberOfCharsWritten should be converted to numofchars in UNICODE */
920 HeapFree( GetProcessHeap(), 0, xstring );
921 return ret;
925 /***********************************************************************
926 * ReadConsoleA (KERNEL32.419)
928 BOOL WINAPI ReadConsoleA( HANDLE hConsoleInput,
929 LPVOID lpBuffer,
930 DWORD nNumberOfCharsToRead,
931 LPDWORD lpNumberOfCharsRead,
932 LPVOID lpReserved )
934 int charsread = 0;
935 LPSTR xbuf = (LPSTR)lpBuffer;
936 LPINPUT_RECORD ir;
938 TRACE("(%d,%p,%ld,%p,%p)\n",
939 hConsoleInput,lpBuffer,nNumberOfCharsToRead,
940 lpNumberOfCharsRead,lpReserved
943 CONSOLE_get_input(hConsoleInput,FALSE);
945 /* FIXME: should we read at least 1 char? The SDK does not say */
946 while (charsread<nNumberOfCharsToRead)
948 struct read_console_input_request *req = get_req_buffer();
949 req->handle = hConsoleInput;
950 req->count = 1;
951 req->flush = 1;
952 if (server_call( REQ_READ_CONSOLE_INPUT )) return FALSE;
953 if (!req->read) break;
954 ir = (LPINPUT_RECORD)(req+1);
955 if (!ir->Event.KeyEvent.bKeyDown)
956 continue;
957 if (ir->EventType != KEY_EVENT)
958 continue;
959 *xbuf++ = ir->Event.KeyEvent.uChar.AsciiChar;
960 charsread++;
962 if (lpNumberOfCharsRead)
963 *lpNumberOfCharsRead = charsread;
964 return TRUE;
967 /***********************************************************************
968 * ReadConsoleW (KERNEL32.427)
970 BOOL WINAPI ReadConsoleW( HANDLE hConsoleInput,
971 LPVOID lpBuffer,
972 DWORD nNumberOfCharsToRead,
973 LPDWORD lpNumberOfCharsRead,
974 LPVOID lpReserved )
976 BOOL ret;
977 LPSTR buf = (LPSTR)HeapAlloc(GetProcessHeap(), 0, nNumberOfCharsToRead);
979 ret = ReadConsoleA(
980 hConsoleInput,
981 buf,
982 nNumberOfCharsToRead,
983 lpNumberOfCharsRead,
984 lpReserved
986 if (ret)
987 lstrcpynAtoW(lpBuffer,buf,nNumberOfCharsToRead);
988 HeapFree( GetProcessHeap(), 0, buf );
989 return ret;
993 /******************************************************************************
994 * ReadConsoleInputA [KERNEL32.569] Reads data from a console
996 * PARAMS
997 * hConsoleInput [I] Handle to console input buffer
998 * lpBuffer [O] Address of buffer for read data
999 * nLength [I] Number of records to read
1000 * lpNumberOfEventsRead [O] Address of number of records read
1002 * RETURNS
1003 * Success: TRUE
1004 * Failure: FALSE
1006 BOOL WINAPI ReadConsoleInputA(HANDLE hConsoleInput, LPINPUT_RECORD lpBuffer,
1007 DWORD nLength, LPDWORD lpNumberOfEventsRead)
1009 struct read_console_input_request *req = get_req_buffer();
1011 /* loop until we get at least one event */
1012 for (;;)
1014 req->handle = hConsoleInput;
1015 req->count = nLength;
1016 req->flush = 1;
1017 if (server_call( REQ_READ_CONSOLE_INPUT )) return FALSE;
1018 if (req->read)
1020 memcpy( lpBuffer, req + 1, req->read * sizeof(*lpBuffer) );
1021 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = req->read;
1022 return TRUE;
1024 CONSOLE_get_input(hConsoleInput,TRUE);
1025 /*WaitForSingleObject( hConsoleInput, INFINITE32 );*/
1030 /***********************************************************************
1031 * ReadConsoleInputW (KERNEL32.570)
1033 BOOL WINAPI ReadConsoleInputW( HANDLE handle, LPINPUT_RECORD buffer,
1034 DWORD count, LPDWORD read )
1036 /* FIXME: Fix this if we get UNICODE input. */
1037 return ReadConsoleInputA( handle, buffer, count, read );
1041 /***********************************************************************
1042 * FlushConsoleInputBuffer (KERNEL32.132)
1044 BOOL WINAPI FlushConsoleInputBuffer( HANDLE handle )
1046 struct read_console_input_request *req = get_req_buffer();
1047 req->handle = handle;
1048 req->count = -1; /* get all records */
1049 req->flush = 1;
1050 return !server_call( REQ_READ_CONSOLE_INPUT );
1054 /***********************************************************************
1055 * PeekConsoleInputA (KERNEL32.550)
1057 * Gets 'count' first events (or less) from input queue.
1059 * Does not need a complex console.
1061 BOOL WINAPI PeekConsoleInputA( HANDLE handle, LPINPUT_RECORD buffer,
1062 DWORD count, LPDWORD read )
1064 struct read_console_input_request *req = get_req_buffer();
1066 CONSOLE_get_input(handle,FALSE);
1068 req->handle = handle;
1069 req->count = count;
1070 req->flush = 0;
1071 if (server_call( REQ_READ_CONSOLE_INPUT )) return FALSE;
1072 if (req->read) memcpy( buffer, req + 1, req->read * sizeof(*buffer) );
1073 if (read) *read = req->read;
1074 return TRUE;
1078 /***********************************************************************
1079 * PeekConsoleInputW (KERNEL32.551)
1081 BOOL WINAPI PeekConsoleInputW(HANDLE hConsoleInput,
1082 LPINPUT_RECORD pirBuffer,
1083 DWORD cInRecords,
1084 LPDWORD lpcRead)
1086 /* FIXME: Hmm. Fix this if we get UNICODE input. */
1087 return PeekConsoleInputA(hConsoleInput,pirBuffer,cInRecords,lpcRead);
1091 /******************************************************************************
1092 * WriteConsoleInputA [KERNEL32.730] Write data to a console input buffer
1095 BOOL WINAPI WriteConsoleInputA( HANDLE handle, INPUT_RECORD *buffer,
1096 DWORD count, LPDWORD written )
1098 struct write_console_input_request *req = get_req_buffer();
1099 const DWORD max = server_remaining( req + 1 ) / sizeof(INPUT_RECORD);
1101 if (written) *written = 0;
1102 while (count)
1104 DWORD len = count < max ? count : max;
1105 req->count = len;
1106 req->handle = handle;
1107 memcpy( req + 1, buffer, len * sizeof(*buffer) );
1108 if (server_call( REQ_WRITE_CONSOLE_INPUT )) return FALSE;
1109 if (written) *written += req->written;
1110 count -= len;
1111 buffer += len;
1113 return TRUE;
1116 /******************************************************************************
1117 * WriteConsoleInputW [KERNEL32.731] Write data to a console input buffer
1120 BOOL WINAPI WriteConsoleInputW( HANDLE handle, INPUT_RECORD *buffer,
1121 DWORD count, LPDWORD written )
1123 FIXME("(%d,%p,%ld,%p): stub!\n", handle, buffer, count, written);
1125 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1126 return FALSE;
1130 /***********************************************************************
1131 * SetConsoleTitleA (KERNEL32.476)
1133 * Sets the console title.
1135 * We do not necessarily need to create a complex console for that,
1136 * but should remember the title and set it on creation of the latter.
1137 * (not fixed at this time).
1139 BOOL WINAPI SetConsoleTitleA(LPCSTR title)
1141 struct set_console_info_request *req = get_req_buffer();
1142 HANDLE hcon;
1143 DWORD written;
1145 if ((hcon = CreateFileA( "CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL,
1146 OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
1147 return FALSE;
1148 req->handle = hcon;
1149 req->mask = SET_CONSOLE_INFO_TITLE;
1150 lstrcpynA( req->title, title, server_remaining(req->title) );
1151 if (server_call( REQ_SET_CONSOLE_INFO )) goto error;
1152 if (CONSOLE_GetPid( hcon ))
1154 /* only set title for complex console (own xterm) */
1155 WriteFile( hcon, "\033]2;", 4, &written, NULL );
1156 WriteFile( hcon, title, strlen(title), &written, NULL );
1157 WriteFile( hcon, "\a", 1, &written, NULL );
1159 CloseHandle( hcon );
1160 return TRUE;
1161 error:
1162 CloseHandle( hcon );
1163 return FALSE;
1167 /******************************************************************************
1168 * SetConsoleTitleW [KERNEL32.477] Sets title bar string for console
1170 * PARAMS
1171 * title [I] Address of new title
1173 * NOTES
1174 * This should not be calling the A version
1176 * RETURNS
1177 * Success: TRUE
1178 * Failure: FALSE
1180 BOOL WINAPI SetConsoleTitleW( LPCWSTR title )
1182 BOOL ret;
1184 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
1185 ret = SetConsoleTitleA(titleA);
1186 HeapFree( GetProcessHeap(), 0, titleA );
1187 return ret;
1190 /******************************************************************************
1191 * SetConsoleCursorPosition [KERNEL32.627]
1192 * Sets the cursor position in console
1194 * PARAMS
1195 * hConsoleOutput [I] Handle of console screen buffer
1196 * dwCursorPosition [I] New cursor position coordinates
1198 * RETURNS STD
1200 BOOL WINAPI SetConsoleCursorPosition( HANDLE hcon, COORD pos )
1202 char xbuf[20];
1203 DWORD xlen;
1205 /* make console complex only if we change lines, not just in the line */
1206 if (pos.Y)
1207 CONSOLE_make_complex(hcon);
1209 TRACE("%d (%dx%d)\n", hcon, pos.X , pos.Y );
1210 /* x are columns, y rows */
1211 if (pos.Y)
1212 /* full screen cursor absolute positioning */
1213 sprintf(xbuf,"%c[%d;%dH", 0x1B, pos.Y+1, pos.X+1);
1214 else
1215 /* relative cursor positioning in line (\r to go to 0) */
1216 sprintf(xbuf,"\r%c[%dC", 0x1B, pos.X);
1217 /* FIXME: store internal if we start using own console buffers */
1218 WriteFile(hcon,xbuf,strlen(xbuf),&xlen,NULL);
1219 return TRUE;
1222 /***********************************************************************
1223 * GetNumberOfConsoleInputEvents (KERNEL32.246)
1225 BOOL WINAPI GetNumberOfConsoleInputEvents(HANDLE hcon,LPDWORD nrofevents)
1227 struct read_console_input_request *req = get_req_buffer();
1229 CONSOLE_get_input(hcon,FALSE);
1231 req->handle = hcon;
1232 req->count = -1;
1233 req->flush = 0;
1234 if (server_call( REQ_READ_CONSOLE_INPUT )) return FALSE;
1235 if (nrofevents) *nrofevents = req->read;
1236 return TRUE;
1239 /***********************************************************************
1240 * GetNumberOfConsoleMouseButtons (KERNEL32.358)
1242 BOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons)
1244 FIXME("(%p): stub\n", nrofbuttons);
1245 *nrofbuttons = 2;
1246 return TRUE;
1249 /******************************************************************************
1250 * GetConsoleCursorInfo [KERNEL32.296] Gets size and visibility of console
1252 * PARAMS
1253 * hcon [I] Handle to console screen buffer
1254 * cinfo [O] Address of cursor information
1256 * RETURNS
1257 * Success: TRUE
1258 * Failure: FALSE
1260 BOOL WINAPI GetConsoleCursorInfo( HANDLE hcon, LPCONSOLE_CURSOR_INFO cinfo )
1262 struct get_console_info_request *req = get_req_buffer();
1263 req->handle = hcon;
1264 if (server_call( REQ_GET_CONSOLE_INFO )) return FALSE;
1265 if (cinfo)
1267 cinfo->dwSize = req->cursor_size;
1268 cinfo->bVisible = req->cursor_visible;
1270 return TRUE;
1274 /******************************************************************************
1275 * SetConsoleCursorInfo [KERNEL32.626] Sets size and visibility of cursor
1277 * RETURNS
1278 * Success: TRUE
1279 * Failure: FALSE
1281 BOOL WINAPI SetConsoleCursorInfo(
1282 HANDLE hcon, /* [in] Handle to console screen buffer */
1283 LPCONSOLE_CURSOR_INFO cinfo) /* [in] Address of cursor information */
1285 struct set_console_info_request *req = get_req_buffer();
1286 char buf[8];
1287 DWORD xlen;
1289 CONSOLE_make_complex(hcon);
1290 sprintf(buf,"\033[?25%c",cinfo->bVisible?'h':'l');
1291 WriteFile(hcon,buf,strlen(buf),&xlen,NULL);
1293 req->handle = hcon;
1294 req->cursor_size = cinfo->dwSize;
1295 req->cursor_visible = cinfo->bVisible;
1296 req->mask = SET_CONSOLE_INFO_CURSOR;
1297 return !server_call( REQ_SET_CONSOLE_INFO );
1301 /******************************************************************************
1302 * SetConsoleWindowInfo [KERNEL32.634] Sets size and position of console
1304 * RETURNS
1305 * Success: TRUE
1306 * Failure: FALSE
1308 BOOL WINAPI SetConsoleWindowInfo(
1309 HANDLE hcon, /* [in] Handle to console screen buffer */
1310 BOOL bAbsolute, /* [in] Coordinate type flag */
1311 LPSMALL_RECT window) /* [in] Address of new window rectangle */
1313 FIXME("(%x,%d,%p): stub\n", hcon, bAbsolute, window);
1314 return TRUE;
1318 /******************************************************************************
1319 * SetConsoleTextAttribute [KERNEL32.631] Sets colors for text
1321 * Sets the foreground and background color attributes of characters
1322 * written to the screen buffer.
1324 * RETURNS
1325 * Success: TRUE
1326 * Failure: FALSE
1328 BOOL WINAPI SetConsoleTextAttribute(HANDLE hConsoleOutput,WORD wAttr)
1330 const int colormap[8] = {
1331 0,4,2,6,
1332 1,5,3,7,
1334 DWORD xlen;
1335 char buffer[20];
1337 TRACE("(%d,%d)\n",hConsoleOutput,wAttr);
1338 sprintf(buffer,"%c[0;%s3%d;4%dm",
1340 (wAttr & FOREGROUND_INTENSITY)?"1;":"",
1341 colormap[wAttr&7],
1342 colormap[(wAttr&0x70)>>4]
1344 WriteFile(hConsoleOutput,buffer,strlen(buffer),&xlen,NULL);
1345 return TRUE;
1349 /******************************************************************************
1350 * SetConsoleScreenBufferSize [KERNEL32.630] Changes size of console
1352 * PARAMS
1353 * hConsoleOutput [I] Handle to console screen buffer
1354 * dwSize [I] New size in character rows and cols
1356 * RETURNS
1357 * Success: TRUE
1358 * Failure: FALSE
1360 BOOL WINAPI SetConsoleScreenBufferSize( HANDLE hConsoleOutput,
1361 COORD dwSize )
1363 FIXME("(%d,%dx%d): stub\n",hConsoleOutput,dwSize.X,dwSize.Y);
1364 return TRUE;
1368 /******************************************************************************
1369 * FillConsoleOutputCharacterA [KERNEL32.242]
1371 * PARAMS
1372 * hConsoleOutput [I] Handle to screen buffer
1373 * cCharacter [I] Character to write
1374 * nLength [I] Number of cells to write to
1375 * dwCoord [I] Coords of first cell
1376 * lpNumCharsWritten [O] Pointer to number of cells written
1378 * RETURNS
1379 * Success: TRUE
1380 * Failure: FALSE
1382 BOOL WINAPI FillConsoleOutputCharacterA(
1383 HANDLE hConsoleOutput,
1384 BYTE cCharacter,
1385 DWORD nLength,
1386 COORD dwCoord,
1387 LPDWORD lpNumCharsWritten)
1389 long count;
1390 DWORD xlen;
1392 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
1393 for(count=0;count<nLength;count++)
1394 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
1395 *lpNumCharsWritten = nLength;
1396 return TRUE;
1400 /******************************************************************************
1401 * FillConsoleOutputCharacterW [KERNEL32.243] Writes characters to console
1403 * PARAMS
1404 * hConsoleOutput [I] Handle to screen buffer
1405 * cCharacter [I] Character to write
1406 * nLength [I] Number of cells to write to
1407 * dwCoord [I] Coords of first cell
1408 * lpNumCharsWritten [O] Pointer to number of cells written
1410 * RETURNS
1411 * Success: TRUE
1412 * Failure: FALSE
1414 BOOL WINAPI FillConsoleOutputCharacterW(HANDLE hConsoleOutput,
1415 WCHAR cCharacter,
1416 DWORD nLength,
1417 COORD dwCoord,
1418 LPDWORD lpNumCharsWritten)
1420 long count;
1421 DWORD xlen;
1423 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
1424 /* FIXME: not quite correct ... but the lower part of UNICODE char comes
1425 * first
1427 for(count=0;count<nLength;count++)
1428 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
1429 *lpNumCharsWritten = nLength;
1430 return TRUE;
1434 /******************************************************************************
1435 * FillConsoleOutputAttribute [KERNEL32.241] Sets attributes for console
1437 * PARAMS
1438 * hConsoleOutput [I] Handle to screen buffer
1439 * wAttribute [I] Color attribute to write
1440 * nLength [I] Number of cells to write to
1441 * dwCoord [I] Coords of first cell
1442 * lpNumAttrsWritten [O] Pointer to number of cells written
1444 * RETURNS
1445 * Success: TRUE
1446 * Failure: FALSE
1448 BOOL WINAPI FillConsoleOutputAttribute( HANDLE hConsoleOutput,
1449 WORD wAttribute, DWORD nLength, COORD dwCoord,
1450 LPDWORD lpNumAttrsWritten)
1452 FIXME("(%d,%d,%ld,%dx%d,%p): stub\n", hConsoleOutput,
1453 wAttribute,nLength,dwCoord.X,dwCoord.Y,lpNumAttrsWritten);
1454 *lpNumAttrsWritten = nLength;
1455 return TRUE;
1458 /******************************************************************************
1459 * ReadConsoleOutputCharacterA [KERNEL32.573]
1461 * BUGS
1462 * Unimplemented
1464 BOOL WINAPI ReadConsoleOutputCharacterA(HANDLE hConsoleOutput,
1465 LPSTR lpstr, DWORD dword, COORD coord, LPDWORD lpdword)
1467 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,lpstr,
1468 dword,coord.X,coord.Y,lpdword);
1469 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1470 return FALSE;
1473 /******************************************************************************
1474 * ReadConsoleOutputCharacterW [KERNEL32.574]
1476 * BUGS
1477 * Unimplemented
1479 BOOL WINAPI ReadConsoleOutputCharacterW(HANDLE hConsoleOutput,
1480 LPWSTR lpstr, DWORD dword, COORD coord, LPDWORD lpdword)
1482 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,lpstr,
1483 dword,coord.X,coord.Y,lpdword);
1484 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1485 return FALSE;
1489 /******************************************************************************
1490 * ScrollConsoleScreenBufferA [KERNEL32.612]
1492 * BUGS
1493 * Unimplemented
1495 BOOL WINAPI ScrollConsoleScreenBufferA( HANDLE hConsoleOutput,
1496 LPSMALL_RECT lpScrollRect, LPSMALL_RECT lpClipRect,
1497 COORD dwDestOrigin, LPCHAR_INFO lpFill)
1499 FIXME("(%d,%p,%p,%dx%d,%p): stub\n", hConsoleOutput,lpScrollRect,
1500 lpClipRect,dwDestOrigin.X,dwDestOrigin.Y,lpFill);
1501 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1502 return FALSE;
1505 /******************************************************************************
1506 * ScrollConsoleScreenBufferW [KERNEL32.613]
1508 * BUGS
1509 * Unimplemented
1511 BOOL WINAPI ScrollConsoleScreenBufferW( HANDLE hConsoleOutput,
1512 LPSMALL_RECT lpScrollRect, LPSMALL_RECT lpClipRect,
1513 COORD dwDestOrigin, LPCHAR_INFO lpFill)
1515 FIXME("(%d,%p,%p,%dx%d,%p): stub\n", hConsoleOutput,lpScrollRect,
1516 lpClipRect,dwDestOrigin.X,dwDestOrigin.Y,lpFill);
1517 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1518 return FALSE;
1521 /******************************************************************************
1522 * ReadConsoleOutputA [KERNEL32.571]
1524 * BUGS
1525 * Unimplemented
1527 BOOL WINAPI ReadConsoleOutputA( HANDLE hConsoleOutput,
1528 LPCHAR_INFO lpBuffer,
1529 COORD dwBufferSize,
1530 COORD dwBufferCoord,
1531 LPSMALL_RECT lpReadRegion )
1533 FIXME("(%d,%p,%dx%d,%dx%d,%p): stub\n", hConsoleOutput, lpBuffer,
1534 dwBufferSize.X, dwBufferSize.Y, dwBufferSize.X, dwBufferSize.Y,
1535 lpReadRegion);
1537 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1538 return FALSE;
1541 /******************************************************************************
1542 * ReadConsoleOutputW [KERNEL32.575]
1544 * BUGS
1545 * Unimplemented
1547 BOOL WINAPI ReadConsoleOutputW( HANDLE hConsoleOutput,
1548 LPCHAR_INFO lpBuffer,
1549 COORD dwBufferSize,
1550 COORD dwBufferCoord,
1551 LPSMALL_RECT lpReadRegion )
1553 FIXME("(%d,%p,%dx%d,%dx%d,%p): stub\n", hConsoleOutput, lpBuffer,
1554 dwBufferSize.X, dwBufferSize.Y, dwBufferSize.X, dwBufferSize.Y,
1555 lpReadRegion);
1557 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1558 return FALSE;
1561 /******************************************************************************
1562 * ReadConsoleOutputAttribute [KERNEL32.572]
1564 * BUGS
1565 * Unimplemented
1567 BOOL WINAPI ReadConsoleOutputAttribute( HANDLE hConsoleOutput,
1568 LPWORD lpAttribute,
1569 DWORD nLength,
1570 COORD dwReadCoord,
1571 LPDWORD lpNumberOfAttrsRead)
1573 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput, lpAttribute,
1574 nLength, dwReadCoord.X, dwReadCoord.Y, lpNumberOfAttrsRead);
1576 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1577 return FALSE;
1580 /******************************************************************************
1581 * SetConsoleCP [KERNEL32.572]
1583 * BUGS
1584 * Unimplemented
1586 BOOL WINAPI SetConsoleCP( UINT cp )
1588 FIXME("(%d): stub\n", cp);
1590 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1591 return FALSE;