Disable DONT_RESOLVE_DLL_REFERENCES for builtin dlls.
[wine/multimedia.git] / win32 / console.c
blobfb1ec7f25fa3a8f80dc3e0f014cd9e0ed70c9839
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( get_console_info )
106 req->handle = handle;
107 if (!SERVER_CALL_ERR()) ret = req->pid;
109 SERVER_END_REQ;
110 return ret;
113 /****************************************************************************
114 * XTERM_string_to_IR [internal]
116 * Transfers a string read from XTERM to INPUT_RECORDs and adds them to the
117 * queue. Does translation of vt100 style function keys and xterm-mouse clicks.
119 static void
120 CONSOLE_string_to_IR( HANDLE hConsoleInput,unsigned char *buf,int len) {
121 int j,k;
122 INPUT_RECORD ir;
123 DWORD junk;
125 for (j=0;j<len;j++) {
126 unsigned char inchar = buf[j];
128 if (inchar!=27) { /* no escape -> 'normal' keyboard event */
129 ir.EventType = 1; /* Key_event */
131 ir.Event.KeyEvent.bKeyDown = 1;
132 ir.Event.KeyEvent.wRepeatCount = 0;
134 ir.Event.KeyEvent.dwControlKeyState = 0;
135 if (inchar & 0x80) {
136 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
137 inchar &= ~0x80;
139 ir.Event.KeyEvent.wVirtualKeyCode = vkkeyscan_table[inchar];
140 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0100)
141 ir.Event.KeyEvent.dwControlKeyState|=SHIFT_PRESSED;
142 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0200)
143 ir.Event.KeyEvent.dwControlKeyState|=LEFT_CTRL_PRESSED;
144 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0400)
145 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
146 ir.Event.KeyEvent.wVirtualScanCode = mapvkey_0[
147 ir.Event.KeyEvent.wVirtualKeyCode & 0x00ff
148 ]; /* VirtualKeyCodes to ScanCode */
149 ir.Event.KeyEvent.uChar.AsciiChar = inchar;
151 if ((inchar==127)||(inchar=='\b')) { /* backspace */
152 ir.Event.KeyEvent.uChar.AsciiChar = '\b'; /* FIXME: hmm */
153 ir.Event.KeyEvent.wVirtualScanCode = 0x0e;
154 ir.Event.KeyEvent.wVirtualKeyCode = VK_BACK;
155 } else {
156 if ((inchar=='\n')||(inchar=='\r')) {
157 ir.Event.KeyEvent.uChar.AsciiChar = '\r';
158 ir.Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
159 ir.Event.KeyEvent.wVirtualScanCode = 0x1c;
160 ir.Event.KeyEvent.dwControlKeyState = 0;
161 } else {
162 if (inchar<' ') {
163 /* FIXME: find good values for ^X */
164 ir.Event.KeyEvent.wVirtualKeyCode = 0xdead;
165 ir.Event.KeyEvent.wVirtualScanCode = 0xbeef;
170 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
171 ir.Event.KeyEvent.bKeyDown = 0;
172 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
173 continue;
175 /* inchar is ESC */
176 if ((j==len-1) || (buf[j+1]!='[')) {/* add ESCape on its own */
177 ir.EventType = 1; /* Key_event */
178 ir.Event.KeyEvent.bKeyDown = 1;
179 ir.Event.KeyEvent.wRepeatCount = 0;
181 ir.Event.KeyEvent.wVirtualKeyCode = VK_ESCAPE;
182 ir.Event.KeyEvent.wVirtualScanCode = mapvkey_0[
183 ir.Event.KeyEvent.wVirtualKeyCode
185 ir.Event.KeyEvent.dwControlKeyState = 0;
186 ir.Event.KeyEvent.uChar.AsciiChar = 27;
187 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
188 ir.Event.KeyEvent.bKeyDown = 0;
189 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
190 continue;
192 for (k=j;k<len;k++) {
193 if (((buf[k]>='A') && (buf[k]<='Z')) ||
194 ((buf[k]>='a') && (buf[k]<='z')) ||
195 (buf[k]=='~')
197 break;
199 if (k<len) {
200 int subid,scancode=0;
202 ir.EventType = 1; /* Key_event */
203 ir.Event.KeyEvent.bKeyDown = 1;
204 ir.Event.KeyEvent.wRepeatCount = 0;
205 ir.Event.KeyEvent.dwControlKeyState = 0;
207 ir.Event.KeyEvent.wVirtualKeyCode = 0xad; /* FIXME */
208 ir.Event.KeyEvent.wVirtualScanCode = 0xad; /* FIXME */
209 ir.Event.KeyEvent.uChar.AsciiChar = 0;
211 switch (buf[k]) {
212 case '~':
213 sscanf(&buf[j+2],"%d",&subid);
214 switch (subid) {
215 case 2:/*INS */scancode = 0xe052;break;
216 case 3:/*DEL */scancode = 0xe053;break;
217 case 6:/*PGDW*/scancode = 0xe051;break;
218 case 5:/*PGUP*/scancode = 0xe049;break;
219 case 11:/*F1 */scancode = 0x003b;break;
220 case 12:/*F2 */scancode = 0x003c;break;
221 case 13:/*F3 */scancode = 0x003d;break;
222 case 14:/*F4 */scancode = 0x003e;break;
223 case 15:/*F5 */scancode = 0x003f;break;
224 case 17:/*F6 */scancode = 0x0040;break;
225 case 18:/*F7 */scancode = 0x0041;break;
226 case 19:/*F8 */scancode = 0x0042;break;
227 case 20:/*F9 */scancode = 0x0043;break;
228 case 21:/*F10 */scancode = 0x0044;break;
229 case 23:/*F11 */scancode = 0x00d9;break;
230 case 24:/*F12 */scancode = 0x00da;break;
231 /* FIXME: Shift-Fx */
232 default:
233 FIXME("parse ESC[%d~\n",subid);
234 break;
236 break;
237 case 'A': /* Cursor Up */scancode = 0xe048;break;
238 case 'B': /* Cursor Down */scancode = 0xe050;break;
239 case 'D': /* Cursor Left */scancode = 0xe04b;break;
240 case 'C': /* Cursor Right */scancode = 0xe04d;break;
241 case 'F': /* End */scancode = 0xe04f;break;
242 case 'H': /* Home */scancode = 0xe047;break;
243 case 'M':
244 /* Mouse Button Press (ESCM<button+'!'><x+'!'><y+'!'>) or
245 * Release (ESCM#<x+'!'><y+'!'>
247 if (k<len-3) {
248 ir.EventType = MOUSE_EVENT;
249 ir.Event.MouseEvent.dwMousePosition.X = buf[k+2]-'!';
250 ir.Event.MouseEvent.dwMousePosition.Y = buf[k+3]-'!';
251 if (buf[k+1]=='#')
252 ir.Event.MouseEvent.dwButtonState = 0;
253 else
254 ir.Event.MouseEvent.dwButtonState = 1<<(buf[k+1]-' ');
255 ir.Event.MouseEvent.dwEventFlags = 0; /* FIXME */
256 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk));
257 j=k+3;
259 break;
260 case 'c':
261 j=k;
262 break;
264 if (scancode) {
265 ir.Event.KeyEvent.wVirtualScanCode = scancode;
266 ir.Event.KeyEvent.wVirtualKeyCode = mapvkey_1[scancode];
267 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
268 ir.Event.KeyEvent.bKeyDown = 0;
269 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
270 j=k;
271 continue;
277 /****************************************************************************
278 * CONSOLE_get_input (internal)
280 * Reads (nonblocking) as much input events as possible and stores them
281 * in an internal queue.
283 static void
284 CONSOLE_get_input( HANDLE handle, BOOL blockwait )
286 char *buf = HeapAlloc(GetProcessHeap(),0,1);
287 int len = 0, escape_seen = 0;
289 while (1)
291 DWORD res;
292 char inchar;
294 /* If we have at one time seen escape in this loop, we are
295 * within an Escape sequence, so wait for a bit more input for the
296 * rest of the loop.
298 if (WaitForSingleObject( handle, escape_seen*10 )) break;
299 if (!ReadFile( handle, &inchar, 1, &res, NULL )) break;
300 if (!res) /* res 0 but readable means EOF? Hmm. */
301 break;
302 buf = HeapReAlloc(GetProcessHeap(),0,buf,len+1);
303 buf[len++]=inchar;
304 if (inchar == 27) {
305 if (len>1) {
306 /* If we spot an ESC, we flush all up to it
307 * since we can be sure that we have a complete
308 * sequence.
310 CONSOLE_string_to_IR(handle,buf,len-1);
311 buf = HeapReAlloc(GetProcessHeap(),0,buf,1);
312 buf[0] = 27;
313 len = 1;
315 escape_seen = 1;
318 CONSOLE_string_to_IR(handle,buf,len);
319 HeapFree(GetProcessHeap(),0,buf);
323 /******************************************************************************
324 * read_console_input
326 * Helper function for ReadConsole, ReadConsoleInput and PeekConsoleInput
328 static BOOL read_console_input( HANDLE handle, LPINPUT_RECORD buffer, DWORD count,
329 LPDWORD read, BOOL flush )
331 BOOL ret;
333 count = min( count, REQUEST_MAX_VAR_SIZE/sizeof(INPUT_RECORD) );
335 SERVER_START_VAR_REQ( read_console_input, count*sizeof(INPUT_RECORD) )
337 req->handle = handle;
338 req->flush = flush;
339 if ((ret = !SERVER_CALL_ERR()))
341 if (count) memcpy( buffer, server_data_ptr(req), server_data_size(req) );
342 if (read) *read = req->read;
345 SERVER_END_VAR_REQ;
346 return ret;
350 /******************************************************************************
351 * SetConsoleCtrlHandler [KERNEL32.@] Adds function to calling process list
353 * PARAMS
354 * func [I] Address of handler function
355 * add [I] Handler to add or remove
357 * RETURNS
358 * Success: TRUE
359 * Failure: FALSE
361 * CHANGED
362 * James Sutherland (JamesSutherland@gmx.de)
363 * Added global variables console_ignore_ctrl_c and handlers[]
364 * Does not yet do any error checking, or set LastError if failed.
365 * This doesn't yet matter, since these handlers are not yet called...!
367 static unsigned int console_ignore_ctrl_c = 0;
368 static HANDLER_ROUTINE *handlers[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
369 BOOL WINAPI SetConsoleCtrlHandler( HANDLER_ROUTINE *func, BOOL add )
371 unsigned int alloc_loop = sizeof(handlers)/sizeof(HANDLER_ROUTINE *);
372 unsigned int done = 0;
373 FIXME("(%p,%i) - no error checking or testing yet\n", func, add);
374 if (!func)
376 console_ignore_ctrl_c = add;
377 return TRUE;
379 if (add)
381 for (;alloc_loop--;)
382 if (!handlers[alloc_loop] && !done)
384 handlers[alloc_loop] = func;
385 done++;
387 if (!done)
388 FIXME("Out of space on CtrlHandler table\n");
389 return(done);
391 else
393 for (;alloc_loop--;)
394 if (handlers[alloc_loop] == func && !done)
396 handlers[alloc_loop] = 0;
397 done++;
399 if (!done)
400 WARN("Attempt to remove non-installed CtrlHandler %p\n",
401 func);
402 return (done);
404 return (done);
408 /******************************************************************************
409 * GenerateConsoleCtrlEvent [KERNEL32.275] Simulate a CTRL-C or CTRL-BREAK
411 * PARAMS
412 * dwCtrlEvent [I] Type of event
413 * dwProcessGroupID [I] Process group ID to send event to
415 * NOTES
416 * Doesn't yet work...!
418 * RETURNS
419 * Success: True
420 * Failure: False (and *should* [but doesn't] set LastError)
422 BOOL WINAPI GenerateConsoleCtrlEvent( DWORD dwCtrlEvent,
423 DWORD dwProcessGroupID )
425 if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
427 ERR("invalid event %d for PGID %ld\n",
428 (unsigned short)dwCtrlEvent, dwProcessGroupID );
429 return FALSE;
431 if (dwProcessGroupID == GetCurrentProcessId() )
433 FIXME("Attempt to send event %d to self - stub\n",
434 (unsigned short)dwCtrlEvent );
435 return FALSE;
437 FIXME("event %d to external PGID %ld - not implemented yet\n",
438 (unsigned short)dwCtrlEvent, dwProcessGroupID );
439 return FALSE;
443 /******************************************************************************
444 * CreateConsoleScreenBuffer [KERNEL32.151] Creates a console screen buffer
446 * PARAMS
447 * dwDesiredAccess [I] Access flag
448 * dwShareMode [I] Buffer share mode
449 * sa [I] Security attributes
450 * dwFlags [I] Type of buffer to create
451 * lpScreenBufferData [I] Reserved
453 * NOTES
454 * Should call SetLastError
456 * RETURNS
457 * Success: Handle to new console screen buffer
458 * Failure: INVALID_HANDLE_VALUE
460 HANDLE WINAPI CreateConsoleScreenBuffer( DWORD dwDesiredAccess,
461 DWORD dwShareMode, LPSECURITY_ATTRIBUTES sa,
462 DWORD dwFlags, LPVOID lpScreenBufferData )
464 FIXME("(%ld,%ld,%p,%ld,%p): stub\n",dwDesiredAccess,
465 dwShareMode, sa, dwFlags, lpScreenBufferData);
466 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
467 return INVALID_HANDLE_VALUE;
471 /***********************************************************************
472 * GetConsoleScreenBufferInfo (KERNEL32.@)
474 BOOL WINAPI GetConsoleScreenBufferInfo( HANDLE hConsoleOutput,
475 LPCONSOLE_SCREEN_BUFFER_INFO csbi )
477 csbi->dwSize.X = 80;
478 csbi->dwSize.Y = 24;
479 csbi->dwCursorPosition.X = 0;
480 csbi->dwCursorPosition.Y = 0;
481 csbi->wAttributes = 0;
482 csbi->srWindow.Left = 0;
483 csbi->srWindow.Right = 79;
484 csbi->srWindow.Top = 0;
485 csbi->srWindow.Bottom = 23;
486 csbi->dwMaximumWindowSize.X = 80;
487 csbi->dwMaximumWindowSize.Y = 24;
488 return TRUE;
492 /******************************************************************************
493 * SetConsoleActiveScreenBuffer [KERNEL32.623] Sets buffer to current console
495 * RETURNS
496 * Success: TRUE
497 * Failure: FALSE
499 BOOL WINAPI SetConsoleActiveScreenBuffer(
500 HANDLE hConsoleOutput) /* [in] Handle to console screen buffer */
502 FIXME("(%x): stub\n", hConsoleOutput);
503 return FALSE;
507 /***********************************************************************
508 * GetLargestConsoleWindowSize (KERNEL32.@)
510 * NOTE
511 * This should return a COORD, but calling convention for returning
512 * structures is different between Windows and gcc on i386.
514 * VERSION: [i386]
516 #ifdef __i386__
517 #undef GetLargestConsoleWindowSize
518 DWORD WINAPI GetLargestConsoleWindowSize( HANDLE hConsoleOutput )
520 COORD c;
521 c.X = 80;
522 c.Y = 24;
523 return *(DWORD *)&c;
525 #endif /* defined(__i386__) */
528 /***********************************************************************
529 * GetLargestConsoleWindowSize (KERNEL32.@)
531 * NOTE
532 * This should return a COORD, but calling convention for returning
533 * structures is different between Windows and gcc on i386.
535 * VERSION: [!i386]
537 #ifndef __i386__
538 COORD WINAPI GetLargestConsoleWindowSize( HANDLE hConsoleOutput )
540 COORD c;
541 c.X = 80;
542 c.Y = 24;
543 return c;
545 #endif /* defined(__i386__) */
548 /***********************************************************************
549 * FreeConsole (KERNEL32.267)
551 BOOL WINAPI FreeConsole(VOID)
553 BOOL ret;
554 SERVER_START_REQ( free_console )
556 ret = !SERVER_CALL_ERR();
558 SERVER_END_REQ;
559 return ret;
563 /*************************************************************************
564 * CONSOLE_make_complex [internal]
566 * Turns a CONSOLE kernel object into a complex one.
567 * (switches from output/input using the terminal where WINE was started to
568 * its own xterm).
570 * This makes simple commandline tools pipeable, while complex commandline
571 * tools work without getting messed up by debugoutput.
573 * All other functions should work independently from this call.
575 * To test for complex console: pid == 0 -> simple, otherwise complex.
577 static BOOL CONSOLE_make_complex(HANDLE handle)
579 struct termios term;
580 char buf[256];
581 char c = '\0';
582 int i,xpid,master,slave;
583 HANDLE pty_handle;
585 if (CONSOLE_GetPid( handle )) return TRUE; /* already complex */
587 MESSAGE("Console: Making console complex (creating an xterm)...\n");
589 if (tcgetattr(0, &term) < 0) {
590 /* ignore failure, or we can't run from a script */
592 term.c_lflag = ~(ECHO|ICANON);
594 if (wine_openpty(&master, &slave, NULL, &term, NULL) < 0)
595 return FALSE;
597 if ((xpid=fork()) == 0) {
598 tcsetattr(slave, TCSADRAIN, &term);
599 close( slave );
600 sprintf(buf, "-Sxx%d", master);
601 /* "-fn vga" for VGA font. Harmless if vga is not present:
602 * xterm: unable to open font "vga", trying "fixed"....
604 execlp("xterm", "xterm", buf, "-fn","vga",NULL);
605 ERR("error creating AllocConsole xterm\n");
606 exit(1);
608 pty_handle = FILE_DupUnixHandle( slave, GENERIC_READ | GENERIC_WRITE );
609 close( master );
610 close( slave );
611 if (!pty_handle) return FALSE;
613 /* most xterms like to print their window ID when used with -S;
614 * read it and continue before the user has a chance...
616 for (i = 0; i < 10000; i++)
618 BOOL ok = ReadFile( pty_handle, &c, 1, NULL, NULL );
619 if (!ok && !c) usleep(100); /* wait for xterm to be created */
620 else if (c == '\n') break;
622 if (i == 10000)
624 ERR("can't read xterm WID\n");
625 CloseHandle( pty_handle );
626 return FALSE;
628 SERVER_START_REQ( set_console_fd )
630 req->handle = handle;
631 req->handle_in = pty_handle;
632 req->handle_out = pty_handle;
633 req->pid = xpid;
634 SERVER_CALL();
636 SERVER_END_REQ;
637 CloseHandle( pty_handle );
639 /* enable mouseclicks */
640 strcpy( buf, "\033[?1002h" );
641 WriteFile(handle,buf,strlen(buf),NULL,NULL);
643 strcpy( buf, "\033]2;" );
644 if (GetConsoleTitleA( buf + 4, sizeof(buf) - 5 ))
646 strcat( buf, "\a" );
647 WriteFile(handle,buf,strlen(buf),NULL,NULL);
649 return TRUE;
654 /***********************************************************************
655 * AllocConsole (KERNEL32.103)
657 * creates an xterm with a pty to our program
659 BOOL WINAPI AllocConsole(VOID)
661 BOOL ret;
662 HANDLE hStderr;
663 int handle_in, handle_out;
665 TRACE("()\n");
667 SERVER_START_REQ( alloc_console )
669 req->access = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE;
670 req->inherit = FALSE;
671 ret = !SERVER_CALL_ERR();
672 handle_in = req->handle_in;
673 handle_out = req->handle_out;
675 SERVER_END_REQ;
676 if (!ret) return FALSE;
678 if (!DuplicateHandle( GetCurrentProcess(), handle_out, GetCurrentProcess(), &hStderr,
679 0, TRUE, DUPLICATE_SAME_ACCESS ))
681 CloseHandle( handle_in );
682 CloseHandle( handle_out );
683 FreeConsole();
684 return FALSE;
687 /* NT resets the STD_*_HANDLEs on console alloc */
688 SetStdHandle( STD_INPUT_HANDLE, handle_in );
689 SetStdHandle( STD_OUTPUT_HANDLE, handle_out );
690 SetStdHandle( STD_ERROR_HANDLE, hStderr );
692 SetLastError(ERROR_SUCCESS);
693 SetConsoleTitleA("Wine Console");
694 return TRUE;
698 /******************************************************************************
699 * GetConsoleCP [KERNEL32.295] Returns the OEM code page for the console
701 * RETURNS
702 * Code page code
704 UINT WINAPI GetConsoleCP(VOID)
706 return GetACP();
710 /***********************************************************************
711 * GetConsoleOutputCP (KERNEL32.@)
713 UINT WINAPI GetConsoleOutputCP(VOID)
715 return GetConsoleCP();
718 /***********************************************************************
719 * GetConsoleMode (KERNEL32.@)
721 BOOL WINAPI GetConsoleMode(HANDLE hcon,LPDWORD mode)
723 BOOL ret;
724 SERVER_START_REQ( get_console_mode )
726 req->handle = hcon;
727 ret = !SERVER_CALL_ERR();
728 if (ret && mode) *mode = req->mode;
730 SERVER_END_REQ;
731 return ret;
735 /******************************************************************************
736 * SetConsoleMode [KERNEL32.628] Sets input mode of console's input buffer
738 * PARAMS
739 * hcon [I] Handle to console input or screen buffer
740 * mode [I] Input or output mode to set
742 * RETURNS
743 * Success: TRUE
744 * Failure: FALSE
746 BOOL WINAPI SetConsoleMode( HANDLE hcon, DWORD mode )
748 BOOL ret;
749 SERVER_START_REQ( set_console_mode )
751 req->handle = hcon;
752 req->mode = mode;
753 ret = !SERVER_CALL_ERR();
755 SERVER_END_REQ;
756 return ret;
760 /******************************************************************************
761 * SetConsoleOutputCP [KERNEL32.629] Set the output codepage used by the console
763 * PARAMS
764 * cp [I] code page to set
766 * RETURNS
767 * Success: TRUE
768 * Failure: FALSE
770 BOOL WINAPI SetConsoleOutputCP( UINT cp )
772 FIXME("stub\n");
773 return TRUE;
777 /***********************************************************************
778 * GetConsoleTitleA (KERNEL32.@)
780 DWORD WINAPI GetConsoleTitleA(LPSTR title,DWORD size)
782 DWORD ret = 0;
783 HANDLE hcon;
785 if ((hcon = CreateFileA( "CONOUT$", GENERIC_READ, 0, NULL,
786 OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
787 return 0;
788 SERVER_START_VAR_REQ( get_console_info, REQUEST_MAX_VAR_SIZE )
790 req->handle = hcon;
791 if (!SERVER_CALL_ERR())
793 ret = server_data_size(req);
794 size = min( size-1, ret );
795 memcpy( title, server_data_ptr(req), size );
796 title[size] = 0;
799 SERVER_END_VAR_REQ;
800 CloseHandle( hcon );
801 return ret;
805 /******************************************************************************
806 * GetConsoleTitleW [KERNEL32.@] Retrieves title string for console
808 * PARAMS
809 * title [O] Address of buffer for title
810 * size [I] Size of buffer
812 * RETURNS
813 * Success: Length of string copied
814 * Failure: 0
816 DWORD WINAPI GetConsoleTitleW( LPWSTR title, DWORD size )
818 char *tmp;
819 DWORD ret;
821 if (!(tmp = HeapAlloc( GetProcessHeap(), 0, size*sizeof(WCHAR) ))) return 0;
822 GetConsoleTitleA( tmp, size*sizeof(WCHAR) );
823 ret = MultiByteToWideChar( CP_ACP, 0, tmp, -1, title, size );
824 HeapFree( GetProcessHeap(), 0, tmp );
825 return ret;
829 /***********************************************************************
830 * WriteConsoleA (KERNEL32.729)
832 BOOL WINAPI WriteConsoleA( HANDLE hConsoleOutput,
833 LPCVOID lpBuffer,
834 DWORD nNumberOfCharsToWrite,
835 LPDWORD lpNumberOfCharsWritten,
836 LPVOID lpReserved )
838 /* FIXME: should I check if this is a console handle? */
839 return WriteFile(hConsoleOutput, lpBuffer, nNumberOfCharsToWrite,
840 lpNumberOfCharsWritten, NULL);
844 #define CADD(c) \
845 if (bufused==curbufsize-1) \
846 buffer = HeapReAlloc(GetProcessHeap(),0,buffer,(curbufsize+=100));\
847 buffer[bufused++]=c;
848 #define SADD(s) { char *x=s;while (*x) {CADD(*x);x++;}}
850 /***********************************************************************
851 * WriteConsoleOutputA (KERNEL32.732)
853 BOOL WINAPI WriteConsoleOutputA( HANDLE hConsoleOutput,
854 LPCHAR_INFO lpBuffer,
855 COORD dwBufferSize,
856 COORD dwBufferCoord,
857 LPSMALL_RECT lpWriteRegion)
859 int i,j,off=0,lastattr=-1;
860 int offbase;
861 char sbuf[20],*buffer=NULL;
862 int bufused=0,curbufsize = 100;
863 DWORD res;
864 CONSOLE_SCREEN_BUFFER_INFO csbi;
865 const int colormap[8] = {
866 0,4,2,6,
867 1,5,3,7,
869 CONSOLE_make_complex(hConsoleOutput);
870 buffer = HeapAlloc(GetProcessHeap(),0,curbufsize);
871 offbase = (dwBufferCoord.Y - 1) * dwBufferSize.X +
872 (dwBufferCoord.X - lpWriteRegion->Left);
874 TRACE("orig rect top = %d, bottom=%d, left=%d, right=%d\n",
875 lpWriteRegion->Top,
876 lpWriteRegion->Bottom,
877 lpWriteRegion->Left,
878 lpWriteRegion->Right
881 GetConsoleScreenBufferInfo(hConsoleOutput, &csbi);
882 sprintf(sbuf,"%c7",27);SADD(sbuf);
884 /* Step 1. Make (Bottom,Right) offset of intersection with
885 Screen Buffer */
886 lpWriteRegion->Bottom = min(lpWriteRegion->Bottom, csbi.dwSize.Y-1) -
887 lpWriteRegion->Top;
888 lpWriteRegion->Right = min(lpWriteRegion->Right, csbi.dwSize.X-1) -
889 lpWriteRegion->Left;
891 /* Step 2. If either offset is negative, then no action
892 should be performed. (Implies that requested rectangle is
893 outside the current screen buffer rectangle.) */
894 if ((lpWriteRegion->Bottom < 0) ||
895 (lpWriteRegion->Right < 0)) {
896 /* readjust (Bottom Right) for rectangle */
897 lpWriteRegion->Bottom += lpWriteRegion->Top;
898 lpWriteRegion->Right += lpWriteRegion->Left;
900 TRACE("invisible rect top = %d, bottom=%d, left=%d, right=%d\n",
901 lpWriteRegion->Top,
902 lpWriteRegion->Bottom,
903 lpWriteRegion->Left,
904 lpWriteRegion->Right
907 HeapFree(GetProcessHeap(),0,buffer);
908 return TRUE;
911 /* Step 3. Intersect with source rectangle */
912 lpWriteRegion->Bottom = lpWriteRegion->Top - dwBufferCoord.Y +
913 min(lpWriteRegion->Bottom + dwBufferCoord.Y, dwBufferSize.Y-1);
914 lpWriteRegion->Right = lpWriteRegion->Left - dwBufferCoord.X +
915 min(lpWriteRegion->Right + dwBufferCoord.X, dwBufferSize.X-1);
917 TRACE("clipped rect top = %d, bottom=%d, left=%d,right=%d\n",
918 lpWriteRegion->Top,
919 lpWriteRegion->Bottom,
920 lpWriteRegion->Left,
921 lpWriteRegion->Right
924 /* Validate above computations made sense, if not then issue
925 error and fudge to single character rectangle */
926 if ((lpWriteRegion->Bottom < lpWriteRegion->Top) ||
927 (lpWriteRegion->Right < lpWriteRegion->Left)) {
928 ERR("Invalid clipped rectangle top = %d, bottom=%d, left=%d,right=%d\n",
929 lpWriteRegion->Top,
930 lpWriteRegion->Bottom,
931 lpWriteRegion->Left,
932 lpWriteRegion->Right
934 lpWriteRegion->Bottom = lpWriteRegion->Top;
935 lpWriteRegion->Right = lpWriteRegion->Left;
938 /* Now do the real processing and move the characters */
939 for (i=lpWriteRegion->Top;i<=lpWriteRegion->Bottom;i++) {
940 offbase += dwBufferSize.X;
941 sprintf(sbuf,"%c[%d;%dH",27,i+1,lpWriteRegion->Left+1);
942 SADD(sbuf);
943 for (j=lpWriteRegion->Left;j<=lpWriteRegion->Right;j++) {
944 off = j + offbase;
945 if (lastattr!=lpBuffer[off].Attributes) {
946 lastattr = lpBuffer[off].Attributes;
947 sprintf(sbuf,"%c[0;%s3%d;4%dm",
949 (lastattr & FOREGROUND_INTENSITY)?"1;":"",
950 colormap[lastattr&7],
951 colormap[(lastattr&0x70)>>4]
953 /* FIXME: BACKGROUND_INTENSITY */
954 SADD(sbuf);
956 CADD(lpBuffer[off].Char.AsciiChar);
959 sprintf(sbuf,"%c[0m%c8",27,27);SADD(sbuf);
960 WriteFile(hConsoleOutput,buffer,bufused,&res,NULL);
961 HeapFree(GetProcessHeap(),0,buffer);
962 return TRUE;
965 /***********************************************************************
966 * WriteConsoleOutputW (KERNEL32.@)
968 BOOL WINAPI WriteConsoleOutputW( HANDLE hConsoleOutput,
969 LPCHAR_INFO lpBuffer,
970 COORD dwBufferSize,
971 COORD dwBufferCoord,
972 LPSMALL_RECT lpWriteRegion)
974 FIXME("(%d,%p,%dx%d,%dx%d,%p): stub\n", hConsoleOutput, lpBuffer,
975 dwBufferSize.X,dwBufferSize.Y,dwBufferCoord.X,dwBufferCoord.Y,lpWriteRegion);
977 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
978 return FALSE;
981 /***********************************************************************
982 * WriteConsoleW (KERNEL32.@)
984 BOOL WINAPI WriteConsoleW( HANDLE hConsoleOutput,
985 LPCVOID lpBuffer,
986 DWORD nNumberOfCharsToWrite,
987 LPDWORD lpNumberOfCharsWritten,
988 LPVOID lpReserved )
990 BOOL ret;
991 LPSTR xstring;
992 DWORD n;
994 n = WideCharToMultiByte(CP_ACP,0,lpBuffer,nNumberOfCharsToWrite,NULL,0,NULL,NULL);
995 xstring=HeapAlloc( GetProcessHeap(), 0, n );
997 n = WideCharToMultiByte(CP_ACP,0,lpBuffer,nNumberOfCharsToWrite,xstring,n,NULL,NULL);
999 /* FIXME: should I check if this is a console handle? */
1000 ret= WriteFile(hConsoleOutput, xstring, n,
1001 lpNumberOfCharsWritten, NULL);
1002 /* FIXME: lpNumberOfCharsWritten should be converted to numofchars in UNICODE */
1003 HeapFree( GetProcessHeap(), 0, xstring );
1004 return ret;
1008 /***********************************************************************
1009 * ReadConsoleA (KERNEL32.@)
1011 BOOL WINAPI ReadConsoleA( HANDLE hConsoleInput,
1012 LPVOID lpBuffer,
1013 DWORD nNumberOfCharsToRead,
1014 LPDWORD lpNumberOfCharsRead,
1015 LPVOID lpReserved )
1017 DWORD charsread = 0;
1018 LPSTR xbuf = (LPSTR)lpBuffer;
1020 TRACE("(%d,%p,%ld,%p,%p)\n",
1021 hConsoleInput,lpBuffer,nNumberOfCharsToRead,
1022 lpNumberOfCharsRead,lpReserved
1025 CONSOLE_get_input(hConsoleInput,FALSE);
1027 /* FIXME: should we read at least 1 char? The SDK does not say */
1028 while (charsread<nNumberOfCharsToRead)
1030 INPUT_RECORD ir;
1031 DWORD count;
1032 if (!read_console_input( hConsoleInput, &ir, 1, &count, TRUE )) return FALSE;
1033 if (!count) break;
1034 if (ir.EventType != KEY_EVENT) continue;
1035 if (!ir.Event.KeyEvent.bKeyDown) continue;
1036 *xbuf++ = ir.Event.KeyEvent.uChar.AsciiChar;
1037 charsread++;
1039 if (lpNumberOfCharsRead)
1040 *lpNumberOfCharsRead = charsread;
1041 return TRUE;
1044 /***********************************************************************
1045 * ReadConsoleW (KERNEL32.@)
1047 BOOL WINAPI ReadConsoleW( HANDLE hConsoleInput,
1048 LPVOID lpBuffer,
1049 DWORD nNumberOfCharsToRead,
1050 LPDWORD lpNumberOfCharsRead,
1051 LPVOID lpReserved )
1053 BOOL ret;
1054 LPSTR buf = (LPSTR)HeapAlloc(GetProcessHeap(), 0, nNumberOfCharsToRead);
1056 ret = ReadConsoleA(
1057 hConsoleInput,
1058 buf,
1059 nNumberOfCharsToRead,
1060 lpNumberOfCharsRead,
1061 lpReserved
1063 if (ret)
1064 MultiByteToWideChar( CP_ACP, 0, buf, -1, lpBuffer, nNumberOfCharsToRead );
1066 HeapFree( GetProcessHeap(), 0, buf );
1067 return ret;
1071 /******************************************************************************
1072 * ReadConsoleInputA [KERNEL32.569] Reads data from a console
1074 * PARAMS
1075 * hConsoleInput [I] Handle to console input buffer
1076 * lpBuffer [O] Address of buffer for read data
1077 * nLength [I] Number of records to read
1078 * lpNumberOfEventsRead [O] Address of number of records read
1080 * RETURNS
1081 * Success: TRUE
1082 * Failure: FALSE
1084 BOOL WINAPI ReadConsoleInputA(HANDLE hConsoleInput, LPINPUT_RECORD lpBuffer,
1085 DWORD nLength, LPDWORD lpNumberOfEventsRead)
1087 if (!nLength)
1089 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = 0;
1090 return TRUE;
1093 /* loop until we get at least one event */
1094 for (;;)
1096 DWORD count;
1097 BOOL ret = read_console_input( hConsoleInput, lpBuffer, nLength, &count, TRUE );
1099 if (!ret) return FALSE;
1100 if (count)
1102 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = count;
1103 return TRUE;
1105 CONSOLE_get_input(hConsoleInput,TRUE);
1106 /*WaitForSingleObject( hConsoleInput, INFINITE32 );*/
1111 /***********************************************************************
1112 * ReadConsoleInputW (KERNEL32.570)
1114 BOOL WINAPI ReadConsoleInputW( HANDLE handle, LPINPUT_RECORD buffer,
1115 DWORD count, LPDWORD read )
1117 /* FIXME: Fix this if we get UNICODE input. */
1118 return ReadConsoleInputA( handle, buffer, count, read );
1122 /***********************************************************************
1123 * FlushConsoleInputBuffer (KERNEL32.@)
1125 BOOL WINAPI FlushConsoleInputBuffer( HANDLE handle )
1127 return read_console_input( handle, NULL, 0, NULL, TRUE );
1131 /***********************************************************************
1132 * PeekConsoleInputA (KERNEL32.550)
1134 * Gets 'count' first events (or less) from input queue.
1136 * Does not need a complex console.
1138 BOOL WINAPI PeekConsoleInputA( HANDLE handle, LPINPUT_RECORD buffer, DWORD count, LPDWORD read )
1140 CONSOLE_get_input(handle,FALSE);
1141 if (!count)
1143 if (read) *read = 0;
1144 return TRUE;
1146 return read_console_input( handle, buffer, count, read, FALSE );
1150 /***********************************************************************
1151 * PeekConsoleInputW (KERNEL32.551)
1153 BOOL WINAPI PeekConsoleInputW(HANDLE hConsoleInput,
1154 LPINPUT_RECORD pirBuffer,
1155 DWORD cInRecords,
1156 LPDWORD lpcRead)
1158 /* FIXME: Hmm. Fix this if we get UNICODE input. */
1159 return PeekConsoleInputA(hConsoleInput,pirBuffer,cInRecords,lpcRead);
1163 /******************************************************************************
1164 * WriteConsoleInputA [KERNEL32.730] Write data to a console input buffer
1167 BOOL WINAPI WriteConsoleInputA( HANDLE handle, INPUT_RECORD *buffer,
1168 DWORD count, LPDWORD written )
1170 BOOL ret = TRUE;
1172 if (written) *written = 0;
1173 while (count && ret)
1175 DWORD len = min( count, REQUEST_MAX_VAR_SIZE/sizeof(INPUT_RECORD) );
1176 SERVER_START_VAR_REQ( write_console_input, len * sizeof(INPUT_RECORD) )
1178 req->handle = handle;
1179 memcpy( server_data_ptr(req), buffer, len * sizeof(INPUT_RECORD) );
1180 if ((ret = !SERVER_CALL_ERR()))
1182 if (written) *written += req->written;
1183 count -= len;
1184 buffer += len;
1187 SERVER_END_VAR_REQ;
1189 return ret;
1192 /******************************************************************************
1193 * WriteConsoleInputW [KERNEL32.731] Write data to a console input buffer
1196 BOOL WINAPI WriteConsoleInputW( HANDLE handle, INPUT_RECORD *buffer,
1197 DWORD count, LPDWORD written )
1199 FIXME("(%d,%p,%ld,%p): stub!\n", handle, buffer, count, written);
1201 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1202 return FALSE;
1206 /***********************************************************************
1207 * SetConsoleTitleA (KERNEL32.@)
1209 * Sets the console title.
1211 * We do not necessarily need to create a complex console for that,
1212 * but should remember the title and set it on creation of the latter.
1213 * (not fixed at this time).
1215 BOOL WINAPI SetConsoleTitleA(LPCSTR title)
1217 size_t len = strlen(title);
1218 HANDLE hcon;
1219 DWORD written;
1220 BOOL ret;
1222 if ((hcon = CreateFileA( "CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL,
1223 OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
1224 return FALSE;
1226 len = min( len, REQUEST_MAX_VAR_SIZE );
1227 SERVER_START_VAR_REQ( set_console_info, len )
1229 req->handle = hcon;
1230 req->mask = SET_CONSOLE_INFO_TITLE;
1231 memcpy( server_data_ptr(req), title, len );
1232 ret = !SERVER_CALL_ERR();
1234 SERVER_END_VAR_REQ;
1236 if (ret && CONSOLE_GetPid( hcon ))
1238 /* only set title for complex console (own xterm) */
1239 WriteFile( hcon, "\033]2;", 4, &written, NULL );
1240 WriteFile( hcon, title, strlen(title), &written, NULL );
1241 WriteFile( hcon, "\a", 1, &written, NULL );
1243 CloseHandle( hcon );
1244 return ret;
1248 /******************************************************************************
1249 * SetConsoleTitleW [KERNEL32.@] Sets title bar string for console
1251 * PARAMS
1252 * title [I] Address of new title
1254 * NOTES
1255 * This should not be calling the A version
1257 * RETURNS
1258 * Success: TRUE
1259 * Failure: FALSE
1261 BOOL WINAPI SetConsoleTitleW( LPCWSTR title )
1263 BOOL ret;
1265 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
1266 ret = SetConsoleTitleA(titleA);
1267 HeapFree( GetProcessHeap(), 0, titleA );
1268 return ret;
1271 /******************************************************************************
1272 * SetConsoleCursorPosition [KERNEL32.627]
1273 * Sets the cursor position in console
1275 * PARAMS
1276 * hConsoleOutput [I] Handle of console screen buffer
1277 * dwCursorPosition [I] New cursor position coordinates
1279 * RETURNS STD
1281 BOOL WINAPI SetConsoleCursorPosition( HANDLE hcon, COORD pos )
1283 char xbuf[20];
1284 DWORD xlen;
1286 /* make console complex only if we change lines, not just in the line */
1287 if (pos.Y)
1288 CONSOLE_make_complex(hcon);
1290 TRACE("%d (%dx%d)\n", hcon, pos.X , pos.Y );
1291 /* x are columns, y rows */
1292 if (pos.Y)
1293 /* full screen cursor absolute positioning */
1294 sprintf(xbuf,"%c[%d;%dH", 0x1B, pos.Y+1, pos.X+1);
1295 else
1296 /* relative cursor positioning in line (\r to go to 0) */
1297 sprintf(xbuf,"\r%c[%dC", 0x1B, pos.X);
1298 /* FIXME: store internal if we start using own console buffers */
1299 WriteFile(hcon,xbuf,strlen(xbuf),&xlen,NULL);
1300 return TRUE;
1303 /***********************************************************************
1304 * GetNumberOfConsoleInputEvents (KERNEL32.@)
1306 BOOL WINAPI GetNumberOfConsoleInputEvents(HANDLE hcon,LPDWORD nrofevents)
1308 CONSOLE_get_input (hcon, FALSE);
1310 return read_console_input( hcon, NULL, 0, nrofevents, FALSE );
1313 /***********************************************************************
1314 * GetNumberOfConsoleMouseButtons (KERNEL32.358)
1316 BOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons)
1318 FIXME("(%p): stub\n", nrofbuttons);
1319 *nrofbuttons = 2;
1320 return TRUE;
1323 /******************************************************************************
1324 * GetConsoleCursorInfo [KERNEL32.296] Gets size and visibility of console
1326 * PARAMS
1327 * hcon [I] Handle to console screen buffer
1328 * cinfo [O] Address of cursor information
1330 * RETURNS
1331 * Success: TRUE
1332 * Failure: FALSE
1334 BOOL WINAPI GetConsoleCursorInfo( HANDLE hcon, LPCONSOLE_CURSOR_INFO cinfo )
1336 BOOL ret;
1338 SERVER_START_REQ( get_console_info )
1340 req->handle = hcon;
1341 ret = !SERVER_CALL_ERR();
1342 if (ret && cinfo)
1344 cinfo->dwSize = req->cursor_size;
1345 cinfo->bVisible = req->cursor_visible;
1348 SERVER_END_REQ;
1349 return ret;
1353 /******************************************************************************
1354 * SetConsoleCursorInfo [KERNEL32.626] Sets size and visibility of cursor
1356 * RETURNS
1357 * Success: TRUE
1358 * Failure: FALSE
1360 BOOL WINAPI SetConsoleCursorInfo(
1361 HANDLE hcon, /* [in] Handle to console screen buffer */
1362 LPCONSOLE_CURSOR_INFO cinfo) /* [in] Address of cursor information */
1364 char buf[8];
1365 DWORD xlen;
1366 BOOL ret;
1368 CONSOLE_make_complex(hcon);
1369 sprintf(buf,"\033[?25%c",cinfo->bVisible?'h':'l');
1370 WriteFile(hcon,buf,strlen(buf),&xlen,NULL);
1372 SERVER_START_REQ( set_console_info )
1374 req->handle = hcon;
1375 req->cursor_size = cinfo->dwSize;
1376 req->cursor_visible = cinfo->bVisible;
1377 req->mask = SET_CONSOLE_INFO_CURSOR;
1378 ret = !SERVER_CALL_ERR();
1380 SERVER_END_REQ;
1381 return ret;
1385 /******************************************************************************
1386 * SetConsoleWindowInfo [KERNEL32.634] Sets size and position of console
1388 * RETURNS
1389 * Success: TRUE
1390 * Failure: FALSE
1392 BOOL WINAPI SetConsoleWindowInfo(
1393 HANDLE hcon, /* [in] Handle to console screen buffer */
1394 BOOL bAbsolute, /* [in] Coordinate type flag */
1395 LPSMALL_RECT window) /* [in] Address of new window rectangle */
1397 FIXME("(%x,%d,%p): stub\n", hcon, bAbsolute, window);
1398 return TRUE;
1402 /******************************************************************************
1403 * SetConsoleTextAttribute [KERNEL32.631] Sets colors for text
1405 * Sets the foreground and background color attributes of characters
1406 * written to the screen buffer.
1408 * RETURNS
1409 * Success: TRUE
1410 * Failure: FALSE
1412 BOOL WINAPI SetConsoleTextAttribute(HANDLE hConsoleOutput,WORD wAttr)
1414 const int colormap[8] = {
1415 0,4,2,6,
1416 1,5,3,7,
1418 DWORD xlen;
1419 char buffer[20];
1421 TRACE("(%d,%d)\n",hConsoleOutput,wAttr);
1422 sprintf(buffer,"%c[0;%s3%d;4%dm",
1424 (wAttr & FOREGROUND_INTENSITY)?"1;":"",
1425 colormap[wAttr&7],
1426 colormap[(wAttr&0x70)>>4]
1428 WriteFile(hConsoleOutput,buffer,strlen(buffer),&xlen,NULL);
1429 return TRUE;
1433 /******************************************************************************
1434 * SetConsoleScreenBufferSize [KERNEL32.630] Changes size of console
1436 * PARAMS
1437 * hConsoleOutput [I] Handle to console screen buffer
1438 * dwSize [I] New size in character rows and cols
1440 * RETURNS
1441 * Success: TRUE
1442 * Failure: FALSE
1444 BOOL WINAPI SetConsoleScreenBufferSize( HANDLE hConsoleOutput,
1445 COORD dwSize )
1447 FIXME("(%d,%dx%d): stub\n",hConsoleOutput,dwSize.X,dwSize.Y);
1448 return TRUE;
1452 /******************************************************************************
1453 * FillConsoleOutputCharacterA [KERNEL32.242]
1455 * PARAMS
1456 * hConsoleOutput [I] Handle to screen buffer
1457 * cCharacter [I] Character to write
1458 * nLength [I] Number of cells to write to
1459 * dwCoord [I] Coords of first cell
1460 * lpNumCharsWritten [O] Pointer to number of cells written
1462 * RETURNS
1463 * Success: TRUE
1464 * Failure: FALSE
1466 BOOL WINAPI FillConsoleOutputCharacterA(
1467 HANDLE hConsoleOutput,
1468 BYTE cCharacter,
1469 DWORD nLength,
1470 COORD dwCoord,
1471 LPDWORD lpNumCharsWritten)
1473 DWORD count;
1474 DWORD xlen;
1476 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
1477 for(count=0;count<nLength;count++)
1478 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
1479 *lpNumCharsWritten = nLength;
1480 return TRUE;
1484 /******************************************************************************
1485 * FillConsoleOutputCharacterW [KERNEL32.243] Writes characters to console
1487 * PARAMS
1488 * hConsoleOutput [I] Handle to screen buffer
1489 * cCharacter [I] Character to write
1490 * nLength [I] Number of cells to write to
1491 * dwCoord [I] Coords of first cell
1492 * lpNumCharsWritten [O] Pointer to number of cells written
1494 * RETURNS
1495 * Success: TRUE
1496 * Failure: FALSE
1498 BOOL WINAPI FillConsoleOutputCharacterW(HANDLE hConsoleOutput,
1499 WCHAR cCharacter,
1500 DWORD nLength,
1501 COORD dwCoord,
1502 LPDWORD lpNumCharsWritten)
1504 DWORD count;
1505 DWORD xlen;
1507 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
1508 /* FIXME: not quite correct ... but the lower part of UNICODE char comes
1509 * first
1511 for(count=0;count<nLength;count++)
1512 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
1513 *lpNumCharsWritten = nLength;
1514 return TRUE;
1518 /******************************************************************************
1519 * FillConsoleOutputAttribute [KERNEL32.241] Sets attributes for console
1521 * PARAMS
1522 * hConsoleOutput [I] Handle to screen buffer
1523 * wAttribute [I] Color attribute to write
1524 * nLength [I] Number of cells to write to
1525 * dwCoord [I] Coords of first cell
1526 * lpNumAttrsWritten [O] Pointer to number of cells written
1528 * RETURNS
1529 * Success: TRUE
1530 * Failure: FALSE
1532 BOOL WINAPI FillConsoleOutputAttribute( HANDLE hConsoleOutput,
1533 WORD wAttribute, DWORD nLength, COORD dwCoord,
1534 LPDWORD lpNumAttrsWritten)
1536 FIXME("(%d,%d,%ld,%dx%d,%p): stub\n", hConsoleOutput,
1537 wAttribute,nLength,dwCoord.X,dwCoord.Y,lpNumAttrsWritten);
1538 *lpNumAttrsWritten = nLength;
1539 return TRUE;
1542 /******************************************************************************
1543 * ReadConsoleOutputCharacterA [KERNEL32.573]
1545 * BUGS
1546 * Unimplemented
1548 BOOL WINAPI ReadConsoleOutputCharacterA(HANDLE hConsoleOutput,
1549 LPSTR lpstr, DWORD dword, COORD coord, LPDWORD lpdword)
1551 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,lpstr,
1552 dword,coord.X,coord.Y,lpdword);
1553 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1554 return FALSE;
1557 /******************************************************************************
1558 * ReadConsoleOutputCharacterW [KERNEL32.574]
1560 * BUGS
1561 * Unimplemented
1563 BOOL WINAPI ReadConsoleOutputCharacterW(HANDLE hConsoleOutput,
1564 LPWSTR lpstr, DWORD dword, COORD coord, LPDWORD lpdword)
1566 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,lpstr,
1567 dword,coord.X,coord.Y,lpdword);
1568 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1569 return FALSE;
1573 /******************************************************************************
1574 * ScrollConsoleScreenBufferA [KERNEL32.612]
1576 * BUGS
1577 * Unimplemented
1579 BOOL WINAPI ScrollConsoleScreenBufferA( HANDLE hConsoleOutput,
1580 LPSMALL_RECT lpScrollRect, LPSMALL_RECT lpClipRect,
1581 COORD dwDestOrigin, LPCHAR_INFO lpFill)
1583 FIXME("(%d,%p,%p,%dx%d,%p): stub\n", hConsoleOutput,lpScrollRect,
1584 lpClipRect,dwDestOrigin.X,dwDestOrigin.Y,lpFill);
1585 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1586 return FALSE;
1589 /******************************************************************************
1590 * ScrollConsoleScreenBufferW [KERNEL32.613]
1592 * BUGS
1593 * Unimplemented
1595 BOOL WINAPI ScrollConsoleScreenBufferW( 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 * ReadConsoleOutputA [KERNEL32.571]
1608 * BUGS
1609 * Unimplemented
1611 BOOL WINAPI ReadConsoleOutputA( HANDLE hConsoleOutput,
1612 LPCHAR_INFO lpBuffer,
1613 COORD dwBufferSize,
1614 COORD dwBufferCoord,
1615 LPSMALL_RECT lpReadRegion )
1617 FIXME("(%d,%p,%dx%d,%dx%d,%p): stub\n", hConsoleOutput, lpBuffer,
1618 dwBufferSize.X, dwBufferSize.Y, dwBufferSize.X, dwBufferSize.Y,
1619 lpReadRegion);
1621 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1622 return FALSE;
1625 /******************************************************************************
1626 * ReadConsoleOutputW [KERNEL32.575]
1628 * BUGS
1629 * Unimplemented
1631 BOOL WINAPI ReadConsoleOutputW( HANDLE hConsoleOutput,
1632 LPCHAR_INFO lpBuffer,
1633 COORD dwBufferSize,
1634 COORD dwBufferCoord,
1635 LPSMALL_RECT lpReadRegion )
1637 FIXME("(%d,%p,%dx%d,%dx%d,%p): stub\n", hConsoleOutput, lpBuffer,
1638 dwBufferSize.X, dwBufferSize.Y, dwBufferSize.X, dwBufferSize.Y,
1639 lpReadRegion);
1641 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1642 return FALSE;
1645 /******************************************************************************
1646 * ReadConsoleOutputAttribute [KERNEL32.572]
1648 * BUGS
1649 * Unimplemented
1651 BOOL WINAPI ReadConsoleOutputAttribute( HANDLE hConsoleOutput,
1652 LPWORD lpAttribute,
1653 DWORD nLength,
1654 COORD dwReadCoord,
1655 LPDWORD lpNumberOfAttrsRead)
1657 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput, lpAttribute,
1658 nLength, dwReadCoord.X, dwReadCoord.Y, lpNumberOfAttrsRead);
1660 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1661 return FALSE;
1664 /******************************************************************************
1665 * SetConsoleCP [KERNEL32.@]
1667 * BUGS
1668 * Unimplemented
1670 BOOL WINAPI SetConsoleCP( UINT cp )
1672 FIXME("(%d): stub\n", cp);
1674 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1675 return FALSE;
1678 /******************************************************************************
1679 * SetConsoleInputExeNameW [KERNEL32.889]
1681 * BUGS
1682 * Unimplemented
1684 BOOL WINAPI SetConsoleInputExeNameW( LPCWSTR name )
1686 FIXME("(%s): stub!\n", debugstr_w(name));
1688 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1689 return TRUE;
1692 /******************************************************************************
1693 * SetConsoleInputExeNameA [KERNEL32.888]
1695 * BUGS
1696 * Unimplemented
1698 BOOL WINAPI SetConsoleInputExeNameA( LPCSTR name )
1700 FIXME("(%s): stub!\n", name);
1702 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1703 return TRUE;