2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
5 * Copyright 1997 Karl Garrison
6 * Copyright 1998 John Richardson
13 #include <sys/ioctl.h>
14 #include <sys/types.h>
19 #include <sys/errno.h>
31 static CONSOLE_SCREEN_BUFFER_INFO dummyinfo
=
40 /* The console -- I chose to keep the master and slave
41 * (UNIX) file descriptors around in case they are needed for
42 * ioctls later. The pid is needed to destroy the xterm on close
44 typedef struct _CONSOLE
{
46 int master
; /* xterm side of pty */
47 int slave
; /* wine side of pty */
48 int pid
; /* xterm's pid, -1 if no xterm */
49 LPSTR title
; /* title of console */
53 /* This probably belongs somewhere else */
54 typedef struct _CONSOLE_CURSOR_INFO
{
55 DWORD dwSize
; /* Between 1 & 100 for percentage of cell filled */
56 BOOL32 bVisible
; /* Visibility of cursor */
57 } CONSOLE_CURSOR_INFO
, *LPCONSOLE_CURSOR_INFO
;
61 static void CONSOLE_Destroy( K32OBJ
*obj
);
62 static BOOL32
CONSOLE_Write(K32OBJ
*ptr
, LPCVOID lpBuffer
,
63 DWORD nNumberOfChars
, LPDWORD lpNumberOfChars
,
64 LPOVERLAPPED lpOverlapped
);
65 static BOOL32
CONSOLE_Read(K32OBJ
*ptr
, LPVOID lpBuffer
,
66 DWORD nNumberOfChars
, LPDWORD lpNumberOfChars
,
67 LPOVERLAPPED lpOverlapped
);
68 static int wine_openpty(int *master
, int *slave
, char *name
,
69 struct termios
*term
, struct winsize
*winsize
);
70 static BOOL32
wine_createConsole(int *master
, int *slave
, int *pid
);
72 const K32OBJ_OPS CONSOLE_Ops
=
77 NULL
, /* remove_wait */
78 CONSOLE_Read
, /* read */
79 CONSOLE_Write
, /* write */
80 CONSOLE_Destroy
/* destroy */
85 /***********************************************************************
88 static void CONSOLE_Destroy(K32OBJ
*obj
)
90 CONSOLE
*console
= (CONSOLE
*)obj
;
91 assert(obj
->type
== K32OBJ_CONSOLE
);
93 obj
->type
= K32OBJ_UNKNOWN
;
96 HeapFree( SystemHeap
, 0, console
->title
);
97 console
->title
= NULL
;
98 /* make sure a xterm exists to kill */
99 if (console
->pid
!= -1) {
100 kill(console
->pid
, SIGTERM
);
102 HeapFree(SystemHeap
, 0, console
);
106 /***********************************************************************
110 * lpOverlapped is ignored
112 static BOOL32
CONSOLE_Read(K32OBJ
*ptr
, LPVOID lpBuffer
, DWORD nNumberOfChars
,
113 LPDWORD lpNumberOfChars
, LPOVERLAPPED lpOverlapped
)
115 CONSOLE
*console
= (CONSOLE
*)ptr
;
118 TRACE(console
, "%p %p %ld\n", ptr
, lpBuffer
,
121 *lpNumberOfChars
= 0;
123 if ((result
= read(console
->slave
, lpBuffer
, nNumberOfChars
)) == -1) {
127 *lpNumberOfChars
= result
;
132 /***********************************************************************
136 * lpOverlapped is ignored
138 static BOOL32
CONSOLE_Write(K32OBJ
*ptr
, LPCVOID lpBuffer
,
139 DWORD nNumberOfChars
,
140 LPDWORD lpNumberOfChars
, LPOVERLAPPED lpOverlapped
)
142 CONSOLE
*console
= (CONSOLE
*)ptr
;
145 TRACE(console
, "%p %p %ld\n", ptr
, lpBuffer
,
148 *lpNumberOfChars
= 0;
151 * I assume this loop around EAGAIN is here because
152 * win32 doesn't have interrupted system calls
157 result
= write(console
->slave
, lpBuffer
, nNumberOfChars
);
159 *lpNumberOfChars
= result
;
162 if (errno
!= EINTR
) {
170 /******************************************************************************
171 * SetConsoleCtrlHandler [KERNEL32.459] Adds function to calling process list
174 * func [I] Address of handler function
175 * add [I] Handler to add or remove
182 * James Sutherland (JamesSutherland@gmx.de)
183 * Added global variables console_ignore_ctrl_c and handlers[]
184 * Does not yet do any error checking, or set LastError if failed.
185 * This doesn't yet matter, since these handlers are not yet called...!
187 static unsigned int console_ignore_ctrl_c
= 0;
188 static HANDLER_ROUTINE
*handlers
[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
189 BOOL32 WINAPI
SetConsoleCtrlHandler( HANDLER_ROUTINE
*func
, BOOL32 add
)
191 unsigned int alloc_loop
= sizeof(handlers
)/sizeof(HANDLER_ROUTINE
*);
192 unsigned int done
= 0;
193 FIXME(console
, "(%p,%i) - no error checking or testing yet\n", func
, add
);
196 console_ignore_ctrl_c
= add
;
202 if (!handlers
[alloc_loop
] && !done
)
204 handlers
[alloc_loop
] = func
;
208 FIXME(console
, "Out of space on CtrlHandler table\n");
214 if (handlers
[alloc_loop
] == func
&& !done
)
216 handlers
[alloc_loop
] = 0;
220 WARN(console
, "Attempt to remove non-installed CtrlHandler %p\n",
228 /******************************************************************************
229 * GenerateConsoleCtrlEvent [KERNEL32.275] Simulate a CTRL-C or CTRL-BREAK
232 * dwCtrlEvent [I] Type of event
233 * dwProcessGroupID [I] Process group ID to send event to
236 * Doesn't yet work...!
240 * Failure: False (and *should* [but doesn't] set LastError)
242 BOOL32 WINAPI
GenerateConsoleCtrlEvent( DWORD dwCtrlEvent
,
243 DWORD dwProcessGroupID
)
245 if (dwCtrlEvent
!= CTRL_C_EVENT
&& dwCtrlEvent
!= CTRL_BREAK_EVENT
)
247 ERR( console
, "invalid event %d for PGID %d\n",
248 (unsigned short)dwCtrlEvent
, dwProcessGroupID
);
251 if (dwProcessGroupID
== GetCurrentProcessId() )
253 FIXME( console
, "Attempt to send event %d to self - stub\n",
254 (unsigned short)dwCtrlEvent
);
257 FIXME( console
,"event %d to external PGID %d - not implemented yet\n",
258 (unsigned short)dwCtrlEvent
, dwProcessGroupID
);
263 /******************************************************************************
264 * CreateConsoleScreenBuffer [KERNEL32.151] Creates a console screen buffer
267 * dwDesiredAccess [I] Access flag
268 * dwShareMode [I] Buffer share mode
269 * sa [I] Security attributes
270 * dwFlags [I] Type of buffer to create
271 * lpScreenBufferData [I] Reserved
274 * Should call SetLastError
277 * Success: Handle to new console screen buffer
278 * Failure: INVALID_HANDLE_VALUE
280 HANDLE32 WINAPI
CreateConsoleScreenBuffer( DWORD dwDesiredAccess
,
281 DWORD dwShareMode
, LPSECURITY_ATTRIBUTES sa
,
282 DWORD dwFlags
, LPVOID lpScreenBufferData
)
284 FIXME(console
, "(%ld,%ld,%p,%ld,%p): stub\n",dwDesiredAccess
,
285 dwShareMode
, sa
, dwFlags
, lpScreenBufferData
);
290 /***********************************************************************
291 * GetConsoleScreenBufferInfo (KERNEL32.190)
293 BOOL32 WINAPI
GetConsoleScreenBufferInfo( HANDLE32 hConsoleOutput
,
294 LPCONSOLE_SCREEN_BUFFER_INFO csbi
)
298 csbi
->dwCursorPosition
.x
= 0;
299 csbi
->dwCursorPosition
.y
= 0;
300 csbi
->wAttributes
= 0;
301 csbi
->srWindow
.Left
= 0;
302 csbi
->srWindow
.Right
= 79;
303 csbi
->srWindow
.Top
= 0;
304 csbi
->srWindow
.Bottom
= 23;
305 csbi
->dwMaximumWindowSize
.x
= 80;
306 csbi
->dwMaximumWindowSize
.y
= 24;
311 /******************************************************************************
312 * SetConsoleActiveScreenBuffer [KERNEL32.623] Sets buffer to current console
318 BOOL32 WINAPI
SetConsoleActiveScreenBuffer(
319 HANDLE32 hConsoleOutput
) /* [in] Handle to console screen buffer */
321 FIXME(console
, "(%x): stub\n", hConsoleOutput
);
326 /***********************************************************************
327 * GetLargestConsoleWindowSize (KERNEL32.226)
329 DWORD WINAPI
GetLargestConsoleWindowSize( HANDLE32 hConsoleOutput
)
331 return (DWORD
)MAKELONG(dummyinfo
.dwMaximumWindowSize
.x
,dummyinfo
.dwMaximumWindowSize
.y
);
334 /***********************************************************************
335 * FreeConsole (KERNEL32.267)
337 BOOL32 WINAPI
FreeConsole(VOID
)
340 PDB32
*pdb
= PROCESS_Current();
345 console
= (CONSOLE
*)pdb
->console
;
347 if (console
== NULL
) {
348 SetLastError(ERROR_INVALID_PARAMETER
);
352 HANDLE_CloseAll( pdb
, &console
->header
);
354 K32OBJ_DecCount( &console
->header
);
362 * It looks like the openpty that comes with glibc in RedHat 5.0
363 * is buggy (second call returns what looks like a dup of 0 and 1
364 * instead of a new pty), this is a generic replacement.
366 static int wine_openpty(int *master
, int *slave
, char *name
,
367 struct termios
*term
, struct winsize
*winsize
)
373 strcpy (pts_name
, "/dev/ptyXY");
375 for (ptr1
= "pqrstuvwxyzPQRST"; *ptr1
!= 0; ptr1
++) {
377 for (ptr2
= "0123456789abcdef"; *ptr2
!= 0; ptr2
++) {
380 if ((fdm
= open(pts_name
, O_RDWR
)) < 0) {
387 if ((fds
= open(pts_name
, O_RDWR
)) < 0) {
395 tcsetattr(*slave
, TCSANOW
, term
);
397 ioctl(*slave
, TIOCSWINSZ
, winsize
);
399 strcpy(name
, pts_name
);
406 static BOOL32
wine_createConsole(int *master
, int *slave
, int *pid
)
414 if (tcgetattr(0, &term
) < 0) return FALSE
;
415 term
.c_lflag
|= ICANON
;
416 term
.c_lflag
&= ~ECHO
;
417 if (wine_openpty(master
, slave
, NULL
, &term
, NULL
) < 0) return FALSE
;
419 if ((*pid
=fork()) == 0) {
420 tcsetattr(*slave
, TCSADRAIN
, &term
);
421 sprintf(buf
, "-Sxx%d", *master
);
422 execlp("xterm", "xterm", buf
, NULL
);
423 ERR(console
, "error creating AllocConsole xterm\n");
427 /* most xterms like to print their window ID when used with -S;
428 * read it and continue before the user has a chance...
429 * NOTE: this is the reason we started xterm with ECHO off,
430 * we'll turn it back on below
433 for (i
=0; c
!='\n'; (status
=read(*slave
, &c
, 1)), i
++) {
434 if (status
== -1 && c
== '\0') {
435 /* wait for xterm to be created */
439 WARN(console
, "can't read xterm WID\n");
444 term
.c_lflag
|= ECHO
;
445 tcsetattr(*master
, TCSADRAIN
, &term
);
451 /***********************************************************************
452 * CONSOLE_GetConsoleHandle
453 * returns a 16-bit style console handle
454 * note: only called from _lopen
456 HFILE32
CONSOLE_GetConsoleHandle(VOID
)
458 PDB32
*pdb
= PROCESS_Current();
459 HFILE32 handle
= HFILE_ERROR32
;
462 if (pdb
->console
!= NULL
) {
463 CONSOLE
*console
= (CONSOLE
*)pdb
->console
;
464 handle
= (HFILE32
)HANDLE_Alloc(pdb
, &console
->header
, 0, TRUE
, -1);
470 /***********************************************************************
471 * AllocConsole (KERNEL32.103)
473 * creates an xterm with a pty to our program
475 BOOL32 WINAPI
AllocConsole(VOID
)
481 PDB32
*pdb
= PROCESS_Current();
483 HANDLE32 hIn
, hOut
, hErr
;
485 SYSTEM_LOCK(); /* FIXME: really only need to lock the process */
487 SetLastError(ERROR_CANNOT_MAKE
); /* this might not be the right
488 error, but it's a good guess :) */
490 console
= (CONSOLE
*)pdb
->console
;
492 /* don't create a console if we already have one */
493 if (console
!= NULL
) {
494 SetLastError(ERROR_ACCESS_DENIED
);
499 if (!(console
= (CONSOLE
*)HeapAlloc( SystemHeap
, 0, sizeof(*console
))))
505 console
->header
.type
= K32OBJ_CONSOLE
;
506 console
->header
.refcount
= 1;
508 console
->title
= NULL
;
510 if (wine_createConsole(&master
, &slave
, &pid
) == FALSE
) {
511 K32OBJ_DecCount(&console
->header
);
516 /* save the pid and other info for future use */
517 console
->master
= master
;
518 console
->slave
= slave
;
521 if ((hIn
= HANDLE_Alloc(pdb
,&console
->header
, 0, TRUE
,-1)) == INVALID_HANDLE_VALUE32
)
523 K32OBJ_DecCount(&console
->header
);
528 if ((hOut
= HANDLE_Alloc(pdb
,&console
->header
, 0, TRUE
,-1)) == INVALID_HANDLE_VALUE32
)
531 K32OBJ_DecCount(&console
->header
);
537 if ((hErr
= HANDLE_Alloc(pdb
,&console
->header
, 0, TRUE
,-1)) == INVALID_HANDLE_VALUE32
)
541 K32OBJ_DecCount(&console
->header
);
546 /* associate this console with the process */
547 if (pdb
->console
) K32OBJ_DecCount( pdb
->console
);
548 pdb
->console
= (K32OBJ
*)console
;
550 /* NT resets the STD_*_HANDLEs on console alloc */
551 SetStdHandle(STD_INPUT_HANDLE
, hIn
);
552 SetStdHandle(STD_OUTPUT_HANDLE
, hOut
);
553 SetStdHandle(STD_ERROR_HANDLE
, hErr
);
555 SetLastError(ERROR_SUCCESS
);
557 SetConsoleTitle32A("Wine Console");
562 /******************************************************************************
563 * GetConsoleCP [KERNEL32.295] Returns the OEM code page for the console
568 UINT32 WINAPI
GetConsoleCP(VOID
)
574 /***********************************************************************
575 * GetConsoleOutputCP (KERNEL32.189)
577 UINT32 WINAPI
GetConsoleOutputCP(VOID
)
579 return GetConsoleCP();
582 /***********************************************************************
583 * GetConsoleMode (KERNEL32.188)
585 BOOL32 WINAPI
GetConsoleMode(HANDLE32 hcon
,LPDWORD mode
)
587 *mode
= ENABLE_PROCESSED_INPUT
|
594 /******************************************************************************
595 * SetConsoleMode [KERNEL32.628] Sets input mode of console's input buffer
598 * hcon [I] Handle to console input or screen buffer
599 * mode [I] Input or output mode to set
605 BOOL32 WINAPI
SetConsoleMode( HANDLE32 hcon
, DWORD mode
)
607 FIXME(console
,"(0x%08x,0x%08lx): stub\n",hcon
,mode
);
612 /***********************************************************************
613 * GetConsoleTitleA (KERNEL32.191)
615 DWORD WINAPI
GetConsoleTitle32A(LPSTR title
,DWORD size
)
617 PDB32
*pdb
= PROCESS_Current();
618 CONSOLE
*console
= (CONSOLE
*)pdb
->console
;
620 if(console
&& console
->title
)
622 lstrcpyn32A(title
,console
->title
,size
);
623 return strlen(title
);
629 /******************************************************************************
630 * GetConsoleTitle32W [KERNEL32.192] Retrieves title string for console
633 * title [O] Address of buffer for title
634 * size [I] Size of buffer
637 * Success: Length of string copied
640 DWORD WINAPI
GetConsoleTitle32W( LPWSTR title
, DWORD size
)
642 PDB32
*pdb
= PROCESS_Current();
643 CONSOLE
*console
= (CONSOLE
*)pdb
->console
;
644 if(console
&& console
->title
)
646 lstrcpynAtoW(title
,console
->title
,size
);
647 return (lstrlen32W(title
));
653 /***********************************************************************
654 * WriteConsoleA (KERNEL32.729)
656 BOOL32 WINAPI
WriteConsole32A( HANDLE32 hConsoleOutput
,
658 DWORD nNumberOfCharsToWrite
,
659 LPDWORD lpNumberOfCharsWritten
,
662 /* FIXME: should I check if this is a console handle? */
663 return WriteFile(hConsoleOutput
, lpBuffer
, nNumberOfCharsToWrite
,
664 lpNumberOfCharsWritten
, NULL
);
668 /***********************************************************************
669 * WriteConsoleOutputA (KERNEL32.732)
671 BOOL32 WINAPI
WriteConsoleOutput32A( HANDLE32 hConsoleOutput
,
672 LPCHAR_INFO lpBuffer
,
675 LPSMALL_RECT lpWriteRegion
)
677 int i
,j
,off
=0,lastattr
=-1;
680 static int colormap
[8] = {
685 TRACE(console
,"wr: top = %d, bottom=%d, left=%d,right=%d\n",
687 lpWriteRegion
->Bottom
,
692 for (i
=lpWriteRegion
->Top
;i
<=lpWriteRegion
->Bottom
;i
++) {
693 sprintf(buffer
,"%c[%d;%dH",27,i
,lpWriteRegion
->Left
);
694 WriteFile(hConsoleOutput
,buffer
,strlen(buffer
),&res
,NULL
);
695 if (lastattr
!= lpBuffer
[off
].Attributes
) {
696 lastattr
= lpBuffer
[off
].Attributes
;
697 sprintf(buffer
,"%c[0;3%d;4%d",27,colormap
[lastattr
&7],colormap
[(lastattr
&0x70)>>4]);
698 if (lastattr
& FOREGROUND_INTENSITY
)
700 /* BACKGROUND_INTENSITY */
702 WriteFile(hConsoleOutput
,buffer
,strlen(buffer
),&res
,NULL
);
704 for (j
=lpWriteRegion
->Left
;j
<=lpWriteRegion
->Right
;j
++)
705 WriteFile(hConsoleOutput
,&(lpBuffer
[off
++].Char
.AsciiChar
),1,&res
,NULL
);
707 sprintf(buffer
,"%c[0m",27);
708 WriteFile(hConsoleOutput
,buffer
,strlen(buffer
),&res
,NULL
);
712 /***********************************************************************
713 * WriteConsoleW (KERNEL32.577)
715 BOOL32 WINAPI
WriteConsole32W( HANDLE32 hConsoleOutput
,
717 DWORD nNumberOfCharsToWrite
,
718 LPDWORD lpNumberOfCharsWritten
,
722 LPSTR xstring
=HeapAlloc( GetProcessHeap(), 0, nNumberOfCharsToWrite
);
724 lstrcpynWtoA( xstring
, lpBuffer
,nNumberOfCharsToWrite
);
726 /* FIXME: should I check if this is a console handle? */
727 ret
= WriteFile(hConsoleOutput
, xstring
, nNumberOfCharsToWrite
,
728 lpNumberOfCharsWritten
, NULL
);
729 HeapFree( GetProcessHeap(), 0, xstring
);
734 /***********************************************************************
735 * ReadConsoleA (KERNEL32.419)
737 BOOL32 WINAPI
ReadConsole32A( HANDLE32 hConsoleInput
,
739 DWORD nNumberOfCharsToRead
,
740 LPDWORD lpNumberOfCharsRead
,
743 return ReadFile(hConsoleInput
, lpBuffer
, nNumberOfCharsToRead
,
744 lpNumberOfCharsRead
, NULL
);
747 fgets(lpBuffer
,nNumberOfCharsToRead
, CONSOLE_console
.conIO
);
748 if (ferror(CONSOLE_console
.conIO
) {
752 *lpNumberOfCharsRead
= strlen(lpBuffer
);
758 /***********************************************************************
759 * ReadConsoleW (KERNEL32.427)
761 BOOL32 WINAPI
ReadConsole32W( HANDLE32 hConsoleInput
,
763 DWORD nNumberOfCharsToRead
,
764 LPDWORD lpNumberOfCharsRead
,
768 LPSTR buf
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0,
769 nNumberOfCharsToRead
);
770 ret
= ReadFile(hConsoleInput
, buf
, nNumberOfCharsToRead
,
771 lpNumberOfCharsRead
, NULL
);
772 lstrcpynAtoW(lpBuffer
,buf
,nNumberOfCharsToRead
);
773 *lpNumberOfCharsRead
= strlen(buf
);
774 HeapFree( GetProcessHeap(), 0, buf
);
778 LPSTR buf
= (LPSTR
)HEAP_xalloc(GetProcessHeap(), 0,
779 nNumberOfCharsToRead
);
780 fgets(buf
, nNumberOfCharsToRead
, CONSOLE_console
.conIO
);
782 if (ferror(CONSOLE_console
.conIO
) {
783 HeapFree( GetProcessHeap(), 0, buf
);
788 lstrcpynAtoW(lpBuffer
,buf
,nNumberOfCharsToRead
);
789 *lpNumberOfCharsRead
= strlen(buf
);
790 HeapFree( GetProcessHeap(), 0, buf
);
797 /******************************************************************************
798 * ReadConsoleInputA [KERNEL32.569] Reads data from a console
801 * hConsoleInput [I] Handle to console input buffer
802 * lpBuffer [O] Address of buffer for read data
803 * nLength [I] Number of records to read
804 * lpNumberOfEventsRead [O] Address of number of records read
810 BOOL32 WINAPI
ReadConsoleInputA( HANDLE32 hConsoleInput
,
811 LPINPUT_RECORD lpBuffer
,
812 DWORD nLength
, LPDWORD lpNumberOfEventsRead
)
814 FIXME(console
, "(%d,%p,%ld,%p): stub\n",hConsoleInput
, lpBuffer
, nLength
,
815 lpNumberOfEventsRead
);
816 return ReadConsole32A(hConsoleInput
, lpBuffer
, nLength
,
817 lpNumberOfEventsRead
, 0);
821 /***********************************************************************
822 * SetConsoleTitle32A (KERNEL32.476)
824 BOOL32 WINAPI
SetConsoleTitle32A(LPCSTR title
)
826 PDB32
*pdb
= PROCESS_Current();
829 char titleformat
[]="\033]2;%s\a"; /*this should work for xterms*/
833 TRACE(console
,"(%s)\n",title
);
835 console
= (CONSOLE
*)pdb
->console
;
838 if(console
->title
) /* Free old title, if there is one */
839 HeapFree( SystemHeap
, 0, console
->title
);
840 console
->title
= (LPSTR
)HeapAlloc(SystemHeap
, 0,strlen(title
)+1);
841 if(console
->title
) strcpy(console
->title
,title
);
843 titlestring
= HeapAlloc(GetProcessHeap(), 0,strlen(title
)+strlen(titleformat
)+1);
847 sprintf(titlestring
,titleformat
,title
);
849 CONSOLE_Write((K32OBJ
*)console
,titlestring
,strlen(titlestring
),&written
,NULL
);
850 if (written
== strlen(titlestring
))
852 HeapFree( GetProcessHeap(), 0, titlestring
);
857 /******************************************************************************
858 * SetConsoleTitle32W [KERNEL32.477] Sets title bar string for console
861 * title [I] Address of new title
864 * This should not be calling the A version
870 BOOL32 WINAPI
SetConsoleTitle32W( LPCWSTR title
)
874 LPSTR titleA
= HEAP_strdupWtoA( GetProcessHeap(), 0, title
);
875 ret
= SetConsoleTitle32A(titleA
);
876 HeapFree( GetProcessHeap(), 0, titleA
);
881 /***********************************************************************
882 * FlushConsoleInputBuffer (KERNEL32.132)
884 BOOL32 WINAPI
FlushConsoleInputBuffer(HANDLE32 hConsoleInput
)
886 FIXME(console
,"(%d): stub\n",hConsoleInput
);
891 /******************************************************************************
892 * SetConsoleCursorPosition [KERNEL32.627]
893 * Sets the cursor position in console
896 * hConsoleOutput [I] Handle of console screen buffer
897 * dwCursorPosition [I] New cursor position coordinates
901 BOOL32 WINAPI
SetConsoleCursorPosition( HANDLE32 hConsoleOutput
,
902 COORD dwCursorPosition
)
904 TRACE(console
, "%d (%d x %d)\n", hConsoleOutput
, dwCursorPosition
.x
,
906 /* x are columns, y rows */
907 fprintf(stderr
,"\r");
908 /* note: 0x1B == ESC */
909 fprintf(stdout
,"%c[%d;%dH", 0x1B, dwCursorPosition
.y
, dwCursorPosition
.x
);
914 /***********************************************************************
915 * GetNumberOfConsoleInputEvents (KERNEL32.246)
917 BOOL32 WINAPI
GetNumberOfConsoleInputEvents(HANDLE32 hcon
,LPDWORD nrofevents
)
920 FIXME(console
,"(%x): stub\n", hcon
);
924 /***********************************************************************
925 * GetNumberOfConsoleMouseButtons (KERNEL32.358)
927 BOOL32 WINAPI
GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons
)
929 FIXME(console
,"(%p): stub\n", nrofbuttons
);
935 /***********************************************************************
936 * PeekConsoleInputA (KERNEL32.550)
938 BOOL32 WINAPI
PeekConsoleInput32A(HANDLE32 hConsoleInput
,
939 LPINPUT_RECORD pirBuffer
,
944 int i
,fd
= FILE_GetUnixHandle(hConsoleInput
);
948 static int keystate
[256];
949 LPINPUT_RECORD ir
= pirBuffer
;
951 TRACE(console
,"(%d,%p,%ld,%p): stub\n",hConsoleInput
, pirBuffer
, cInRecords
, lpcRead
);
953 memset(&tv
,0,sizeof(tv
));
956 select(fd
+1,&infds
,NULL
,NULL
,&tv
);
958 if (FD_ISSET(fd
,&infds
)) {
959 ReadFile(hConsoleInput
,&inchar
,1,&res
,NULL
);
960 for (i
=0;i
<256;i
++) {
961 if (keystate
[i
] && i
!=inchar
) {
963 ir
->Event
.KeyEvent
.bKeyDown
= 0;
964 ir
->Event
.KeyEvent
.wRepeatCount
= 0;
965 ir
->Event
.KeyEvent
.wVirtualKeyCode
= 0;
966 ir
->Event
.KeyEvent
.wVirtualScanCode
= 0;
967 ir
->Event
.KeyEvent
.uChar
.AsciiChar
= i
;
968 ir
->Event
.KeyEvent
.dwControlKeyState
= 0;
974 ir
->EventType
= 1; /* Key_event */
975 ir
->Event
.KeyEvent
.bKeyDown
= 1;
976 ir
->Event
.KeyEvent
.wRepeatCount
= 0;
977 ir
->Event
.KeyEvent
.wVirtualKeyCode
= 0;
978 ir
->Event
.KeyEvent
.wVirtualScanCode
= 0;
979 ir
->Event
.KeyEvent
.uChar
.AsciiChar
= inchar
;
980 ir
->Event
.KeyEvent
.dwControlKeyState
= 0;
983 *lpcRead
= ir
-pirBuffer
;
991 /***********************************************************************
992 * PeekConsoleInputW (KERNEL32.551)
994 BOOL32 WINAPI
PeekConsoleInput32W(HANDLE32 hConsoleInput
,
995 LPINPUT_RECORD pirBuffer
,
1002 FIXME(console
,"(%d,%p,%ld,%p): stub\n", hConsoleInput
, pirBuffer
,
1003 cInRecords
, lpcRead
);
1008 /******************************************************************************
1009 * GetConsoleCursorInfo32 [KERNEL32.296] Gets size and visibility of console
1012 * hcon [I] Handle to console screen buffer
1013 * cinfo [O] Address of cursor information
1019 BOOL32 WINAPI
GetConsoleCursorInfo32( HANDLE32 hcon
,
1020 LPCONSOLE_CURSOR_INFO cinfo
)
1022 FIXME(console
, "(%x,%p): stub\n", hcon
, cinfo
);
1023 if (!cinfo
) return FALSE
;
1024 cinfo
->dwSize
= 10; /* 10% of character box is cursor. */
1025 cinfo
->bVisible
= TRUE
; /* Cursor is visible. */
1030 /******************************************************************************
1031 * SetConsoleCursorInfo32 [KERNEL32.626] Sets size and visibility of cursor
1037 BOOL32 WINAPI
SetConsoleCursorInfo32(
1038 HANDLE32 hcon
, /* [in] Handle to console screen buffer */
1039 LPCONSOLE_CURSOR_INFO cinfo
) /* [in] Address of cursor information */
1041 FIXME(console
, "(%x,%ld,%i): stub\n", hcon
,cinfo
->dwSize
,cinfo
->bVisible
);
1046 /******************************************************************************
1047 * SetConsoleWindowInfo [KERNEL32.634] Sets size and position of console
1053 BOOL32 WINAPI
SetConsoleWindowInfo(
1054 HANDLE32 hcon
, /* [in] Handle to console screen buffer */
1055 BOOL32 bAbsolute
, /* [in] Coordinate type flag */
1056 LPSMALL_RECT window
) /* [in] Address of new window rectangle */
1058 FIXME(console
, "(%x,%d,%p): stub\n", hcon
, bAbsolute
, window
);
1063 /******************************************************************************
1064 * SetConsoleTextAttribute32 [KERNEL32.631] Sets colors for text
1066 * Sets the foreground and background color attributes of characters
1067 * written to the screen buffer.
1073 BOOL32 WINAPI
SetConsoleTextAttribute32(HANDLE32 hConsoleOutput
,WORD wAttr
)
1078 unsigned int attrib
;
1081 if( attrib
>= BACKGROUND_INTENSITY
)
1082 attrib
-= BACKGROUND_INTENSITY
; /* Background intensity is ignored */
1083 if( attrib
>= BACKGROUND_RED
)
1085 attrib
-= BACKGROUND_RED
;
1086 if( attrib
>= BACKGROUND_GREEN
)
1088 attrib
-= BACKGROUND_GREEN
;
1089 if( attrib
>= BACKGROUND_BLUE
)
1091 attrib
-= BACKGROUND_BLUE
;
1092 backcolor
= 47; /* White background */
1095 backcolor
= 43; /* Yellow background */
1097 else if( attrib
>= BACKGROUND_BLUE
)
1099 attrib
-= BACKGROUND_BLUE
;
1100 backcolor
= 45; /* Magenta background */
1103 backcolor
= 41; /* Red Background */
1105 else if( attrib
>= BACKGROUND_GREEN
)
1107 attrib
-= BACKGROUND_GREEN
;
1108 if( attrib
>= BACKGROUND_BLUE
)
1110 attrib
-= BACKGROUND_BLUE
;
1111 backcolor
= 46; /* Cyan background */
1114 backcolor
= 42; /* Green background */
1116 else if( attrib
>= BACKGROUND_BLUE
)
1118 attrib
-= BACKGROUND_BLUE
;
1119 backcolor
= 44; /* Blue background */
1122 backcolor
= 40; /* Black background */
1123 if( attrib
>= FOREGROUND_INTENSITY
)
1125 attrib
-= FOREGROUND_INTENSITY
;
1126 boldtext
= 1; /* Bold attribute is on */
1128 if( attrib
>= FOREGROUND_RED
)
1130 attrib
-= FOREGROUND_RED
;
1131 if( attrib
>= FOREGROUND_GREEN
)
1133 attrib
-= FOREGROUND_GREEN
;
1134 if( attrib
>= FOREGROUND_BLUE
)
1136 attrib
-= FOREGROUND_BLUE
;
1137 forecolor
= 37; /* White foreground */
1140 forecolor
= 33; /* Yellow foreground */
1142 else if( attrib
>= FOREGROUND_BLUE
)
1144 attrib
-= FOREGROUND_BLUE
;
1145 forecolor
= 35; /* Magenta foreground */
1148 forecolor
= 31; /* Red foreground */
1150 else if( attrib
>= FOREGROUND_GREEN
)
1152 attrib
-= FOREGROUND_GREEN
;
1153 if( attrib
>= FOREGROUND_BLUE
)
1155 attrib
-= FOREGROUND_BLUE
;
1156 forecolor
= 36; /* Cyan foreground */
1159 forecolor
= 32; /* Green foreground */
1161 else if( attrib
>= FOREGROUND_BLUE
)
1163 attrib
-= FOREGROUND_BLUE
;
1164 forecolor
= 34; /* Blue foreground */
1167 forecolor
= 30; /* Black foreground */
1169 fprintf(stdout
,"%c[%d;%d;%dm",0x1B,boldtext
,forecolor
,backcolor
);
1174 /******************************************************************************
1175 * SetConsoleScreenBufferSize [KERNEL32.630] Changes size of console
1178 * hConsoleOutput [I] Handle to console screen buffer
1179 * dwSize [I] New size in character rows and cols
1185 BOOL32 WINAPI
SetConsoleScreenBufferSize( HANDLE32 hConsoleOutput
,
1188 FIXME(console
, "(%d,%dx%d): stub\n",hConsoleOutput
,dwSize
.x
,dwSize
.y
);
1193 /******************************************************************************
1194 * FillConsoleOutputCharacterA [KERNEL32.242]
1197 * hConsoleOutput [I] Handle to screen buffer
1198 * cCharacter [I] Character to write
1199 * nLength [I] Number of cells to write to
1200 * dwCoord [I] Coords of first cell
1201 * lpNumCharsWritten [O] Pointer to number of cells written
1207 BOOL32 WINAPI
FillConsoleOutputCharacterA(
1208 HANDLE32 hConsoleOutput
,
1212 LPDWORD lpNumCharsWritten
)
1215 SetConsoleCursorPosition(hConsoleOutput
,dwCoord
);
1216 for(count
=0;count
<nLength
;count
++)
1217 putc(cCharacter
,stdout
);
1218 *lpNumCharsWritten
= nLength
;
1223 /******************************************************************************
1224 * FillConsoleOutputCharacterW [KERNEL32.243] Writes characters to console
1227 * hConsoleOutput [I] Handle to screen buffer
1228 * cCharacter [I] Character to write
1229 * nLength [I] Number of cells to write to
1230 * dwCoord [I] Coords of first cell
1231 * lpNumCharsWritten [O] Pointer to number of cells written
1237 BOOL32 WINAPI
FillConsoleOutputCharacterW(HANDLE32 hConsoleOutput
,
1241 LPDWORD lpNumCharsWritten
)
1244 SetConsoleCursorPosition(hConsoleOutput
,dwCoord
);
1245 for(count
=0;count
<nLength
;count
++)
1246 putc(cCharacter
,stdout
);
1247 *lpNumCharsWritten
= nLength
;
1252 /******************************************************************************
1253 * FillConsoleOutputAttribute [KERNEL32.241] Sets attributes for console
1256 * hConsoleOutput [I] Handle to screen buffer
1257 * wAttribute [I] Color attribute to write
1258 * nLength [I] Number of cells to write to
1259 * dwCoord [I] Coords of first cell
1260 * lpNumAttrsWritten [O] Pointer to number of cells written
1266 BOOL32 WINAPI
FillConsoleOutputAttribute( HANDLE32 hConsoleOutput
,
1267 WORD wAttribute
, DWORD nLength
, COORD dwCoord
,
1268 LPDWORD lpNumAttrsWritten
)
1270 FIXME(console
, "(%d,%d,%ld,%dx%d,%p): stub\n", hConsoleOutput
,
1271 wAttribute
,nLength
,dwCoord
.x
,dwCoord
.y
,lpNumAttrsWritten
);
1272 *lpNumAttrsWritten
= nLength
;
1276 /******************************************************************************
1277 * ReadConsoleOutputCharacter32A [KERNEL32.573]
1282 BOOL32 WINAPI
ReadConsoleOutputCharacter32A(HANDLE32 hConsoleOutput
,
1283 LPSTR lpstr
, DWORD dword
, COORD coord
, LPDWORD lpdword
)
1285 FIXME(console
, "(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput
,lpstr
,
1286 dword
,coord
.x
,coord
.y
,lpdword
);
1287 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1292 /******************************************************************************
1293 * ScrollConsoleScreenBuffer [KERNEL32.612]
1298 BOOL32 WINAPI
ScrollConsoleScreenBuffer( HANDLE32 hConsoleOutput
,
1299 LPSMALL_RECT lpScrollRect
, LPSMALL_RECT lpClipRect
,
1300 COORD dwDestOrigin
, LPCHAR_INFO lpFill
)
1302 FIXME(console
, "(%d,%p,%p,%dx%d,%p): stub\n", hConsoleOutput
,lpScrollRect
,
1303 lpClipRect
,dwDestOrigin
.x
,dwDestOrigin
.y
,lpFill
);
1304 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);