Translated new common dialog resources into German.
[wine.git] / win32 / console.c
blobacd4cecfd8cb29e89b9769735a63ee4886b363d7
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 * - Output sometimes is buffered (We switched off buffering by ~ICANON ?)
15 /* Reference applications:
16 * - IDA (interactive disassembler) full version 3.75. Works.
17 * - LYNX/W32. Works mostly, some keys crash it.
20 #include "config.h"
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <unistd.h>
25 #include <termios.h>
26 #include <string.h>
27 #include <sys/ioctl.h>
28 #include <sys/types.h>
29 #include <sys/time.h>
30 #include <fcntl.h>
31 #include <errno.h>
32 #ifdef HAVE_SYS_ERRNO_H
33 #include <sys/errno.h>
34 #endif
35 #include <signal.h>
36 #include <assert.h>
38 #include "windef.h"
39 #include "winbase.h"
40 #include "winnls.h"
41 #include "wingdi.h"
42 #include "wine/winuser16.h"
43 #include "wine/keyboard16.h"
44 #include "thread.h"
45 #include "file.h"
46 #include "winerror.h"
47 #include "wincon.h"
48 #include "heap.h"
49 #include "server.h"
50 #include "debugtools.h"
52 DEFAULT_DEBUG_CHANNEL(console);
54 /* Ascii -> VK, generated by calling VkKeyScanA(i) */
55 static int vkkeyscan_table[256] = {
56 0,0,0,0,0,0,0,0,8,9,0,0,0,13,0,0,0,0,0,19,145,556,0,0,0,0,0,27,0,0,0,
57 0,32,305,478,307,308,309,311,222,313,304,312,443,188,189,190,191,48,
58 49,50,51,52,53,54,55,56,57,442,186,444,187,446,447,306,321,322,323,
59 324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,
60 341,342,343,344,345,346,219,220,221,310,445,192,65,66,67,68,69,70,71,
61 72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,475,476,477,
62 448,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
63 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
64 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
65 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,400,0,0,0,0,0,0
68 static int mapvkey_0[256]={
69 0,0,0,0,0,0,0,0,14,15,0,0,0,28,0,0,42,29,56,69,58,0,0,0,0,0,0,1,0,0,
70 0,0,57,73,81,79,71,75,72,77,80,0,0,0,55,82,83,0,11,2,3,4,5,6,7,8,9,
71 10,0,0,0,0,0,0,0,30,48,46,32,18,33,34,35,23,36,37,38,50,49,24,25,16,
72 19,31,20,22,47,17,45,21,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,78,0,74,
73 0,53,59,60,61,62,63,64,65,66,67,68,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
74 0,0,0,0,0,0,69,70,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
75 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,39,13,51,12,52,53,41,0,0,0,0,0,0,0,0,0,
76 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26,43,27,40,76,96,0,0,0,0,0,0,0,0,
77 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
80 static int mapvkey_1[256]={
81 0,27,49,50,51,52,53,54,55,56,57,48,189,187,8,9,81,87,69,82,84,89,85,
82 73,79,80,219,221,13,17,65,83,68,70,71,72,74,75,76,186,222,192,16,220,
83 90,88,67,86,66,78,77,188,190,191,16,106,18,32,20,112,113,114,115,116,
84 117,118,119,120,121,144,145,36,38,33,109,37,223,39,107,35,40,34,45,
85 46,0,0,0,122,123,0,0,0,0,0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
86 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
87 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
88 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
89 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
90 0,0,0,0,0,0,0
93 /* FIXME: Should be in an internal header file. OK, so which one?
94 Used by CONSOLE_make_complex. */
95 extern int wine_openpty(int *master, int *slave, char *name,
96 struct termios *term, struct winsize *winsize);
98 /****************************************************************************
99 * CONSOLE_GetPid
101 static int CONSOLE_GetPid( HANDLE handle )
103 int ret = 0;
104 SERVER_START_REQ
106 struct get_console_info_request *req = server_alloc_req( sizeof(*req), 0 );
107 req->handle = handle;
108 if (!server_call( REQ_GET_CONSOLE_INFO )) ret = req->pid;
110 SERVER_END_REQ;
111 return ret;
114 /****************************************************************************
115 * XTERM_string_to_IR [internal]
117 * Transfers a string read from XTERM to INPUT_RECORDs and adds them to the
118 * queue. Does translation of vt100 style function keys and xterm-mouse clicks.
120 static void
121 CONSOLE_string_to_IR( HANDLE hConsoleInput,unsigned char *buf,int len) {
122 int j,k;
123 INPUT_RECORD ir;
124 DWORD junk;
126 for (j=0;j<len;j++) {
127 unsigned char inchar = buf[j];
129 if (inchar!=27) { /* no escape -> 'normal' keyboard event */
130 ir.EventType = 1; /* Key_event */
132 ir.Event.KeyEvent.bKeyDown = 1;
133 ir.Event.KeyEvent.wRepeatCount = 0;
135 ir.Event.KeyEvent.dwControlKeyState = 0;
136 if (inchar & 0x80) {
137 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
138 inchar &= ~0x80;
140 ir.Event.KeyEvent.wVirtualKeyCode = vkkeyscan_table[inchar];
141 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0100)
142 ir.Event.KeyEvent.dwControlKeyState|=SHIFT_PRESSED;
143 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0200)
144 ir.Event.KeyEvent.dwControlKeyState|=LEFT_CTRL_PRESSED;
145 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0400)
146 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
147 ir.Event.KeyEvent.wVirtualScanCode = mapvkey_0[
148 ir.Event.KeyEvent.wVirtualKeyCode & 0x00ff
149 ]; /* VirtualKeyCodes to ScanCode */
150 ir.Event.KeyEvent.uChar.AsciiChar = inchar;
152 if ((inchar==127)||(inchar=='\b')) { /* backspace */
153 ir.Event.KeyEvent.uChar.AsciiChar = '\b'; /* FIXME: hmm */
154 ir.Event.KeyEvent.wVirtualScanCode = 0x0e;
155 ir.Event.KeyEvent.wVirtualKeyCode = VK_BACK;
156 } else {
157 if ((inchar=='\n')||(inchar=='\r')) {
158 ir.Event.KeyEvent.uChar.AsciiChar = '\r';
159 ir.Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
160 ir.Event.KeyEvent.wVirtualScanCode = 0x1c;
161 ir.Event.KeyEvent.dwControlKeyState = 0;
162 } else {
163 if (inchar<' ') {
164 /* FIXME: find good values for ^X */
165 ir.Event.KeyEvent.wVirtualKeyCode = 0xdead;
166 ir.Event.KeyEvent.wVirtualScanCode = 0xbeef;
171 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
172 ir.Event.KeyEvent.bKeyDown = 0;
173 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
174 continue;
176 /* inchar is ESC */
177 if ((j==len-1) || (buf[j+1]!='[')) {/* add ESCape on its own */
178 ir.EventType = 1; /* Key_event */
179 ir.Event.KeyEvent.bKeyDown = 1;
180 ir.Event.KeyEvent.wRepeatCount = 0;
182 ir.Event.KeyEvent.wVirtualKeyCode = VK_ESCAPE;
183 ir.Event.KeyEvent.wVirtualScanCode = mapvkey_0[
184 ir.Event.KeyEvent.wVirtualKeyCode
186 ir.Event.KeyEvent.dwControlKeyState = 0;
187 ir.Event.KeyEvent.uChar.AsciiChar = 27;
188 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
189 ir.Event.KeyEvent.bKeyDown = 0;
190 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
191 continue;
193 for (k=j;k<len;k++) {
194 if (((buf[k]>='A') && (buf[k]<='Z')) ||
195 ((buf[k]>='a') && (buf[k]<='z')) ||
196 (buf[k]=='~')
198 break;
200 if (k<len) {
201 int subid,scancode=0;
203 ir.EventType = 1; /* Key_event */
204 ir.Event.KeyEvent.bKeyDown = 1;
205 ir.Event.KeyEvent.wRepeatCount = 0;
206 ir.Event.KeyEvent.dwControlKeyState = 0;
208 ir.Event.KeyEvent.wVirtualKeyCode = 0xad; /* FIXME */
209 ir.Event.KeyEvent.wVirtualScanCode = 0xad; /* FIXME */
210 ir.Event.KeyEvent.uChar.AsciiChar = 0;
212 switch (buf[k]) {
213 case '~':
214 sscanf(&buf[j+2],"%d",&subid);
215 switch (subid) {
216 case 2:/*INS */scancode = 0xe052;break;
217 case 3:/*DEL */scancode = 0xe053;break;
218 case 6:/*PGDW*/scancode = 0xe051;break;
219 case 5:/*PGUP*/scancode = 0xe049;break;
220 case 11:/*F1 */scancode = 0x003b;break;
221 case 12:/*F2 */scancode = 0x003c;break;
222 case 13:/*F3 */scancode = 0x003d;break;
223 case 14:/*F4 */scancode = 0x003e;break;
224 case 15:/*F5 */scancode = 0x003f;break;
225 case 17:/*F6 */scancode = 0x0040;break;
226 case 18:/*F7 */scancode = 0x0041;break;
227 case 19:/*F8 */scancode = 0x0042;break;
228 case 20:/*F9 */scancode = 0x0043;break;
229 case 21:/*F10 */scancode = 0x0044;break;
230 case 23:/*F11 */scancode = 0x00d9;break;
231 case 24:/*F12 */scancode = 0x00da;break;
232 /* FIXME: Shift-Fx */
233 default:
234 FIXME("parse ESC[%d~\n",subid);
235 break;
237 break;
238 case 'A': /* Cursor Up */scancode = 0xe048;break;
239 case 'B': /* Cursor Down */scancode = 0xe050;break;
240 case 'D': /* Cursor Left */scancode = 0xe04b;break;
241 case 'C': /* Cursor Right */scancode = 0xe04d;break;
242 case 'F': /* End */scancode = 0xe04f;break;
243 case 'H': /* Home */scancode = 0xe047;break;
244 case 'M':
245 /* Mouse Button Press (ESCM<button+'!'><x+'!'><y+'!'>) or
246 * Release (ESCM#<x+'!'><y+'!'>
248 if (k<len-3) {
249 ir.EventType = MOUSE_EVENT;
250 ir.Event.MouseEvent.dwMousePosition.X = buf[k+2]-'!';
251 ir.Event.MouseEvent.dwMousePosition.Y = buf[k+3]-'!';
252 if (buf[k+1]=='#')
253 ir.Event.MouseEvent.dwButtonState = 0;
254 else
255 ir.Event.MouseEvent.dwButtonState = 1<<(buf[k+1]-' ');
256 ir.Event.MouseEvent.dwEventFlags = 0; /* FIXME */
257 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk));
258 j=k+3;
260 break;
261 case 'c':
262 j=k;
263 break;
265 if (scancode) {
266 ir.Event.KeyEvent.wVirtualScanCode = scancode;
267 ir.Event.KeyEvent.wVirtualKeyCode = mapvkey_1[scancode];
268 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
269 ir.Event.KeyEvent.bKeyDown = 0;
270 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
271 j=k;
272 continue;
278 /****************************************************************************
279 * CONSOLE_get_input (internal)
281 * Reads (nonblocking) as much input events as possible and stores them
282 * in an internal queue.
284 static void
285 CONSOLE_get_input( HANDLE handle, BOOL blockwait )
287 char *buf = HeapAlloc(GetProcessHeap(),0,1);
288 int len = 0, escape_seen = 0;
290 while (1)
292 DWORD res;
293 char inchar;
295 /* If we have at one time seen escape in this loop, we are
296 * within an Escape sequence, so wait for a bit more input for the
297 * rest of the loop.
299 if (WaitForSingleObject( handle, escape_seen*10 )) break;
300 if (!ReadFile( handle, &inchar, 1, &res, NULL )) break;
301 if (!res) /* res 0 but readable means EOF? Hmm. */
302 break;
303 buf = HeapReAlloc(GetProcessHeap(),0,buf,len+1);
304 buf[len++]=inchar;
305 if (inchar == 27) {
306 if (len>1) {
307 /* If we spot an ESC, we flush all up to it
308 * since we can be sure that we have a complete
309 * sequence.
311 CONSOLE_string_to_IR(handle,buf,len-1);
312 buf = HeapReAlloc(GetProcessHeap(),0,buf,1);
313 buf[0] = 27;
314 len = 1;
316 escape_seen = 1;
319 CONSOLE_string_to_IR(handle,buf,len);
320 HeapFree(GetProcessHeap(),0,buf);
324 /******************************************************************************
325 * read_console_input
327 * Helper function for ReadConsole, ReadConsoleInput and PeekConsoleInput
329 static BOOL read_console_input( HANDLE handle, LPINPUT_RECORD buffer, DWORD count,
330 LPDWORD read, BOOL flush )
332 BOOL ret;
334 count = min( count, REQUEST_MAX_VAR_SIZE/sizeof(INPUT_RECORD) );
336 SERVER_START_REQ
338 struct read_console_input_request *req = server_alloc_req( sizeof(*req),
339 count*sizeof(INPUT_RECORD) );
340 req->handle = handle;
341 req->flush = flush;
342 if ((ret = !server_call( REQ_READ_CONSOLE_INPUT )))
344 if (count) memcpy( buffer, server_data_ptr(req), server_data_size(req) );
345 if (read) *read = req->read;
348 SERVER_END_REQ;
349 return ret;
353 /******************************************************************************
354 * SetConsoleCtrlHandler [KERNEL32.@] Adds function to calling process list
356 * PARAMS
357 * func [I] Address of handler function
358 * add [I] Handler to add or remove
360 * RETURNS
361 * Success: TRUE
362 * Failure: FALSE
364 * CHANGED
365 * James Sutherland (JamesSutherland@gmx.de)
366 * Added global variables console_ignore_ctrl_c and handlers[]
367 * Does not yet do any error checking, or set LastError if failed.
368 * This doesn't yet matter, since these handlers are not yet called...!
370 static unsigned int console_ignore_ctrl_c = 0;
371 static HANDLER_ROUTINE *handlers[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
372 BOOL WINAPI SetConsoleCtrlHandler( HANDLER_ROUTINE *func, BOOL add )
374 unsigned int alloc_loop = sizeof(handlers)/sizeof(HANDLER_ROUTINE *);
375 unsigned int done = 0;
376 FIXME("(%p,%i) - no error checking or testing yet\n", func, add);
377 if (!func)
379 console_ignore_ctrl_c = add;
380 return TRUE;
382 if (add)
384 for (;alloc_loop--;)
385 if (!handlers[alloc_loop] && !done)
387 handlers[alloc_loop] = func;
388 done++;
390 if (!done)
391 FIXME("Out of space on CtrlHandler table\n");
392 return(done);
394 else
396 for (;alloc_loop--;)
397 if (handlers[alloc_loop] == func && !done)
399 handlers[alloc_loop] = 0;
400 done++;
402 if (!done)
403 WARN("Attempt to remove non-installed CtrlHandler %p\n",
404 func);
405 return (done);
407 return (done);
411 /******************************************************************************
412 * GenerateConsoleCtrlEvent [KERNEL32.275] Simulate a CTRL-C or CTRL-BREAK
414 * PARAMS
415 * dwCtrlEvent [I] Type of event
416 * dwProcessGroupID [I] Process group ID to send event to
418 * NOTES
419 * Doesn't yet work...!
421 * RETURNS
422 * Success: True
423 * Failure: False (and *should* [but doesn't] set LastError)
425 BOOL WINAPI GenerateConsoleCtrlEvent( DWORD dwCtrlEvent,
426 DWORD dwProcessGroupID )
428 if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
430 ERR("invalid event %d for PGID %ld\n",
431 (unsigned short)dwCtrlEvent, dwProcessGroupID );
432 return FALSE;
434 if (dwProcessGroupID == GetCurrentProcessId() )
436 FIXME("Attempt to send event %d to self - stub\n",
437 (unsigned short)dwCtrlEvent );
438 return FALSE;
440 FIXME("event %d to external PGID %ld - not implemented yet\n",
441 (unsigned short)dwCtrlEvent, dwProcessGroupID );
442 return FALSE;
446 /******************************************************************************
447 * CreateConsoleScreenBuffer [KERNEL32.151] Creates a console screen buffer
449 * PARAMS
450 * dwDesiredAccess [I] Access flag
451 * dwShareMode [I] Buffer share mode
452 * sa [I] Security attributes
453 * dwFlags [I] Type of buffer to create
454 * lpScreenBufferData [I] Reserved
456 * NOTES
457 * Should call SetLastError
459 * RETURNS
460 * Success: Handle to new console screen buffer
461 * Failure: INVALID_HANDLE_VALUE
463 HANDLE WINAPI CreateConsoleScreenBuffer( DWORD dwDesiredAccess,
464 DWORD dwShareMode, LPSECURITY_ATTRIBUTES sa,
465 DWORD dwFlags, LPVOID lpScreenBufferData )
467 FIXME("(%ld,%ld,%p,%ld,%p): stub\n",dwDesiredAccess,
468 dwShareMode, sa, dwFlags, lpScreenBufferData);
469 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
470 return INVALID_HANDLE_VALUE;
474 /***********************************************************************
475 * GetConsoleScreenBufferInfo (KERNEL32.@)
477 BOOL WINAPI GetConsoleScreenBufferInfo( HANDLE hConsoleOutput,
478 LPCONSOLE_SCREEN_BUFFER_INFO csbi )
480 csbi->dwSize.X = 80;
481 csbi->dwSize.Y = 24;
482 csbi->dwCursorPosition.X = 0;
483 csbi->dwCursorPosition.Y = 0;
484 csbi->wAttributes = 0;
485 csbi->srWindow.Left = 0;
486 csbi->srWindow.Right = 79;
487 csbi->srWindow.Top = 0;
488 csbi->srWindow.Bottom = 23;
489 csbi->dwMaximumWindowSize.X = 80;
490 csbi->dwMaximumWindowSize.Y = 24;
491 return TRUE;
495 /******************************************************************************
496 * SetConsoleActiveScreenBuffer [KERNEL32.623] Sets buffer to current console
498 * RETURNS
499 * Success: TRUE
500 * Failure: FALSE
502 BOOL WINAPI SetConsoleActiveScreenBuffer(
503 HANDLE hConsoleOutput) /* [in] Handle to console screen buffer */
505 FIXME("(%x): stub\n", hConsoleOutput);
506 return FALSE;
510 /***********************************************************************
511 * GetLargestConsoleWindowSize (KERNEL32.@)
513 * NOTE
514 * This should return a COORD, but calling convention for returning
515 * structures is different between Windows and gcc on i386.
517 * VERSION: [i386]
519 #ifdef __i386__
520 #undef GetLargestConsoleWindowSize
521 DWORD WINAPI GetLargestConsoleWindowSize( HANDLE hConsoleOutput )
523 COORD c;
524 c.X = 80;
525 c.Y = 24;
526 return *(DWORD *)&c;
528 #endif /* defined(__i386__) */
531 /***********************************************************************
532 * GetLargestConsoleWindowSize (KERNEL32.@)
534 * NOTE
535 * This should return a COORD, but calling convention for returning
536 * structures is different between Windows and gcc on i386.
538 * VERSION: [!i386]
540 #ifndef __i386__
541 COORD WINAPI GetLargestConsoleWindowSize( HANDLE hConsoleOutput )
543 COORD c;
544 c.X = 80;
545 c.Y = 24;
546 return c;
548 #endif /* defined(__i386__) */
551 /***********************************************************************
552 * FreeConsole (KERNEL32.267)
554 BOOL WINAPI FreeConsole(VOID)
556 BOOL ret;
557 SERVER_START_REQ
559 struct free_console_request *req = server_alloc_req( sizeof(*req), 0 );
560 ret = !server_call( REQ_FREE_CONSOLE );
562 SERVER_END_REQ;
563 return ret;
567 /*************************************************************************
568 * CONSOLE_make_complex [internal]
570 * Turns a CONSOLE kernel object into a complex one.
571 * (switches from output/input using the terminal where WINE was started to
572 * its own xterm).
574 * This makes simple commandline tools pipeable, while complex commandline
575 * tools work without getting messed up by debugoutput.
577 * All other functions should work independently from this call.
579 * To test for complex console: pid == 0 -> simple, otherwise complex.
581 static BOOL CONSOLE_make_complex(HANDLE handle)
583 struct termios term;
584 char buf[256];
585 char c = '\0';
586 int i,xpid,master,slave;
587 HANDLE pty_handle;
589 if (CONSOLE_GetPid( handle )) return TRUE; /* already complex */
591 MESSAGE("Console: Making console complex (creating an xterm)...\n");
593 if (tcgetattr(0, &term) < 0) {
594 /* ignore failure, or we can't run from a script */
596 term.c_lflag = ~(ECHO|ICANON);
598 if (wine_openpty(&master, &slave, NULL, &term, NULL) < 0)
599 return FALSE;
601 if ((xpid=fork()) == 0) {
602 tcsetattr(slave, TCSADRAIN, &term);
603 close( slave );
604 sprintf(buf, "-Sxx%d", master);
605 /* "-fn vga" for VGA font. Harmless if vga is not present:
606 * xterm: unable to open font "vga", trying "fixed"....
608 execlp("xterm", "xterm", buf, "-fn","vga",NULL);
609 ERR("error creating AllocConsole xterm\n");
610 exit(1);
612 pty_handle = FILE_DupUnixHandle( slave, GENERIC_READ | GENERIC_WRITE );
613 close( master );
614 close( slave );
615 if (!pty_handle) return FALSE;
617 /* most xterms like to print their window ID when used with -S;
618 * read it and continue before the user has a chance...
620 for (i = 0; i < 10000; i++)
622 BOOL ok = ReadFile( pty_handle, &c, 1, NULL, NULL );
623 if (!ok && !c) usleep(100); /* wait for xterm to be created */
624 else if (c == '\n') break;
626 if (i == 10000)
628 ERR("can't read xterm WID\n");
629 CloseHandle( pty_handle );
630 return FALSE;
632 SERVER_START_REQ
634 struct set_console_fd_request *req = server_alloc_req( sizeof(*req), 0 );
635 req->handle = handle;
636 req->handle_in = pty_handle;
637 req->handle_out = pty_handle;
638 req->pid = xpid;
639 server_call( REQ_SET_CONSOLE_FD );
641 SERVER_END_REQ;
642 CloseHandle( pty_handle );
644 /* enable mouseclicks */
645 strcpy( buf, "\033[?1002h" );
646 WriteFile(handle,buf,strlen(buf),NULL,NULL);
648 strcpy( buf, "\033]2;" );
649 if (GetConsoleTitleA( buf + 4, sizeof(buf) - 5 ))
651 strcat( buf, "\a" );
652 WriteFile(handle,buf,strlen(buf),NULL,NULL);
654 return TRUE;
659 /***********************************************************************
660 * AllocConsole (KERNEL32.103)
662 * creates an xterm with a pty to our program
664 BOOL WINAPI AllocConsole(VOID)
666 BOOL ret;
667 HANDLE hStderr;
668 int handle_in, handle_out;
670 TRACE("()\n");
672 SERVER_START_REQ
674 struct alloc_console_request *req = server_alloc_req( sizeof(*req), 0 );
676 req->access = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE;
677 req->inherit = FALSE;
678 ret = !server_call( REQ_ALLOC_CONSOLE );
679 handle_in = req->handle_in;
680 handle_out = req->handle_out;
682 SERVER_END_REQ;
683 if (!ret) return FALSE;
685 if (!DuplicateHandle( GetCurrentProcess(), handle_out, GetCurrentProcess(), &hStderr,
686 0, TRUE, DUPLICATE_SAME_ACCESS ))
688 CloseHandle( handle_in );
689 CloseHandle( handle_out );
690 FreeConsole();
691 return FALSE;
694 /* NT resets the STD_*_HANDLEs on console alloc */
695 SetStdHandle( STD_INPUT_HANDLE, handle_in );
696 SetStdHandle( STD_OUTPUT_HANDLE, handle_out );
697 SetStdHandle( STD_ERROR_HANDLE, hStderr );
699 SetLastError(ERROR_SUCCESS);
700 SetConsoleTitleA("Wine Console");
701 return TRUE;
705 /******************************************************************************
706 * GetConsoleCP [KERNEL32.295] Returns the OEM code page for the console
708 * RETURNS
709 * Code page code
711 UINT WINAPI GetConsoleCP(VOID)
713 return GetACP();
717 /***********************************************************************
718 * GetConsoleOutputCP (KERNEL32.@)
720 UINT WINAPI GetConsoleOutputCP(VOID)
722 return GetConsoleCP();
725 /***********************************************************************
726 * GetConsoleMode (KERNEL32.@)
728 BOOL WINAPI GetConsoleMode(HANDLE hcon,LPDWORD mode)
730 BOOL ret;
731 SERVER_START_REQ
733 struct get_console_mode_request *req = server_alloc_req( sizeof(*req), 0 );
734 req->handle = hcon;
735 ret = !server_call( REQ_GET_CONSOLE_MODE );
736 if (ret && mode) *mode = req->mode;
738 SERVER_END_REQ;
739 return ret;
743 /******************************************************************************
744 * SetConsoleMode [KERNEL32.628] Sets input mode of console's input buffer
746 * PARAMS
747 * hcon [I] Handle to console input or screen buffer
748 * mode [I] Input or output mode to set
750 * RETURNS
751 * Success: TRUE
752 * Failure: FALSE
754 BOOL WINAPI SetConsoleMode( HANDLE hcon, DWORD mode )
756 BOOL ret;
757 SERVER_START_REQ
759 struct set_console_mode_request *req = server_alloc_req( sizeof(*req), 0 );
760 req->handle = hcon;
761 req->mode = mode;
762 ret = !server_call( REQ_SET_CONSOLE_MODE );
764 SERVER_END_REQ;
765 return ret;
769 /******************************************************************************
770 * SetConsoleOutputCP [KERNEL32.629] Set the output codepage used by the console
772 * PARAMS
773 * cp [I] code page to set
775 * RETURNS
776 * Success: TRUE
777 * Failure: FALSE
779 BOOL WINAPI SetConsoleOutputCP( UINT cp )
781 FIXME("stub\n");
782 return TRUE;
786 /***********************************************************************
787 * GetConsoleTitleA (KERNEL32.@)
789 DWORD WINAPI GetConsoleTitleA(LPSTR title,DWORD size)
791 DWORD ret = 0;
792 HANDLE hcon;
794 if ((hcon = CreateFileA( "CONOUT$", GENERIC_READ, 0, NULL,
795 OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
796 return 0;
797 SERVER_START_REQ
799 struct get_console_info_request *req = server_alloc_req( sizeof(*req),
800 REQUEST_MAX_VAR_SIZE );
801 req->handle = hcon;
802 if (!server_call( REQ_GET_CONSOLE_INFO ))
804 ret = server_data_size(req);
805 size = min( size-1, ret );
806 memcpy( title, server_data_ptr(req), size );
807 title[size] = 0;
810 SERVER_END_REQ;
811 CloseHandle( hcon );
812 return ret;
816 /******************************************************************************
817 * GetConsoleTitleW [KERNEL32.@] Retrieves title string for console
819 * PARAMS
820 * title [O] Address of buffer for title
821 * size [I] Size of buffer
823 * RETURNS
824 * Success: Length of string copied
825 * Failure: 0
827 DWORD WINAPI GetConsoleTitleW( LPWSTR title, DWORD size )
829 char *tmp;
830 DWORD ret;
832 if (!(tmp = HeapAlloc( GetProcessHeap(), 0, size*sizeof(WCHAR) ))) return 0;
833 GetConsoleTitleA( tmp, size*sizeof(WCHAR) );
834 ret = MultiByteToWideChar( CP_ACP, 0, tmp, -1, title, size );
835 HeapFree( GetProcessHeap(), 0, tmp );
836 return ret;
840 /***********************************************************************
841 * WriteConsoleA (KERNEL32.729)
843 BOOL WINAPI WriteConsoleA( HANDLE hConsoleOutput,
844 LPCVOID lpBuffer,
845 DWORD nNumberOfCharsToWrite,
846 LPDWORD lpNumberOfCharsWritten,
847 LPVOID lpReserved )
849 /* FIXME: should I check if this is a console handle? */
850 return WriteFile(hConsoleOutput, lpBuffer, nNumberOfCharsToWrite,
851 lpNumberOfCharsWritten, NULL);
855 #define CADD(c) \
856 if (bufused==curbufsize-1) \
857 buffer = HeapReAlloc(GetProcessHeap(),0,buffer,(curbufsize+=100));\
858 buffer[bufused++]=c;
859 #define SADD(s) { char *x=s;while (*x) {CADD(*x);x++;}}
861 /***********************************************************************
862 * WriteConsoleOutputA (KERNEL32.732)
864 BOOL WINAPI WriteConsoleOutputA( HANDLE hConsoleOutput,
865 LPCHAR_INFO lpBuffer,
866 COORD dwBufferSize,
867 COORD dwBufferCoord,
868 LPSMALL_RECT lpWriteRegion)
870 int i,j,off=0,lastattr=-1;
871 int offbase;
872 char sbuf[20],*buffer=NULL;
873 int bufused=0,curbufsize = 100;
874 DWORD res;
875 CONSOLE_SCREEN_BUFFER_INFO csbi;
876 const int colormap[8] = {
877 0,4,2,6,
878 1,5,3,7,
880 CONSOLE_make_complex(hConsoleOutput);
881 buffer = HeapAlloc(GetProcessHeap(),0,curbufsize);
882 offbase = (dwBufferCoord.Y - 1) * dwBufferSize.X +
883 (dwBufferCoord.X - lpWriteRegion->Left);
885 TRACE("orig rect top = %d, bottom=%d, left=%d, right=%d\n",
886 lpWriteRegion->Top,
887 lpWriteRegion->Bottom,
888 lpWriteRegion->Left,
889 lpWriteRegion->Right
892 GetConsoleScreenBufferInfo(hConsoleOutput, &csbi);
893 sprintf(sbuf,"%c7",27);SADD(sbuf);
895 /* Step 1. Make (Bottom,Right) offset of intersection with
896 Screen Buffer */
897 lpWriteRegion->Bottom = min(lpWriteRegion->Bottom, csbi.dwSize.Y-1) -
898 lpWriteRegion->Top;
899 lpWriteRegion->Right = min(lpWriteRegion->Right, csbi.dwSize.X-1) -
900 lpWriteRegion->Left;
902 /* Step 2. If either offset is negative, then no action
903 should be performed. (Implies that requested rectangle is
904 outside the current screen buffer rectangle.) */
905 if ((lpWriteRegion->Bottom < 0) ||
906 (lpWriteRegion->Right < 0)) {
907 /* readjust (Bottom Right) for rectangle */
908 lpWriteRegion->Bottom += lpWriteRegion->Top;
909 lpWriteRegion->Right += lpWriteRegion->Left;
911 TRACE("invisible rect top = %d, bottom=%d, left=%d, right=%d\n",
912 lpWriteRegion->Top,
913 lpWriteRegion->Bottom,
914 lpWriteRegion->Left,
915 lpWriteRegion->Right
918 HeapFree(GetProcessHeap(),0,buffer);
919 return TRUE;
922 /* Step 3. Intersect with source rectangle */
923 lpWriteRegion->Bottom = lpWriteRegion->Top - dwBufferCoord.Y +
924 min(lpWriteRegion->Bottom + dwBufferCoord.Y, dwBufferSize.Y-1);
925 lpWriteRegion->Right = lpWriteRegion->Left - dwBufferCoord.X +
926 min(lpWriteRegion->Right + dwBufferCoord.X, dwBufferSize.X-1);
928 TRACE("clipped rect top = %d, bottom=%d, left=%d,right=%d\n",
929 lpWriteRegion->Top,
930 lpWriteRegion->Bottom,
931 lpWriteRegion->Left,
932 lpWriteRegion->Right
935 /* Validate above computations made sense, if not then issue
936 error and fudge to single character rectangle */
937 if ((lpWriteRegion->Bottom < lpWriteRegion->Top) ||
938 (lpWriteRegion->Right < lpWriteRegion->Left)) {
939 ERR("Invalid clipped rectangle top = %d, bottom=%d, left=%d,right=%d\n",
940 lpWriteRegion->Top,
941 lpWriteRegion->Bottom,
942 lpWriteRegion->Left,
943 lpWriteRegion->Right
945 lpWriteRegion->Bottom = lpWriteRegion->Top;
946 lpWriteRegion->Right = lpWriteRegion->Left;
949 /* Now do the real processing and move the characters */
950 for (i=lpWriteRegion->Top;i<=lpWriteRegion->Bottom;i++) {
951 offbase += dwBufferSize.X;
952 sprintf(sbuf,"%c[%d;%dH",27,i+1,lpWriteRegion->Left+1);
953 SADD(sbuf);
954 for (j=lpWriteRegion->Left;j<=lpWriteRegion->Right;j++) {
955 off = j + offbase;
956 if (lastattr!=lpBuffer[off].Attributes) {
957 lastattr = lpBuffer[off].Attributes;
958 sprintf(sbuf,"%c[0;%s3%d;4%dm",
960 (lastattr & FOREGROUND_INTENSITY)?"1;":"",
961 colormap[lastattr&7],
962 colormap[(lastattr&0x70)>>4]
964 /* FIXME: BACKGROUND_INTENSITY */
965 SADD(sbuf);
967 CADD(lpBuffer[off].Char.AsciiChar);
970 sprintf(sbuf,"%c[0m%c8",27,27);SADD(sbuf);
971 WriteFile(hConsoleOutput,buffer,bufused,&res,NULL);
972 HeapFree(GetProcessHeap(),0,buffer);
973 return TRUE;
976 /***********************************************************************
977 * WriteConsoleOutputW (KERNEL32.@)
979 BOOL WINAPI WriteConsoleOutputW( HANDLE hConsoleOutput,
980 LPCHAR_INFO lpBuffer,
981 COORD dwBufferSize,
982 COORD dwBufferCoord,
983 LPSMALL_RECT lpWriteRegion)
985 FIXME("(%d,%p,%dx%d,%dx%d,%p): stub\n", hConsoleOutput, lpBuffer,
986 dwBufferSize.X,dwBufferSize.Y,dwBufferCoord.X,dwBufferCoord.Y,lpWriteRegion);
988 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
989 return FALSE;
992 /***********************************************************************
993 * WriteConsoleW (KERNEL32.@)
995 BOOL WINAPI WriteConsoleW( HANDLE hConsoleOutput,
996 LPCVOID lpBuffer,
997 DWORD nNumberOfCharsToWrite,
998 LPDWORD lpNumberOfCharsWritten,
999 LPVOID lpReserved )
1001 BOOL ret;
1002 LPSTR xstring;
1003 DWORD n;
1005 n = WideCharToMultiByte(CP_ACP,0,lpBuffer,nNumberOfCharsToWrite,NULL,0,NULL,NULL);
1006 xstring=HeapAlloc( GetProcessHeap(), 0, n );
1008 n = WideCharToMultiByte(CP_ACP,0,lpBuffer,nNumberOfCharsToWrite,xstring,n,NULL,NULL);
1010 /* FIXME: should I check if this is a console handle? */
1011 ret= WriteFile(hConsoleOutput, xstring, n,
1012 lpNumberOfCharsWritten, NULL);
1013 /* FIXME: lpNumberOfCharsWritten should be converted to numofchars in UNICODE */
1014 HeapFree( GetProcessHeap(), 0, xstring );
1015 return ret;
1019 /***********************************************************************
1020 * ReadConsoleA (KERNEL32.@)
1022 BOOL WINAPI ReadConsoleA( HANDLE hConsoleInput,
1023 LPVOID lpBuffer,
1024 DWORD nNumberOfCharsToRead,
1025 LPDWORD lpNumberOfCharsRead,
1026 LPVOID lpReserved )
1028 DWORD charsread = 0;
1029 LPSTR xbuf = (LPSTR)lpBuffer;
1031 TRACE("(%d,%p,%ld,%p,%p)\n",
1032 hConsoleInput,lpBuffer,nNumberOfCharsToRead,
1033 lpNumberOfCharsRead,lpReserved
1036 CONSOLE_get_input(hConsoleInput,FALSE);
1038 /* FIXME: should we read at least 1 char? The SDK does not say */
1039 while (charsread<nNumberOfCharsToRead)
1041 INPUT_RECORD ir;
1042 DWORD count;
1043 if (!read_console_input( hConsoleInput, &ir, 1, &count, TRUE )) return FALSE;
1044 if (!count) break;
1045 if (ir.EventType != KEY_EVENT) continue;
1046 if (!ir.Event.KeyEvent.bKeyDown) continue;
1047 *xbuf++ = ir.Event.KeyEvent.uChar.AsciiChar;
1048 charsread++;
1050 if (lpNumberOfCharsRead)
1051 *lpNumberOfCharsRead = charsread;
1052 return TRUE;
1055 /***********************************************************************
1056 * ReadConsoleW (KERNEL32.@)
1058 BOOL WINAPI ReadConsoleW( HANDLE hConsoleInput,
1059 LPVOID lpBuffer,
1060 DWORD nNumberOfCharsToRead,
1061 LPDWORD lpNumberOfCharsRead,
1062 LPVOID lpReserved )
1064 BOOL ret;
1065 LPSTR buf = (LPSTR)HeapAlloc(GetProcessHeap(), 0, nNumberOfCharsToRead);
1067 ret = ReadConsoleA(
1068 hConsoleInput,
1069 buf,
1070 nNumberOfCharsToRead,
1071 lpNumberOfCharsRead,
1072 lpReserved
1074 if (ret)
1075 MultiByteToWideChar( CP_ACP, 0, buf, -1, lpBuffer, nNumberOfCharsToRead );
1077 HeapFree( GetProcessHeap(), 0, buf );
1078 return ret;
1082 /******************************************************************************
1083 * ReadConsoleInputA [KERNEL32.569] Reads data from a console
1085 * PARAMS
1086 * hConsoleInput [I] Handle to console input buffer
1087 * lpBuffer [O] Address of buffer for read data
1088 * nLength [I] Number of records to read
1089 * lpNumberOfEventsRead [O] Address of number of records read
1091 * RETURNS
1092 * Success: TRUE
1093 * Failure: FALSE
1095 BOOL WINAPI ReadConsoleInputA(HANDLE hConsoleInput, LPINPUT_RECORD lpBuffer,
1096 DWORD nLength, LPDWORD lpNumberOfEventsRead)
1098 if (!nLength)
1100 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = 0;
1101 return TRUE;
1104 /* loop until we get at least one event */
1105 for (;;)
1107 DWORD count;
1108 BOOL ret = read_console_input( hConsoleInput, lpBuffer, nLength, &count, TRUE );
1110 if (!ret) return FALSE;
1111 if (count)
1113 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = count;
1114 return TRUE;
1116 CONSOLE_get_input(hConsoleInput,TRUE);
1117 /*WaitForSingleObject( hConsoleInput, INFINITE32 );*/
1122 /***********************************************************************
1123 * ReadConsoleInputW (KERNEL32.570)
1125 BOOL WINAPI ReadConsoleInputW( HANDLE handle, LPINPUT_RECORD buffer,
1126 DWORD count, LPDWORD read )
1128 /* FIXME: Fix this if we get UNICODE input. */
1129 return ReadConsoleInputA( handle, buffer, count, read );
1133 /***********************************************************************
1134 * FlushConsoleInputBuffer (KERNEL32.@)
1136 BOOL WINAPI FlushConsoleInputBuffer( HANDLE handle )
1138 return read_console_input( handle, NULL, 0, NULL, TRUE );
1142 /***********************************************************************
1143 * PeekConsoleInputA (KERNEL32.550)
1145 * Gets 'count' first events (or less) from input queue.
1147 * Does not need a complex console.
1149 BOOL WINAPI PeekConsoleInputA( HANDLE handle, LPINPUT_RECORD buffer, DWORD count, LPDWORD read )
1151 CONSOLE_get_input(handle,FALSE);
1152 if (!count)
1154 if (read) *read = 0;
1155 return TRUE;
1157 return read_console_input( handle, buffer, count, read, FALSE );
1161 /***********************************************************************
1162 * PeekConsoleInputW (KERNEL32.551)
1164 BOOL WINAPI PeekConsoleInputW(HANDLE hConsoleInput,
1165 LPINPUT_RECORD pirBuffer,
1166 DWORD cInRecords,
1167 LPDWORD lpcRead)
1169 /* FIXME: Hmm. Fix this if we get UNICODE input. */
1170 return PeekConsoleInputA(hConsoleInput,pirBuffer,cInRecords,lpcRead);
1174 /******************************************************************************
1175 * WriteConsoleInputA [KERNEL32.730] Write data to a console input buffer
1178 BOOL WINAPI WriteConsoleInputA( HANDLE handle, INPUT_RECORD *buffer,
1179 DWORD count, LPDWORD written )
1181 BOOL ret = TRUE;
1183 if (written) *written = 0;
1184 while (count && ret)
1186 DWORD len = min( count, REQUEST_MAX_VAR_SIZE/sizeof(INPUT_RECORD) );
1187 SERVER_START_REQ
1189 struct write_console_input_request *req = server_alloc_req( sizeof(*req),
1190 len*sizeof(INPUT_RECORD) );
1191 req->handle = handle;
1192 memcpy( server_data_ptr(req), buffer, len * sizeof(INPUT_RECORD) );
1193 if ((ret = !server_call( REQ_WRITE_CONSOLE_INPUT )))
1195 if (written) *written += req->written;
1196 count -= len;
1197 buffer += len;
1200 SERVER_END_REQ;
1202 return ret;
1205 /******************************************************************************
1206 * WriteConsoleInputW [KERNEL32.731] Write data to a console input buffer
1209 BOOL WINAPI WriteConsoleInputW( HANDLE handle, INPUT_RECORD *buffer,
1210 DWORD count, LPDWORD written )
1212 FIXME("(%d,%p,%ld,%p): stub!\n", handle, buffer, count, written);
1214 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1215 return FALSE;
1219 /***********************************************************************
1220 * SetConsoleTitleA (KERNEL32.@)
1222 * Sets the console title.
1224 * We do not necessarily need to create a complex console for that,
1225 * but should remember the title and set it on creation of the latter.
1226 * (not fixed at this time).
1228 BOOL WINAPI SetConsoleTitleA(LPCSTR title)
1230 size_t len = strlen(title);
1231 HANDLE hcon;
1232 DWORD written;
1233 BOOL ret;
1235 if ((hcon = CreateFileA( "CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL,
1236 OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
1237 return FALSE;
1239 len = min( len, REQUEST_MAX_VAR_SIZE );
1240 SERVER_START_REQ
1242 struct set_console_info_request *req = server_alloc_req( sizeof(*req), len );
1243 req->handle = hcon;
1244 req->mask = SET_CONSOLE_INFO_TITLE;
1245 memcpy( server_data_ptr(req), title, len );
1246 ret = !server_call( REQ_SET_CONSOLE_INFO );
1248 SERVER_END_REQ;
1250 if (ret && CONSOLE_GetPid( hcon ))
1252 /* only set title for complex console (own xterm) */
1253 WriteFile( hcon, "\033]2;", 4, &written, NULL );
1254 WriteFile( hcon, title, strlen(title), &written, NULL );
1255 WriteFile( hcon, "\a", 1, &written, NULL );
1257 CloseHandle( hcon );
1258 return ret;
1262 /******************************************************************************
1263 * SetConsoleTitleW [KERNEL32.@] Sets title bar string for console
1265 * PARAMS
1266 * title [I] Address of new title
1268 * NOTES
1269 * This should not be calling the A version
1271 * RETURNS
1272 * Success: TRUE
1273 * Failure: FALSE
1275 BOOL WINAPI SetConsoleTitleW( LPCWSTR title )
1277 BOOL ret;
1279 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
1280 ret = SetConsoleTitleA(titleA);
1281 HeapFree( GetProcessHeap(), 0, titleA );
1282 return ret;
1285 /******************************************************************************
1286 * SetConsoleCursorPosition [KERNEL32.627]
1287 * Sets the cursor position in console
1289 * PARAMS
1290 * hConsoleOutput [I] Handle of console screen buffer
1291 * dwCursorPosition [I] New cursor position coordinates
1293 * RETURNS STD
1295 BOOL WINAPI SetConsoleCursorPosition( HANDLE hcon, COORD pos )
1297 char xbuf[20];
1298 DWORD xlen;
1300 /* make console complex only if we change lines, not just in the line */
1301 if (pos.Y)
1302 CONSOLE_make_complex(hcon);
1304 TRACE("%d (%dx%d)\n", hcon, pos.X , pos.Y );
1305 /* x are columns, y rows */
1306 if (pos.Y)
1307 /* full screen cursor absolute positioning */
1308 sprintf(xbuf,"%c[%d;%dH", 0x1B, pos.Y+1, pos.X+1);
1309 else
1310 /* relative cursor positioning in line (\r to go to 0) */
1311 sprintf(xbuf,"\r%c[%dC", 0x1B, pos.X);
1312 /* FIXME: store internal if we start using own console buffers */
1313 WriteFile(hcon,xbuf,strlen(xbuf),&xlen,NULL);
1314 return TRUE;
1317 /***********************************************************************
1318 * GetNumberOfConsoleInputEvents (KERNEL32.@)
1320 BOOL WINAPI GetNumberOfConsoleInputEvents(HANDLE hcon,LPDWORD nrofevents)
1322 CONSOLE_get_input (hcon, FALSE);
1324 return read_console_input( hcon, NULL, 0, nrofevents, FALSE );
1327 /***********************************************************************
1328 * GetNumberOfConsoleMouseButtons (KERNEL32.358)
1330 BOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons)
1332 FIXME("(%p): stub\n", nrofbuttons);
1333 *nrofbuttons = 2;
1334 return TRUE;
1337 /******************************************************************************
1338 * GetConsoleCursorInfo [KERNEL32.296] Gets size and visibility of console
1340 * PARAMS
1341 * hcon [I] Handle to console screen buffer
1342 * cinfo [O] Address of cursor information
1344 * RETURNS
1345 * Success: TRUE
1346 * Failure: FALSE
1348 BOOL WINAPI GetConsoleCursorInfo( HANDLE hcon, LPCONSOLE_CURSOR_INFO cinfo )
1350 BOOL ret;
1352 SERVER_START_REQ
1354 struct get_console_info_request *req = server_alloc_req( sizeof(*req), 0 );
1355 req->handle = hcon;
1356 ret = !server_call( REQ_GET_CONSOLE_INFO );
1357 if (ret && cinfo)
1359 cinfo->dwSize = req->cursor_size;
1360 cinfo->bVisible = req->cursor_visible;
1363 SERVER_END_REQ;
1364 return ret;
1368 /******************************************************************************
1369 * SetConsoleCursorInfo [KERNEL32.626] Sets size and visibility of cursor
1371 * RETURNS
1372 * Success: TRUE
1373 * Failure: FALSE
1375 BOOL WINAPI SetConsoleCursorInfo(
1376 HANDLE hcon, /* [in] Handle to console screen buffer */
1377 LPCONSOLE_CURSOR_INFO cinfo) /* [in] Address of cursor information */
1379 char buf[8];
1380 DWORD xlen;
1381 BOOL ret;
1383 CONSOLE_make_complex(hcon);
1384 sprintf(buf,"\033[?25%c",cinfo->bVisible?'h':'l');
1385 WriteFile(hcon,buf,strlen(buf),&xlen,NULL);
1387 SERVER_START_REQ
1389 struct set_console_info_request *req = server_alloc_req( sizeof(*req), 0 );
1390 req->handle = hcon;
1391 req->cursor_size = cinfo->dwSize;
1392 req->cursor_visible = cinfo->bVisible;
1393 req->mask = SET_CONSOLE_INFO_CURSOR;
1394 ret = !server_call( REQ_SET_CONSOLE_INFO );
1396 SERVER_END_REQ;
1397 return ret;
1401 /******************************************************************************
1402 * SetConsoleWindowInfo [KERNEL32.634] Sets size and position of console
1404 * RETURNS
1405 * Success: TRUE
1406 * Failure: FALSE
1408 BOOL WINAPI SetConsoleWindowInfo(
1409 HANDLE hcon, /* [in] Handle to console screen buffer */
1410 BOOL bAbsolute, /* [in] Coordinate type flag */
1411 LPSMALL_RECT window) /* [in] Address of new window rectangle */
1413 FIXME("(%x,%d,%p): stub\n", hcon, bAbsolute, window);
1414 return TRUE;
1418 /******************************************************************************
1419 * SetConsoleTextAttribute [KERNEL32.631] Sets colors for text
1421 * Sets the foreground and background color attributes of characters
1422 * written to the screen buffer.
1424 * RETURNS
1425 * Success: TRUE
1426 * Failure: FALSE
1428 BOOL WINAPI SetConsoleTextAttribute(HANDLE hConsoleOutput,WORD wAttr)
1430 const int colormap[8] = {
1431 0,4,2,6,
1432 1,5,3,7,
1434 DWORD xlen;
1435 char buffer[20];
1437 TRACE("(%d,%d)\n",hConsoleOutput,wAttr);
1438 sprintf(buffer,"%c[0;%s3%d;4%dm",
1440 (wAttr & FOREGROUND_INTENSITY)?"1;":"",
1441 colormap[wAttr&7],
1442 colormap[(wAttr&0x70)>>4]
1444 WriteFile(hConsoleOutput,buffer,strlen(buffer),&xlen,NULL);
1445 return TRUE;
1449 /******************************************************************************
1450 * SetConsoleScreenBufferSize [KERNEL32.630] Changes size of console
1452 * PARAMS
1453 * hConsoleOutput [I] Handle to console screen buffer
1454 * dwSize [I] New size in character rows and cols
1456 * RETURNS
1457 * Success: TRUE
1458 * Failure: FALSE
1460 BOOL WINAPI SetConsoleScreenBufferSize( HANDLE hConsoleOutput,
1461 COORD dwSize )
1463 FIXME("(%d,%dx%d): stub\n",hConsoleOutput,dwSize.X,dwSize.Y);
1464 return TRUE;
1468 /******************************************************************************
1469 * FillConsoleOutputCharacterA [KERNEL32.242]
1471 * PARAMS
1472 * hConsoleOutput [I] Handle to screen buffer
1473 * cCharacter [I] Character to write
1474 * nLength [I] Number of cells to write to
1475 * dwCoord [I] Coords of first cell
1476 * lpNumCharsWritten [O] Pointer to number of cells written
1478 * RETURNS
1479 * Success: TRUE
1480 * Failure: FALSE
1482 BOOL WINAPI FillConsoleOutputCharacterA(
1483 HANDLE hConsoleOutput,
1484 BYTE cCharacter,
1485 DWORD nLength,
1486 COORD dwCoord,
1487 LPDWORD lpNumCharsWritten)
1489 DWORD count;
1490 DWORD xlen;
1492 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
1493 for(count=0;count<nLength;count++)
1494 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
1495 *lpNumCharsWritten = nLength;
1496 return TRUE;
1500 /******************************************************************************
1501 * FillConsoleOutputCharacterW [KERNEL32.243] Writes characters to console
1503 * PARAMS
1504 * hConsoleOutput [I] Handle to screen buffer
1505 * cCharacter [I] Character to write
1506 * nLength [I] Number of cells to write to
1507 * dwCoord [I] Coords of first cell
1508 * lpNumCharsWritten [O] Pointer to number of cells written
1510 * RETURNS
1511 * Success: TRUE
1512 * Failure: FALSE
1514 BOOL WINAPI FillConsoleOutputCharacterW(HANDLE hConsoleOutput,
1515 WCHAR cCharacter,
1516 DWORD nLength,
1517 COORD dwCoord,
1518 LPDWORD lpNumCharsWritten)
1520 DWORD count;
1521 DWORD xlen;
1523 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
1524 /* FIXME: not quite correct ... but the lower part of UNICODE char comes
1525 * first
1527 for(count=0;count<nLength;count++)
1528 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
1529 *lpNumCharsWritten = nLength;
1530 return TRUE;
1534 /******************************************************************************
1535 * FillConsoleOutputAttribute [KERNEL32.241] Sets attributes for console
1537 * PARAMS
1538 * hConsoleOutput [I] Handle to screen buffer
1539 * wAttribute [I] Color attribute to write
1540 * nLength [I] Number of cells to write to
1541 * dwCoord [I] Coords of first cell
1542 * lpNumAttrsWritten [O] Pointer to number of cells written
1544 * RETURNS
1545 * Success: TRUE
1546 * Failure: FALSE
1548 BOOL WINAPI FillConsoleOutputAttribute( HANDLE hConsoleOutput,
1549 WORD wAttribute, DWORD nLength, COORD dwCoord,
1550 LPDWORD lpNumAttrsWritten)
1552 FIXME("(%d,%d,%ld,%dx%d,%p): stub\n", hConsoleOutput,
1553 wAttribute,nLength,dwCoord.X,dwCoord.Y,lpNumAttrsWritten);
1554 *lpNumAttrsWritten = nLength;
1555 return TRUE;
1558 /******************************************************************************
1559 * ReadConsoleOutputCharacterA [KERNEL32.573]
1561 * BUGS
1562 * Unimplemented
1564 BOOL WINAPI ReadConsoleOutputCharacterA(HANDLE hConsoleOutput,
1565 LPSTR lpstr, DWORD dword, COORD coord, LPDWORD lpdword)
1567 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,lpstr,
1568 dword,coord.X,coord.Y,lpdword);
1569 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1570 return FALSE;
1573 /******************************************************************************
1574 * ReadConsoleOutputCharacterW [KERNEL32.574]
1576 * BUGS
1577 * Unimplemented
1579 BOOL WINAPI ReadConsoleOutputCharacterW(HANDLE hConsoleOutput,
1580 LPWSTR lpstr, DWORD dword, COORD coord, LPDWORD lpdword)
1582 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,lpstr,
1583 dword,coord.X,coord.Y,lpdword);
1584 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1585 return FALSE;
1589 /******************************************************************************
1590 * ScrollConsoleScreenBufferA [KERNEL32.612]
1592 * BUGS
1593 * Unimplemented
1595 BOOL WINAPI ScrollConsoleScreenBufferA( HANDLE hConsoleOutput,
1596 LPSMALL_RECT lpScrollRect, LPSMALL_RECT lpClipRect,
1597 COORD dwDestOrigin, LPCHAR_INFO lpFill)
1599 FIXME("(%d,%p,%p,%dx%d,%p): stub\n", hConsoleOutput,lpScrollRect,
1600 lpClipRect,dwDestOrigin.X,dwDestOrigin.Y,lpFill);
1601 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1602 return FALSE;
1605 /******************************************************************************
1606 * ScrollConsoleScreenBufferW [KERNEL32.613]
1608 * BUGS
1609 * Unimplemented
1611 BOOL WINAPI ScrollConsoleScreenBufferW( HANDLE hConsoleOutput,
1612 LPSMALL_RECT lpScrollRect, LPSMALL_RECT lpClipRect,
1613 COORD dwDestOrigin, LPCHAR_INFO lpFill)
1615 FIXME("(%d,%p,%p,%dx%d,%p): stub\n", hConsoleOutput,lpScrollRect,
1616 lpClipRect,dwDestOrigin.X,dwDestOrigin.Y,lpFill);
1617 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1618 return FALSE;
1621 /******************************************************************************
1622 * ReadConsoleOutputA [KERNEL32.571]
1624 * BUGS
1625 * Unimplemented
1627 BOOL WINAPI ReadConsoleOutputA( HANDLE hConsoleOutput,
1628 LPCHAR_INFO lpBuffer,
1629 COORD dwBufferSize,
1630 COORD dwBufferCoord,
1631 LPSMALL_RECT lpReadRegion )
1633 FIXME("(%d,%p,%dx%d,%dx%d,%p): stub\n", hConsoleOutput, lpBuffer,
1634 dwBufferSize.X, dwBufferSize.Y, dwBufferSize.X, dwBufferSize.Y,
1635 lpReadRegion);
1637 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1638 return FALSE;
1641 /******************************************************************************
1642 * ReadConsoleOutputW [KERNEL32.575]
1644 * BUGS
1645 * Unimplemented
1647 BOOL WINAPI ReadConsoleOutputW( HANDLE hConsoleOutput,
1648 LPCHAR_INFO lpBuffer,
1649 COORD dwBufferSize,
1650 COORD dwBufferCoord,
1651 LPSMALL_RECT lpReadRegion )
1653 FIXME("(%d,%p,%dx%d,%dx%d,%p): stub\n", hConsoleOutput, lpBuffer,
1654 dwBufferSize.X, dwBufferSize.Y, dwBufferSize.X, dwBufferSize.Y,
1655 lpReadRegion);
1657 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1658 return FALSE;
1661 /******************************************************************************
1662 * ReadConsoleOutputAttribute [KERNEL32.572]
1664 * BUGS
1665 * Unimplemented
1667 BOOL WINAPI ReadConsoleOutputAttribute( HANDLE hConsoleOutput,
1668 LPWORD lpAttribute,
1669 DWORD nLength,
1670 COORD dwReadCoord,
1671 LPDWORD lpNumberOfAttrsRead)
1673 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput, lpAttribute,
1674 nLength, dwReadCoord.X, dwReadCoord.Y, lpNumberOfAttrsRead);
1676 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1677 return FALSE;
1680 /******************************************************************************
1681 * SetConsoleCP [KERNEL32.@]
1683 * BUGS
1684 * Unimplemented
1686 BOOL WINAPI SetConsoleCP( UINT cp )
1688 FIXME("(%d): stub\n", cp);
1690 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1691 return FALSE;
1694 /******************************************************************************
1695 * SetConsoleInputExeNameW [KERNEL32.889]
1697 * BUGS
1698 * Unimplemented
1700 BOOL WINAPI SetConsoleInputExeNameW( LPCWSTR name )
1702 FIXME("(%s): stub!\n", debugstr_w(name));
1704 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1705 return TRUE;
1708 /******************************************************************************
1709 * SetConsoleInputExeNameA [KERNEL32.888]
1711 * BUGS
1712 * Unimplemented
1714 BOOL WINAPI SetConsoleInputExeNameA( LPCSTR name )
1716 FIXME("(%s): stub!\n", name);
1718 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1719 return TRUE;