Re-implemented using a real semaphore.
[wine/multimedia.git] / win32 / console.c
blobae53a8b5a296e4a21850c429f46dea60925a39e2
1 /*
2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
5 * Copyright 1997 Karl Garrison
6 * Copyright 1998 John Richardson
7 * Copyright 1998 Marcus Meissner
8 */
10 /* FIXME:
11 * - Completely lacks SCREENBUFFER interface.
12 * - No abstraction for something other than xterm.
13 * - Key input translation shouldn't use VkKeyScan and MapVirtualKey, since
14 * they are window (USER) driver dependend.
15 * - Output sometimes is buffered (We switched off buffering by ~ICANON ?)
17 /* Reference applications:
18 * - IDA (interactive disassembler) full version 3.75. Works.
19 * - LYNX/W32. Works mostly, some keys crash it.
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <termios.h>
25 #include <strings.h>
26 #include <sys/ioctl.h>
27 #include <sys/types.h>
28 #include <sys/time.h>
29 #include <unistd.h>
30 #include <fcntl.h>
31 #include <errno.h>
32 #include <sys/errno.h>
33 #include <signal.h>
34 #include <assert.h>
36 #include "windows.h"
37 #include "k32obj.h"
38 #include "thread.h"
39 #include "async.h"
40 #include "file.h"
41 #include "process.h"
42 #include "winerror.h"
43 #include "wincon.h"
44 #include "heap.h"
45 #include "debug.h"
47 #include "server/request.h"
48 #include "server.h"
50 /* The CONSOLE kernel32 Object */
51 typedef struct _CONSOLE {
52 K32OBJ header;
53 DWORD mode;
54 CONSOLE_CURSOR_INFO cinfo;
56 int master; /* xterm side of pty */
57 int infd,outfd;
58 int hread, hwrite; /* server handles (hack) */
59 int pid; /* xterm's pid, -1 if no xterm */
60 LPSTR title; /* title of console */
61 INPUT_RECORD *irs; /* buffered input records */
62 int nrofirs;/* nr of buffered input records */
63 THREAD_QUEUE wait_queue;
64 } CONSOLE;
66 static void CONSOLE_Destroy( K32OBJ *obj );
68 const K32OBJ_OPS CONSOLE_Ops =
70 CONSOLE_Destroy /* destroy */
73 /***********************************************************************
74 * CONSOLE_Destroy
76 static void CONSOLE_Destroy(K32OBJ *obj)
78 CONSOLE *console = (CONSOLE *)obj;
79 assert(obj->type == K32OBJ_CONSOLE);
81 obj->type = K32OBJ_UNKNOWN;
83 if (console->title)
84 HeapFree( SystemHeap, 0, console->title );
85 console->title = NULL;
86 /* if there is a xterm, kill it. */
87 if (console->pid != -1)
88 kill(console->pid, SIGTERM);
89 HeapFree(SystemHeap, 0, console);
93 /****************************************************************************
94 * CONSOLE_add_input_record [internal]
96 * Adds an INPUT_RECORD to the CONSOLEs input queue.
98 static void
99 CONSOLE_add_input_record(CONSOLE *console,INPUT_RECORD *inp) {
100 console->irs = HeapReAlloc(GetProcessHeap(),0,console->irs,sizeof(INPUT_RECORD)*(console->nrofirs+1));
101 console->irs[console->nrofirs++]=*inp;
104 /****************************************************************************
105 * XTERM_string_to_IR [internal]
107 * Transfers a string read from XTERM to INPUT_RECORDs and adds them to the
108 * queue. Does translation of vt100 style function keys and xterm-mouse clicks.
110 static void
111 CONSOLE_string_to_IR( HANDLE32 hConsoleInput,unsigned char *buf,int len) {
112 int j,k;
113 INPUT_RECORD ir;
114 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hConsoleInput,
115 K32OBJ_CONSOLE, 0, NULL);
117 for (j=0;j<len;j++) {
118 unsigned char inchar = buf[j];
120 if (inchar!=27) { /* no escape -> 'normal' keyboard event */
121 ir.EventType = 1; /* Key_event */
123 ir.Event.KeyEvent.bKeyDown = 1;
124 ir.Event.KeyEvent.wRepeatCount = 0;
126 ir.Event.KeyEvent.dwControlKeyState = 0;
127 if (inchar & 0x80) {
128 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
129 inchar &= ~0x80;
131 ir.Event.KeyEvent.wVirtualKeyCode = VkKeyScan16(inchar);
132 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0100)
133 ir.Event.KeyEvent.dwControlKeyState|=SHIFT_PRESSED;
134 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0200)
135 ir.Event.KeyEvent.dwControlKeyState|=LEFT_CTRL_PRESSED;
136 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0400)
137 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
138 ir.Event.KeyEvent.wVirtualScanCode = MapVirtualKey16(
139 ir.Event.KeyEvent.wVirtualKeyCode & 0x00ff,
140 0 /* VirtualKeyCodes to ScanCode */
142 if (inchar=='\n') {
143 ir.Event.KeyEvent.uChar.AsciiChar = '\r';
144 ir.Event.KeyEvent.wVirtualKeyCode = 0x0d;
145 ir.Event.KeyEvent.wVirtualScanCode = 0x1c;
146 } else {
147 ir.Event.KeyEvent.uChar.AsciiChar = inchar;
148 if (inchar<' ') {
149 /* FIXME: find good values for ^X */
150 ir.Event.KeyEvent.wVirtualKeyCode = 0xdead;
151 ir.Event.KeyEvent.wVirtualScanCode = 0xbeef;
155 CONSOLE_add_input_record(console,&ir);
156 ir.Event.KeyEvent.bKeyDown = 0;
157 CONSOLE_add_input_record(console,&ir);
158 continue;
160 /* inchar is ESC */
161 if ((j==len-1) || (buf[j+1]!='[')) {/* add ESCape on its own */
162 ir.EventType = 1; /* Key_event */
163 ir.Event.KeyEvent.bKeyDown = 1;
164 ir.Event.KeyEvent.wRepeatCount = 0;
166 ir.Event.KeyEvent.wVirtualKeyCode = VkKeyScan16(27);
167 ir.Event.KeyEvent.wVirtualScanCode = MapVirtualKey16(
168 ir.Event.KeyEvent.wVirtualKeyCode,0
170 ir.Event.KeyEvent.dwControlKeyState = 0;
171 ir.Event.KeyEvent.uChar.AsciiChar = 27;
172 CONSOLE_add_input_record(console,&ir);
173 ir.Event.KeyEvent.bKeyDown = 0;
174 CONSOLE_add_input_record(console,&ir);
175 continue;
177 for (k=j;k<len;k++) {
178 if (((buf[k]>='A') && (buf[k]<='Z')) ||
179 ((buf[k]>='a') && (buf[k]<='z')) ||
180 (buf[k]=='~')
182 break;
184 if (k<len) {
185 int subid,scancode=0;
187 ir.EventType = 1; /* Key_event */
188 ir.Event.KeyEvent.bKeyDown = 1;
189 ir.Event.KeyEvent.wRepeatCount = 0;
190 ir.Event.KeyEvent.dwControlKeyState = 0;
192 ir.Event.KeyEvent.wVirtualKeyCode = 0xad; /* FIXME */
193 ir.Event.KeyEvent.wVirtualScanCode = 0xad; /* FIXME */
194 ir.Event.KeyEvent.uChar.AsciiChar = 0;
196 switch (buf[k]) {
197 case '~':
198 sscanf(&buf[j+2],"%d",&subid);
199 switch (subid) {
200 case 2:/*INS */scancode = 0xe052;break;
201 case 3:/*DEL */scancode = 0xe053;break;
202 case 6:/*PGDW*/scancode = 0xe051;break;
203 case 5:/*PGUP*/scancode = 0xe049;break;
204 case 11:/*F1 */scancode = 0x003b;break;
205 case 12:/*F2 */scancode = 0x003c;break;
206 case 13:/*F3 */scancode = 0x003d;break;
207 case 14:/*F4 */scancode = 0x003e;break;
208 case 15:/*F5 */scancode = 0x003f;break;
209 case 17:/*F6 */scancode = 0x0040;break;
210 case 18:/*F7 */scancode = 0x0041;break;
211 case 19:/*F8 */scancode = 0x0042;break;
212 case 20:/*F9 */scancode = 0x0043;break;
213 case 21:/*F10 */scancode = 0x0044;break;
214 case 23:/*F11 */scancode = 0x00d9;break;
215 case 24:/*F12 */scancode = 0x00da;break;
216 /* FIXME: Shift-Fx */
217 default:
218 FIXME(console,"parse ESC[%d~\n",subid);
219 break;
221 break;
222 case 'A': /* Cursor Up */scancode = 0xe048;break;
223 case 'B': /* Cursor Down */scancode = 0xe050;break;
224 case 'D': /* Cursor Left */scancode = 0xe04b;break;
225 case 'C': /* Cursor Right */scancode = 0xe04d;break;
226 case 'F': /* End */scancode = 0xe04f;break;
227 case 'H': /* Home */scancode = 0xe047;break;
228 case 'M':
229 /* Mouse Button Press (ESCM<button+'!'><x+'!'><y+'!'>) or
230 * Release (ESCM#<x+'!'><y+'!'>
232 if (k<len-3) {
233 ir.EventType = MOUSE_EVENT;
234 ir.Event.MouseEvent.dwMousePosition.x = buf[k+2]-'!';
235 ir.Event.MouseEvent.dwMousePosition.y = buf[k+3]-'!';
236 if (buf[k+1]=='#')
237 ir.Event.MouseEvent.dwButtonState = 0;
238 else
239 ir.Event.MouseEvent.dwButtonState = 1<<(buf[k+1]-' ');
240 ir.Event.MouseEvent.dwEventFlags = 0; /* FIXME */
241 CONSOLE_add_input_record(console,&ir);
242 j=k+3;
244 break;
247 if (scancode) {
248 ir.Event.KeyEvent.wVirtualScanCode = scancode;
249 ir.Event.KeyEvent.wVirtualKeyCode = MapVirtualKey16(scancode,1);
250 CONSOLE_add_input_record(console,&ir);
251 ir.Event.KeyEvent.bKeyDown = 0;
252 CONSOLE_add_input_record(console,&ir);
253 j=k;
254 continue;
258 K32OBJ_DecCount(&console->header);
261 /****************************************************************************
262 * CONSOLE_get_input (internal)
264 * Reads (nonblocking) as much input events as possible and stores them
265 * in an internal queue.
267 static void
268 CONSOLE_get_input( HANDLE32 handle )
270 char *buf = HeapAlloc(GetProcessHeap(),0,1);
271 int len = 0;
273 while (1)
275 DWORD res;
276 char inchar;
277 if (!WaitForSingleObject( handle, 0 )) break;
278 if (!ReadFile( handle, &inchar, 1, &res, NULL )) break;
279 buf = HeapReAlloc(GetProcessHeap(),0,buf,len+1);
280 buf[len++]=inchar;
282 CONSOLE_string_to_IR(handle,buf,len);
283 HeapFree(GetProcessHeap(),0,buf);
286 /****************************************************************************
287 * CONSOLE_drain_input (internal)
289 * Drains 'n' console input events from the queue.
291 static void
292 CONSOLE_drain_input(CONSOLE *console,int n) {
293 assert(n<=console->nrofirs);
294 if (n) {
295 console->nrofirs-=n;
296 memcpy( &console->irs[0],
297 &console->irs[n],
298 console->nrofirs*sizeof(INPUT_RECORD)
300 console->irs = HeapReAlloc(
301 GetProcessHeap(),
303 console->irs,
304 console->nrofirs*sizeof(INPUT_RECORD)
310 /******************************************************************************
311 * SetConsoleCtrlHandler [KERNEL32.459] Adds function to calling process list
313 * PARAMS
314 * func [I] Address of handler function
315 * add [I] Handler to add or remove
317 * RETURNS
318 * Success: TRUE
319 * Failure: FALSE
321 * CHANGED
322 * James Sutherland (JamesSutherland@gmx.de)
323 * Added global variables console_ignore_ctrl_c and handlers[]
324 * Does not yet do any error checking, or set LastError if failed.
325 * This doesn't yet matter, since these handlers are not yet called...!
327 static unsigned int console_ignore_ctrl_c = 0;
328 static HANDLER_ROUTINE *handlers[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
329 BOOL32 WINAPI SetConsoleCtrlHandler( HANDLER_ROUTINE *func, BOOL32 add )
331 unsigned int alloc_loop = sizeof(handlers)/sizeof(HANDLER_ROUTINE *);
332 unsigned int done = 0;
333 FIXME(console, "(%p,%i) - no error checking or testing yet\n", func, add);
334 if (!func)
336 console_ignore_ctrl_c = add;
337 return TRUE;
339 if (add)
341 for (;alloc_loop--;)
342 if (!handlers[alloc_loop] && !done)
344 handlers[alloc_loop] = func;
345 done++;
347 if (!done)
348 FIXME(console, "Out of space on CtrlHandler table\n");
349 return(done);
351 else
353 for (;alloc_loop--;)
354 if (handlers[alloc_loop] == func && !done)
356 handlers[alloc_loop] = 0;
357 done++;
359 if (!done)
360 WARN(console, "Attempt to remove non-installed CtrlHandler %p\n",
361 func);
362 return (done);
364 return (done);
368 /******************************************************************************
369 * GenerateConsoleCtrlEvent [KERNEL32.275] Simulate a CTRL-C or CTRL-BREAK
371 * PARAMS
372 * dwCtrlEvent [I] Type of event
373 * dwProcessGroupID [I] Process group ID to send event to
375 * NOTES
376 * Doesn't yet work...!
378 * RETURNS
379 * Success: True
380 * Failure: False (and *should* [but doesn't] set LastError)
382 BOOL32 WINAPI GenerateConsoleCtrlEvent( DWORD dwCtrlEvent,
383 DWORD dwProcessGroupID )
385 if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
387 ERR( console, "invalid event %d for PGID %ld\n",
388 (unsigned short)dwCtrlEvent, dwProcessGroupID );
389 return FALSE;
391 if (dwProcessGroupID == GetCurrentProcessId() )
393 FIXME( console, "Attempt to send event %d to self - stub\n",
394 (unsigned short)dwCtrlEvent );
395 return FALSE;
397 FIXME( console,"event %d to external PGID %ld - not implemented yet\n",
398 (unsigned short)dwCtrlEvent, dwProcessGroupID );
399 return FALSE;
403 /******************************************************************************
404 * CreateConsoleScreenBuffer [KERNEL32.151] Creates a console screen buffer
406 * PARAMS
407 * dwDesiredAccess [I] Access flag
408 * dwShareMode [I] Buffer share mode
409 * sa [I] Security attributes
410 * dwFlags [I] Type of buffer to create
411 * lpScreenBufferData [I] Reserved
413 * NOTES
414 * Should call SetLastError
416 * RETURNS
417 * Success: Handle to new console screen buffer
418 * Failure: INVALID_HANDLE_VALUE
420 HANDLE32 WINAPI CreateConsoleScreenBuffer( DWORD dwDesiredAccess,
421 DWORD dwShareMode, LPSECURITY_ATTRIBUTES sa,
422 DWORD dwFlags, LPVOID lpScreenBufferData )
424 FIXME(console, "(%ld,%ld,%p,%ld,%p): stub\n",dwDesiredAccess,
425 dwShareMode, sa, dwFlags, lpScreenBufferData);
426 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
427 return INVALID_HANDLE_VALUE32;
431 /***********************************************************************
432 * GetConsoleScreenBufferInfo (KERNEL32.190)
434 BOOL32 WINAPI GetConsoleScreenBufferInfo( HANDLE32 hConsoleOutput,
435 LPCONSOLE_SCREEN_BUFFER_INFO csbi )
437 csbi->dwSize.x = 80;
438 csbi->dwSize.y = 24;
439 csbi->dwCursorPosition.x = 0;
440 csbi->dwCursorPosition.y = 0;
441 csbi->wAttributes = 0;
442 csbi->srWindow.Left = 0;
443 csbi->srWindow.Right = 79;
444 csbi->srWindow.Top = 0;
445 csbi->srWindow.Bottom = 23;
446 csbi->dwMaximumWindowSize.x = 80;
447 csbi->dwMaximumWindowSize.y = 24;
448 return TRUE;
452 /******************************************************************************
453 * SetConsoleActiveScreenBuffer [KERNEL32.623] Sets buffer to current console
455 * RETURNS
456 * Success: TRUE
457 * Failure: FALSE
459 BOOL32 WINAPI SetConsoleActiveScreenBuffer(
460 HANDLE32 hConsoleOutput) /* [in] Handle to console screen buffer */
462 FIXME(console, "(%x): stub\n", hConsoleOutput);
463 return FALSE;
467 /***********************************************************************
468 * GetLargestConsoleWindowSize (KERNEL32.226)
470 DWORD WINAPI GetLargestConsoleWindowSize( HANDLE32 hConsoleOutput )
472 return (DWORD)MAKELONG(80,24);
475 /***********************************************************************
476 * FreeConsole (KERNEL32.267)
478 BOOL32 WINAPI FreeConsole(VOID)
481 PDB32 *pdb = PROCESS_Current();
482 CONSOLE *console;
484 SYSTEM_LOCK();
486 console = (CONSOLE *)pdb->console;
488 if (console == NULL) {
489 SetLastError(ERROR_INVALID_PARAMETER);
490 return FALSE;
493 HANDLE_CloseAll( pdb, &console->header );
495 K32OBJ_DecCount( &console->header );
496 pdb->console = NULL;
497 SYSTEM_UNLOCK();
498 return TRUE;
502 /**
503 * It looks like the openpty that comes with glibc in RedHat 5.0
504 * is buggy (second call returns what looks like a dup of 0 and 1
505 * instead of a new pty), this is a generic replacement.
507 static int CONSOLE_openpty(CONSOLE *console, char *name,
508 struct termios *term, struct winsize *winsize)
510 int fdm, fds;
511 char *ptr1, *ptr2;
512 char pts_name[512];
513 struct set_console_fd_request req;
515 strcpy (pts_name, "/dev/ptyXY");
517 for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) {
518 pts_name[8] = *ptr1;
519 for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++) {
520 pts_name[9] = *ptr2;
522 if ((fdm = open(pts_name, O_RDWR)) < 0) {
523 if (errno == ENOENT)
524 return -1;
525 else
526 continue;
528 pts_name[5] = 't';
529 if ((fds = open(pts_name, O_RDWR)) < 0) {
530 pts_name[5] = 'p';
531 continue;
533 console->master = fdm;
534 console->infd = console->outfd = fds;
535 req.handle = console->hread;
536 CLIENT_SendRequest( REQ_SET_CONSOLE_FD, dup(fds), 1, &req, sizeof(req) );
537 CLIENT_WaitReply( NULL, NULL, 0 );
538 req.handle = console->hwrite;
539 CLIENT_SendRequest( REQ_SET_CONSOLE_FD, dup(fds), 1, &req, sizeof(req) );
540 CLIENT_WaitReply( NULL, NULL, 0 );
542 if (term != NULL)
543 tcsetattr(console->infd, TCSANOW, term);
544 if (winsize != NULL)
545 ioctl(console->outfd, TIOCSWINSZ, winsize);
546 if (name != NULL)
547 strcpy(name, pts_name);
548 return fds;
551 return -1;
554 /*************************************************************************
555 * CONSOLE_make_complex [internal]
557 * Turns a CONSOLE kernel object into a complex one.
558 * (switches from output/input using the terminal where WINE was started to
559 * its own xterm).
561 * This makes simple commandline tools pipeable, while complex commandline
562 * tools work without getting messed up by debugoutput.
564 * All other functions should work indedependend from this call.
566 * To test for complex console: pid == -1 -> simple, otherwise complex.
568 static BOOL32 CONSOLE_make_complex(HANDLE32 handle,CONSOLE *console)
570 struct termios term;
571 char buf[30];
572 char c = '\0';
573 int status = 0;
574 int i,xpid;
575 DWORD xlen;
577 if (console->pid != -1)
578 return TRUE; /* already complex */
580 MSG("Console: Making console complex (creating an xterm)...\n");
582 if (tcgetattr(0, &term) < 0) return FALSE;
583 term.c_lflag = ~(ECHO|ICANON);
584 if (CONSOLE_openpty(console, NULL, &term, NULL) < 0) return FALSE;
586 if ((xpid=fork()) == 0) {
587 tcsetattr(console->infd, TCSADRAIN, &term);
588 sprintf(buf, "-Sxx%d", console->master);
589 /* "-fn vga" for VGA font. Harmless if vga is not present:
590 * xterm: unable to open font "vga", trying "fixed"....
592 execlp("xterm", "xterm", buf, "-fn","vga",NULL);
593 ERR(console, "error creating AllocConsole xterm\n");
594 exit(1);
596 console->pid = xpid;
598 /* most xterms like to print their window ID when used with -S;
599 * read it and continue before the user has a chance...
601 for (i=0; c!='\n'; (status=read(console->infd, &c, 1)), i++) {
602 if (status == -1 && c == '\0') {
603 /* wait for xterm to be created */
604 usleep(100);
606 if (i > 10000) {
607 ERR(console, "can't read xterm WID\n");
608 kill(console->pid, SIGKILL);
609 return FALSE;
612 /* enable mouseclicks */
613 sprintf(buf,"%c[?1001s%c[?1000h",27,27);
614 WriteFile(handle,buf,strlen(buf),&xlen,NULL);
615 return TRUE;
619 /***********************************************************************
620 * CONSOLE_GetConsoleHandle
621 * returns a 16-bit style console handle
622 * note: only called from _lopen
624 HFILE32 CONSOLE_GetConsoleHandle(VOID)
626 PDB32 *pdb = PROCESS_Current();
627 HFILE32 handle = HFILE_ERROR32;
629 SYSTEM_LOCK();
630 if (pdb->console != NULL) {
631 CONSOLE *console = (CONSOLE *)pdb->console;
632 handle = (HFILE32)HANDLE_Alloc(pdb, &console->header, 0, TRUE, -1);
634 SYSTEM_UNLOCK();
635 return handle;
638 /***********************************************************************
639 * AllocConsole (KERNEL32.103)
641 * creates an xterm with a pty to our program
643 BOOL32 WINAPI AllocConsole(VOID)
645 struct create_console_request req;
646 struct create_console_reply reply;
647 int len;
648 PDB32 *pdb = PROCESS_Current();
649 CONSOLE *console;
650 HANDLE32 hIn, hOut, hErr;
652 SYSTEM_LOCK(); /* FIXME: really only need to lock the process */
654 SetLastError(ERROR_CANNOT_MAKE); /* this might not be the right
655 error, but it's a good guess :) */
657 console = (CONSOLE *)pdb->console;
659 /* don't create a console if we already have one */
660 if (console != NULL) {
661 SetLastError(ERROR_ACCESS_DENIED);
662 SYSTEM_UNLOCK();
663 return FALSE;
666 if (!(console = (CONSOLE*)HeapAlloc( SystemHeap, 0, sizeof(*console))))
668 SYSTEM_UNLOCK();
669 return FALSE;
672 console->header.type = K32OBJ_CONSOLE;
673 console->header.refcount = 1;
674 console->pid = -1;
675 console->title = NULL;
676 console->nrofirs = 0;
677 console->wait_queue = NULL;
678 console->irs = HeapAlloc(GetProcessHeap(),0,1);;
679 console->mode = ENABLE_PROCESSED_INPUT
680 | ENABLE_LINE_INPUT
681 | ENABLE_ECHO_INPUT;
682 /* FIXME: we shouldn't probably use hardcoded UNIX values here. */
683 console->infd = 0;
684 console->outfd = 1;
685 console->hread = console->hwrite = -1;
687 CLIENT_SendRequest( REQ_CREATE_CONSOLE, -1, 1, &req, sizeof(req) );
688 if (CLIENT_WaitReply( &len, NULL, 1, &reply, sizeof(reply) ) != ERROR_SUCCESS)
690 K32OBJ_DecCount(&console->header);
691 SYSTEM_UNLOCK();
692 return FALSE;
694 CHECK_LEN( len, sizeof(reply) );
695 console->hread = reply.handle_read;
696 console->hwrite = reply.handle_write;
698 if ((hIn = HANDLE_Alloc(pdb,&console->header, 0, TRUE,
699 reply.handle_read)) == INVALID_HANDLE_VALUE32)
701 CLIENT_CloseHandle( reply.handle_write );
702 K32OBJ_DecCount(&console->header);
703 SYSTEM_UNLOCK();
704 return FALSE;
707 if ((hOut = HANDLE_Alloc(pdb,&console->header, 0, TRUE,
708 reply.handle_write)) == INVALID_HANDLE_VALUE32)
710 CloseHandle(hIn);
711 K32OBJ_DecCount(&console->header);
712 SYSTEM_UNLOCK();
713 return FALSE;
716 if (!DuplicateHandle( GetCurrentProcess(), hOut,
717 GetCurrentProcess(), &hErr,
718 0, TRUE, DUPLICATE_SAME_ACCESS ))
720 CloseHandle(hIn);
721 CloseHandle(hOut);
722 K32OBJ_DecCount(&console->header);
723 SYSTEM_UNLOCK();
724 return FALSE;
727 if (pdb->console) K32OBJ_DecCount( pdb->console );
728 pdb->console = (K32OBJ *)console;
729 K32OBJ_IncCount( pdb->console );
731 /* NT resets the STD_*_HANDLEs on console alloc */
732 SetStdHandle(STD_INPUT_HANDLE, hIn);
733 SetStdHandle(STD_OUTPUT_HANDLE, hOut);
734 SetStdHandle(STD_ERROR_HANDLE, hErr);
736 SetLastError(ERROR_SUCCESS);
737 SYSTEM_UNLOCK();
738 SetConsoleTitle32A("Wine Console");
739 return TRUE;
743 /******************************************************************************
744 * GetConsoleCP [KERNEL32.295] Returns the OEM code page for the console
746 * RETURNS
747 * Code page code
749 UINT32 WINAPI GetConsoleCP(VOID)
751 return GetACP();
755 /***********************************************************************
756 * GetConsoleOutputCP (KERNEL32.189)
758 UINT32 WINAPI GetConsoleOutputCP(VOID)
760 return GetConsoleCP();
763 /***********************************************************************
764 * GetConsoleMode (KERNEL32.188)
766 BOOL32 WINAPI GetConsoleMode(HANDLE32 hcon,LPDWORD mode)
768 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hcon, K32OBJ_CONSOLE, 0, NULL);
770 if (!console) {
771 FIXME(console,"(%d,%p), no console handle passed!\n",hcon,mode);
772 return FALSE;
774 *mode = console->mode;
775 K32OBJ_DecCount(&console->header);
776 return TRUE;
780 /******************************************************************************
781 * SetConsoleMode [KERNEL32.628] Sets input mode of console's input buffer
783 * PARAMS
784 * hcon [I] Handle to console input or screen buffer
785 * mode [I] Input or output mode to set
787 * RETURNS
788 * Success: TRUE
789 * Failure: FALSE
791 BOOL32 WINAPI SetConsoleMode( HANDLE32 hcon, DWORD mode )
793 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hcon, K32OBJ_CONSOLE, 0, NULL);
795 if (!console) {
796 FIXME(console,"(%d,%ld), no console handle passed!\n",hcon,mode);
797 return FALSE;
799 FIXME(console,"(0x%08x,0x%08lx): stub\n",hcon,mode);
800 console->mode = mode;
801 K32OBJ_DecCount(&console->header);
802 return TRUE;
806 /***********************************************************************
807 * GetConsoleTitleA (KERNEL32.191)
809 DWORD WINAPI GetConsoleTitle32A(LPSTR title,DWORD size)
811 PDB32 *pdb = PROCESS_Current();
812 CONSOLE *console= (CONSOLE *)pdb->console;
814 if(console && console->title) {
815 lstrcpyn32A(title,console->title,size);
816 return strlen(title);
818 return 0;
822 /******************************************************************************
823 * GetConsoleTitle32W [KERNEL32.192] Retrieves title string for console
825 * PARAMS
826 * title [O] Address of buffer for title
827 * size [I] Size of buffer
829 * RETURNS
830 * Success: Length of string copied
831 * Failure: 0
833 DWORD WINAPI GetConsoleTitle32W( LPWSTR title, DWORD size )
835 PDB32 *pdb = PROCESS_Current();
836 CONSOLE *console= (CONSOLE *)pdb->console;
837 if(console && console->title)
839 lstrcpynAtoW(title,console->title,size);
840 return (lstrlen32W(title));
842 return 0;
846 /***********************************************************************
847 * WriteConsoleA (KERNEL32.729)
849 BOOL32 WINAPI WriteConsole32A( HANDLE32 hConsoleOutput,
850 LPCVOID lpBuffer,
851 DWORD nNumberOfCharsToWrite,
852 LPDWORD lpNumberOfCharsWritten,
853 LPVOID lpReserved )
855 /* FIXME: should I check if this is a console handle? */
856 return WriteFile(hConsoleOutput, lpBuffer, nNumberOfCharsToWrite,
857 lpNumberOfCharsWritten, NULL);
861 #define CADD(c) \
862 if (bufused==curbufsize-1) \
863 buffer = HeapReAlloc(GetProcessHeap(),0,buffer,(curbufsize+=100));\
864 buffer[bufused++]=c;
865 #define SADD(s) { char *x=s;while (*x) {CADD(*x);x++;}}
867 /***********************************************************************
868 * WriteConsoleOutputA (KERNEL32.732)
870 BOOL32 WINAPI WriteConsoleOutput32A( HANDLE32 hConsoleOutput,
871 LPCHAR_INFO lpBuffer,
872 COORD dwBufferSize,
873 COORD dwBufferCoord,
874 LPSMALL_RECT lpWriteRegion)
876 int i,j,off=0,lastattr=-1;
877 char sbuf[20],*buffer=NULL;
878 int bufused=0,curbufsize = 100;
879 DWORD res;
880 const int colormap[8] = {
881 0,4,2,6,
882 1,5,3,7,
884 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hConsoleOutput, K32OBJ_CONSOLE, 0, NULL);
886 if (!console) {
887 FIXME(console,"(%d,...): no console handle!\n",hConsoleOutput);
888 return FALSE;
890 CONSOLE_make_complex(hConsoleOutput,console);
891 buffer = HeapAlloc(GetProcessHeap(),0,100);;
892 curbufsize = 100;
894 TRACE(console,"wr: top = %d, bottom=%d, left=%d,right=%d\n",
895 lpWriteRegion->Top,
896 lpWriteRegion->Bottom,
897 lpWriteRegion->Left,
898 lpWriteRegion->Right
901 for (i=lpWriteRegion->Top;i<=lpWriteRegion->Bottom;i++) {
902 sprintf(sbuf,"%c[%d;%dH",27,i+1,lpWriteRegion->Left+1);
903 SADD(sbuf);
904 for (j=lpWriteRegion->Left;j<=lpWriteRegion->Right;j++) {
905 if (lastattr!=lpBuffer[off].Attributes) {
906 lastattr = lpBuffer[off].Attributes;
907 sprintf(sbuf,"%c[0;%s3%d;4%dm",
909 (lastattr & FOREGROUND_INTENSITY)?"1;":"",
910 colormap[lastattr&7],
911 colormap[(lastattr&0x70)>>4]
913 /* FIXME: BACKGROUND_INTENSITY */
914 SADD(sbuf);
916 CADD(lpBuffer[off].Char.AsciiChar);
917 off++;
920 sprintf(sbuf,"%c[0m",27);SADD(sbuf);
921 WriteFile(hConsoleOutput,buffer,bufused,&res,NULL);
922 HeapFree(GetProcessHeap(),0,buffer);
923 K32OBJ_DecCount(&console->header);
924 return TRUE;
927 /***********************************************************************
928 * WriteConsoleW (KERNEL32.577)
930 BOOL32 WINAPI WriteConsole32W( HANDLE32 hConsoleOutput,
931 LPCVOID lpBuffer,
932 DWORD nNumberOfCharsToWrite,
933 LPDWORD lpNumberOfCharsWritten,
934 LPVOID lpReserved )
936 BOOL32 ret;
937 LPSTR xstring=HeapAlloc( GetProcessHeap(), 0, nNumberOfCharsToWrite );
939 lstrcpynWtoA( xstring, lpBuffer,nNumberOfCharsToWrite);
941 /* FIXME: should I check if this is a console handle? */
942 ret= WriteFile(hConsoleOutput, xstring, nNumberOfCharsToWrite,
943 lpNumberOfCharsWritten, NULL);
944 HeapFree( GetProcessHeap(), 0, xstring );
945 return ret;
949 /***********************************************************************
950 * ReadConsoleA (KERNEL32.419)
952 BOOL32 WINAPI ReadConsole32A( HANDLE32 hConsoleInput,
953 LPVOID lpBuffer,
954 DWORD nNumberOfCharsToRead,
955 LPDWORD lpNumberOfCharsRead,
956 LPVOID lpReserved )
958 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hConsoleInput, K32OBJ_CONSOLE, 0, NULL);
959 int i,charsread = 0;
960 LPSTR xbuf = (LPSTR)lpBuffer;
962 if (!console) {
963 SetLastError(ERROR_INVALID_HANDLE);
964 FIXME(console,"(%d,...), no console handle!\n",hConsoleInput);
965 return FALSE;
967 TRACE(console,"(%d,%p,%ld,%p,%p)\n",
968 hConsoleInput,lpBuffer,nNumberOfCharsToRead,
969 lpNumberOfCharsRead,lpReserved
971 CONSOLE_get_input(hConsoleInput);
973 /* FIXME: should this drain everything from the input queue and just
974 * put the keypresses in the buffer? Needs further thought.
976 for (i=0;(i<console->nrofirs)&&(charsread<nNumberOfCharsToRead);i++) {
977 if (console->irs[i].EventType != KEY_EVENT)
978 continue;
979 if (!console->irs[i].Event.KeyEvent.bKeyDown)
980 continue;
981 *xbuf++ = console->irs[i].Event.KeyEvent.uChar.AsciiChar;
982 charsread++;
984 CONSOLE_drain_input(console,i);
985 if (lpNumberOfCharsRead)
986 *lpNumberOfCharsRead = charsread;
987 K32OBJ_DecCount(&console->header);
988 return TRUE;
991 /***********************************************************************
992 * ReadConsoleW (KERNEL32.427)
994 BOOL32 WINAPI ReadConsole32W( HANDLE32 hConsoleInput,
995 LPVOID lpBuffer,
996 DWORD nNumberOfCharsToRead,
997 LPDWORD lpNumberOfCharsRead,
998 LPVOID lpReserved )
1000 BOOL32 ret;
1001 LPSTR buf = (LPSTR)HeapAlloc(GetProcessHeap(), 0, nNumberOfCharsToRead);
1003 ret = ReadConsole32A(
1004 hConsoleInput,
1005 buf,
1006 nNumberOfCharsToRead,
1007 lpNumberOfCharsRead,
1008 lpReserved
1010 if (ret)
1011 lstrcpynAtoW(lpBuffer,buf,nNumberOfCharsToRead);
1012 HeapFree( GetProcessHeap(), 0, buf );
1013 return ret;
1017 /******************************************************************************
1018 * ReadConsoleInput32A [KERNEL32.569] Reads data from a console
1020 * PARAMS
1021 * hConsoleInput [I] Handle to console input buffer
1022 * lpBuffer [O] Address of buffer for read data
1023 * nLength [I] Number of records to read
1024 * lpNumberOfEventsRead [O] Address of number of records read
1026 * RETURNS
1027 * Success: TRUE
1028 * Failure: FALSE
1030 BOOL32 WINAPI ReadConsoleInput32A(HANDLE32 hConsoleInput,
1031 LPINPUT_RECORD lpBuffer,
1032 DWORD nLength, LPDWORD lpNumberOfEventsRead)
1034 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hConsoleInput, K32OBJ_CONSOLE, 0, NULL);
1036 TRACE(console, "(%d,%p,%ld,%p)\n",hConsoleInput, lpBuffer, nLength,
1037 lpNumberOfEventsRead);
1038 if (!console) {
1039 FIXME(console, "(%d,%p,%ld,%p), No console handle!\n",hConsoleInput,
1040 lpBuffer, nLength, lpNumberOfEventsRead);
1041 return FALSE;
1043 CONSOLE_get_input(hConsoleInput);
1044 if (nLength>console->nrofirs)
1045 nLength = console->nrofirs;
1046 memcpy(lpBuffer,console->irs,sizeof(INPUT_RECORD)*nLength);
1047 if (lpNumberOfEventsRead)
1048 *lpNumberOfEventsRead = nLength;
1049 CONSOLE_drain_input(console,nLength);
1050 K32OBJ_DecCount(&console->header);
1051 return TRUE;
1054 /***********************************************************************
1055 * SetConsoleTitle32A (KERNEL32.476)
1057 * Sets the console title.
1059 * We do not necessarily need to create a complex console for that,
1060 * but should remember the title and set it on creation of the latter.
1061 * (not fixed at this time).
1063 BOOL32 WINAPI SetConsoleTitle32A(LPCSTR title)
1065 PDB32 *pdb = PROCESS_Current();
1066 CONSOLE *console;
1067 DWORD written;
1068 char titleformat[]="\033]2;%s\a"; /*this should work for xterms*/
1069 LPSTR titlestring;
1070 BOOL32 ret=FALSE;
1072 TRACE(console,"(%s)\n",title);
1074 console = (CONSOLE *)pdb->console;
1075 if (!console)
1076 return FALSE;
1077 if(console->title) /* Free old title, if there is one */
1078 HeapFree( SystemHeap, 0, console->title );
1079 console->title = (LPSTR)HeapAlloc(SystemHeap, 0,strlen(title)+1);
1080 if(console->title) strcpy(console->title,title);
1081 titlestring = HeapAlloc(GetProcessHeap(), 0,strlen(title)+strlen(titleformat)+1);
1082 if (!titlestring) {
1083 K32OBJ_DecCount(&console->header);
1084 return FALSE;
1087 sprintf(titlestring,titleformat,title);
1088 /* FIXME: hmm, should use WriteFile probably... */
1089 /*CONSOLE_Write(&console->header,titlestring,strlen(titlestring),&written,NULL);*/
1090 WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),titlestring,strlen(titlestring),&written,NULL);
1091 if (written == strlen(titlestring))
1092 ret =TRUE;
1093 HeapFree( GetProcessHeap(), 0, titlestring );
1094 K32OBJ_DecCount(&console->header);
1095 return ret;
1099 /******************************************************************************
1100 * SetConsoleTitle32W [KERNEL32.477] Sets title bar string for console
1102 * PARAMS
1103 * title [I] Address of new title
1105 * NOTES
1106 * This should not be calling the A version
1108 * RETURNS
1109 * Success: TRUE
1110 * Failure: FALSE
1112 BOOL32 WINAPI SetConsoleTitle32W( LPCWSTR title )
1114 BOOL32 ret;
1116 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
1117 ret = SetConsoleTitle32A(titleA);
1118 HeapFree( GetProcessHeap(), 0, titleA );
1119 return ret;
1122 /***********************************************************************
1123 * ReadConsoleInput32W (KERNEL32.570)
1125 BOOL32 WINAPI ReadConsoleInput32W(HANDLE32 hConsoleInput,
1126 LPINPUT_RECORD lpBuffer,
1127 DWORD nLength, LPDWORD lpNumberOfEventsRead)
1129 FIXME(console, "(%d,%p,%ld,%p): stub\n",hConsoleInput, lpBuffer, nLength,
1130 lpNumberOfEventsRead);
1131 return 0;
1134 /***********************************************************************
1135 * FlushConsoleInputBuffer (KERNEL32.132)
1137 BOOL32 WINAPI FlushConsoleInputBuffer(HANDLE32 hConsoleInput)
1139 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hConsoleInput, K32OBJ_CONSOLE, 0, NULL);
1141 if (!console)
1142 return FALSE;
1143 CONSOLE_drain_input(console,console->nrofirs);
1144 K32OBJ_DecCount(&console->header);
1145 return TRUE;
1149 /******************************************************************************
1150 * SetConsoleCursorPosition [KERNEL32.627]
1151 * Sets the cursor position in console
1153 * PARAMS
1154 * hConsoleOutput [I] Handle of console screen buffer
1155 * dwCursorPosition [I] New cursor position coordinates
1157 * RETURNS STD
1159 BOOL32 WINAPI SetConsoleCursorPosition( HANDLE32 hcon, COORD pos )
1161 char xbuf[20];
1162 DWORD xlen;
1163 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hcon, K32OBJ_CONSOLE, 0, NULL);
1165 if (!console) {
1166 FIXME(console,"(%d,...), no console handle!\n",hcon);
1167 return FALSE;
1169 CONSOLE_make_complex(hcon,console);
1170 TRACE(console, "%d (%dx%d)\n", hcon, pos.x , pos.y );
1171 /* x are columns, y rows */
1172 sprintf(xbuf,"%c[%d;%dH", 0x1B, pos.y+1, pos.x+1);
1173 /* FIXME: store internal if we start using own console buffers */
1174 WriteFile(hcon,xbuf,strlen(xbuf),&xlen,NULL);
1175 K32OBJ_DecCount(&console->header);
1176 return TRUE;
1179 /***********************************************************************
1180 * GetNumberOfConsoleInputEvents (KERNEL32.246)
1182 BOOL32 WINAPI GetNumberOfConsoleInputEvents(HANDLE32 hcon,LPDWORD nrofevents)
1184 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hcon, K32OBJ_CONSOLE, 0, NULL);
1186 if (!console) {
1187 FIXME(console,"(%d,%p), no console handle!\n",hcon,nrofevents);
1188 return FALSE;
1190 CONSOLE_get_input(hcon);
1191 *nrofevents = console->nrofirs;
1192 K32OBJ_DecCount(&console->header);
1193 return TRUE;
1196 /***********************************************************************
1197 * GetNumberOfConsoleMouseButtons (KERNEL32.358)
1199 BOOL32 WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons)
1201 FIXME(console,"(%p): stub\n", nrofbuttons);
1202 *nrofbuttons = 2;
1203 return TRUE;
1206 /***********************************************************************
1207 * PeekConsoleInputA (KERNEL32.550)
1209 * Gets 'cInRecords' first events (or less) from input queue.
1211 * Does not need a complex console.
1213 BOOL32 WINAPI PeekConsoleInput32A(HANDLE32 hConsoleInput,
1214 LPINPUT_RECORD pirBuffer,
1215 DWORD cInRecords,
1216 LPDWORD lpcRead)
1218 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hConsoleInput, K32OBJ_CONSOLE, 0, NULL);
1220 if (!console) {
1221 FIXME(console,"(%d,%p,%ld,%p), No console handle passed!\n",hConsoleInput, pirBuffer, cInRecords, lpcRead);
1222 return FALSE;
1224 TRACE(console,"(%d,%p,%ld,%p)\n",hConsoleInput, pirBuffer, cInRecords, lpcRead);
1225 CONSOLE_get_input(hConsoleInput);
1226 if (cInRecords>console->nrofirs)
1227 cInRecords = console->nrofirs;
1228 if (pirBuffer)
1229 memcpy(pirBuffer,console->irs,cInRecords*sizeof(INPUT_RECORD));
1230 if (lpcRead)
1231 *lpcRead = cInRecords;
1232 K32OBJ_DecCount(&console->header);
1233 return TRUE;
1236 /***********************************************************************
1237 * PeekConsoleInputW (KERNEL32.551)
1239 BOOL32 WINAPI PeekConsoleInput32W(HANDLE32 hConsoleInput,
1240 LPINPUT_RECORD pirBuffer,
1241 DWORD cInRecords,
1242 LPDWORD lpcRead)
1244 /* FIXME: Hmm. Fix this if we get UNICODE input. */
1245 return PeekConsoleInput32A(hConsoleInput,pirBuffer,cInRecords,lpcRead);
1249 /******************************************************************************
1250 * GetConsoleCursorInfo32 [KERNEL32.296] Gets size and visibility of console
1252 * PARAMS
1253 * hcon [I] Handle to console screen buffer
1254 * cinfo [O] Address of cursor information
1256 * RETURNS
1257 * Success: TRUE
1258 * Failure: FALSE
1260 BOOL32 WINAPI GetConsoleCursorInfo32( HANDLE32 hcon,
1261 LPCONSOLE_CURSOR_INFO cinfo )
1263 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hcon, K32OBJ_CONSOLE, 0, NULL);
1265 if (!console) {
1266 FIXME(console, "(%x,%p), no console handle!\n", hcon, cinfo);
1267 return FALSE;
1269 TRACE(console, "(%x,%p)\n", hcon, cinfo);
1270 if (!cinfo)
1271 return FALSE;
1272 *cinfo = console->cinfo;
1273 K32OBJ_DecCount(&console->header);
1274 return TRUE;
1278 /******************************************************************************
1279 * SetConsoleCursorInfo32 [KERNEL32.626] Sets size and visibility of cursor
1281 * RETURNS
1282 * Success: TRUE
1283 * Failure: FALSE
1285 BOOL32 WINAPI SetConsoleCursorInfo32(
1286 HANDLE32 hcon, /* [in] Handle to console screen buffer */
1287 LPCONSOLE_CURSOR_INFO cinfo) /* [in] Address of cursor information */
1289 char buf[8];
1290 DWORD xlen;
1291 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hcon, K32OBJ_CONSOLE, 0, NULL);
1293 TRACE(console, "(%x,%ld,%i): stub\n", hcon,cinfo->dwSize,cinfo->bVisible);
1294 if (!console)
1295 return FALSE;
1296 CONSOLE_make_complex(hcon,console);
1297 sprintf(buf,"%c[?25%c",27,cinfo->bVisible?'h':'l');
1298 WriteFile(hcon,buf,strlen(buf),&xlen,NULL);
1299 console->cinfo = *cinfo;
1300 K32OBJ_DecCount(&console->header);
1301 return TRUE;
1305 /******************************************************************************
1306 * SetConsoleWindowInfo [KERNEL32.634] Sets size and position of console
1308 * RETURNS
1309 * Success: TRUE
1310 * Failure: FALSE
1312 BOOL32 WINAPI SetConsoleWindowInfo(
1313 HANDLE32 hcon, /* [in] Handle to console screen buffer */
1314 BOOL32 bAbsolute, /* [in] Coordinate type flag */
1315 LPSMALL_RECT window) /* [in] Address of new window rectangle */
1317 FIXME(console, "(%x,%d,%p): stub\n", hcon, bAbsolute, window);
1318 return TRUE;
1322 /******************************************************************************
1323 * SetConsoleTextAttribute32 [KERNEL32.631] Sets colors for text
1325 * Sets the foreground and background color attributes of characters
1326 * written to the screen buffer.
1328 * RETURNS
1329 * Success: TRUE
1330 * Failure: FALSE
1332 BOOL32 WINAPI SetConsoleTextAttribute32(HANDLE32 hConsoleOutput,WORD wAttr)
1334 const int colormap[8] = {
1335 0,4,2,6,
1336 1,5,3,7,
1338 DWORD xlen;
1339 char buffer[20];
1341 TRACE(console,"(%d,%d)\n",hConsoleOutput,wAttr);
1342 sprintf(buffer,"%c[0;%s3%d;4%dm",
1344 (wAttr & FOREGROUND_INTENSITY)?"1;":"",
1345 colormap[wAttr&7],
1346 colormap[(wAttr&0x70)>>4]
1348 WriteFile(hConsoleOutput,buffer,strlen(buffer),&xlen,NULL);
1349 return TRUE;
1353 /******************************************************************************
1354 * SetConsoleScreenBufferSize [KERNEL32.630] Changes size of console
1356 * PARAMS
1357 * hConsoleOutput [I] Handle to console screen buffer
1358 * dwSize [I] New size in character rows and cols
1360 * RETURNS
1361 * Success: TRUE
1362 * Failure: FALSE
1364 BOOL32 WINAPI SetConsoleScreenBufferSize( HANDLE32 hConsoleOutput,
1365 COORD dwSize )
1367 FIXME(console, "(%d,%dx%d): stub\n",hConsoleOutput,dwSize.x,dwSize.y);
1368 return TRUE;
1372 /******************************************************************************
1373 * FillConsoleOutputCharacterA [KERNEL32.242]
1375 * PARAMS
1376 * hConsoleOutput [I] Handle to screen buffer
1377 * cCharacter [I] Character to write
1378 * nLength [I] Number of cells to write to
1379 * dwCoord [I] Coords of first cell
1380 * lpNumCharsWritten [O] Pointer to number of cells written
1382 * RETURNS
1383 * Success: TRUE
1384 * Failure: FALSE
1386 BOOL32 WINAPI FillConsoleOutputCharacterA(
1387 HANDLE32 hConsoleOutput,
1388 BYTE cCharacter,
1389 DWORD nLength,
1390 COORD dwCoord,
1391 LPDWORD lpNumCharsWritten)
1393 long count;
1394 DWORD xlen;
1396 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
1397 for(count=0;count<nLength;count++)
1398 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
1399 *lpNumCharsWritten = nLength;
1400 return TRUE;
1404 /******************************************************************************
1405 * FillConsoleOutputCharacterW [KERNEL32.243] Writes characters to console
1407 * PARAMS
1408 * hConsoleOutput [I] Handle to screen buffer
1409 * cCharacter [I] Character to write
1410 * nLength [I] Number of cells to write to
1411 * dwCoord [I] Coords of first cell
1412 * lpNumCharsWritten [O] Pointer to number of cells written
1414 * RETURNS
1415 * Success: TRUE
1416 * Failure: FALSE
1418 BOOL32 WINAPI FillConsoleOutputCharacterW(HANDLE32 hConsoleOutput,
1419 WCHAR cCharacter,
1420 DWORD nLength,
1421 COORD dwCoord,
1422 LPDWORD lpNumCharsWritten)
1424 long count;
1425 DWORD xlen;
1427 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
1428 /* FIXME: not quite correct ... but the lower part of UNICODE char comes
1429 * first
1431 for(count=0;count<nLength;count++)
1432 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
1433 *lpNumCharsWritten = nLength;
1434 return TRUE;
1438 /******************************************************************************
1439 * FillConsoleOutputAttribute [KERNEL32.241] Sets attributes for console
1441 * PARAMS
1442 * hConsoleOutput [I] Handle to screen buffer
1443 * wAttribute [I] Color attribute to write
1444 * nLength [I] Number of cells to write to
1445 * dwCoord [I] Coords of first cell
1446 * lpNumAttrsWritten [O] Pointer to number of cells written
1448 * RETURNS
1449 * Success: TRUE
1450 * Failure: FALSE
1452 BOOL32 WINAPI FillConsoleOutputAttribute( HANDLE32 hConsoleOutput,
1453 WORD wAttribute, DWORD nLength, COORD dwCoord,
1454 LPDWORD lpNumAttrsWritten)
1456 FIXME(console, "(%d,%d,%ld,%dx%d,%p): stub\n", hConsoleOutput,
1457 wAttribute,nLength,dwCoord.x,dwCoord.y,lpNumAttrsWritten);
1458 *lpNumAttrsWritten = nLength;
1459 return TRUE;
1462 /******************************************************************************
1463 * ReadConsoleOutputCharacter32A [KERNEL32.573]
1465 * BUGS
1466 * Unimplemented
1468 BOOL32 WINAPI ReadConsoleOutputCharacter32A(HANDLE32 hConsoleOutput,
1469 LPSTR lpstr, DWORD dword, COORD coord, LPDWORD lpdword)
1471 FIXME(console, "(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,lpstr,
1472 dword,coord.x,coord.y,lpdword);
1473 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1474 return FALSE;
1478 /******************************************************************************
1479 * ScrollConsoleScreenBuffer [KERNEL32.612]
1481 * BUGS
1482 * Unimplemented
1484 BOOL32 WINAPI ScrollConsoleScreenBuffer( HANDLE32 hConsoleOutput,
1485 LPSMALL_RECT lpScrollRect, LPSMALL_RECT lpClipRect,
1486 COORD dwDestOrigin, LPCHAR_INFO lpFill)
1488 FIXME(console, "(%d,%p,%p,%dx%d,%p): stub\n", hConsoleOutput,lpScrollRect,
1489 lpClipRect,dwDestOrigin.x,dwDestOrigin.y,lpFill);
1490 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1491 return FALSE;