Added a few missing languages.
[wine/multimedia.git] / win32 / console.c
blob3ac3ed3e16a98f4749f5c05a81dc6e0aa57322be
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 "winbase.h"
39 #include "windef.h"
40 #include "wingdi.h"
41 #include "wine/winuser16.h"
42 #include "wine/winestring.h"
43 #include "wine/keyboard16.h"
44 #include "thread.h"
45 #include "file.h"
46 #include "process.h"
47 #include "winerror.h"
48 #include "wincon.h"
49 #include "heap.h"
50 #include "server.h"
51 #include "debugtools.h"
52 #include "winnls.h"
54 DEFAULT_DEBUG_CHANNEL(console)
56 /* Ascii -> VK, generated by calling VkKeyScanA(i) */
57 static int vkkeyscan_table[256] = {
58 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,
59 0,32,305,478,307,308,309,311,222,313,304,312,443,188,189,190,191,48,
60 49,50,51,52,53,54,55,56,57,442,186,444,187,446,447,306,321,322,323,
61 324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,
62 341,342,343,344,345,346,219,220,221,310,445,192,65,66,67,68,69,70,71,
63 72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,475,476,477,
64 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,
65 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,
66 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,
67 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
70 static int mapvkey_0[256]={
71 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,
72 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,
73 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,
74 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,
75 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,
76 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,
77 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,
78 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,
79 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
82 static int mapvkey_1[256]={
83 0,27,49,50,51,52,53,54,55,56,57,48,189,187,8,9,81,87,69,82,84,89,85,
84 73,79,80,219,221,13,17,65,83,68,70,71,72,74,75,76,186,222,192,16,220,
85 90,88,67,86,66,78,77,188,190,191,16,106,18,32,20,112,113,114,115,116,
86 117,118,119,120,121,144,145,36,38,33,109,37,223,39,107,35,40,34,45,
87 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,
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,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,
91 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,
92 0,0,0,0,0,0,0
95 /* FIXME: Should be in an internal header file. OK, so which one?
96 Used by CONSOLE_make_complex. */
97 extern int wine_openpty(int *master, int *slave, char *name,
98 struct termios *term, struct winsize *winsize);
100 /****************************************************************************
101 * CONSOLE_GetPid
103 static int CONSOLE_GetPid( HANDLE handle )
105 int ret = 0;
106 SERVER_START_REQ
108 struct get_console_info_request *req = server_alloc_req( sizeof(*req), 0 );
109 req->handle = handle;
110 if (!server_call( REQ_GET_CONSOLE_INFO )) ret = req->pid;
112 SERVER_END_REQ;
113 return ret;
116 /****************************************************************************
117 * XTERM_string_to_IR [internal]
119 * Transfers a string read from XTERM to INPUT_RECORDs and adds them to the
120 * queue. Does translation of vt100 style function keys and xterm-mouse clicks.
122 static void
123 CONSOLE_string_to_IR( HANDLE hConsoleInput,unsigned char *buf,int len) {
124 int j,k;
125 INPUT_RECORD ir;
126 DWORD junk;
128 for (j=0;j<len;j++) {
129 unsigned char inchar = buf[j];
131 if (inchar!=27) { /* no escape -> 'normal' keyboard event */
132 ir.EventType = 1; /* Key_event */
134 ir.Event.KeyEvent.bKeyDown = 1;
135 ir.Event.KeyEvent.wRepeatCount = 0;
137 ir.Event.KeyEvent.dwControlKeyState = 0;
138 if (inchar & 0x80) {
139 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
140 inchar &= ~0x80;
142 ir.Event.KeyEvent.wVirtualKeyCode = vkkeyscan_table[inchar];
143 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0100)
144 ir.Event.KeyEvent.dwControlKeyState|=SHIFT_PRESSED;
145 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0200)
146 ir.Event.KeyEvent.dwControlKeyState|=LEFT_CTRL_PRESSED;
147 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0400)
148 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
149 ir.Event.KeyEvent.wVirtualScanCode = mapvkey_0[
150 ir.Event.KeyEvent.wVirtualKeyCode & 0x00ff
151 ]; /* VirtualKeyCodes to ScanCode */
152 ir.Event.KeyEvent.uChar.AsciiChar = inchar;
154 if ((inchar==127)||(inchar=='\b')) { /* backspace */
155 ir.Event.KeyEvent.uChar.AsciiChar = '\b'; /* FIXME: hmm */
156 ir.Event.KeyEvent.wVirtualScanCode = 0x0e;
157 ir.Event.KeyEvent.wVirtualKeyCode = VK_BACK;
158 } else {
159 if ((inchar=='\n')||(inchar=='\r')) {
160 ir.Event.KeyEvent.uChar.AsciiChar = '\r';
161 ir.Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
162 ir.Event.KeyEvent.wVirtualScanCode = 0x1c;
163 ir.Event.KeyEvent.dwControlKeyState = 0;
164 } else {
165 if (inchar<' ') {
166 /* FIXME: find good values for ^X */
167 ir.Event.KeyEvent.wVirtualKeyCode = 0xdead;
168 ir.Event.KeyEvent.wVirtualScanCode = 0xbeef;
173 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
174 ir.Event.KeyEvent.bKeyDown = 0;
175 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
176 continue;
178 /* inchar is ESC */
179 if ((j==len-1) || (buf[j+1]!='[')) {/* add ESCape on its own */
180 ir.EventType = 1; /* Key_event */
181 ir.Event.KeyEvent.bKeyDown = 1;
182 ir.Event.KeyEvent.wRepeatCount = 0;
184 ir.Event.KeyEvent.wVirtualKeyCode = VK_ESCAPE;
185 ir.Event.KeyEvent.wVirtualScanCode = mapvkey_0[
186 ir.Event.KeyEvent.wVirtualKeyCode
188 ir.Event.KeyEvent.dwControlKeyState = 0;
189 ir.Event.KeyEvent.uChar.AsciiChar = 27;
190 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
191 ir.Event.KeyEvent.bKeyDown = 0;
192 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
193 continue;
195 for (k=j;k<len;k++) {
196 if (((buf[k]>='A') && (buf[k]<='Z')) ||
197 ((buf[k]>='a') && (buf[k]<='z')) ||
198 (buf[k]=='~')
200 break;
202 if (k<len) {
203 int subid,scancode=0;
205 ir.EventType = 1; /* Key_event */
206 ir.Event.KeyEvent.bKeyDown = 1;
207 ir.Event.KeyEvent.wRepeatCount = 0;
208 ir.Event.KeyEvent.dwControlKeyState = 0;
210 ir.Event.KeyEvent.wVirtualKeyCode = 0xad; /* FIXME */
211 ir.Event.KeyEvent.wVirtualScanCode = 0xad; /* FIXME */
212 ir.Event.KeyEvent.uChar.AsciiChar = 0;
214 switch (buf[k]) {
215 case '~':
216 sscanf(&buf[j+2],"%d",&subid);
217 switch (subid) {
218 case 2:/*INS */scancode = 0xe052;break;
219 case 3:/*DEL */scancode = 0xe053;break;
220 case 6:/*PGDW*/scancode = 0xe051;break;
221 case 5:/*PGUP*/scancode = 0xe049;break;
222 case 11:/*F1 */scancode = 0x003b;break;
223 case 12:/*F2 */scancode = 0x003c;break;
224 case 13:/*F3 */scancode = 0x003d;break;
225 case 14:/*F4 */scancode = 0x003e;break;
226 case 15:/*F5 */scancode = 0x003f;break;
227 case 17:/*F6 */scancode = 0x0040;break;
228 case 18:/*F7 */scancode = 0x0041;break;
229 case 19:/*F8 */scancode = 0x0042;break;
230 case 20:/*F9 */scancode = 0x0043;break;
231 case 21:/*F10 */scancode = 0x0044;break;
232 case 23:/*F11 */scancode = 0x00d9;break;
233 case 24:/*F12 */scancode = 0x00da;break;
234 /* FIXME: Shift-Fx */
235 default:
236 FIXME("parse ESC[%d~\n",subid);
237 break;
239 break;
240 case 'A': /* Cursor Up */scancode = 0xe048;break;
241 case 'B': /* Cursor Down */scancode = 0xe050;break;
242 case 'D': /* Cursor Left */scancode = 0xe04b;break;
243 case 'C': /* Cursor Right */scancode = 0xe04d;break;
244 case 'F': /* End */scancode = 0xe04f;break;
245 case 'H': /* Home */scancode = 0xe047;break;
246 case 'M':
247 /* Mouse Button Press (ESCM<button+'!'><x+'!'><y+'!'>) or
248 * Release (ESCM#<x+'!'><y+'!'>
250 if (k<len-3) {
251 ir.EventType = MOUSE_EVENT;
252 ir.Event.MouseEvent.dwMousePosition.X = buf[k+2]-'!';
253 ir.Event.MouseEvent.dwMousePosition.Y = buf[k+3]-'!';
254 if (buf[k+1]=='#')
255 ir.Event.MouseEvent.dwButtonState = 0;
256 else
257 ir.Event.MouseEvent.dwButtonState = 1<<(buf[k+1]-' ');
258 ir.Event.MouseEvent.dwEventFlags = 0; /* FIXME */
259 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk));
260 j=k+3;
262 break;
263 case 'c':
264 j=k;
265 break;
267 if (scancode) {
268 ir.Event.KeyEvent.wVirtualScanCode = scancode;
269 ir.Event.KeyEvent.wVirtualKeyCode = mapvkey_1[scancode];
270 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
271 ir.Event.KeyEvent.bKeyDown = 0;
272 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
273 j=k;
274 continue;
280 /****************************************************************************
281 * CONSOLE_get_input (internal)
283 * Reads (nonblocking) as much input events as possible and stores them
284 * in an internal queue.
286 static void
287 CONSOLE_get_input( HANDLE handle, BOOL blockwait )
289 char *buf = HeapAlloc(GetProcessHeap(),0,1);
290 int len = 0, escape_seen = 0;
292 while (1)
294 DWORD res;
295 char inchar;
297 /* If we have at one time seen escape in this loop, we are
298 * within an Escape sequence, so wait for a bit more input for the
299 * rest of the loop.
301 if (WaitForSingleObject( handle, escape_seen*10 )) break;
302 if (!ReadFile( handle, &inchar, 1, &res, NULL )) break;
303 if (!res) /* res 0 but readable means EOF? Hmm. */
304 break;
305 buf = HeapReAlloc(GetProcessHeap(),0,buf,len+1);
306 buf[len++]=inchar;
307 if (inchar == 27) {
308 if (len>1) {
309 /* If we spot an ESC, we flush all up to it
310 * since we can be sure that we have a complete
311 * sequence.
313 CONSOLE_string_to_IR(handle,buf,len-1);
314 buf = HeapReAlloc(GetProcessHeap(),0,buf,1);
315 buf[0] = 27;
316 len = 1;
318 escape_seen = 1;
321 CONSOLE_string_to_IR(handle,buf,len);
322 HeapFree(GetProcessHeap(),0,buf);
326 /******************************************************************************
327 * read_console_input
329 * Helper function for ReadConsole, ReadConsoleInput and PeekConsoleInput
331 static BOOL read_console_input( HANDLE handle, LPINPUT_RECORD buffer, DWORD count,
332 LPDWORD read, BOOL flush )
334 BOOL ret;
336 count = min( count, REQUEST_MAX_VAR_SIZE/sizeof(INPUT_RECORD) );
338 SERVER_START_REQ
340 struct read_console_input_request *req = server_alloc_req( sizeof(*req),
341 count*sizeof(INPUT_RECORD) );
342 req->handle = handle;
343 req->flush = flush;
344 if ((ret = !server_call( REQ_READ_CONSOLE_INPUT )))
346 if (count) memcpy( buffer, server_data_ptr(req), server_data_size(req) );
347 if (read) *read = req->read;
350 SERVER_END_REQ;
351 return ret;
355 /******************************************************************************
356 * SetConsoleCtrlHandler [KERNEL32.459] Adds function to calling process list
358 * PARAMS
359 * func [I] Address of handler function
360 * add [I] Handler to add or remove
362 * RETURNS
363 * Success: TRUE
364 * Failure: FALSE
366 * CHANGED
367 * James Sutherland (JamesSutherland@gmx.de)
368 * Added global variables console_ignore_ctrl_c and handlers[]
369 * Does not yet do any error checking, or set LastError if failed.
370 * This doesn't yet matter, since these handlers are not yet called...!
372 static unsigned int console_ignore_ctrl_c = 0;
373 static HANDLER_ROUTINE *handlers[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
374 BOOL WINAPI SetConsoleCtrlHandler( HANDLER_ROUTINE *func, BOOL add )
376 unsigned int alloc_loop = sizeof(handlers)/sizeof(HANDLER_ROUTINE *);
377 unsigned int done = 0;
378 FIXME("(%p,%i) - no error checking or testing yet\n", func, add);
379 if (!func)
381 console_ignore_ctrl_c = add;
382 return TRUE;
384 if (add)
386 for (;alloc_loop--;)
387 if (!handlers[alloc_loop] && !done)
389 handlers[alloc_loop] = func;
390 done++;
392 if (!done)
393 FIXME("Out of space on CtrlHandler table\n");
394 return(done);
396 else
398 for (;alloc_loop--;)
399 if (handlers[alloc_loop] == func && !done)
401 handlers[alloc_loop] = 0;
402 done++;
404 if (!done)
405 WARN("Attempt to remove non-installed CtrlHandler %p\n",
406 func);
407 return (done);
409 return (done);
413 /******************************************************************************
414 * GenerateConsoleCtrlEvent [KERNEL32.275] Simulate a CTRL-C or CTRL-BREAK
416 * PARAMS
417 * dwCtrlEvent [I] Type of event
418 * dwProcessGroupID [I] Process group ID to send event to
420 * NOTES
421 * Doesn't yet work...!
423 * RETURNS
424 * Success: True
425 * Failure: False (and *should* [but doesn't] set LastError)
427 BOOL WINAPI GenerateConsoleCtrlEvent( DWORD dwCtrlEvent,
428 DWORD dwProcessGroupID )
430 if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
432 ERR("invalid event %d for PGID %ld\n",
433 (unsigned short)dwCtrlEvent, dwProcessGroupID );
434 return FALSE;
436 if (dwProcessGroupID == GetCurrentProcessId() )
438 FIXME("Attempt to send event %d to self - stub\n",
439 (unsigned short)dwCtrlEvent );
440 return FALSE;
442 FIXME("event %d to external PGID %ld - not implemented yet\n",
443 (unsigned short)dwCtrlEvent, dwProcessGroupID );
444 return FALSE;
448 /******************************************************************************
449 * CreateConsoleScreenBuffer [KERNEL32.151] Creates a console screen buffer
451 * PARAMS
452 * dwDesiredAccess [I] Access flag
453 * dwShareMode [I] Buffer share mode
454 * sa [I] Security attributes
455 * dwFlags [I] Type of buffer to create
456 * lpScreenBufferData [I] Reserved
458 * NOTES
459 * Should call SetLastError
461 * RETURNS
462 * Success: Handle to new console screen buffer
463 * Failure: INVALID_HANDLE_VALUE
465 HANDLE WINAPI CreateConsoleScreenBuffer( DWORD dwDesiredAccess,
466 DWORD dwShareMode, LPSECURITY_ATTRIBUTES sa,
467 DWORD dwFlags, LPVOID lpScreenBufferData )
469 FIXME("(%ld,%ld,%p,%ld,%p): stub\n",dwDesiredAccess,
470 dwShareMode, sa, dwFlags, lpScreenBufferData);
471 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
472 return INVALID_HANDLE_VALUE;
476 /***********************************************************************
477 * GetConsoleScreenBufferInfo (KERNEL32.190)
479 BOOL WINAPI GetConsoleScreenBufferInfo( HANDLE hConsoleOutput,
480 LPCONSOLE_SCREEN_BUFFER_INFO csbi )
482 csbi->dwSize.X = 80;
483 csbi->dwSize.Y = 24;
484 csbi->dwCursorPosition.X = 0;
485 csbi->dwCursorPosition.Y = 0;
486 csbi->wAttributes = 0;
487 csbi->srWindow.Left = 0;
488 csbi->srWindow.Right = 79;
489 csbi->srWindow.Top = 0;
490 csbi->srWindow.Bottom = 23;
491 csbi->dwMaximumWindowSize.X = 80;
492 csbi->dwMaximumWindowSize.Y = 24;
493 return TRUE;
497 /******************************************************************************
498 * SetConsoleActiveScreenBuffer [KERNEL32.623] Sets buffer to current console
500 * RETURNS
501 * Success: TRUE
502 * Failure: FALSE
504 BOOL WINAPI SetConsoleActiveScreenBuffer(
505 HANDLE hConsoleOutput) /* [in] Handle to console screen buffer */
507 FIXME("(%x): stub\n", hConsoleOutput);
508 return FALSE;
512 /***********************************************************************
513 * GetLargestConsoleWindowSize (KERNEL32.226)
515 * Note: this should return a COORD, but calling convention for returning
516 * structures is different between Windows and gcc on i386.
518 #ifdef __i386__
519 #undef GetLargestConsoleWindowSize
520 DWORD WINAPI GetLargestConsoleWindowSize( HANDLE hConsoleOutput )
522 COORD c;
523 c.X = 80;
524 c.Y = 24;
525 return *(DWORD *)&c;
527 #else /* __i386__ */
528 COORD WINAPI GetLargestConsoleWindowSize( HANDLE hConsoleOutput )
530 COORD c;
531 c.X = 80;
532 c.Y = 24;
533 return c;
535 #endif /* __i386__ */
537 /***********************************************************************
538 * FreeConsole (KERNEL32.267)
540 BOOL WINAPI FreeConsole(VOID)
542 BOOL ret;
543 SERVER_START_REQ
545 struct free_console_request *req = server_alloc_req( sizeof(*req), 0 );
546 ret = !server_call( REQ_FREE_CONSOLE );
548 SERVER_END_REQ;
549 return ret;
553 /*************************************************************************
554 * CONSOLE_make_complex [internal]
556 * Turns a CONSOLE kernel object into a complex one.
557 * (switches from output/input using the terminal where WINE was started to
558 * its own xterm).
560 * This makes simple commandline tools pipeable, while complex commandline
561 * tools work without getting messed up by debugoutput.
563 * All other functions should work independent from this call.
565 * To test for complex console: pid == 0 -> simple, otherwise complex.
567 static BOOL CONSOLE_make_complex(HANDLE handle)
569 struct termios term;
570 char buf[256];
571 char c = '\0';
572 int i,xpid,master,slave,pty_handle;
574 if (CONSOLE_GetPid( handle )) return TRUE; /* already complex */
576 MESSAGE("Console: Making console complex (creating an xterm)...\n");
578 if (tcgetattr(0, &term) < 0) {
579 /* ignore failure, or we can't run from a script */
581 term.c_lflag = ~(ECHO|ICANON);
583 if (wine_openpty(&master, &slave, NULL, &term, NULL) < 0)
584 return FALSE;
586 if ((xpid=fork()) == 0) {
587 tcsetattr(slave, TCSADRAIN, &term);
588 close( slave );
589 sprintf(buf, "-Sxx%d", master);
590 /* "-fn vga" for VGA font. Harmless if vga is not present:
591 * xterm: unable to open font "vga", trying "fixed"....
593 execlp("xterm", "xterm", buf, "-fn","vga",NULL);
594 ERR("error creating AllocConsole xterm\n");
595 exit(1);
597 pty_handle = FILE_DupUnixHandle( slave, GENERIC_READ | GENERIC_WRITE );
598 close( master );
599 close( slave );
600 if (pty_handle == -1) return FALSE;
602 /* most xterms like to print their window ID when used with -S;
603 * read it and continue before the user has a chance...
605 for (i = 0; i < 10000; i++)
607 BOOL ok = ReadFile( pty_handle, &c, 1, NULL, NULL );
608 if (!ok && !c) usleep(100); /* wait for xterm to be created */
609 else if (c == '\n') break;
611 if (i == 10000)
613 ERR("can't read xterm WID\n");
614 CloseHandle( pty_handle );
615 return FALSE;
617 SERVER_START_REQ
619 struct set_console_fd_request *req = server_alloc_req( sizeof(*req), 0 );
620 req->handle = handle;
621 req->file_handle = pty_handle;
622 req->pid = xpid;
623 server_call( REQ_SET_CONSOLE_FD );
625 SERVER_END_REQ;
626 CloseHandle( pty_handle );
628 /* enable mouseclicks */
629 strcpy( buf, "\033[?1002h" );
630 WriteFile(handle,buf,strlen(buf),NULL,NULL);
632 strcpy( buf, "\033]2;" );
633 if (GetConsoleTitleA( buf + 4, sizeof(buf) - 5 ))
635 strcat( buf, "\a" );
636 WriteFile(handle,buf,strlen(buf),NULL,NULL);
638 return TRUE;
643 /***********************************************************************
644 * AllocConsole (KERNEL32.103)
646 * creates an xterm with a pty to our program
648 BOOL WINAPI AllocConsole(VOID)
650 BOOL ret;
651 HANDLE hStderr;
652 int handle_in, handle_out;
654 TRACE("()\n");
656 SERVER_START_REQ
658 struct alloc_console_request *req = server_alloc_req( sizeof(*req), 0 );
660 req->access = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE;
661 req->inherit = FALSE;
662 ret = !server_call( REQ_ALLOC_CONSOLE );
663 handle_in = req->handle_in;
664 handle_out = req->handle_out;
666 SERVER_END_REQ;
667 if (!ret) return FALSE;
669 if (!DuplicateHandle( GetCurrentProcess(), handle_out, GetCurrentProcess(), &hStderr,
670 0, TRUE, DUPLICATE_SAME_ACCESS ))
672 CloseHandle( handle_in );
673 CloseHandle( handle_out );
674 FreeConsole();
675 return FALSE;
678 /* NT resets the STD_*_HANDLEs on console alloc */
679 SetStdHandle( STD_INPUT_HANDLE, handle_in );
680 SetStdHandle( STD_OUTPUT_HANDLE, handle_out );
681 SetStdHandle( STD_ERROR_HANDLE, hStderr );
683 SetLastError(ERROR_SUCCESS);
684 SetConsoleTitleA("Wine Console");
685 return TRUE;
689 /******************************************************************************
690 * GetConsoleCP [KERNEL32.295] Returns the OEM code page for the console
692 * RETURNS
693 * Code page code
695 UINT WINAPI GetConsoleCP(VOID)
697 return GetACP();
701 /***********************************************************************
702 * GetConsoleOutputCP (KERNEL32.189)
704 UINT WINAPI GetConsoleOutputCP(VOID)
706 return GetConsoleCP();
709 /***********************************************************************
710 * GetConsoleMode (KERNEL32.188)
712 BOOL WINAPI GetConsoleMode(HANDLE hcon,LPDWORD mode)
714 BOOL ret;
715 SERVER_START_REQ
717 struct get_console_mode_request *req = server_alloc_req( sizeof(*req), 0 );
718 req->handle = hcon;
719 ret = !server_call( REQ_GET_CONSOLE_MODE );
720 if (ret && mode) *mode = req->mode;
722 SERVER_END_REQ;
723 return ret;
727 /******************************************************************************
728 * SetConsoleMode [KERNEL32.628] Sets input mode of console's input buffer
730 * PARAMS
731 * hcon [I] Handle to console input or screen buffer
732 * mode [I] Input or output mode to set
734 * RETURNS
735 * Success: TRUE
736 * Failure: FALSE
738 BOOL WINAPI SetConsoleMode( HANDLE hcon, DWORD mode )
740 BOOL ret;
741 SERVER_START_REQ
743 struct set_console_mode_request *req = server_alloc_req( sizeof(*req), 0 );
744 req->handle = hcon;
745 req->mode = mode;
746 ret = !server_call( REQ_SET_CONSOLE_MODE );
748 SERVER_END_REQ;
749 return ret;
753 /******************************************************************************
754 * SetConsoleOutputCP [KERNEL32.629] Set the output codepage used by the console
756 * PARAMS
757 * cp [I] code page to set
759 * RETURNS
760 * Success: TRUE
761 * Failure: FALSE
763 BOOL WINAPI SetConsoleOutputCP( UINT cp )
765 FIXME("stub\n");
766 return TRUE;
770 /***********************************************************************
771 * GetConsoleTitleA (KERNEL32.191)
773 DWORD WINAPI GetConsoleTitleA(LPSTR title,DWORD size)
775 DWORD ret = 0;
776 HANDLE hcon;
778 if ((hcon = CreateFileA( "CONOUT$", GENERIC_READ, 0, NULL,
779 OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
780 return 0;
781 SERVER_START_REQ
783 struct get_console_info_request *req = server_alloc_req( sizeof(*req),
784 REQUEST_MAX_VAR_SIZE );
785 req->handle = hcon;
786 if (!server_call( REQ_GET_CONSOLE_INFO ))
788 ret = server_data_size(req);
789 size = min( size-1, ret );
790 memcpy( title, server_data_ptr(req), size );
791 title[size] = 0;
794 SERVER_END_REQ;
795 CloseHandle( hcon );
796 return ret;
800 /******************************************************************************
801 * GetConsoleTitleW [KERNEL32.192] Retrieves title string for console
803 * PARAMS
804 * title [O] Address of buffer for title
805 * size [I] Size of buffer
807 * RETURNS
808 * Success: Length of string copied
809 * Failure: 0
811 DWORD WINAPI GetConsoleTitleW( LPWSTR title, DWORD size )
813 char *tmp;
814 DWORD ret;
816 if (!(tmp = HeapAlloc( GetProcessHeap(), 0, size ))) return 0;
817 ret = GetConsoleTitleA( tmp, size );
818 lstrcpyAtoW( title, tmp );
819 HeapFree( GetProcessHeap(), 0, tmp );
820 return ret;
824 /***********************************************************************
825 * WriteConsoleA (KERNEL32.729)
827 BOOL WINAPI WriteConsoleA( HANDLE hConsoleOutput,
828 LPCVOID lpBuffer,
829 DWORD nNumberOfCharsToWrite,
830 LPDWORD lpNumberOfCharsWritten,
831 LPVOID lpReserved )
833 /* FIXME: should I check if this is a console handle? */
834 return WriteFile(hConsoleOutput, lpBuffer, nNumberOfCharsToWrite,
835 lpNumberOfCharsWritten, NULL);
839 #define CADD(c) \
840 if (bufused==curbufsize-1) \
841 buffer = HeapReAlloc(GetProcessHeap(),0,buffer,(curbufsize+=100));\
842 buffer[bufused++]=c;
843 #define SADD(s) { char *x=s;while (*x) {CADD(*x);x++;}}
845 /***********************************************************************
846 * WriteConsoleOutputA (KERNEL32.732)
848 BOOL WINAPI WriteConsoleOutputA( HANDLE hConsoleOutput,
849 LPCHAR_INFO lpBuffer,
850 COORD dwBufferSize,
851 COORD dwBufferCoord,
852 LPSMALL_RECT lpWriteRegion)
854 int i,j,off=0,lastattr=-1;
855 int offbase;
856 char sbuf[20],*buffer=NULL;
857 int bufused=0,curbufsize = 100;
858 DWORD res;
859 CONSOLE_SCREEN_BUFFER_INFO csbi;
860 const int colormap[8] = {
861 0,4,2,6,
862 1,5,3,7,
864 CONSOLE_make_complex(hConsoleOutput);
865 buffer = HeapAlloc(GetProcessHeap(),0,curbufsize);
866 offbase = (dwBufferCoord.Y - 1) * dwBufferSize.X +
867 (dwBufferCoord.X - lpWriteRegion->Left);
869 TRACE("orig rect top = %d, bottom=%d, left=%d, right=%d\n",
870 lpWriteRegion->Top,
871 lpWriteRegion->Bottom,
872 lpWriteRegion->Left,
873 lpWriteRegion->Right
876 GetConsoleScreenBufferInfo(hConsoleOutput, &csbi);
877 sprintf(sbuf,"%c7",27);SADD(sbuf);
879 /* Step 1. Make (Bottom,Right) offset of intersection with
880 Screen Buffer */
881 lpWriteRegion->Bottom = min(lpWriteRegion->Bottom, csbi.dwSize.Y-1) -
882 lpWriteRegion->Top;
883 lpWriteRegion->Right = min(lpWriteRegion->Right, csbi.dwSize.X-1) -
884 lpWriteRegion->Left;
886 /* Step 2. If either offset is negative, then no action
887 should be performed. (Implies that requested rectangle is
888 outside the current screen buffer rectangle.) */
889 if ((lpWriteRegion->Bottom < 0) ||
890 (lpWriteRegion->Right < 0)) {
891 /* readjust (Bottom Right) for rectangle */
892 lpWriteRegion->Bottom += lpWriteRegion->Top;
893 lpWriteRegion->Right += lpWriteRegion->Left;
895 TRACE("invisible rect top = %d, bottom=%d, left=%d, right=%d\n",
896 lpWriteRegion->Top,
897 lpWriteRegion->Bottom,
898 lpWriteRegion->Left,
899 lpWriteRegion->Right
902 HeapFree(GetProcessHeap(),0,buffer);
903 return TRUE;
906 /* Step 3. Intersect with source rectangle */
907 lpWriteRegion->Bottom = lpWriteRegion->Top - dwBufferCoord.Y +
908 min(lpWriteRegion->Bottom + dwBufferCoord.Y, dwBufferSize.Y-1);
909 lpWriteRegion->Right = lpWriteRegion->Left - dwBufferCoord.X +
910 min(lpWriteRegion->Right + dwBufferCoord.X, dwBufferSize.X-1);
912 TRACE("clipped rect top = %d, bottom=%d, left=%d,right=%d\n",
913 lpWriteRegion->Top,
914 lpWriteRegion->Bottom,
915 lpWriteRegion->Left,
916 lpWriteRegion->Right
919 /* Validate above computations made sense, if not then issue
920 error and fudge to single character rectangle */
921 if ((lpWriteRegion->Bottom < lpWriteRegion->Top) ||
922 (lpWriteRegion->Right < lpWriteRegion->Left)) {
923 ERR("Invalid clipped rectangle top = %d, bottom=%d, left=%d,right=%d\n",
924 lpWriteRegion->Top,
925 lpWriteRegion->Bottom,
926 lpWriteRegion->Left,
927 lpWriteRegion->Right
929 lpWriteRegion->Bottom = lpWriteRegion->Top;
930 lpWriteRegion->Right = lpWriteRegion->Left;
933 /* Now do the real processing and move the characters */
934 for (i=lpWriteRegion->Top;i<=lpWriteRegion->Bottom;i++) {
935 offbase += dwBufferSize.X;
936 sprintf(sbuf,"%c[%d;%dH",27,i+1,lpWriteRegion->Left+1);
937 SADD(sbuf);
938 for (j=lpWriteRegion->Left;j<=lpWriteRegion->Right;j++) {
939 off = j + offbase;
940 if (lastattr!=lpBuffer[off].Attributes) {
941 lastattr = lpBuffer[off].Attributes;
942 sprintf(sbuf,"%c[0;%s3%d;4%dm",
944 (lastattr & FOREGROUND_INTENSITY)?"1;":"",
945 colormap[lastattr&7],
946 colormap[(lastattr&0x70)>>4]
948 /* FIXME: BACKGROUND_INTENSITY */
949 SADD(sbuf);
951 CADD(lpBuffer[off].Char.AsciiChar);
954 sprintf(sbuf,"%c[0m%c8",27,27);SADD(sbuf);
955 WriteFile(hConsoleOutput,buffer,bufused,&res,NULL);
956 HeapFree(GetProcessHeap(),0,buffer);
957 return TRUE;
960 /***********************************************************************
961 * WriteConsoleOutputW (KERNEL32.734)
963 BOOL WINAPI WriteConsoleOutputW( HANDLE hConsoleOutput,
964 LPCHAR_INFO lpBuffer,
965 COORD dwBufferSize,
966 COORD dwBufferCoord,
967 LPSMALL_RECT lpWriteRegion)
969 FIXME("(%d,%p,%dx%d,%dx%d,%p): stub\n", hConsoleOutput, lpBuffer,
970 dwBufferSize.X,dwBufferSize.Y,dwBufferCoord.X,dwBufferCoord.Y,lpWriteRegion);
972 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
973 return FALSE;
976 /***********************************************************************
977 * WriteConsoleW (KERNEL32.577)
979 BOOL WINAPI WriteConsoleW( HANDLE hConsoleOutput,
980 LPCVOID lpBuffer,
981 DWORD nNumberOfCharsToWrite,
982 LPDWORD lpNumberOfCharsWritten,
983 LPVOID lpReserved )
985 BOOL ret;
986 LPSTR xstring;
987 DWORD n;
989 n = WideCharToMultiByte(CP_ACP,0,lpBuffer,nNumberOfCharsToWrite,NULL,0,NULL,NULL);
990 xstring=HeapAlloc( GetProcessHeap(), 0, n );
992 n = WideCharToMultiByte(CP_ACP,0,lpBuffer,nNumberOfCharsToWrite,xstring,n,NULL,NULL);
994 /* FIXME: should I check if this is a console handle? */
995 ret= WriteFile(hConsoleOutput, xstring, n,
996 lpNumberOfCharsWritten, NULL);
997 /* FIXME: lpNumberOfCharsWritten should be converted to numofchars in UNICODE */
998 HeapFree( GetProcessHeap(), 0, xstring );
999 return ret;
1003 /***********************************************************************
1004 * ReadConsoleA (KERNEL32.419)
1006 BOOL WINAPI ReadConsoleA( HANDLE hConsoleInput,
1007 LPVOID lpBuffer,
1008 DWORD nNumberOfCharsToRead,
1009 LPDWORD lpNumberOfCharsRead,
1010 LPVOID lpReserved )
1012 DWORD charsread = 0;
1013 LPSTR xbuf = (LPSTR)lpBuffer;
1015 TRACE("(%d,%p,%ld,%p,%p)\n",
1016 hConsoleInput,lpBuffer,nNumberOfCharsToRead,
1017 lpNumberOfCharsRead,lpReserved
1020 CONSOLE_get_input(hConsoleInput,FALSE);
1022 /* FIXME: should we read at least 1 char? The SDK does not say */
1023 while (charsread<nNumberOfCharsToRead)
1025 INPUT_RECORD ir;
1026 DWORD count;
1027 if (!read_console_input( hConsoleInput, &ir, 1, &count, TRUE )) return FALSE;
1028 if (!count) break;
1029 if (ir.EventType != KEY_EVENT) continue;
1030 if (!ir.Event.KeyEvent.bKeyDown) continue;
1031 *xbuf++ = ir.Event.KeyEvent.uChar.AsciiChar;
1032 charsread++;
1034 if (lpNumberOfCharsRead)
1035 *lpNumberOfCharsRead = charsread;
1036 return TRUE;
1039 /***********************************************************************
1040 * ReadConsoleW (KERNEL32.427)
1042 BOOL WINAPI ReadConsoleW( HANDLE hConsoleInput,
1043 LPVOID lpBuffer,
1044 DWORD nNumberOfCharsToRead,
1045 LPDWORD lpNumberOfCharsRead,
1046 LPVOID lpReserved )
1048 BOOL ret;
1049 LPSTR buf = (LPSTR)HeapAlloc(GetProcessHeap(), 0, nNumberOfCharsToRead);
1051 ret = ReadConsoleA(
1052 hConsoleInput,
1053 buf,
1054 nNumberOfCharsToRead,
1055 lpNumberOfCharsRead,
1056 lpReserved
1058 if (ret)
1059 lstrcpynAtoW(lpBuffer,buf,nNumberOfCharsToRead);
1060 HeapFree( GetProcessHeap(), 0, buf );
1061 return ret;
1065 /******************************************************************************
1066 * ReadConsoleInputA [KERNEL32.569] Reads data from a console
1068 * PARAMS
1069 * hConsoleInput [I] Handle to console input buffer
1070 * lpBuffer [O] Address of buffer for read data
1071 * nLength [I] Number of records to read
1072 * lpNumberOfEventsRead [O] Address of number of records read
1074 * RETURNS
1075 * Success: TRUE
1076 * Failure: FALSE
1078 BOOL WINAPI ReadConsoleInputA(HANDLE hConsoleInput, LPINPUT_RECORD lpBuffer,
1079 DWORD nLength, LPDWORD lpNumberOfEventsRead)
1081 if (!nLength)
1083 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = 0;
1084 return TRUE;
1087 /* loop until we get at least one event */
1088 for (;;)
1090 DWORD count;
1091 BOOL ret = read_console_input( hConsoleInput, lpBuffer, nLength, &count, TRUE );
1093 if (!ret) return FALSE;
1094 if (count)
1096 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = count;
1097 return TRUE;
1099 CONSOLE_get_input(hConsoleInput,TRUE);
1100 /*WaitForSingleObject( hConsoleInput, INFINITE32 );*/
1105 /***********************************************************************
1106 * ReadConsoleInputW (KERNEL32.570)
1108 BOOL WINAPI ReadConsoleInputW( HANDLE handle, LPINPUT_RECORD buffer,
1109 DWORD count, LPDWORD read )
1111 /* FIXME: Fix this if we get UNICODE input. */
1112 return ReadConsoleInputA( handle, buffer, count, read );
1116 /***********************************************************************
1117 * FlushConsoleInputBuffer (KERNEL32.132)
1119 BOOL WINAPI FlushConsoleInputBuffer( HANDLE handle )
1121 return read_console_input( handle, NULL, 0, NULL, TRUE );
1125 /***********************************************************************
1126 * PeekConsoleInputA (KERNEL32.550)
1128 * Gets 'count' first events (or less) from input queue.
1130 * Does not need a complex console.
1132 BOOL WINAPI PeekConsoleInputA( HANDLE handle, LPINPUT_RECORD buffer, DWORD count, LPDWORD read )
1134 CONSOLE_get_input(handle,FALSE);
1135 if (!count)
1137 if (read) *read = 0;
1138 return TRUE;
1140 return read_console_input( handle, buffer, count, read, FALSE );
1144 /***********************************************************************
1145 * PeekConsoleInputW (KERNEL32.551)
1147 BOOL WINAPI PeekConsoleInputW(HANDLE hConsoleInput,
1148 LPINPUT_RECORD pirBuffer,
1149 DWORD cInRecords,
1150 LPDWORD lpcRead)
1152 /* FIXME: Hmm. Fix this if we get UNICODE input. */
1153 return PeekConsoleInputA(hConsoleInput,pirBuffer,cInRecords,lpcRead);
1157 /******************************************************************************
1158 * WriteConsoleInputA [KERNEL32.730] Write data to a console input buffer
1161 BOOL WINAPI WriteConsoleInputA( HANDLE handle, INPUT_RECORD *buffer,
1162 DWORD count, LPDWORD written )
1164 BOOL ret = TRUE;
1166 if (written) *written = 0;
1167 while (count && ret)
1169 DWORD len = min( count, REQUEST_MAX_VAR_SIZE/sizeof(INPUT_RECORD) );
1170 SERVER_START_REQ
1172 struct write_console_input_request *req = server_alloc_req( sizeof(*req),
1173 len*sizeof(INPUT_RECORD) );
1174 req->handle = handle;
1175 memcpy( server_data_ptr(req), buffer, len * sizeof(INPUT_RECORD) );
1176 if ((ret = !server_call( REQ_WRITE_CONSOLE_INPUT )))
1178 if (written) *written += req->written;
1179 count -= len;
1180 buffer += len;
1183 SERVER_END_REQ;
1185 return ret;
1188 /******************************************************************************
1189 * WriteConsoleInputW [KERNEL32.731] Write data to a console input buffer
1192 BOOL WINAPI WriteConsoleInputW( HANDLE handle, INPUT_RECORD *buffer,
1193 DWORD count, LPDWORD written )
1195 FIXME("(%d,%p,%ld,%p): stub!\n", handle, buffer, count, written);
1197 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1198 return FALSE;
1202 /***********************************************************************
1203 * SetConsoleTitleA (KERNEL32.476)
1205 * Sets the console title.
1207 * We do not necessarily need to create a complex console for that,
1208 * but should remember the title and set it on creation of the latter.
1209 * (not fixed at this time).
1211 BOOL WINAPI SetConsoleTitleA(LPCSTR title)
1213 size_t len = strlen(title);
1214 HANDLE hcon;
1215 DWORD written;
1216 BOOL ret;
1218 if ((hcon = CreateFileA( "CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL,
1219 OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
1220 return FALSE;
1222 len = min( len, REQUEST_MAX_VAR_SIZE );
1223 SERVER_START_REQ
1225 struct set_console_info_request *req = server_alloc_req( sizeof(*req), len );
1226 req->handle = hcon;
1227 req->mask = SET_CONSOLE_INFO_TITLE;
1228 memcpy( server_data_ptr(req), title, len );
1229 ret = !server_call( REQ_SET_CONSOLE_INFO );
1231 SERVER_END_REQ;
1233 if (ret && CONSOLE_GetPid( hcon ))
1235 /* only set title for complex console (own xterm) */
1236 WriteFile( hcon, "\033]2;", 4, &written, NULL );
1237 WriteFile( hcon, title, strlen(title), &written, NULL );
1238 WriteFile( hcon, "\a", 1, &written, NULL );
1240 CloseHandle( hcon );
1241 return ret;
1245 /******************************************************************************
1246 * SetConsoleTitleW [KERNEL32.477] Sets title bar string for console
1248 * PARAMS
1249 * title [I] Address of new title
1251 * NOTES
1252 * This should not be calling the A version
1254 * RETURNS
1255 * Success: TRUE
1256 * Failure: FALSE
1258 BOOL WINAPI SetConsoleTitleW( LPCWSTR title )
1260 BOOL ret;
1262 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
1263 ret = SetConsoleTitleA(titleA);
1264 HeapFree( GetProcessHeap(), 0, titleA );
1265 return ret;
1268 /******************************************************************************
1269 * SetConsoleCursorPosition [KERNEL32.627]
1270 * Sets the cursor position in console
1272 * PARAMS
1273 * hConsoleOutput [I] Handle of console screen buffer
1274 * dwCursorPosition [I] New cursor position coordinates
1276 * RETURNS STD
1278 BOOL WINAPI SetConsoleCursorPosition( HANDLE hcon, COORD pos )
1280 char xbuf[20];
1281 DWORD xlen;
1283 /* make console complex only if we change lines, not just in the line */
1284 if (pos.Y)
1285 CONSOLE_make_complex(hcon);
1287 TRACE("%d (%dx%d)\n", hcon, pos.X , pos.Y );
1288 /* x are columns, y rows */
1289 if (pos.Y)
1290 /* full screen cursor absolute positioning */
1291 sprintf(xbuf,"%c[%d;%dH", 0x1B, pos.Y+1, pos.X+1);
1292 else
1293 /* relative cursor positioning in line (\r to go to 0) */
1294 sprintf(xbuf,"\r%c[%dC", 0x1B, pos.X);
1295 /* FIXME: store internal if we start using own console buffers */
1296 WriteFile(hcon,xbuf,strlen(xbuf),&xlen,NULL);
1297 return TRUE;
1300 /***********************************************************************
1301 * GetNumberOfConsoleInputEvents (KERNEL32.246)
1303 BOOL WINAPI GetNumberOfConsoleInputEvents(HANDLE hcon,LPDWORD nrofevents)
1305 CONSOLE_get_input (hcon, FALSE);
1307 return read_console_input( hcon, NULL, 0, nrofevents, FALSE );
1310 /***********************************************************************
1311 * GetNumberOfConsoleMouseButtons (KERNEL32.358)
1313 BOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons)
1315 FIXME("(%p): stub\n", nrofbuttons);
1316 *nrofbuttons = 2;
1317 return TRUE;
1320 /******************************************************************************
1321 * GetConsoleCursorInfo [KERNEL32.296] Gets size and visibility of console
1323 * PARAMS
1324 * hcon [I] Handle to console screen buffer
1325 * cinfo [O] Address of cursor information
1327 * RETURNS
1328 * Success: TRUE
1329 * Failure: FALSE
1331 BOOL WINAPI GetConsoleCursorInfo( HANDLE hcon, LPCONSOLE_CURSOR_INFO cinfo )
1333 BOOL ret;
1335 SERVER_START_REQ
1337 struct get_console_info_request *req = server_alloc_req( sizeof(*req), 0 );
1338 req->handle = hcon;
1339 ret = !server_call( REQ_GET_CONSOLE_INFO );
1340 if (ret && cinfo)
1342 cinfo->dwSize = req->cursor_size;
1343 cinfo->bVisible = req->cursor_visible;
1346 SERVER_END_REQ;
1347 return ret;
1351 /******************************************************************************
1352 * SetConsoleCursorInfo [KERNEL32.626] Sets size and visibility of cursor
1354 * RETURNS
1355 * Success: TRUE
1356 * Failure: FALSE
1358 BOOL WINAPI SetConsoleCursorInfo(
1359 HANDLE hcon, /* [in] Handle to console screen buffer */
1360 LPCONSOLE_CURSOR_INFO cinfo) /* [in] Address of cursor information */
1362 char buf[8];
1363 DWORD xlen;
1364 BOOL ret;
1366 CONSOLE_make_complex(hcon);
1367 sprintf(buf,"\033[?25%c",cinfo->bVisible?'h':'l');
1368 WriteFile(hcon,buf,strlen(buf),&xlen,NULL);
1370 SERVER_START_REQ
1372 struct set_console_info_request *req = server_alloc_req( sizeof(*req), 0 );
1373 req->handle = hcon;
1374 req->cursor_size = cinfo->dwSize;
1375 req->cursor_visible = cinfo->bVisible;
1376 req->mask = SET_CONSOLE_INFO_CURSOR;
1377 ret = !server_call( REQ_SET_CONSOLE_INFO );
1379 SERVER_END_REQ;
1380 return ret;
1384 /******************************************************************************
1385 * SetConsoleWindowInfo [KERNEL32.634] Sets size and position of console
1387 * RETURNS
1388 * Success: TRUE
1389 * Failure: FALSE
1391 BOOL WINAPI SetConsoleWindowInfo(
1392 HANDLE hcon, /* [in] Handle to console screen buffer */
1393 BOOL bAbsolute, /* [in] Coordinate type flag */
1394 LPSMALL_RECT window) /* [in] Address of new window rectangle */
1396 FIXME("(%x,%d,%p): stub\n", hcon, bAbsolute, window);
1397 return TRUE;
1401 /******************************************************************************
1402 * SetConsoleTextAttribute [KERNEL32.631] Sets colors for text
1404 * Sets the foreground and background color attributes of characters
1405 * written to the screen buffer.
1407 * RETURNS
1408 * Success: TRUE
1409 * Failure: FALSE
1411 BOOL WINAPI SetConsoleTextAttribute(HANDLE hConsoleOutput,WORD wAttr)
1413 const int colormap[8] = {
1414 0,4,2,6,
1415 1,5,3,7,
1417 DWORD xlen;
1418 char buffer[20];
1420 TRACE("(%d,%d)\n",hConsoleOutput,wAttr);
1421 sprintf(buffer,"%c[0;%s3%d;4%dm",
1423 (wAttr & FOREGROUND_INTENSITY)?"1;":"",
1424 colormap[wAttr&7],
1425 colormap[(wAttr&0x70)>>4]
1427 WriteFile(hConsoleOutput,buffer,strlen(buffer),&xlen,NULL);
1428 return TRUE;
1432 /******************************************************************************
1433 * SetConsoleScreenBufferSize [KERNEL32.630] Changes size of console
1435 * PARAMS
1436 * hConsoleOutput [I] Handle to console screen buffer
1437 * dwSize [I] New size in character rows and cols
1439 * RETURNS
1440 * Success: TRUE
1441 * Failure: FALSE
1443 BOOL WINAPI SetConsoleScreenBufferSize( HANDLE hConsoleOutput,
1444 COORD dwSize )
1446 FIXME("(%d,%dx%d): stub\n",hConsoleOutput,dwSize.X,dwSize.Y);
1447 return TRUE;
1451 /******************************************************************************
1452 * FillConsoleOutputCharacterA [KERNEL32.242]
1454 * PARAMS
1455 * hConsoleOutput [I] Handle to screen buffer
1456 * cCharacter [I] Character to write
1457 * nLength [I] Number of cells to write to
1458 * dwCoord [I] Coords of first cell
1459 * lpNumCharsWritten [O] Pointer to number of cells written
1461 * RETURNS
1462 * Success: TRUE
1463 * Failure: FALSE
1465 BOOL WINAPI FillConsoleOutputCharacterA(
1466 HANDLE hConsoleOutput,
1467 BYTE cCharacter,
1468 DWORD nLength,
1469 COORD dwCoord,
1470 LPDWORD lpNumCharsWritten)
1472 DWORD count;
1473 DWORD xlen;
1475 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
1476 for(count=0;count<nLength;count++)
1477 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
1478 *lpNumCharsWritten = nLength;
1479 return TRUE;
1483 /******************************************************************************
1484 * FillConsoleOutputCharacterW [KERNEL32.243] Writes characters to console
1486 * PARAMS
1487 * hConsoleOutput [I] Handle to screen buffer
1488 * cCharacter [I] Character to write
1489 * nLength [I] Number of cells to write to
1490 * dwCoord [I] Coords of first cell
1491 * lpNumCharsWritten [O] Pointer to number of cells written
1493 * RETURNS
1494 * Success: TRUE
1495 * Failure: FALSE
1497 BOOL WINAPI FillConsoleOutputCharacterW(HANDLE hConsoleOutput,
1498 WCHAR cCharacter,
1499 DWORD nLength,
1500 COORD dwCoord,
1501 LPDWORD lpNumCharsWritten)
1503 DWORD count;
1504 DWORD xlen;
1506 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
1507 /* FIXME: not quite correct ... but the lower part of UNICODE char comes
1508 * first
1510 for(count=0;count<nLength;count++)
1511 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
1512 *lpNumCharsWritten = nLength;
1513 return TRUE;
1517 /******************************************************************************
1518 * FillConsoleOutputAttribute [KERNEL32.241] Sets attributes for console
1520 * PARAMS
1521 * hConsoleOutput [I] Handle to screen buffer
1522 * wAttribute [I] Color attribute to write
1523 * nLength [I] Number of cells to write to
1524 * dwCoord [I] Coords of first cell
1525 * lpNumAttrsWritten [O] Pointer to number of cells written
1527 * RETURNS
1528 * Success: TRUE
1529 * Failure: FALSE
1531 BOOL WINAPI FillConsoleOutputAttribute( HANDLE hConsoleOutput,
1532 WORD wAttribute, DWORD nLength, COORD dwCoord,
1533 LPDWORD lpNumAttrsWritten)
1535 FIXME("(%d,%d,%ld,%dx%d,%p): stub\n", hConsoleOutput,
1536 wAttribute,nLength,dwCoord.X,dwCoord.Y,lpNumAttrsWritten);
1537 *lpNumAttrsWritten = nLength;
1538 return TRUE;
1541 /******************************************************************************
1542 * ReadConsoleOutputCharacterA [KERNEL32.573]
1544 * BUGS
1545 * Unimplemented
1547 BOOL WINAPI ReadConsoleOutputCharacterA(HANDLE hConsoleOutput,
1548 LPSTR lpstr, DWORD dword, COORD coord, LPDWORD lpdword)
1550 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,lpstr,
1551 dword,coord.X,coord.Y,lpdword);
1552 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1553 return FALSE;
1556 /******************************************************************************
1557 * ReadConsoleOutputCharacterW [KERNEL32.574]
1559 * BUGS
1560 * Unimplemented
1562 BOOL WINAPI ReadConsoleOutputCharacterW(HANDLE hConsoleOutput,
1563 LPWSTR lpstr, DWORD dword, COORD coord, LPDWORD lpdword)
1565 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,lpstr,
1566 dword,coord.X,coord.Y,lpdword);
1567 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1568 return FALSE;
1572 /******************************************************************************
1573 * ScrollConsoleScreenBufferA [KERNEL32.612]
1575 * BUGS
1576 * Unimplemented
1578 BOOL WINAPI ScrollConsoleScreenBufferA( HANDLE hConsoleOutput,
1579 LPSMALL_RECT lpScrollRect, LPSMALL_RECT lpClipRect,
1580 COORD dwDestOrigin, LPCHAR_INFO lpFill)
1582 FIXME("(%d,%p,%p,%dx%d,%p): stub\n", hConsoleOutput,lpScrollRect,
1583 lpClipRect,dwDestOrigin.X,dwDestOrigin.Y,lpFill);
1584 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1585 return FALSE;
1588 /******************************************************************************
1589 * ScrollConsoleScreenBufferW [KERNEL32.613]
1591 * BUGS
1592 * Unimplemented
1594 BOOL WINAPI ScrollConsoleScreenBufferW( HANDLE hConsoleOutput,
1595 LPSMALL_RECT lpScrollRect, LPSMALL_RECT lpClipRect,
1596 COORD dwDestOrigin, LPCHAR_INFO lpFill)
1598 FIXME("(%d,%p,%p,%dx%d,%p): stub\n", hConsoleOutput,lpScrollRect,
1599 lpClipRect,dwDestOrigin.X,dwDestOrigin.Y,lpFill);
1600 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1601 return FALSE;
1604 /******************************************************************************
1605 * ReadConsoleOutputA [KERNEL32.571]
1607 * BUGS
1608 * Unimplemented
1610 BOOL WINAPI ReadConsoleOutputA( HANDLE hConsoleOutput,
1611 LPCHAR_INFO lpBuffer,
1612 COORD dwBufferSize,
1613 COORD dwBufferCoord,
1614 LPSMALL_RECT lpReadRegion )
1616 FIXME("(%d,%p,%dx%d,%dx%d,%p): stub\n", hConsoleOutput, lpBuffer,
1617 dwBufferSize.X, dwBufferSize.Y, dwBufferSize.X, dwBufferSize.Y,
1618 lpReadRegion);
1620 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1621 return FALSE;
1624 /******************************************************************************
1625 * ReadConsoleOutputW [KERNEL32.575]
1627 * BUGS
1628 * Unimplemented
1630 BOOL WINAPI ReadConsoleOutputW( HANDLE hConsoleOutput,
1631 LPCHAR_INFO lpBuffer,
1632 COORD dwBufferSize,
1633 COORD dwBufferCoord,
1634 LPSMALL_RECT lpReadRegion )
1636 FIXME("(%d,%p,%dx%d,%dx%d,%p): stub\n", hConsoleOutput, lpBuffer,
1637 dwBufferSize.X, dwBufferSize.Y, dwBufferSize.X, dwBufferSize.Y,
1638 lpReadRegion);
1640 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1641 return FALSE;
1644 /******************************************************************************
1645 * ReadConsoleOutputAttribute [KERNEL32.572]
1647 * BUGS
1648 * Unimplemented
1650 BOOL WINAPI ReadConsoleOutputAttribute( HANDLE hConsoleOutput,
1651 LPWORD lpAttribute,
1652 DWORD nLength,
1653 COORD dwReadCoord,
1654 LPDWORD lpNumberOfAttrsRead)
1656 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput, lpAttribute,
1657 nLength, dwReadCoord.X, dwReadCoord.Y, lpNumberOfAttrsRead);
1659 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1660 return FALSE;
1663 /******************************************************************************
1664 * SetConsoleCP [KERNEL32.572]
1666 * BUGS
1667 * Unimplemented
1669 BOOL WINAPI SetConsoleCP( UINT cp )
1671 FIXME("(%d): stub\n", cp);
1673 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1674 return FALSE;
1677 /******************************************************************************
1678 * SetConsoleInputExeNameW [KERNEL32.889]
1680 * BUGS
1681 * Unimplemented
1683 BOOL WINAPI SetConsoleInputExeNameW( LPCWSTR name )
1685 FIXME("(%s): stub!\n", debugstr_w(name));
1687 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1688 return TRUE;
1691 /******************************************************************************
1692 * SetConsoleInputExeNameA [KERNEL32.888]
1694 * BUGS
1695 * Unimplemented
1697 BOOL WINAPI SetConsoleInputExeNameA( LPCSTR name )
1699 FIXME("(%s): stub!\n", name);
1701 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1702 return TRUE;