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
181 BOOL32 WINAPI
SetConsoleCtrlHandler( HANDLER_ROUTINE
*func
, BOOL32 add
)
183 FIXME(console
, "(%p,%i): stub\n",func
,add
);
188 /******************************************************************************
189 * CreateConsoleScreenBuffer [KERNEL32.151] Creates a console screen buffer
192 * dwDesiredAccess [I] Access flag
193 * dwShareMode [I] Buffer share mode
194 * sa [I] Security attributes
195 * dwFlags [I] Type of buffer to create
196 * lpScreenBufferData [I] Reserved
199 * Should call SetLastError
202 * Success: Handle to new console screen buffer
203 * Failure: INVALID_HANDLE_VALUE
205 HANDLE32 WINAPI
CreateConsoleScreenBuffer( DWORD dwDesiredAccess
,
206 DWORD dwShareMode
, LPSECURITY_ATTRIBUTES sa
,
207 DWORD dwFlags
, LPVOID lpScreenBufferData
)
209 FIXME(console
, "(%ld,%ld,%p,%ld,%p): stub\n",dwDesiredAccess
,
210 dwShareMode
, sa
, dwFlags
, lpScreenBufferData
);
215 /***********************************************************************
216 * GetConsoleScreenBufferInfo (KERNEL32.190)
218 BOOL32 WINAPI
GetConsoleScreenBufferInfo( HANDLE32 hConsoleOutput
,
219 LPCONSOLE_SCREEN_BUFFER_INFO csbi
)
223 csbi
->dwCursorPosition
.x
= 0;
224 csbi
->dwCursorPosition
.y
= 0;
225 csbi
->wAttributes
= 0;
226 csbi
->srWindow
.Left
= 0;
227 csbi
->srWindow
.Right
= 79;
228 csbi
->srWindow
.Top
= 0;
229 csbi
->srWindow
.Bottom
= 23;
230 csbi
->dwMaximumWindowSize
.x
= 80;
231 csbi
->dwMaximumWindowSize
.y
= 24;
236 /******************************************************************************
237 * SetConsoleActiveScreenBuffer [KERNEL32.623] Sets buffer to current console
243 BOOL32 WINAPI
SetConsoleActiveScreenBuffer(
244 HANDLE32 hConsoleOutput
) /* [in] Handle to console screen buffer */
246 FIXME(console
, "(%x): stub\n", hConsoleOutput
);
251 /***********************************************************************
252 * GetLargestConsoleWindowSize (KERNEL32.226)
254 DWORD WINAPI
GetLargestConsoleWindowSize( HANDLE32 hConsoleOutput
)
256 return (DWORD
)MAKELONG(dummyinfo
.dwMaximumWindowSize
.x
,dummyinfo
.dwMaximumWindowSize
.y
);
259 /***********************************************************************
260 * FreeConsole (KERNEL32.267)
262 BOOL32 WINAPI
FreeConsole(VOID
)
265 PDB32
*pdb
= PROCESS_Current();
270 console
= (CONSOLE
*)pdb
->console
;
272 if (console
== NULL
) {
273 SetLastError(ERROR_INVALID_PARAMETER
);
277 HANDLE_CloseAll( pdb
, &console
->header
);
279 K32OBJ_DecCount( &console
->header
);
287 * It looks like the openpty that comes with glibc in RedHat 5.0
288 * is buggy (second call returns what looks like a dup of 0 and 1
289 * instead of a new pty), this is a generic replacement.
291 static int wine_openpty(int *master
, int *slave
, char *name
,
292 struct termios
*term
, struct winsize
*winsize
)
298 strcpy (pts_name
, "/dev/ptyXY");
300 for (ptr1
= "pqrstuvwxyzPQRST"; *ptr1
!= 0; ptr1
++) {
302 for (ptr2
= "0123456789abcdef"; *ptr2
!= 0; ptr2
++) {
305 if ((fdm
= open(pts_name
, O_RDWR
)) < 0) {
312 if ((fds
= open(pts_name
, O_RDWR
)) < 0) {
320 tcsetattr(*slave
, TCSANOW
, term
);
322 ioctl(*slave
, TIOCSWINSZ
, winsize
);
324 strcpy(name
, pts_name
);
331 static BOOL32
wine_createConsole(int *master
, int *slave
, int *pid
)
339 if (tcgetattr(0, &term
) < 0) return FALSE
;
340 term
.c_lflag
|= ICANON
;
341 term
.c_lflag
&= ~ECHO
;
342 if (wine_openpty(master
, slave
, NULL
, &term
, NULL
) < 0) return FALSE
;
344 if ((*pid
=fork()) == 0) {
345 tcsetattr(*slave
, TCSADRAIN
, &term
);
346 sprintf(buf
, "-Sxx%d", *master
);
347 execlp("xterm", "xterm", buf
, NULL
);
348 ERR(console
, "error creating AllocConsole xterm\n");
352 /* most xterms like to print their window ID when used with -S;
353 * read it and continue before the user has a chance...
354 * NOTE: this is the reason we started xterm with ECHO off,
355 * we'll turn it back on below
358 for (i
=0; c
!='\n'; (status
=read(*slave
, &c
, 1)), i
++) {
359 if (status
== -1 && c
== '\0') {
360 /* wait for xterm to be created */
364 WARN(console
, "can't read xterm WID\n");
369 term
.c_lflag
|= ECHO
;
370 tcsetattr(*master
, TCSADRAIN
, &term
);
376 /***********************************************************************
377 * CONSOLE_GetConsoleHandle
378 * returns a 16-bit style console handle
379 * note: only called from _lopen
381 HFILE32
CONSOLE_GetConsoleHandle(VOID
)
383 PDB32
*pdb
= PROCESS_Current();
384 HFILE32 handle
= HFILE_ERROR32
;
387 if (pdb
->console
!= NULL
) {
388 CONSOLE
*console
= (CONSOLE
*)pdb
->console
;
389 handle
= (HFILE32
)HANDLE_Alloc(pdb
, &console
->header
, 0, TRUE
, -1);
395 /***********************************************************************
396 * AllocConsole (KERNEL32.103)
398 * creates an xterm with a pty to our program
400 BOOL32 WINAPI
AllocConsole(VOID
)
406 PDB32
*pdb
= PROCESS_Current();
408 HANDLE32 hIn
, hOut
, hErr
;
410 SYSTEM_LOCK(); /* FIXME: really only need to lock the process */
412 SetLastError(ERROR_CANNOT_MAKE
); /* this might not be the right
413 error, but it's a good guess :) */
415 console
= (CONSOLE
*)pdb
->console
;
417 /* don't create a console if we already have one */
418 if (console
!= NULL
) {
419 SetLastError(ERROR_ACCESS_DENIED
);
424 if (!(console
= (CONSOLE
*)HeapAlloc( SystemHeap
, 0, sizeof(*console
))))
430 console
->header
.type
= K32OBJ_CONSOLE
;
431 console
->header
.refcount
= 1;
433 console
->title
= NULL
;
435 if (wine_createConsole(&master
, &slave
, &pid
) == FALSE
) {
436 K32OBJ_DecCount(&console
->header
);
441 /* save the pid and other info for future use */
442 console
->master
= master
;
443 console
->slave
= slave
;
446 if ((hIn
= HANDLE_Alloc(pdb
,&console
->header
, 0, TRUE
,-1)) == INVALID_HANDLE_VALUE32
)
448 K32OBJ_DecCount(&console
->header
);
453 if ((hOut
= HANDLE_Alloc(pdb
,&console
->header
, 0, TRUE
,-1)) == INVALID_HANDLE_VALUE32
)
456 K32OBJ_DecCount(&console
->header
);
462 if ((hErr
= HANDLE_Alloc(pdb
,&console
->header
, 0, TRUE
,-1)) == INVALID_HANDLE_VALUE32
)
466 K32OBJ_DecCount(&console
->header
);
471 /* associate this console with the process */
472 if (pdb
->console
) K32OBJ_DecCount( pdb
->console
);
473 pdb
->console
= (K32OBJ
*)console
;
475 /* NT resets the STD_*_HANDLEs on console alloc */
476 SetStdHandle(STD_INPUT_HANDLE
, hIn
);
477 SetStdHandle(STD_OUTPUT_HANDLE
, hOut
);
478 SetStdHandle(STD_ERROR_HANDLE
, hErr
);
480 SetLastError(ERROR_SUCCESS
);
482 SetConsoleTitle32A("Wine Console");
487 /******************************************************************************
488 * GetConsoleCP [KERNEL32.295] Returns the OEM code page for the console
493 UINT32 WINAPI
GetConsoleCP(VOID
)
499 /***********************************************************************
500 * GetConsoleOutputCP (KERNEL32.189)
502 UINT32 WINAPI
GetConsoleOutputCP(VOID
)
504 return GetConsoleCP();
507 /***********************************************************************
508 * GetConsoleMode (KERNEL32.188)
510 BOOL32 WINAPI
GetConsoleMode(HANDLE32 hcon
,LPDWORD mode
)
512 *mode
= ENABLE_PROCESSED_INPUT
|
519 /******************************************************************************
520 * SetConsoleMode [KERNEL32.628] Sets input mode of console's input buffer
523 * hcon [I] Handle to console input or screen buffer
524 * mode [I] Input or output mode to set
530 BOOL32 WINAPI
SetConsoleMode( HANDLE32 hcon
, DWORD mode
)
532 FIXME(console
,"(0x%08x,0x%08lx): stub\n",hcon
,mode
);
537 /***********************************************************************
538 * GetConsoleTitleA (KERNEL32.191)
540 DWORD WINAPI
GetConsoleTitle32A(LPSTR title
,DWORD size
)
542 PDB32
*pdb
= PROCESS_Current();
543 CONSOLE
*console
= (CONSOLE
*)pdb
->console
;
545 if(console
&& console
->title
)
547 lstrcpyn32A(title
,console
->title
,size
);
548 return strlen(title
);
554 /******************************************************************************
555 * GetConsoleTitle32W [KERNEL32.192] Retrieves title string for console
558 * title [O] Address of buffer for title
559 * size [I] Size of buffer
562 * Success: Length of string copied
565 DWORD WINAPI
GetConsoleTitle32W( LPWSTR title
, DWORD size
)
567 PDB32
*pdb
= PROCESS_Current();
568 CONSOLE
*console
= (CONSOLE
*)pdb
->console
;
569 if(console
&& console
->title
)
571 lstrcpynAtoW(title
,console
->title
,size
);
572 return (lstrlen32W(title
));
578 /***********************************************************************
579 * WriteConsoleA (KERNEL32.729)
581 BOOL32 WINAPI
WriteConsole32A( HANDLE32 hConsoleOutput
,
583 DWORD nNumberOfCharsToWrite
,
584 LPDWORD lpNumberOfCharsWritten
,
587 /* FIXME: should I check if this is a console handle? */
588 return WriteFile(hConsoleOutput
, lpBuffer
, nNumberOfCharsToWrite
,
589 lpNumberOfCharsWritten
, NULL
);
593 /***********************************************************************
594 * WriteConsoleOutputA (KERNEL32.732)
596 BOOL32 WINAPI
WriteConsoleOutput32A( HANDLE32 hConsoleOutput
,
597 LPCHAR_INFO lpBuffer
,
600 LPSMALL_RECT lpWriteRegion
)
602 int i
,j
,off
=0,lastattr
=-1;
605 static int colormap
[8] = {
610 TRACE(console
,"wr: top = %d, bottom=%d, left=%d,right=%d\n",
612 lpWriteRegion
->Bottom
,
617 for (i
=lpWriteRegion
->Top
;i
<=lpWriteRegion
->Bottom
;i
++) {
618 sprintf(buffer
,"%c[%d;%dH",27,i
,lpWriteRegion
->Left
);
619 WriteFile(hConsoleOutput
,buffer
,strlen(buffer
),&res
,NULL
);
620 if (lastattr
!= lpBuffer
[off
].Attributes
) {
621 lastattr
= lpBuffer
[off
].Attributes
;
622 sprintf(buffer
,"%c[0;3%d;4%d",27,colormap
[lastattr
&7],colormap
[(lastattr
&0x70)>>4]);
623 if (lastattr
& FOREGROUND_INTENSITY
)
625 /* BACKGROUND_INTENSITY */
627 WriteFile(hConsoleOutput
,buffer
,strlen(buffer
),&res
,NULL
);
629 for (j
=lpWriteRegion
->Left
;j
<=lpWriteRegion
->Right
;j
++)
630 WriteFile(hConsoleOutput
,&(lpBuffer
[off
++].Char
.AsciiChar
),1,&res
,NULL
);
632 sprintf(buffer
,"%c[0m",27);
633 WriteFile(hConsoleOutput
,buffer
,strlen(buffer
),&res
,NULL
);
637 /***********************************************************************
638 * WriteConsoleW (KERNEL32.577)
640 BOOL32 WINAPI
WriteConsole32W( HANDLE32 hConsoleOutput
,
642 DWORD nNumberOfCharsToWrite
,
643 LPDWORD lpNumberOfCharsWritten
,
647 LPSTR xstring
=HeapAlloc( GetProcessHeap(), 0, nNumberOfCharsToWrite
);
649 lstrcpynWtoA( xstring
, lpBuffer
,nNumberOfCharsToWrite
);
651 /* FIXME: should I check if this is a console handle? */
652 ret
= WriteFile(hConsoleOutput
, xstring
, nNumberOfCharsToWrite
,
653 lpNumberOfCharsWritten
, NULL
);
654 HeapFree( GetProcessHeap(), 0, xstring
);
659 /***********************************************************************
660 * ReadConsoleA (KERNEL32.419)
662 BOOL32 WINAPI
ReadConsole32A( HANDLE32 hConsoleInput
,
664 DWORD nNumberOfCharsToRead
,
665 LPDWORD lpNumberOfCharsRead
,
668 return ReadFile(hConsoleInput
, lpBuffer
, nNumberOfCharsToRead
,
669 lpNumberOfCharsRead
, NULL
);
672 fgets(lpBuffer
,nNumberOfCharsToRead
, CONSOLE_console
.conIO
);
673 if (ferror(CONSOLE_console
.conIO
) {
677 *lpNumberOfCharsRead
= strlen(lpBuffer
);
683 /***********************************************************************
684 * ReadConsoleW (KERNEL32.427)
686 BOOL32 WINAPI
ReadConsole32W( HANDLE32 hConsoleInput
,
688 DWORD nNumberOfCharsToRead
,
689 LPDWORD lpNumberOfCharsRead
,
693 LPSTR buf
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0,
694 nNumberOfCharsToRead
);
695 ret
= ReadFile(hConsoleInput
, buf
, nNumberOfCharsToRead
,
696 lpNumberOfCharsRead
, NULL
);
697 lstrcpynAtoW(lpBuffer
,buf
,nNumberOfCharsToRead
);
698 *lpNumberOfCharsRead
= strlen(buf
);
699 HeapFree( GetProcessHeap(), 0, buf
);
703 LPSTR buf
= (LPSTR
)HEAP_xalloc(GetProcessHeap(), 0,
704 nNumberOfCharsToRead
);
705 fgets(buf
, nNumberOfCharsToRead
, CONSOLE_console
.conIO
);
707 if (ferror(CONSOLE_console
.conIO
) {
708 HeapFree( GetProcessHeap(), 0, buf
);
713 lstrcpynAtoW(lpBuffer
,buf
,nNumberOfCharsToRead
);
714 *lpNumberOfCharsRead
= strlen(buf
);
715 HeapFree( GetProcessHeap(), 0, buf
);
722 /******************************************************************************
723 * ReadConsoleInputA [KERNEL32.569] Reads data from a console
726 * hConsoleInput [I] Handle to console input buffer
727 * lpBuffer [O] Address of buffer for read data
728 * nLength [I] Number of records to read
729 * lpNumberOfEventsRead [O] Address of number of records read
735 BOOL32 WINAPI
ReadConsoleInputA( HANDLE32 hConsoleInput
,
736 LPINPUT_RECORD lpBuffer
,
737 DWORD nLength
, LPDWORD lpNumberOfEventsRead
)
739 FIXME(console
, "(%d,%p,%ld,%p): stub\n",hConsoleInput
, lpBuffer
, nLength
,
740 lpNumberOfEventsRead
);
741 return ReadConsole32A(hConsoleInput
, lpBuffer
, nLength
,
742 lpNumberOfEventsRead
, 0);
746 /***********************************************************************
747 * SetConsoleTitle32A (KERNEL32.476)
749 BOOL32 WINAPI
SetConsoleTitle32A(LPCSTR title
)
751 PDB32
*pdb
= PROCESS_Current();
754 char titleformat
[]="\033]2;%s\a"; /*this should work for xterms*/
758 TRACE(console
,"(%s)\n",title
);
760 console
= (CONSOLE
*)pdb
->console
;
763 if(console
->title
) /* Free old title, if there is one */
764 HeapFree( SystemHeap
, 0, console
->title
);
765 console
->title
= (LPSTR
)HeapAlloc(SystemHeap
, 0,strlen(title
)+1);
766 if(console
->title
) strcpy(console
->title
,title
);
768 titlestring
= HeapAlloc(GetProcessHeap(), 0,strlen(title
)+strlen(titleformat
)+1);
772 sprintf(titlestring
,titleformat
,title
);
774 CONSOLE_Write((K32OBJ
*)console
,titlestring
,strlen(titlestring
),&written
,NULL
);
775 if (written
== strlen(titlestring
))
777 HeapFree( GetProcessHeap(), 0, titlestring
);
782 /******************************************************************************
783 * SetConsoleTitle32W [KERNEL32.477] Sets title bar string for console
786 * title [I] Address of new title
789 * This should not be calling the A version
795 BOOL32 WINAPI
SetConsoleTitle32W( LPCWSTR title
)
799 LPSTR titleA
= HEAP_strdupWtoA( GetProcessHeap(), 0, title
);
800 ret
= SetConsoleTitle32A(titleA
);
801 HeapFree( GetProcessHeap(), 0, titleA
);
806 /***********************************************************************
807 * FlushConsoleInputBuffer (KERNEL32.132)
809 BOOL32 WINAPI
FlushConsoleInputBuffer(HANDLE32 hConsoleInput
)
811 FIXME(console
,"(%d): stub\n",hConsoleInput
);
816 /******************************************************************************
817 * SetConsoleCursorPosition [KERNEL32.627]
818 * Sets the cursor position in console
821 * hConsoleOutput [I] Handle of console screen buffer
822 * dwCursorPosition [I] New cursor position coordinates
826 BOOL32 WINAPI
SetConsoleCursorPosition( HANDLE32 hConsoleOutput
,
827 COORD dwCursorPosition
)
829 TRACE(console
, "%d (%d x %d)\n", hConsoleOutput
, dwCursorPosition
.x
,
831 /* x are columns, y rows */
832 fprintf(stderr
,"\r");
833 /* note: 0x1B == ESC */
834 fprintf(stdout
,"%c[%d;%dH", 0x1B, dwCursorPosition
.y
, dwCursorPosition
.x
);
839 /***********************************************************************
840 * GetNumberOfConsoleInputEvents (KERNEL32.246)
842 BOOL32 WINAPI
GetNumberOfConsoleInputEvents(HANDLE32 hcon
,LPDWORD nrofevents
)
845 FIXME(console
,"(%x): stub\n", hcon
);
849 /***********************************************************************
850 * GetNumberOfConsoleMouseButtons (KERNEL32.358)
852 BOOL32 WINAPI
GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons
)
854 FIXME(console
,"(%p): stub\n", nrofbuttons
);
860 /***********************************************************************
861 * PeekConsoleInputA (KERNEL32.550)
863 BOOL32 WINAPI
PeekConsoleInput32A(HANDLE32 hConsoleInput
,
864 LPINPUT_RECORD pirBuffer
,
869 int i
,fd
= FILE_GetUnixHandle(hConsoleInput
);
873 static int keystate
[256];
874 LPINPUT_RECORD ir
= pirBuffer
;
876 TRACE(console
,"(%d,%p,%ld,%p): stub\n",hConsoleInput
, pirBuffer
, cInRecords
, lpcRead
);
878 memset(&tv
,0,sizeof(tv
));
881 select(fd
+1,&infds
,NULL
,NULL
,&tv
);
883 if (FD_ISSET(fd
,&infds
)) {
884 ReadFile(hConsoleInput
,&inchar
,1,&res
,NULL
);
885 for (i
=0;i
<256;i
++) {
886 if (keystate
[i
] && i
!=inchar
) {
888 ir
->Event
.KeyEvent
.bKeyDown
= 0;
889 ir
->Event
.KeyEvent
.wRepeatCount
= 0;
890 ir
->Event
.KeyEvent
.wVirtualKeyCode
= 0;
891 ir
->Event
.KeyEvent
.wVirtualScanCode
= 0;
892 ir
->Event
.KeyEvent
.uChar
.AsciiChar
= i
;
893 ir
->Event
.KeyEvent
.dwControlKeyState
= 0;
899 ir
->EventType
= 1; /* Key_event */
900 ir
->Event
.KeyEvent
.bKeyDown
= 1;
901 ir
->Event
.KeyEvent
.wRepeatCount
= 0;
902 ir
->Event
.KeyEvent
.wVirtualKeyCode
= 0;
903 ir
->Event
.KeyEvent
.wVirtualScanCode
= 0;
904 ir
->Event
.KeyEvent
.uChar
.AsciiChar
= inchar
;
905 ir
->Event
.KeyEvent
.dwControlKeyState
= 0;
908 *lpcRead
= ir
-pirBuffer
;
916 /***********************************************************************
917 * PeekConsoleInputW (KERNEL32.551)
919 BOOL32 WINAPI
PeekConsoleInput32W(HANDLE32 hConsoleInput
,
920 LPINPUT_RECORD pirBuffer
,
927 FIXME(console
,"(%d,%p,%ld,%p): stub\n", hConsoleInput
, pirBuffer
,
928 cInRecords
, lpcRead
);
933 /******************************************************************************
934 * GetConsoleCursorInfo32 [KERNEL32.296] Gets size and visibility of console
937 * hcon [I] Handle to console screen buffer
938 * cinfo [O] Address of cursor information
944 BOOL32 WINAPI
GetConsoleCursorInfo32( HANDLE32 hcon
,
945 LPCONSOLE_CURSOR_INFO cinfo
)
947 FIXME(console
, "(%x,%p): stub\n", hcon
, cinfo
);
948 if (!cinfo
) return FALSE
;
949 cinfo
->dwSize
= 10; /* 10% of character box is cursor. */
950 cinfo
->bVisible
= TRUE
; /* Cursor is visible. */
955 /******************************************************************************
956 * SetConsoleCursorInfo32 [KERNEL32.626] Sets size and visibility of cursor
962 BOOL32 WINAPI
SetConsoleCursorInfo32(
963 HANDLE32 hcon
, /* [in] Handle to console screen buffer */
964 LPCONSOLE_CURSOR_INFO cinfo
) /* [in] Address of cursor information */
966 FIXME(console
, "(%x,%ld,%i): stub\n", hcon
,cinfo
->dwSize
,cinfo
->bVisible
);
971 /******************************************************************************
972 * SetConsoleWindowInfo [KERNEL32.634] Sets size and position of console
978 BOOL32 WINAPI
SetConsoleWindowInfo(
979 HANDLE32 hcon
, /* [in] Handle to console screen buffer */
980 BOOL32 bAbsolute
, /* [in] Coordinate type flag */
981 LPSMALL_RECT window
) /* [in] Address of new window rectangle */
983 FIXME(console
, "(%x,%d,%p): stub\n", hcon
, bAbsolute
, window
);
988 /******************************************************************************
989 * SetConsoleTextAttribute32 [KERNEL32.631] Sets colors for text
991 * Sets the foreground and background color attributes of characters
992 * written to the screen buffer.
998 BOOL32 WINAPI
SetConsoleTextAttribute32(HANDLE32 hConsoleOutput
,WORD wAttr
)
1003 unsigned int attrib
;
1006 if( attrib
>= BACKGROUND_INTENSITY
)
1007 attrib
-= BACKGROUND_INTENSITY
; /* Background intensity is ignored */
1008 if( attrib
>= BACKGROUND_RED
)
1010 attrib
-= BACKGROUND_RED
;
1011 if( attrib
>= BACKGROUND_GREEN
)
1013 attrib
-= BACKGROUND_GREEN
;
1014 if( attrib
>= BACKGROUND_BLUE
)
1016 attrib
-= BACKGROUND_BLUE
;
1017 backcolor
= 47; /* White background */
1020 backcolor
= 43; /* Yellow background */
1022 else if( attrib
>= BACKGROUND_BLUE
)
1024 attrib
-= BACKGROUND_BLUE
;
1025 backcolor
= 45; /* Magenta background */
1028 backcolor
= 41; /* Red Background */
1030 else if( attrib
>= BACKGROUND_GREEN
)
1032 attrib
-= BACKGROUND_GREEN
;
1033 if( attrib
>= BACKGROUND_BLUE
)
1035 attrib
-= BACKGROUND_BLUE
;
1036 backcolor
= 46; /* Cyan background */
1039 backcolor
= 42; /* Green background */
1041 else if( attrib
>= BACKGROUND_BLUE
)
1043 attrib
-= BACKGROUND_BLUE
;
1044 backcolor
= 44; /* Blue background */
1047 backcolor
= 40; /* Black background */
1048 if( attrib
>= FOREGROUND_INTENSITY
)
1050 attrib
-= FOREGROUND_INTENSITY
;
1051 boldtext
= 1; /* Bold attribute is on */
1053 if( attrib
>= FOREGROUND_RED
)
1055 attrib
-= FOREGROUND_RED
;
1056 if( attrib
>= FOREGROUND_GREEN
)
1058 attrib
-= FOREGROUND_GREEN
;
1059 if( attrib
>= FOREGROUND_BLUE
)
1061 attrib
-= FOREGROUND_BLUE
;
1062 forecolor
= 37; /* White foreground */
1065 forecolor
= 33; /* Yellow foreground */
1067 else if( attrib
>= FOREGROUND_BLUE
)
1069 attrib
-= FOREGROUND_BLUE
;
1070 forecolor
= 35; /* Magenta foreground */
1073 forecolor
= 31; /* Red foreground */
1075 else if( attrib
>= FOREGROUND_GREEN
)
1077 attrib
-= FOREGROUND_GREEN
;
1078 if( attrib
>= FOREGROUND_BLUE
)
1080 attrib
-= FOREGROUND_BLUE
;
1081 forecolor
= 36; /* Cyan foreground */
1084 forecolor
= 32; /* Green foreground */
1086 else if( attrib
>= FOREGROUND_BLUE
)
1088 attrib
-= FOREGROUND_BLUE
;
1089 forecolor
= 34; /* Blue foreground */
1092 forecolor
= 30; /* Black foreground */
1094 fprintf(stdout
,"%c[%d;%d;%dm",0x1B,boldtext
,forecolor
,backcolor
);
1099 /******************************************************************************
1100 * SetConsoleScreenBufferSize [KERNEL32.630] Changes size of console
1103 * hConsoleOutput [I] Handle to console screen buffer
1104 * dwSize [I] New size in character rows and cols
1110 BOOL32 WINAPI
SetConsoleScreenBufferSize( HANDLE32 hConsoleOutput
,
1113 FIXME(console
, "(%d,%dx%d): stub\n",hConsoleOutput
,dwSize
.x
,dwSize
.y
);
1118 /******************************************************************************
1119 * FillConsoleOutputCharacterA [KERNEL32.242]
1122 * hConsoleOutput [I] Handle to screen buffer
1123 * cCharacter [I] Character to write
1124 * nLength [I] Number of cells to write to
1125 * dwCoord [I] Coords of first cell
1126 * lpNumCharsWritten [O] Pointer to number of cells written
1132 BOOL32 WINAPI
FillConsoleOutputCharacterA(
1133 HANDLE32 hConsoleOutput
,
1137 LPDWORD lpNumCharsWritten
)
1140 SetConsoleCursorPosition(hConsoleOutput
,dwCoord
);
1141 for(count
=0;count
<nLength
;count
++)
1142 putc(cCharacter
,stdout
);
1143 *lpNumCharsWritten
= nLength
;
1148 /******************************************************************************
1149 * FillConsoleOutputCharacterW [KERNEL32.243] Writes characters to console
1152 * hConsoleOutput [I] Handle to screen buffer
1153 * cCharacter [I] Character to write
1154 * nLength [I] Number of cells to write to
1155 * dwCoord [I] Coords of first cell
1156 * lpNumCharsWritten [O] Pointer to number of cells written
1162 BOOL32 WINAPI
FillConsoleOutputCharacterW(HANDLE32 hConsoleOutput
,
1166 LPDWORD lpNumCharsWritten
)
1169 SetConsoleCursorPosition(hConsoleOutput
,dwCoord
);
1170 for(count
=0;count
<nLength
;count
++)
1171 putc(cCharacter
,stdout
);
1172 *lpNumCharsWritten
= nLength
;
1177 /******************************************************************************
1178 * FillConsoleOutputAttribute [KERNEL32.241] Sets attributes for console
1181 * hConsoleOutput [I] Handle to screen buffer
1182 * wAttribute [I] Color attribute to write
1183 * nLength [I] Number of cells to write to
1184 * dwCoord [I] Coords of first cell
1185 * lpNumAttrsWritten [O] Pointer to number of cells written
1191 BOOL32 WINAPI
FillConsoleOutputAttribute( HANDLE32 hConsoleOutput
,
1192 WORD wAttribute
, DWORD nLength
, COORD dwCoord
,
1193 LPDWORD lpNumAttrsWritten
)
1195 FIXME(console
, "(%d,%d,%ld,%dx%d,%p): stub\n", hConsoleOutput
,
1196 wAttribute
,nLength
,dwCoord
.x
,dwCoord
.y
,lpNumAttrsWritten
);
1197 *lpNumAttrsWritten
= nLength
;
1201 /******************************************************************************
1202 * ReadConsoleOutputCharacter32A [KERNEL32.573]
1207 BOOL32 WINAPI
ReadConsoleOutputCharacter32A(HANDLE32 hConsoleOutput
,
1208 LPSTR lpstr
, DWORD dword
, COORD coord
, LPDWORD lpdword
)
1210 FIXME(console
, "(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput
,lpstr
,
1211 dword
,coord
.x
,coord
.y
,lpdword
);
1212 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1217 /******************************************************************************
1218 * ScrollConsoleScreenBuffer [KERNEL32.612]
1223 BOOL32 WINAPI
ScrollConsoleScreenBuffer( HANDLE32 hConsoleOutput
,
1224 LPSMALL_RECT lpScrollRect
, LPSMALL_RECT lpClipRect
,
1225 COORD dwDestOrigin
, LPCHAR_INFO lpFill
)
1227 FIXME(console
, "(%d,%p,%p,%dx%d,%p): stub\n", hConsoleOutput
,lpScrollRect
,
1228 lpClipRect
,dwDestOrigin
.x
,dwDestOrigin
.y
,lpFill
);
1229 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);