Cleaned up and removed some no longer used code.
[wine/multimedia.git] / win32 / console.c
blob31c9d8791014334b4ef828f05fc4b3d70fa7da01
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 } CONSOLE;
65 static void CONSOLE_Destroy( K32OBJ *obj );
67 const K32OBJ_OPS CONSOLE_Ops =
69 CONSOLE_Destroy /* destroy */
72 /***********************************************************************
73 * CONSOLE_Destroy
75 static void CONSOLE_Destroy(K32OBJ *obj)
77 CONSOLE *console = (CONSOLE *)obj;
78 assert(obj->type == K32OBJ_CONSOLE);
80 obj->type = K32OBJ_UNKNOWN;
82 if (console->title)
83 HeapFree( SystemHeap, 0, console->title );
84 console->title = NULL;
85 /* if there is a xterm, kill it. */
86 if (console->pid != -1)
87 kill(console->pid, SIGTERM);
88 HeapFree(SystemHeap, 0, console);
92 /****************************************************************************
93 * CONSOLE_add_input_record [internal]
95 * Adds an INPUT_RECORD to the CONSOLEs input queue.
97 static void
98 CONSOLE_add_input_record(CONSOLE *console,INPUT_RECORD *inp) {
99 console->irs = HeapReAlloc(GetProcessHeap(),0,console->irs,sizeof(INPUT_RECORD)*(console->nrofirs+1));
100 console->irs[console->nrofirs++]=*inp;
103 /****************************************************************************
104 * XTERM_string_to_IR [internal]
106 * Transfers a string read from XTERM to INPUT_RECORDs and adds them to the
107 * queue. Does translation of vt100 style function keys and xterm-mouse clicks.
109 static void
110 CONSOLE_string_to_IR( HANDLE32 hConsoleInput,unsigned char *buf,int len) {
111 int j,k;
112 INPUT_RECORD ir;
113 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hConsoleInput,
114 K32OBJ_CONSOLE, 0, NULL);
116 for (j=0;j<len;j++) {
117 unsigned char inchar = buf[j];
119 if (inchar!=27) { /* no escape -> 'normal' keyboard event */
120 ir.EventType = 1; /* Key_event */
122 ir.Event.KeyEvent.bKeyDown = 1;
123 ir.Event.KeyEvent.wRepeatCount = 0;
125 ir.Event.KeyEvent.dwControlKeyState = 0;
126 if (inchar & 0x80) {
127 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
128 inchar &= ~0x80;
130 ir.Event.KeyEvent.wVirtualKeyCode = VkKeyScan16(inchar);
131 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0100)
132 ir.Event.KeyEvent.dwControlKeyState|=SHIFT_PRESSED;
133 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0200)
134 ir.Event.KeyEvent.dwControlKeyState|=LEFT_CTRL_PRESSED;
135 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0400)
136 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
137 ir.Event.KeyEvent.wVirtualScanCode = MapVirtualKey16(
138 ir.Event.KeyEvent.wVirtualKeyCode & 0x00ff,
139 0 /* VirtualKeyCodes to ScanCode */
141 if (inchar=='\n') {
142 ir.Event.KeyEvent.uChar.AsciiChar = '\r';
143 ir.Event.KeyEvent.wVirtualKeyCode = 0x0d;
144 ir.Event.KeyEvent.wVirtualScanCode = 0x1c;
145 } else {
146 ir.Event.KeyEvent.uChar.AsciiChar = inchar;
147 if (inchar<' ') {
148 /* FIXME: find good values for ^X */
149 ir.Event.KeyEvent.wVirtualKeyCode = 0xdead;
150 ir.Event.KeyEvent.wVirtualScanCode = 0xbeef;
154 CONSOLE_add_input_record(console,&ir);
155 ir.Event.KeyEvent.bKeyDown = 0;
156 CONSOLE_add_input_record(console,&ir);
157 continue;
159 /* inchar is ESC */
160 if ((j==len-1) || (buf[j+1]!='[')) {/* add ESCape on its own */
161 ir.EventType = 1; /* Key_event */
162 ir.Event.KeyEvent.bKeyDown = 1;
163 ir.Event.KeyEvent.wRepeatCount = 0;
165 ir.Event.KeyEvent.wVirtualKeyCode = VkKeyScan16(27);
166 ir.Event.KeyEvent.wVirtualScanCode = MapVirtualKey16(
167 ir.Event.KeyEvent.wVirtualKeyCode,0
169 ir.Event.KeyEvent.dwControlKeyState = 0;
170 ir.Event.KeyEvent.uChar.AsciiChar = 27;
171 CONSOLE_add_input_record(console,&ir);
172 ir.Event.KeyEvent.bKeyDown = 0;
173 CONSOLE_add_input_record(console,&ir);
174 continue;
176 for (k=j;k<len;k++) {
177 if (((buf[k]>='A') && (buf[k]<='Z')) ||
178 ((buf[k]>='a') && (buf[k]<='z')) ||
179 (buf[k]=='~')
181 break;
183 if (k<len) {
184 int subid,scancode=0;
186 ir.EventType = 1; /* Key_event */
187 ir.Event.KeyEvent.bKeyDown = 1;
188 ir.Event.KeyEvent.wRepeatCount = 0;
189 ir.Event.KeyEvent.dwControlKeyState = 0;
191 ir.Event.KeyEvent.wVirtualKeyCode = 0xad; /* FIXME */
192 ir.Event.KeyEvent.wVirtualScanCode = 0xad; /* FIXME */
193 ir.Event.KeyEvent.uChar.AsciiChar = 0;
195 switch (buf[k]) {
196 case '~':
197 sscanf(&buf[j+2],"%d",&subid);
198 switch (subid) {
199 case 2:/*INS */scancode = 0xe052;break;
200 case 3:/*DEL */scancode = 0xe053;break;
201 case 6:/*PGDW*/scancode = 0xe051;break;
202 case 5:/*PGUP*/scancode = 0xe049;break;
203 case 11:/*F1 */scancode = 0x003b;break;
204 case 12:/*F2 */scancode = 0x003c;break;
205 case 13:/*F3 */scancode = 0x003d;break;
206 case 14:/*F4 */scancode = 0x003e;break;
207 case 15:/*F5 */scancode = 0x003f;break;
208 case 17:/*F6 */scancode = 0x0040;break;
209 case 18:/*F7 */scancode = 0x0041;break;
210 case 19:/*F8 */scancode = 0x0042;break;
211 case 20:/*F9 */scancode = 0x0043;break;
212 case 21:/*F10 */scancode = 0x0044;break;
213 case 23:/*F11 */scancode = 0x00d9;break;
214 case 24:/*F12 */scancode = 0x00da;break;
215 /* FIXME: Shift-Fx */
216 default:
217 FIXME(console,"parse ESC[%d~\n",subid);
218 break;
220 break;
221 case 'A': /* Cursor Up */scancode = 0xe048;break;
222 case 'B': /* Cursor Down */scancode = 0xe050;break;
223 case 'D': /* Cursor Left */scancode = 0xe04b;break;
224 case 'C': /* Cursor Right */scancode = 0xe04d;break;
225 case 'F': /* End */scancode = 0xe04f;break;
226 case 'H': /* Home */scancode = 0xe047;break;
227 case 'M':
228 /* Mouse Button Press (ESCM<button+'!'><x+'!'><y+'!'>) or
229 * Release (ESCM#<x+'!'><y+'!'>
231 if (k<len-3) {
232 ir.EventType = MOUSE_EVENT;
233 ir.Event.MouseEvent.dwMousePosition.x = buf[k+2]-'!';
234 ir.Event.MouseEvent.dwMousePosition.y = buf[k+3]-'!';
235 if (buf[k+1]=='#')
236 ir.Event.MouseEvent.dwButtonState = 0;
237 else
238 ir.Event.MouseEvent.dwButtonState = 1<<(buf[k+1]-' ');
239 ir.Event.MouseEvent.dwEventFlags = 0; /* FIXME */
240 CONSOLE_add_input_record(console,&ir);
241 j=k+3;
243 break;
246 if (scancode) {
247 ir.Event.KeyEvent.wVirtualScanCode = scancode;
248 ir.Event.KeyEvent.wVirtualKeyCode = MapVirtualKey16(scancode,1);
249 CONSOLE_add_input_record(console,&ir);
250 ir.Event.KeyEvent.bKeyDown = 0;
251 CONSOLE_add_input_record(console,&ir);
252 j=k;
253 continue;
257 K32OBJ_DecCount(&console->header);
260 /****************************************************************************
261 * CONSOLE_get_input (internal)
263 * Reads (nonblocking) as much input events as possible and stores them
264 * in an internal queue.
266 static void
267 CONSOLE_get_input( HANDLE32 handle )
269 char *buf = HeapAlloc(GetProcessHeap(),0,1);
270 int len = 0;
272 while (1)
274 DWORD res;
275 char inchar;
276 if (!WaitForSingleObject( handle, 0 )) break;
277 if (!ReadFile( handle, &inchar, 1, &res, NULL )) break;
278 buf = HeapReAlloc(GetProcessHeap(),0,buf,len+1);
279 buf[len++]=inchar;
281 CONSOLE_string_to_IR(handle,buf,len);
282 HeapFree(GetProcessHeap(),0,buf);
285 /****************************************************************************
286 * CONSOLE_drain_input (internal)
288 * Drains 'n' console input events from the queue.
290 static void
291 CONSOLE_drain_input(CONSOLE *console,int n) {
292 assert(n<=console->nrofirs);
293 if (n) {
294 console->nrofirs-=n;
295 memcpy( &console->irs[0],
296 &console->irs[n],
297 console->nrofirs*sizeof(INPUT_RECORD)
299 console->irs = HeapReAlloc(
300 GetProcessHeap(),
302 console->irs,
303 console->nrofirs*sizeof(INPUT_RECORD)
309 /******************************************************************************
310 * SetConsoleCtrlHandler [KERNEL32.459] Adds function to calling process list
312 * PARAMS
313 * func [I] Address of handler function
314 * add [I] Handler to add or remove
316 * RETURNS
317 * Success: TRUE
318 * Failure: FALSE
320 * CHANGED
321 * James Sutherland (JamesSutherland@gmx.de)
322 * Added global variables console_ignore_ctrl_c and handlers[]
323 * Does not yet do any error checking, or set LastError if failed.
324 * This doesn't yet matter, since these handlers are not yet called...!
326 static unsigned int console_ignore_ctrl_c = 0;
327 static HANDLER_ROUTINE *handlers[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
328 BOOL32 WINAPI SetConsoleCtrlHandler( HANDLER_ROUTINE *func, BOOL32 add )
330 unsigned int alloc_loop = sizeof(handlers)/sizeof(HANDLER_ROUTINE *);
331 unsigned int done = 0;
332 FIXME(console, "(%p,%i) - no error checking or testing yet\n", func, add);
333 if (!func)
335 console_ignore_ctrl_c = add;
336 return TRUE;
338 if (add)
340 for (;alloc_loop--;)
341 if (!handlers[alloc_loop] && !done)
343 handlers[alloc_loop] = func;
344 done++;
346 if (!done)
347 FIXME(console, "Out of space on CtrlHandler table\n");
348 return(done);
350 else
352 for (;alloc_loop--;)
353 if (handlers[alloc_loop] == func && !done)
355 handlers[alloc_loop] = 0;
356 done++;
358 if (!done)
359 WARN(console, "Attempt to remove non-installed CtrlHandler %p\n",
360 func);
361 return (done);
363 return (done);
367 /******************************************************************************
368 * GenerateConsoleCtrlEvent [KERNEL32.275] Simulate a CTRL-C or CTRL-BREAK
370 * PARAMS
371 * dwCtrlEvent [I] Type of event
372 * dwProcessGroupID [I] Process group ID to send event to
374 * NOTES
375 * Doesn't yet work...!
377 * RETURNS
378 * Success: True
379 * Failure: False (and *should* [but doesn't] set LastError)
381 BOOL32 WINAPI GenerateConsoleCtrlEvent( DWORD dwCtrlEvent,
382 DWORD dwProcessGroupID )
384 if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
386 ERR( console, "invalid event %d for PGID %ld\n",
387 (unsigned short)dwCtrlEvent, dwProcessGroupID );
388 return FALSE;
390 if (dwProcessGroupID == GetCurrentProcessId() )
392 FIXME( console, "Attempt to send event %d to self - stub\n",
393 (unsigned short)dwCtrlEvent );
394 return FALSE;
396 FIXME( console,"event %d to external PGID %ld - not implemented yet\n",
397 (unsigned short)dwCtrlEvent, dwProcessGroupID );
398 return FALSE;
402 /******************************************************************************
403 * CreateConsoleScreenBuffer [KERNEL32.151] Creates a console screen buffer
405 * PARAMS
406 * dwDesiredAccess [I] Access flag
407 * dwShareMode [I] Buffer share mode
408 * sa [I] Security attributes
409 * dwFlags [I] Type of buffer to create
410 * lpScreenBufferData [I] Reserved
412 * NOTES
413 * Should call SetLastError
415 * RETURNS
416 * Success: Handle to new console screen buffer
417 * Failure: INVALID_HANDLE_VALUE
419 HANDLE32 WINAPI CreateConsoleScreenBuffer( DWORD dwDesiredAccess,
420 DWORD dwShareMode, LPSECURITY_ATTRIBUTES sa,
421 DWORD dwFlags, LPVOID lpScreenBufferData )
423 FIXME(console, "(%ld,%ld,%p,%ld,%p): stub\n",dwDesiredAccess,
424 dwShareMode, sa, dwFlags, lpScreenBufferData);
425 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
426 return INVALID_HANDLE_VALUE32;
430 /***********************************************************************
431 * GetConsoleScreenBufferInfo (KERNEL32.190)
433 BOOL32 WINAPI GetConsoleScreenBufferInfo( HANDLE32 hConsoleOutput,
434 LPCONSOLE_SCREEN_BUFFER_INFO csbi )
436 csbi->dwSize.x = 80;
437 csbi->dwSize.y = 24;
438 csbi->dwCursorPosition.x = 0;
439 csbi->dwCursorPosition.y = 0;
440 csbi->wAttributes = 0;
441 csbi->srWindow.Left = 0;
442 csbi->srWindow.Right = 79;
443 csbi->srWindow.Top = 0;
444 csbi->srWindow.Bottom = 23;
445 csbi->dwMaximumWindowSize.x = 80;
446 csbi->dwMaximumWindowSize.y = 24;
447 return TRUE;
451 /******************************************************************************
452 * SetConsoleActiveScreenBuffer [KERNEL32.623] Sets buffer to current console
454 * RETURNS
455 * Success: TRUE
456 * Failure: FALSE
458 BOOL32 WINAPI SetConsoleActiveScreenBuffer(
459 HANDLE32 hConsoleOutput) /* [in] Handle to console screen buffer */
461 FIXME(console, "(%x): stub\n", hConsoleOutput);
462 return FALSE;
466 /***********************************************************************
467 * GetLargestConsoleWindowSize (KERNEL32.226)
469 DWORD WINAPI GetLargestConsoleWindowSize( HANDLE32 hConsoleOutput )
471 return (DWORD)MAKELONG(80,24);
474 /***********************************************************************
475 * FreeConsole (KERNEL32.267)
477 BOOL32 WINAPI FreeConsole(VOID)
480 PDB32 *pdb = PROCESS_Current();
481 CONSOLE *console;
483 SYSTEM_LOCK();
485 console = (CONSOLE *)pdb->console;
487 if (console == NULL) {
488 SetLastError(ERROR_INVALID_PARAMETER);
489 return FALSE;
492 HANDLE_CloseAll( pdb, &console->header );
494 K32OBJ_DecCount( &console->header );
495 pdb->console = NULL;
496 SYSTEM_UNLOCK();
497 return TRUE;
501 /**
502 * It looks like the openpty that comes with glibc in RedHat 5.0
503 * is buggy (second call returns what looks like a dup of 0 and 1
504 * instead of a new pty), this is a generic replacement.
506 static int CONSOLE_openpty(CONSOLE *console, char *name,
507 struct termios *term, struct winsize *winsize)
509 int fdm, fds;
510 char *ptr1, *ptr2;
511 char pts_name[512];
512 struct set_console_fd_request req;
514 strcpy (pts_name, "/dev/ptyXY");
516 for (ptr1 = "pqrstuvwxyzPQRST"; *ptr1 != 0; ptr1++) {
517 pts_name[8] = *ptr1;
518 for (ptr2 = "0123456789abcdef"; *ptr2 != 0; ptr2++) {
519 pts_name[9] = *ptr2;
521 if ((fdm = open(pts_name, O_RDWR)) < 0) {
522 if (errno == ENOENT)
523 return -1;
524 else
525 continue;
527 pts_name[5] = 't';
528 if ((fds = open(pts_name, O_RDWR)) < 0) {
529 pts_name[5] = 'p';
530 continue;
532 console->master = fdm;
533 console->infd = console->outfd = fds;
534 req.handle = console->hread;
535 CLIENT_SendRequest( REQ_SET_CONSOLE_FD, dup(fds), 1, &req, sizeof(req) );
536 CLIENT_WaitReply( NULL, NULL, 0 );
537 req.handle = console->hwrite;
538 CLIENT_SendRequest( REQ_SET_CONSOLE_FD, dup(fds), 1, &req, sizeof(req) );
539 CLIENT_WaitReply( NULL, NULL, 0 );
541 if (term != NULL)
542 tcsetattr(console->infd, TCSANOW, term);
543 if (winsize != NULL)
544 ioctl(console->outfd, TIOCSWINSZ, winsize);
545 if (name != NULL)
546 strcpy(name, pts_name);
547 return fds;
550 return -1;
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 indedependend from this call.
565 * To test for complex console: pid == -1 -> simple, otherwise complex.
567 static BOOL32 CONSOLE_make_complex(HANDLE32 handle,CONSOLE *console)
569 struct termios term;
570 char buf[30];
571 char c = '\0';
572 int status = 0;
573 int i,xpid;
574 DWORD xlen;
576 if (console->pid != -1)
577 return TRUE; /* already complex */
579 MSG("Console: Making console complex (creating an xterm)...\n");
581 if (tcgetattr(0, &term) < 0) return FALSE;
582 term.c_lflag = ~(ECHO|ICANON);
583 if (CONSOLE_openpty(console, NULL, &term, NULL) < 0) return FALSE;
585 if ((xpid=fork()) == 0) {
586 tcsetattr(console->infd, TCSADRAIN, &term);
587 sprintf(buf, "-Sxx%d", console->master);
588 /* "-fn vga" for VGA font. Harmless if vga is not present:
589 * xterm: unable to open font "vga", trying "fixed"....
591 execlp("xterm", "xterm", buf, "-fn","vga",NULL);
592 ERR(console, "error creating AllocConsole xterm\n");
593 exit(1);
595 console->pid = xpid;
597 /* most xterms like to print their window ID when used with -S;
598 * read it and continue before the user has a chance...
600 for (i=0; c!='\n'; (status=read(console->infd, &c, 1)), i++) {
601 if (status == -1 && c == '\0') {
602 /* wait for xterm to be created */
603 usleep(100);
605 if (i > 10000) {
606 ERR(console, "can't read xterm WID\n");
607 kill(console->pid, SIGKILL);
608 return FALSE;
611 /* enable mouseclicks */
612 sprintf(buf,"%c[?1001s%c[?1000h",27,27);
613 WriteFile(handle,buf,strlen(buf),&xlen,NULL);
614 return TRUE;
618 /***********************************************************************
619 * CONSOLE_GetConsoleHandle
620 * returns a 16-bit style console handle
621 * note: only called from _lopen
623 HFILE32 CONSOLE_GetConsoleHandle(VOID)
625 PDB32 *pdb = PROCESS_Current();
626 HFILE32 handle = HFILE_ERROR32;
628 SYSTEM_LOCK();
629 if (pdb->console != NULL) {
630 CONSOLE *console = (CONSOLE *)pdb->console;
631 handle = (HFILE32)HANDLE_Alloc(pdb, &console->header, 0, TRUE, -1);
633 SYSTEM_UNLOCK();
634 return handle;
637 /***********************************************************************
638 * AllocConsole (KERNEL32.103)
640 * creates an xterm with a pty to our program
642 BOOL32 WINAPI AllocConsole(VOID)
644 struct create_console_request req;
645 struct create_console_reply reply;
646 PDB32 *pdb = PROCESS_Current();
647 CONSOLE *console;
648 HANDLE32 hIn, hOut, hErr;
650 SYSTEM_LOCK(); /* FIXME: really only need to lock the process */
652 SetLastError(ERROR_CANNOT_MAKE); /* this might not be the right
653 error, but it's a good guess :) */
655 console = (CONSOLE *)pdb->console;
657 /* don't create a console if we already have one */
658 if (console != NULL) {
659 SetLastError(ERROR_ACCESS_DENIED);
660 SYSTEM_UNLOCK();
661 return FALSE;
664 if (!(console = (CONSOLE*)HeapAlloc( SystemHeap, 0, sizeof(*console))))
666 SYSTEM_UNLOCK();
667 return FALSE;
670 console->header.type = K32OBJ_CONSOLE;
671 console->header.refcount = 1;
672 console->pid = -1;
673 console->title = NULL;
674 console->nrofirs = 0;
675 console->irs = HeapAlloc(GetProcessHeap(),0,1);;
676 console->mode = ENABLE_PROCESSED_INPUT
677 | ENABLE_LINE_INPUT
678 | ENABLE_ECHO_INPUT;
679 /* FIXME: we shouldn't probably use hardcoded UNIX values here. */
680 console->infd = 0;
681 console->outfd = 1;
682 console->hread = console->hwrite = -1;
684 CLIENT_SendRequest( REQ_CREATE_CONSOLE, -1, 1, &req, sizeof(req) );
685 if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ) != ERROR_SUCCESS)
687 K32OBJ_DecCount(&console->header);
688 SYSTEM_UNLOCK();
689 return FALSE;
691 console->hread = reply.handle_read;
692 console->hwrite = reply.handle_write;
694 if ((hIn = HANDLE_Alloc(pdb,&console->header, 0, TRUE,
695 reply.handle_read)) == INVALID_HANDLE_VALUE32)
697 CLIENT_CloseHandle( reply.handle_write );
698 K32OBJ_DecCount(&console->header);
699 SYSTEM_UNLOCK();
700 return FALSE;
703 if ((hOut = HANDLE_Alloc(pdb,&console->header, 0, TRUE,
704 reply.handle_write)) == INVALID_HANDLE_VALUE32)
706 CloseHandle(hIn);
707 K32OBJ_DecCount(&console->header);
708 SYSTEM_UNLOCK();
709 return FALSE;
712 if (!DuplicateHandle( GetCurrentProcess(), hOut,
713 GetCurrentProcess(), &hErr,
714 0, TRUE, DUPLICATE_SAME_ACCESS ))
716 CloseHandle(hIn);
717 CloseHandle(hOut);
718 K32OBJ_DecCount(&console->header);
719 SYSTEM_UNLOCK();
720 return FALSE;
723 if (pdb->console) K32OBJ_DecCount( pdb->console );
724 pdb->console = (K32OBJ *)console;
725 K32OBJ_IncCount( pdb->console );
727 /* NT resets the STD_*_HANDLEs on console alloc */
728 SetStdHandle(STD_INPUT_HANDLE, hIn);
729 SetStdHandle(STD_OUTPUT_HANDLE, hOut);
730 SetStdHandle(STD_ERROR_HANDLE, hErr);
732 SetLastError(ERROR_SUCCESS);
733 SYSTEM_UNLOCK();
734 SetConsoleTitle32A("Wine Console");
735 return TRUE;
739 /******************************************************************************
740 * GetConsoleCP [KERNEL32.295] Returns the OEM code page for the console
742 * RETURNS
743 * Code page code
745 UINT32 WINAPI GetConsoleCP(VOID)
747 return GetACP();
751 /***********************************************************************
752 * GetConsoleOutputCP (KERNEL32.189)
754 UINT32 WINAPI GetConsoleOutputCP(VOID)
756 return GetConsoleCP();
759 /***********************************************************************
760 * GetConsoleMode (KERNEL32.188)
762 BOOL32 WINAPI GetConsoleMode(HANDLE32 hcon,LPDWORD mode)
764 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hcon, K32OBJ_CONSOLE, 0, NULL);
766 if (!console) {
767 FIXME(console,"(%d,%p), no console handle passed!\n",hcon,mode);
768 return FALSE;
770 *mode = console->mode;
771 K32OBJ_DecCount(&console->header);
772 return TRUE;
776 /******************************************************************************
777 * SetConsoleMode [KERNEL32.628] Sets input mode of console's input buffer
779 * PARAMS
780 * hcon [I] Handle to console input or screen buffer
781 * mode [I] Input or output mode to set
783 * RETURNS
784 * Success: TRUE
785 * Failure: FALSE
787 BOOL32 WINAPI SetConsoleMode( HANDLE32 hcon, DWORD mode )
789 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hcon, K32OBJ_CONSOLE, 0, NULL);
791 if (!console) {
792 FIXME(console,"(%d,%ld), no console handle passed!\n",hcon,mode);
793 return FALSE;
795 FIXME(console,"(0x%08x,0x%08lx): stub\n",hcon,mode);
796 console->mode = mode;
797 K32OBJ_DecCount(&console->header);
798 return TRUE;
802 /***********************************************************************
803 * GetConsoleTitleA (KERNEL32.191)
805 DWORD WINAPI GetConsoleTitle32A(LPSTR title,DWORD size)
807 PDB32 *pdb = PROCESS_Current();
808 CONSOLE *console= (CONSOLE *)pdb->console;
810 if(console && console->title) {
811 lstrcpyn32A(title,console->title,size);
812 return strlen(title);
814 return 0;
818 /******************************************************************************
819 * GetConsoleTitle32W [KERNEL32.192] Retrieves title string for console
821 * PARAMS
822 * title [O] Address of buffer for title
823 * size [I] Size of buffer
825 * RETURNS
826 * Success: Length of string copied
827 * Failure: 0
829 DWORD WINAPI GetConsoleTitle32W( LPWSTR title, DWORD size )
831 PDB32 *pdb = PROCESS_Current();
832 CONSOLE *console= (CONSOLE *)pdb->console;
833 if(console && console->title)
835 lstrcpynAtoW(title,console->title,size);
836 return (lstrlen32W(title));
838 return 0;
842 /***********************************************************************
843 * WriteConsoleA (KERNEL32.729)
845 BOOL32 WINAPI WriteConsole32A( HANDLE32 hConsoleOutput,
846 LPCVOID lpBuffer,
847 DWORD nNumberOfCharsToWrite,
848 LPDWORD lpNumberOfCharsWritten,
849 LPVOID lpReserved )
851 /* FIXME: should I check if this is a console handle? */
852 return WriteFile(hConsoleOutput, lpBuffer, nNumberOfCharsToWrite,
853 lpNumberOfCharsWritten, NULL);
857 #define CADD(c) \
858 if (bufused==curbufsize-1) \
859 buffer = HeapReAlloc(GetProcessHeap(),0,buffer,(curbufsize+=100));\
860 buffer[bufused++]=c;
861 #define SADD(s) { char *x=s;while (*x) {CADD(*x);x++;}}
863 /***********************************************************************
864 * WriteConsoleOutputA (KERNEL32.732)
866 BOOL32 WINAPI WriteConsoleOutput32A( HANDLE32 hConsoleOutput,
867 LPCHAR_INFO lpBuffer,
868 COORD dwBufferSize,
869 COORD dwBufferCoord,
870 LPSMALL_RECT lpWriteRegion)
872 int i,j,off=0,lastattr=-1;
873 char sbuf[20],*buffer=NULL;
874 int bufused=0,curbufsize = 100;
875 DWORD res;
876 const int colormap[8] = {
877 0,4,2,6,
878 1,5,3,7,
880 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hConsoleOutput, K32OBJ_CONSOLE, 0, NULL);
882 if (!console) {
883 FIXME(console,"(%d,...): no console handle!\n",hConsoleOutput);
884 return FALSE;
886 CONSOLE_make_complex(hConsoleOutput,console);
887 buffer = HeapAlloc(GetProcessHeap(),0,100);;
888 curbufsize = 100;
890 TRACE(console,"wr: top = %d, bottom=%d, left=%d,right=%d\n",
891 lpWriteRegion->Top,
892 lpWriteRegion->Bottom,
893 lpWriteRegion->Left,
894 lpWriteRegion->Right
897 for (i=lpWriteRegion->Top;i<=lpWriteRegion->Bottom;i++) {
898 sprintf(sbuf,"%c[%d;%dH",27,i+1,lpWriteRegion->Left+1);
899 SADD(sbuf);
900 for (j=lpWriteRegion->Left;j<=lpWriteRegion->Right;j++) {
901 if (lastattr!=lpBuffer[off].Attributes) {
902 lastattr = lpBuffer[off].Attributes;
903 sprintf(sbuf,"%c[0;%s3%d;4%dm",
905 (lastattr & FOREGROUND_INTENSITY)?"1;":"",
906 colormap[lastattr&7],
907 colormap[(lastattr&0x70)>>4]
909 /* FIXME: BACKGROUND_INTENSITY */
910 SADD(sbuf);
912 CADD(lpBuffer[off].Char.AsciiChar);
913 off++;
916 sprintf(sbuf,"%c[0m",27);SADD(sbuf);
917 WriteFile(hConsoleOutput,buffer,bufused,&res,NULL);
918 HeapFree(GetProcessHeap(),0,buffer);
919 K32OBJ_DecCount(&console->header);
920 return TRUE;
923 /***********************************************************************
924 * WriteConsoleW (KERNEL32.577)
926 BOOL32 WINAPI WriteConsole32W( HANDLE32 hConsoleOutput,
927 LPCVOID lpBuffer,
928 DWORD nNumberOfCharsToWrite,
929 LPDWORD lpNumberOfCharsWritten,
930 LPVOID lpReserved )
932 BOOL32 ret;
933 LPSTR xstring=HeapAlloc( GetProcessHeap(), 0, nNumberOfCharsToWrite );
935 lstrcpynWtoA( xstring, lpBuffer,nNumberOfCharsToWrite);
937 /* FIXME: should I check if this is a console handle? */
938 ret= WriteFile(hConsoleOutput, xstring, nNumberOfCharsToWrite,
939 lpNumberOfCharsWritten, NULL);
940 HeapFree( GetProcessHeap(), 0, xstring );
941 return ret;
945 /***********************************************************************
946 * ReadConsoleA (KERNEL32.419)
948 BOOL32 WINAPI ReadConsole32A( HANDLE32 hConsoleInput,
949 LPVOID lpBuffer,
950 DWORD nNumberOfCharsToRead,
951 LPDWORD lpNumberOfCharsRead,
952 LPVOID lpReserved )
954 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hConsoleInput, K32OBJ_CONSOLE, 0, NULL);
955 int i,charsread = 0;
956 LPSTR xbuf = (LPSTR)lpBuffer;
958 if (!console) {
959 SetLastError(ERROR_INVALID_HANDLE);
960 FIXME(console,"(%d,...), no console handle!\n",hConsoleInput);
961 return FALSE;
963 TRACE(console,"(%d,%p,%ld,%p,%p)\n",
964 hConsoleInput,lpBuffer,nNumberOfCharsToRead,
965 lpNumberOfCharsRead,lpReserved
967 CONSOLE_get_input(hConsoleInput);
969 /* FIXME: should this drain everything from the input queue and just
970 * put the keypresses in the buffer? Needs further thought.
972 for (i=0;(i<console->nrofirs)&&(charsread<nNumberOfCharsToRead);i++) {
973 if (console->irs[i].EventType != KEY_EVENT)
974 continue;
975 if (!console->irs[i].Event.KeyEvent.bKeyDown)
976 continue;
977 *xbuf++ = console->irs[i].Event.KeyEvent.uChar.AsciiChar;
978 charsread++;
980 CONSOLE_drain_input(console,i);
981 if (lpNumberOfCharsRead)
982 *lpNumberOfCharsRead = charsread;
983 K32OBJ_DecCount(&console->header);
984 return TRUE;
987 /***********************************************************************
988 * ReadConsoleW (KERNEL32.427)
990 BOOL32 WINAPI ReadConsole32W( HANDLE32 hConsoleInput,
991 LPVOID lpBuffer,
992 DWORD nNumberOfCharsToRead,
993 LPDWORD lpNumberOfCharsRead,
994 LPVOID lpReserved )
996 BOOL32 ret;
997 LPSTR buf = (LPSTR)HeapAlloc(GetProcessHeap(), 0, nNumberOfCharsToRead);
999 ret = ReadConsole32A(
1000 hConsoleInput,
1001 buf,
1002 nNumberOfCharsToRead,
1003 lpNumberOfCharsRead,
1004 lpReserved
1006 if (ret)
1007 lstrcpynAtoW(lpBuffer,buf,nNumberOfCharsToRead);
1008 HeapFree( GetProcessHeap(), 0, buf );
1009 return ret;
1013 /******************************************************************************
1014 * ReadConsoleInput32A [KERNEL32.569] Reads data from a console
1016 * PARAMS
1017 * hConsoleInput [I] Handle to console input buffer
1018 * lpBuffer [O] Address of buffer for read data
1019 * nLength [I] Number of records to read
1020 * lpNumberOfEventsRead [O] Address of number of records read
1022 * RETURNS
1023 * Success: TRUE
1024 * Failure: FALSE
1026 BOOL32 WINAPI ReadConsoleInput32A(HANDLE32 hConsoleInput,
1027 LPINPUT_RECORD lpBuffer,
1028 DWORD nLength, LPDWORD lpNumberOfEventsRead)
1030 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hConsoleInput, K32OBJ_CONSOLE, 0, NULL);
1032 TRACE(console, "(%d,%p,%ld,%p)\n",hConsoleInput, lpBuffer, nLength,
1033 lpNumberOfEventsRead);
1034 if (!console) {
1035 FIXME(console, "(%d,%p,%ld,%p), No console handle!\n",hConsoleInput,
1036 lpBuffer, nLength, lpNumberOfEventsRead);
1037 return FALSE;
1039 CONSOLE_get_input(hConsoleInput);
1040 if (nLength>console->nrofirs)
1041 nLength = console->nrofirs;
1042 memcpy(lpBuffer,console->irs,sizeof(INPUT_RECORD)*nLength);
1043 if (lpNumberOfEventsRead)
1044 *lpNumberOfEventsRead = nLength;
1045 CONSOLE_drain_input(console,nLength);
1046 K32OBJ_DecCount(&console->header);
1047 return TRUE;
1050 /***********************************************************************
1051 * SetConsoleTitle32A (KERNEL32.476)
1053 * Sets the console title.
1055 * We do not necessarily need to create a complex console for that,
1056 * but should remember the title and set it on creation of the latter.
1057 * (not fixed at this time).
1059 BOOL32 WINAPI SetConsoleTitle32A(LPCSTR title)
1061 PDB32 *pdb = PROCESS_Current();
1062 CONSOLE *console;
1063 DWORD written;
1064 char titleformat[]="\033]2;%s\a"; /*this should work for xterms*/
1065 LPSTR titlestring;
1066 BOOL32 ret=FALSE;
1068 TRACE(console,"(%s)\n",title);
1070 console = (CONSOLE *)pdb->console;
1071 if (!console)
1072 return FALSE;
1073 if(console->title) /* Free old title, if there is one */
1074 HeapFree( SystemHeap, 0, console->title );
1075 console->title = (LPSTR)HeapAlloc(SystemHeap, 0,strlen(title)+1);
1076 if(console->title) strcpy(console->title,title);
1077 titlestring = HeapAlloc(GetProcessHeap(), 0,strlen(title)+strlen(titleformat)+1);
1078 if (!titlestring) {
1079 K32OBJ_DecCount(&console->header);
1080 return FALSE;
1083 sprintf(titlestring,titleformat,title);
1084 /* FIXME: hmm, should use WriteFile probably... */
1085 /*CONSOLE_Write(&console->header,titlestring,strlen(titlestring),&written,NULL);*/
1086 WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),titlestring,strlen(titlestring),&written,NULL);
1087 if (written == strlen(titlestring))
1088 ret =TRUE;
1089 HeapFree( GetProcessHeap(), 0, titlestring );
1090 K32OBJ_DecCount(&console->header);
1091 return ret;
1095 /******************************************************************************
1096 * SetConsoleTitle32W [KERNEL32.477] Sets title bar string for console
1098 * PARAMS
1099 * title [I] Address of new title
1101 * NOTES
1102 * This should not be calling the A version
1104 * RETURNS
1105 * Success: TRUE
1106 * Failure: FALSE
1108 BOOL32 WINAPI SetConsoleTitle32W( LPCWSTR title )
1110 BOOL32 ret;
1112 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
1113 ret = SetConsoleTitle32A(titleA);
1114 HeapFree( GetProcessHeap(), 0, titleA );
1115 return ret;
1118 /***********************************************************************
1119 * ReadConsoleInput32W (KERNEL32.570)
1121 BOOL32 WINAPI ReadConsoleInput32W(HANDLE32 hConsoleInput,
1122 LPINPUT_RECORD lpBuffer,
1123 DWORD nLength, LPDWORD lpNumberOfEventsRead)
1125 FIXME(console, "(%d,%p,%ld,%p): stub\n",hConsoleInput, lpBuffer, nLength,
1126 lpNumberOfEventsRead);
1127 return 0;
1130 /***********************************************************************
1131 * FlushConsoleInputBuffer (KERNEL32.132)
1133 BOOL32 WINAPI FlushConsoleInputBuffer(HANDLE32 hConsoleInput)
1135 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hConsoleInput, K32OBJ_CONSOLE, 0, NULL);
1137 if (!console)
1138 return FALSE;
1139 CONSOLE_drain_input(console,console->nrofirs);
1140 K32OBJ_DecCount(&console->header);
1141 return TRUE;
1145 /******************************************************************************
1146 * SetConsoleCursorPosition [KERNEL32.627]
1147 * Sets the cursor position in console
1149 * PARAMS
1150 * hConsoleOutput [I] Handle of console screen buffer
1151 * dwCursorPosition [I] New cursor position coordinates
1153 * RETURNS STD
1155 BOOL32 WINAPI SetConsoleCursorPosition( HANDLE32 hcon, COORD pos )
1157 char xbuf[20];
1158 DWORD xlen;
1159 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hcon, K32OBJ_CONSOLE, 0, NULL);
1161 if (!console) {
1162 FIXME(console,"(%d,...), no console handle!\n",hcon);
1163 return FALSE;
1165 CONSOLE_make_complex(hcon,console);
1166 TRACE(console, "%d (%dx%d)\n", hcon, pos.x , pos.y );
1167 /* x are columns, y rows */
1168 sprintf(xbuf,"%c[%d;%dH", 0x1B, pos.y+1, pos.x+1);
1169 /* FIXME: store internal if we start using own console buffers */
1170 WriteFile(hcon,xbuf,strlen(xbuf),&xlen,NULL);
1171 K32OBJ_DecCount(&console->header);
1172 return TRUE;
1175 /***********************************************************************
1176 * GetNumberOfConsoleInputEvents (KERNEL32.246)
1178 BOOL32 WINAPI GetNumberOfConsoleInputEvents(HANDLE32 hcon,LPDWORD nrofevents)
1180 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hcon, K32OBJ_CONSOLE, 0, NULL);
1182 if (!console) {
1183 FIXME(console,"(%d,%p), no console handle!\n",hcon,nrofevents);
1184 return FALSE;
1186 CONSOLE_get_input(hcon);
1187 *nrofevents = console->nrofirs;
1188 K32OBJ_DecCount(&console->header);
1189 return TRUE;
1192 /***********************************************************************
1193 * GetNumberOfConsoleMouseButtons (KERNEL32.358)
1195 BOOL32 WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons)
1197 FIXME(console,"(%p): stub\n", nrofbuttons);
1198 *nrofbuttons = 2;
1199 return TRUE;
1202 /***********************************************************************
1203 * PeekConsoleInputA (KERNEL32.550)
1205 * Gets 'cInRecords' first events (or less) from input queue.
1207 * Does not need a complex console.
1209 BOOL32 WINAPI PeekConsoleInput32A(HANDLE32 hConsoleInput,
1210 LPINPUT_RECORD pirBuffer,
1211 DWORD cInRecords,
1212 LPDWORD lpcRead)
1214 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hConsoleInput, K32OBJ_CONSOLE, 0, NULL);
1216 if (!console) {
1217 FIXME(console,"(%d,%p,%ld,%p), No console handle passed!\n",hConsoleInput, pirBuffer, cInRecords, lpcRead);
1218 return FALSE;
1220 TRACE(console,"(%d,%p,%ld,%p)\n",hConsoleInput, pirBuffer, cInRecords, lpcRead);
1221 CONSOLE_get_input(hConsoleInput);
1222 if (cInRecords>console->nrofirs)
1223 cInRecords = console->nrofirs;
1224 if (pirBuffer)
1225 memcpy(pirBuffer,console->irs,cInRecords*sizeof(INPUT_RECORD));
1226 if (lpcRead)
1227 *lpcRead = cInRecords;
1228 K32OBJ_DecCount(&console->header);
1229 return TRUE;
1232 /***********************************************************************
1233 * PeekConsoleInputW (KERNEL32.551)
1235 BOOL32 WINAPI PeekConsoleInput32W(HANDLE32 hConsoleInput,
1236 LPINPUT_RECORD pirBuffer,
1237 DWORD cInRecords,
1238 LPDWORD lpcRead)
1240 /* FIXME: Hmm. Fix this if we get UNICODE input. */
1241 return PeekConsoleInput32A(hConsoleInput,pirBuffer,cInRecords,lpcRead);
1245 /******************************************************************************
1246 * GetConsoleCursorInfo32 [KERNEL32.296] Gets size and visibility of console
1248 * PARAMS
1249 * hcon [I] Handle to console screen buffer
1250 * cinfo [O] Address of cursor information
1252 * RETURNS
1253 * Success: TRUE
1254 * Failure: FALSE
1256 BOOL32 WINAPI GetConsoleCursorInfo32( HANDLE32 hcon,
1257 LPCONSOLE_CURSOR_INFO cinfo )
1259 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hcon, K32OBJ_CONSOLE, 0, NULL);
1261 if (!console) {
1262 FIXME(console, "(%x,%p), no console handle!\n", hcon, cinfo);
1263 return FALSE;
1265 TRACE(console, "(%x,%p)\n", hcon, cinfo);
1266 if (!cinfo)
1267 return FALSE;
1268 *cinfo = console->cinfo;
1269 K32OBJ_DecCount(&console->header);
1270 return TRUE;
1274 /******************************************************************************
1275 * SetConsoleCursorInfo32 [KERNEL32.626] Sets size and visibility of cursor
1277 * RETURNS
1278 * Success: TRUE
1279 * Failure: FALSE
1281 BOOL32 WINAPI SetConsoleCursorInfo32(
1282 HANDLE32 hcon, /* [in] Handle to console screen buffer */
1283 LPCONSOLE_CURSOR_INFO cinfo) /* [in] Address of cursor information */
1285 char buf[8];
1286 DWORD xlen;
1287 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hcon, K32OBJ_CONSOLE, 0, NULL);
1289 TRACE(console, "(%x,%ld,%i): stub\n", hcon,cinfo->dwSize,cinfo->bVisible);
1290 if (!console)
1291 return FALSE;
1292 CONSOLE_make_complex(hcon,console);
1293 sprintf(buf,"%c[?25%c",27,cinfo->bVisible?'h':'l');
1294 WriteFile(hcon,buf,strlen(buf),&xlen,NULL);
1295 console->cinfo = *cinfo;
1296 K32OBJ_DecCount(&console->header);
1297 return TRUE;
1301 /******************************************************************************
1302 * SetConsoleWindowInfo [KERNEL32.634] Sets size and position of console
1304 * RETURNS
1305 * Success: TRUE
1306 * Failure: FALSE
1308 BOOL32 WINAPI SetConsoleWindowInfo(
1309 HANDLE32 hcon, /* [in] Handle to console screen buffer */
1310 BOOL32 bAbsolute, /* [in] Coordinate type flag */
1311 LPSMALL_RECT window) /* [in] Address of new window rectangle */
1313 FIXME(console, "(%x,%d,%p): stub\n", hcon, bAbsolute, window);
1314 return TRUE;
1318 /******************************************************************************
1319 * SetConsoleTextAttribute32 [KERNEL32.631] Sets colors for text
1321 * Sets the foreground and background color attributes of characters
1322 * written to the screen buffer.
1324 * RETURNS
1325 * Success: TRUE
1326 * Failure: FALSE
1328 BOOL32 WINAPI SetConsoleTextAttribute32(HANDLE32 hConsoleOutput,WORD wAttr)
1330 const int colormap[8] = {
1331 0,4,2,6,
1332 1,5,3,7,
1334 DWORD xlen;
1335 char buffer[20];
1337 TRACE(console,"(%d,%d)\n",hConsoleOutput,wAttr);
1338 sprintf(buffer,"%c[0;%s3%d;4%dm",
1340 (wAttr & FOREGROUND_INTENSITY)?"1;":"",
1341 colormap[wAttr&7],
1342 colormap[(wAttr&0x70)>>4]
1344 WriteFile(hConsoleOutput,buffer,strlen(buffer),&xlen,NULL);
1345 return TRUE;
1349 /******************************************************************************
1350 * SetConsoleScreenBufferSize [KERNEL32.630] Changes size of console
1352 * PARAMS
1353 * hConsoleOutput [I] Handle to console screen buffer
1354 * dwSize [I] New size in character rows and cols
1356 * RETURNS
1357 * Success: TRUE
1358 * Failure: FALSE
1360 BOOL32 WINAPI SetConsoleScreenBufferSize( HANDLE32 hConsoleOutput,
1361 COORD dwSize )
1363 FIXME(console, "(%d,%dx%d): stub\n",hConsoleOutput,dwSize.x,dwSize.y);
1364 return TRUE;
1368 /******************************************************************************
1369 * FillConsoleOutputCharacterA [KERNEL32.242]
1371 * PARAMS
1372 * hConsoleOutput [I] Handle to screen buffer
1373 * cCharacter [I] Character to write
1374 * nLength [I] Number of cells to write to
1375 * dwCoord [I] Coords of first cell
1376 * lpNumCharsWritten [O] Pointer to number of cells written
1378 * RETURNS
1379 * Success: TRUE
1380 * Failure: FALSE
1382 BOOL32 WINAPI FillConsoleOutputCharacterA(
1383 HANDLE32 hConsoleOutput,
1384 BYTE cCharacter,
1385 DWORD nLength,
1386 COORD dwCoord,
1387 LPDWORD lpNumCharsWritten)
1389 long count;
1390 DWORD xlen;
1392 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
1393 for(count=0;count<nLength;count++)
1394 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
1395 *lpNumCharsWritten = nLength;
1396 return TRUE;
1400 /******************************************************************************
1401 * FillConsoleOutputCharacterW [KERNEL32.243] Writes characters to console
1403 * PARAMS
1404 * hConsoleOutput [I] Handle to screen buffer
1405 * cCharacter [I] Character to write
1406 * nLength [I] Number of cells to write to
1407 * dwCoord [I] Coords of first cell
1408 * lpNumCharsWritten [O] Pointer to number of cells written
1410 * RETURNS
1411 * Success: TRUE
1412 * Failure: FALSE
1414 BOOL32 WINAPI FillConsoleOutputCharacterW(HANDLE32 hConsoleOutput,
1415 WCHAR cCharacter,
1416 DWORD nLength,
1417 COORD dwCoord,
1418 LPDWORD lpNumCharsWritten)
1420 long count;
1421 DWORD xlen;
1423 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
1424 /* FIXME: not quite correct ... but the lower part of UNICODE char comes
1425 * first
1427 for(count=0;count<nLength;count++)
1428 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
1429 *lpNumCharsWritten = nLength;
1430 return TRUE;
1434 /******************************************************************************
1435 * FillConsoleOutputAttribute [KERNEL32.241] Sets attributes for console
1437 * PARAMS
1438 * hConsoleOutput [I] Handle to screen buffer
1439 * wAttribute [I] Color attribute to write
1440 * nLength [I] Number of cells to write to
1441 * dwCoord [I] Coords of first cell
1442 * lpNumAttrsWritten [O] Pointer to number of cells written
1444 * RETURNS
1445 * Success: TRUE
1446 * Failure: FALSE
1448 BOOL32 WINAPI FillConsoleOutputAttribute( HANDLE32 hConsoleOutput,
1449 WORD wAttribute, DWORD nLength, COORD dwCoord,
1450 LPDWORD lpNumAttrsWritten)
1452 FIXME(console, "(%d,%d,%ld,%dx%d,%p): stub\n", hConsoleOutput,
1453 wAttribute,nLength,dwCoord.x,dwCoord.y,lpNumAttrsWritten);
1454 *lpNumAttrsWritten = nLength;
1455 return TRUE;
1458 /******************************************************************************
1459 * ReadConsoleOutputCharacter32A [KERNEL32.573]
1461 * BUGS
1462 * Unimplemented
1464 BOOL32 WINAPI ReadConsoleOutputCharacter32A(HANDLE32 hConsoleOutput,
1465 LPSTR lpstr, DWORD dword, COORD coord, LPDWORD lpdword)
1467 FIXME(console, "(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,lpstr,
1468 dword,coord.x,coord.y,lpdword);
1469 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1470 return FALSE;
1474 /******************************************************************************
1475 * ScrollConsoleScreenBuffer [KERNEL32.612]
1477 * BUGS
1478 * Unimplemented
1480 BOOL32 WINAPI ScrollConsoleScreenBuffer( HANDLE32 hConsoleOutput,
1481 LPSMALL_RECT lpScrollRect, LPSMALL_RECT lpClipRect,
1482 COORD dwDestOrigin, LPCHAR_INFO lpFill)
1484 FIXME(console, "(%d,%p,%p,%dx%d,%p): stub\n", hConsoleOutput,lpScrollRect,
1485 lpClipRect,dwDestOrigin.x,dwDestOrigin.y,lpFill);
1486 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1487 return FALSE;