Group commit for recovery after disk crash.
[wine/multimedia.git] / win32 / console.c
blobe2bc6229269804f93498a5f5a9468f4141d8cba9
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 temp, slave;
510 struct set_console_fd_request req;
512 temp = wine_openpty(&console->master, &slave, name, term,
513 winsize);
514 console->infd = console->outfd = slave;
516 req.handle = console->hread;
517 CLIENT_SendRequest(REQ_SET_CONSOLE_FD, dup(slave), 1,
518 &req, sizeof(req));
519 CLIENT_WaitReply( NULL, NULL, 0);
520 req.handle = console->hwrite;
521 CLIENT_SendRequest( REQ_SET_CONSOLE_FD, dup(slave), 1,
522 &req, sizeof(req));
523 CLIENT_WaitReply( NULL, NULL, 0);
525 return temp; /* The same result as the openpty call */
528 /*************************************************************************
529 * CONSOLE_make_complex [internal]
531 * Turns a CONSOLE kernel object into a complex one.
532 * (switches from output/input using the terminal where WINE was started to
533 * its own xterm).
535 * This makes simple commandline tools pipeable, while complex commandline
536 * tools work without getting messed up by debugoutput.
538 * All other functions should work indedependend from this call.
540 * To test for complex console: pid == -1 -> simple, otherwise complex.
542 static BOOL32 CONSOLE_make_complex(HANDLE32 handle,CONSOLE *console)
544 struct termios term;
545 char buf[30],*title;
546 char c = '\0';
547 int status = 0;
548 int i,xpid;
549 DWORD xlen;
551 if (console->pid != -1)
552 return TRUE; /* already complex */
554 MSG("Console: Making console complex (creating an xterm)...\n");
556 if (tcgetattr(0, &term) < 0) return FALSE;
557 term.c_lflag = ~(ECHO|ICANON);
558 if (CONSOLE_openpty(console, NULL, &term, NULL) < 0) return FALSE;
560 if ((xpid=fork()) == 0) {
561 tcsetattr(console->infd, TCSADRAIN, &term);
562 sprintf(buf, "-Sxx%d", console->master);
563 /* "-fn vga" for VGA font. Harmless if vga is not present:
564 * xterm: unable to open font "vga", trying "fixed"....
566 execlp("xterm", "xterm", buf, "-fn","vga",NULL);
567 ERR(console, "error creating AllocConsole xterm\n");
568 exit(1);
570 console->pid = xpid;
572 /* most xterms like to print their window ID when used with -S;
573 * read it and continue before the user has a chance...
575 for (i=0; c!='\n'; (status=read(console->infd, &c, 1)), i++) {
576 if (status == -1 && c == '\0') {
577 /* wait for xterm to be created */
578 usleep(100);
580 if (i > 10000) {
581 ERR(console, "can't read xterm WID\n");
582 kill(console->pid, SIGKILL);
583 return FALSE;
586 /* enable mouseclicks */
587 sprintf(buf,"%c[?1001s%c[?1000h",27,27);
588 WriteFile(handle,buf,strlen(buf),&xlen,NULL);
589 if (console->title) {
590 title = HeapAlloc(GetProcessHeap(),0,strlen("\033]2;\a")+1+strlen(console->title));
591 sprintf(title,"\033]2;%s\a",console->title);
592 WriteFile(handle,title,strlen(title),&xlen,NULL);
593 HeapFree(GetProcessHeap(),0,title);
595 return TRUE;
599 /***********************************************************************
600 * CONSOLE_GetConsoleHandle
601 * returns a 16-bit style console handle
602 * note: only called from _lopen
604 HFILE32 CONSOLE_GetConsoleHandle(VOID)
606 PDB32 *pdb = PROCESS_Current();
607 HFILE32 handle = HFILE_ERROR32;
609 SYSTEM_LOCK();
610 if (pdb->console != NULL) {
611 CONSOLE *console = (CONSOLE *)pdb->console;
612 handle = (HFILE32)HANDLE_Alloc(pdb, &console->header, 0, TRUE, -1);
614 SYSTEM_UNLOCK();
615 return handle;
618 /***********************************************************************
619 * AllocConsole (KERNEL32.103)
621 * creates an xterm with a pty to our program
623 BOOL32 WINAPI AllocConsole(VOID)
625 struct create_console_request req;
626 struct create_console_reply reply;
627 PDB32 *pdb = PROCESS_Current();
628 CONSOLE *console;
629 HANDLE32 hIn, hOut, hErr;
631 SYSTEM_LOCK(); /* FIXME: really only need to lock the process */
633 SetLastError(ERROR_CANNOT_MAKE); /* this might not be the right
634 error, but it's a good guess :) */
636 console = (CONSOLE *)pdb->console;
638 /* don't create a console if we already have one */
639 if (console != NULL) {
640 SetLastError(ERROR_ACCESS_DENIED);
641 SYSTEM_UNLOCK();
642 return FALSE;
645 if (!(console = (CONSOLE*)HeapAlloc( SystemHeap, 0, sizeof(*console))))
647 SYSTEM_UNLOCK();
648 return FALSE;
651 console->header.type = K32OBJ_CONSOLE;
652 console->header.refcount = 1;
653 console->pid = -1;
654 console->title = NULL;
655 console->nrofirs = 0;
656 console->irs = HeapAlloc(GetProcessHeap(),0,1);;
657 console->mode = ENABLE_PROCESSED_INPUT
658 | ENABLE_LINE_INPUT
659 | ENABLE_ECHO_INPUT;
660 /* FIXME: we shouldn't probably use hardcoded UNIX values here. */
661 console->infd = 0;
662 console->outfd = 1;
663 console->hread = console->hwrite = -1;
665 CLIENT_SendRequest( REQ_CREATE_CONSOLE, -1, 1, &req, sizeof(req) );
666 if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ) != ERROR_SUCCESS)
668 K32OBJ_DecCount(&console->header);
669 SYSTEM_UNLOCK();
670 return FALSE;
672 console->hread = reply.handle_read;
673 console->hwrite = reply.handle_write;
675 if ((hIn = HANDLE_Alloc(pdb,&console->header, 0, TRUE,
676 reply.handle_read)) == INVALID_HANDLE_VALUE32)
678 CLIENT_CloseHandle( reply.handle_write );
679 K32OBJ_DecCount(&console->header);
680 SYSTEM_UNLOCK();
681 return FALSE;
684 if ((hOut = HANDLE_Alloc(pdb,&console->header, 0, TRUE,
685 reply.handle_write)) == INVALID_HANDLE_VALUE32)
687 CloseHandle(hIn);
688 K32OBJ_DecCount(&console->header);
689 SYSTEM_UNLOCK();
690 return FALSE;
693 if (!DuplicateHandle( GetCurrentProcess(), hOut,
694 GetCurrentProcess(), &hErr,
695 0, TRUE, DUPLICATE_SAME_ACCESS ))
697 CloseHandle(hIn);
698 CloseHandle(hOut);
699 K32OBJ_DecCount(&console->header);
700 SYSTEM_UNLOCK();
701 return FALSE;
704 if (pdb->console) K32OBJ_DecCount( pdb->console );
705 pdb->console = (K32OBJ *)console;
706 K32OBJ_IncCount( pdb->console );
708 /* NT resets the STD_*_HANDLEs on console alloc */
709 SetStdHandle(STD_INPUT_HANDLE, hIn);
710 SetStdHandle(STD_OUTPUT_HANDLE, hOut);
711 SetStdHandle(STD_ERROR_HANDLE, hErr);
713 SetLastError(ERROR_SUCCESS);
714 SYSTEM_UNLOCK();
715 SetConsoleTitle32A("Wine Console");
716 return TRUE;
720 /******************************************************************************
721 * GetConsoleCP [KERNEL32.295] Returns the OEM code page for the console
723 * RETURNS
724 * Code page code
726 UINT32 WINAPI GetConsoleCP(VOID)
728 return GetACP();
732 /***********************************************************************
733 * GetConsoleOutputCP (KERNEL32.189)
735 UINT32 WINAPI GetConsoleOutputCP(VOID)
737 return GetConsoleCP();
740 /***********************************************************************
741 * GetConsoleMode (KERNEL32.188)
743 BOOL32 WINAPI GetConsoleMode(HANDLE32 hcon,LPDWORD mode)
745 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hcon, K32OBJ_CONSOLE, 0, NULL);
747 if (!console) {
748 FIXME(console,"(%d,%p), no console handle passed!\n",hcon,mode);
749 return FALSE;
751 *mode = console->mode;
752 K32OBJ_DecCount(&console->header);
753 return TRUE;
757 /******************************************************************************
758 * SetConsoleMode [KERNEL32.628] Sets input mode of console's input buffer
760 * PARAMS
761 * hcon [I] Handle to console input or screen buffer
762 * mode [I] Input or output mode to set
764 * RETURNS
765 * Success: TRUE
766 * Failure: FALSE
768 BOOL32 WINAPI SetConsoleMode( HANDLE32 hcon, DWORD mode )
770 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hcon, K32OBJ_CONSOLE, 0, NULL);
772 if (!console) {
773 FIXME(console,"(%d,%ld), no console handle passed!\n",hcon,mode);
774 return FALSE;
776 FIXME(console,"(0x%08x,0x%08lx): stub\n",hcon,mode);
777 console->mode = mode;
778 K32OBJ_DecCount(&console->header);
779 return TRUE;
783 /***********************************************************************
784 * GetConsoleTitleA (KERNEL32.191)
786 DWORD WINAPI GetConsoleTitle32A(LPSTR title,DWORD size)
788 PDB32 *pdb = PROCESS_Current();
789 CONSOLE *console= (CONSOLE *)pdb->console;
791 if(console && console->title) {
792 lstrcpyn32A(title,console->title,size);
793 return strlen(title);
795 return 0;
799 /******************************************************************************
800 * GetConsoleTitle32W [KERNEL32.192] Retrieves title string for console
802 * PARAMS
803 * title [O] Address of buffer for title
804 * size [I] Size of buffer
806 * RETURNS
807 * Success: Length of string copied
808 * Failure: 0
810 DWORD WINAPI GetConsoleTitle32W( LPWSTR title, DWORD size )
812 PDB32 *pdb = PROCESS_Current();
813 CONSOLE *console= (CONSOLE *)pdb->console;
814 if(console && console->title)
816 lstrcpynAtoW(title,console->title,size);
817 return (lstrlen32W(title));
819 return 0;
823 /***********************************************************************
824 * WriteConsoleA (KERNEL32.729)
826 BOOL32 WINAPI WriteConsole32A( HANDLE32 hConsoleOutput,
827 LPCVOID lpBuffer,
828 DWORD nNumberOfCharsToWrite,
829 LPDWORD lpNumberOfCharsWritten,
830 LPVOID lpReserved )
832 /* FIXME: should I check if this is a console handle? */
833 return WriteFile(hConsoleOutput, lpBuffer, nNumberOfCharsToWrite,
834 lpNumberOfCharsWritten, NULL);
838 #define CADD(c) \
839 if (bufused==curbufsize-1) \
840 buffer = HeapReAlloc(GetProcessHeap(),0,buffer,(curbufsize+=100));\
841 buffer[bufused++]=c;
842 #define SADD(s) { char *x=s;while (*x) {CADD(*x);x++;}}
844 /***********************************************************************
845 * WriteConsoleOutputA (KERNEL32.732)
847 BOOL32 WINAPI WriteConsoleOutput32A( HANDLE32 hConsoleOutput,
848 LPCHAR_INFO lpBuffer,
849 COORD dwBufferSize,
850 COORD dwBufferCoord,
851 LPSMALL_RECT lpWriteRegion)
853 int i,j,off=0,lastattr=-1;
854 char sbuf[20],*buffer=NULL;
855 int bufused=0,curbufsize = 100;
856 DWORD res;
857 const int colormap[8] = {
858 0,4,2,6,
859 1,5,3,7,
861 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hConsoleOutput, K32OBJ_CONSOLE, 0, NULL);
863 if (!console) {
864 FIXME(console,"(%d,...): no console handle!\n",hConsoleOutput);
865 return FALSE;
867 CONSOLE_make_complex(hConsoleOutput,console);
868 buffer = HeapAlloc(GetProcessHeap(),0,100);;
869 curbufsize = 100;
871 TRACE(console,"wr: top = %d, bottom=%d, left=%d,right=%d\n",
872 lpWriteRegion->Top,
873 lpWriteRegion->Bottom,
874 lpWriteRegion->Left,
875 lpWriteRegion->Right
878 for (i=lpWriteRegion->Top;i<=lpWriteRegion->Bottom;i++) {
879 sprintf(sbuf,"%c[%d;%dH",27,i+1,lpWriteRegion->Left+1);
880 SADD(sbuf);
881 for (j=lpWriteRegion->Left;j<=lpWriteRegion->Right;j++) {
882 if (lastattr!=lpBuffer[off].Attributes) {
883 lastattr = lpBuffer[off].Attributes;
884 sprintf(sbuf,"%c[0;%s3%d;4%dm",
886 (lastattr & FOREGROUND_INTENSITY)?"1;":"",
887 colormap[lastattr&7],
888 colormap[(lastattr&0x70)>>4]
890 /* FIXME: BACKGROUND_INTENSITY */
891 SADD(sbuf);
893 CADD(lpBuffer[off].Char.AsciiChar);
894 off++;
897 sprintf(sbuf,"%c[0m",27);SADD(sbuf);
898 WriteFile(hConsoleOutput,buffer,bufused,&res,NULL);
899 HeapFree(GetProcessHeap(),0,buffer);
900 K32OBJ_DecCount(&console->header);
901 return TRUE;
904 /***********************************************************************
905 * WriteConsoleW (KERNEL32.577)
907 BOOL32 WINAPI WriteConsole32W( HANDLE32 hConsoleOutput,
908 LPCVOID lpBuffer,
909 DWORD nNumberOfCharsToWrite,
910 LPDWORD lpNumberOfCharsWritten,
911 LPVOID lpReserved )
913 BOOL32 ret;
914 LPSTR xstring=HeapAlloc( GetProcessHeap(), 0, nNumberOfCharsToWrite );
916 lstrcpynWtoA( xstring, lpBuffer,nNumberOfCharsToWrite);
918 /* FIXME: should I check if this is a console handle? */
919 ret= WriteFile(hConsoleOutput, xstring, nNumberOfCharsToWrite,
920 lpNumberOfCharsWritten, NULL);
921 HeapFree( GetProcessHeap(), 0, xstring );
922 return ret;
926 /***********************************************************************
927 * ReadConsoleA (KERNEL32.419)
929 BOOL32 WINAPI ReadConsole32A( HANDLE32 hConsoleInput,
930 LPVOID lpBuffer,
931 DWORD nNumberOfCharsToRead,
932 LPDWORD lpNumberOfCharsRead,
933 LPVOID lpReserved )
935 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hConsoleInput, K32OBJ_CONSOLE, 0, NULL);
936 int i,charsread = 0;
937 LPSTR xbuf = (LPSTR)lpBuffer;
939 if (!console) {
940 SetLastError(ERROR_INVALID_HANDLE);
941 FIXME(console,"(%d,...), no console handle!\n",hConsoleInput);
942 return FALSE;
944 TRACE(console,"(%d,%p,%ld,%p,%p)\n",
945 hConsoleInput,lpBuffer,nNumberOfCharsToRead,
946 lpNumberOfCharsRead,lpReserved
948 CONSOLE_get_input(hConsoleInput);
950 /* FIXME: should we read at least 1 char? The SDK does not say */
951 for (i=0;(i<console->nrofirs)&&(charsread<nNumberOfCharsToRead);i++) {
952 if (console->irs[i].EventType != KEY_EVENT)
953 continue;
954 if (!console->irs[i].Event.KeyEvent.bKeyDown)
955 continue;
956 *xbuf++ = console->irs[i].Event.KeyEvent.uChar.AsciiChar;
957 charsread++;
959 /* SDK says: Drains all other input events from queue. */
960 CONSOLE_drain_input(console,i);
961 if (lpNumberOfCharsRead)
962 *lpNumberOfCharsRead = charsread;
963 K32OBJ_DecCount(&console->header);
964 return TRUE;
967 /***********************************************************************
968 * ReadConsoleW (KERNEL32.427)
970 BOOL32 WINAPI ReadConsole32W( HANDLE32 hConsoleInput,
971 LPVOID lpBuffer,
972 DWORD nNumberOfCharsToRead,
973 LPDWORD lpNumberOfCharsRead,
974 LPVOID lpReserved )
976 BOOL32 ret;
977 LPSTR buf = (LPSTR)HeapAlloc(GetProcessHeap(), 0, nNumberOfCharsToRead);
979 ret = ReadConsole32A(
980 hConsoleInput,
981 buf,
982 nNumberOfCharsToRead,
983 lpNumberOfCharsRead,
984 lpReserved
986 if (ret)
987 lstrcpynAtoW(lpBuffer,buf,nNumberOfCharsToRead);
988 HeapFree( GetProcessHeap(), 0, buf );
989 return ret;
993 /******************************************************************************
994 * ReadConsoleInput32A [KERNEL32.569] Reads data from a console
996 * PARAMS
997 * hConsoleInput [I] Handle to console input buffer
998 * lpBuffer [O] Address of buffer for read data
999 * nLength [I] Number of records to read
1000 * lpNumberOfEventsRead [O] Address of number of records read
1002 * RETURNS
1003 * Success: TRUE
1004 * Failure: FALSE
1006 BOOL32 WINAPI ReadConsoleInput32A(HANDLE32 hConsoleInput,
1007 LPINPUT_RECORD lpBuffer,
1008 DWORD nLength, LPDWORD lpNumberOfEventsRead)
1010 CONSOLE *console = (CONSOLE*)HANDLE_GetObjPtr( PROCESS_Current(), hConsoleInput, K32OBJ_CONSOLE, 0, NULL);
1012 TRACE(console, "(%d,%p,%ld,%p)\n",hConsoleInput, lpBuffer, nLength,
1013 lpNumberOfEventsRead);
1014 if (!console) {
1015 FIXME(console, "(%d,%p,%ld,%p), No console handle!\n",hConsoleInput,
1016 lpBuffer, nLength, lpNumberOfEventsRead);
1018 /* Indicate that nothing was read */
1019 *lpNumberOfEventsRead = 0;
1021 return FALSE;
1023 CONSOLE_get_input(hConsoleInput);
1024 /* SDK: return at least 1 input record */
1025 while (!console->nrofirs) {
1026 DWORD res;
1028 res=WaitForSingleObject(hConsoleInput,0);
1029 switch (res) {
1030 case STATUS_TIMEOUT: continue;
1031 case 0: break; /*ok*/
1032 case WAIT_FAILED: return 0;/*FIXME: SetLastError?*/
1033 default: break; /*hmm*/
1035 CONSOLE_get_input(hConsoleInput);
1038 if (nLength>console->nrofirs)
1039 nLength = console->nrofirs;
1040 memcpy(lpBuffer,console->irs,sizeof(INPUT_RECORD)*nLength);
1041 if (lpNumberOfEventsRead)
1042 *lpNumberOfEventsRead = nLength;
1043 CONSOLE_drain_input(console,nLength);
1044 K32OBJ_DecCount(&console->header);
1045 return TRUE;
1048 /***********************************************************************
1049 * SetConsoleTitle32A (KERNEL32.476)
1051 * Sets the console title.
1053 * We do not necessarily need to create a complex console for that,
1054 * but should remember the title and set it on creation of the latter.
1055 * (not fixed at this time).
1057 BOOL32 WINAPI SetConsoleTitle32A(LPCSTR title)
1059 PDB32 *pdb = PROCESS_Current();
1060 CONSOLE *console;
1061 DWORD written;
1062 char titleformat[]="\033]2;%s\a"; /*this should work for xterms*/
1063 LPSTR titlestring;
1064 BOOL32 ret=FALSE;
1066 TRACE(console,"(%s)\n",title);
1068 console = (CONSOLE *)pdb->console;
1069 if (!console)
1070 return FALSE;
1071 if(console->title) /* Free old title, if there is one */
1072 HeapFree( SystemHeap, 0, console->title );
1073 console->title = (LPSTR)HeapAlloc(SystemHeap, 0,strlen(title)+1);
1074 if(console->title) strcpy(console->title,title);
1075 titlestring = HeapAlloc(GetProcessHeap(), 0,strlen(title)+strlen(titleformat)+1);
1076 if (!titlestring) {
1077 K32OBJ_DecCount(&console->header);
1078 return FALSE;
1081 sprintf(titlestring,titleformat,title);
1082 /* only set title for complex console (own xterm) */
1083 if (console->pid != -1) {
1084 WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),titlestring,strlen(titlestring),&written,NULL);
1085 if (written == strlen(titlestring))
1086 ret =TRUE;
1087 } else
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);
1219 /* Indicate that nothing was read */
1220 *lpcRead = 0;
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;