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>
29 static CONSOLE_SCREEN_BUFFER_INFO dummyinfo
=
38 /* The console -- I chose to keep the master and slave
39 * (UNIX) file descriptors around in case they are needed for
40 * ioctls later. The pid is needed to destroy the xterm on close
42 typedef struct _CONSOLE
{
44 int master
; /* xterm side of pty */
45 int slave
; /* wine side of pty */
46 int pid
; /* xterm's pid, -1 if no xterm */
47 LPSTR title
; /* title of console */
51 /* This probably belongs somewhere else */
52 typedef struct _CONSOLE_CURSOR_INFO
{
53 DWORD dwSize
; /* Between 1 & 100 for percentage of cell filled */
54 BOOL32 bVisible
; /* Visibility of cursor */
55 } CONSOLE_CURSOR_INFO
, *LPCONSOLE_CURSOR_INFO
;
59 static void CONSOLE_Destroy( K32OBJ
*obj
);
60 static BOOL32
CONSOLE_Write(K32OBJ
*ptr
, LPCVOID lpBuffer
,
61 DWORD nNumberOfChars
, LPDWORD lpNumberOfChars
,
62 LPOVERLAPPED lpOverlapped
);
63 static BOOL32
CONSOLE_Read(K32OBJ
*ptr
, LPVOID lpBuffer
,
64 DWORD nNumberOfChars
, LPDWORD lpNumberOfChars
,
65 LPOVERLAPPED lpOverlapped
);
66 static int wine_openpty(int *master
, int *slave
, char *name
,
67 struct termios
*term
, struct winsize
*winsize
);
68 static BOOL32
wine_createConsole(int *master
, int *slave
, int *pid
);
70 const K32OBJ_OPS CONSOLE_Ops
=
75 NULL
, /* remove_wait */
76 CONSOLE_Read
, /* read */
77 CONSOLE_Write
, /* write */
78 CONSOLE_Destroy
/* destroy */
83 /***********************************************************************
86 static void CONSOLE_Destroy(K32OBJ
*obj
)
88 CONSOLE
*console
= (CONSOLE
*)obj
;
89 assert(obj
->type
== K32OBJ_CONSOLE
);
91 obj
->type
= K32OBJ_UNKNOWN
;
94 HeapFree( SystemHeap
, 0, console
->title
);
95 console
->title
= NULL
;
96 /* make sure a xterm exists to kill */
97 if (console
->pid
!= -1) {
98 kill(console
->pid
, SIGTERM
);
100 HeapFree(SystemHeap
, 0, console
);
104 /***********************************************************************
108 * lpOverlapped is ignored
110 static BOOL32
CONSOLE_Read(K32OBJ
*ptr
, LPVOID lpBuffer
, DWORD nNumberOfChars
,
111 LPDWORD lpNumberOfChars
, LPOVERLAPPED lpOverlapped
)
113 CONSOLE
*console
= (CONSOLE
*)ptr
;
116 TRACE(console
, "%p %p %ld\n", ptr
, lpBuffer
,
119 *lpNumberOfChars
= 0;
121 if ((result
= read(console
->slave
, lpBuffer
, nNumberOfChars
)) == -1) {
125 *lpNumberOfChars
= result
;
130 /***********************************************************************
134 * lpOverlapped is ignored
136 static BOOL32
CONSOLE_Write(K32OBJ
*ptr
, LPCVOID lpBuffer
,
137 DWORD nNumberOfChars
,
138 LPDWORD lpNumberOfChars
, LPOVERLAPPED lpOverlapped
)
140 CONSOLE
*console
= (CONSOLE
*)ptr
;
143 TRACE(console
, "%p %p %ld\n", ptr
, lpBuffer
,
146 *lpNumberOfChars
= 0;
149 * I assume this loop around EAGAIN is here because
150 * win32 doesn't have interrupted system calls
155 result
= write(console
->slave
, lpBuffer
, nNumberOfChars
);
157 *lpNumberOfChars
= result
;
160 if (errno
!= EINTR
) {
168 /******************************************************************************
169 * SetConsoleCtrlHandler [KERNEL32.459] Adds function to calling process list
172 * func [I] Address of handler function
173 * add [I] Handler to add or remove
179 BOOL32 WINAPI
SetConsoleCtrlHandler( HANDLER_ROUTINE
*func
, BOOL32 add
)
181 FIXME(console
, "(%p,%i): stub\n",func
,add
);
186 /******************************************************************************
187 * CreateConsoleScreenBuffer [KERNEL32.151] Creates a console screen buffer
190 * dwDesiredAccess [I] Access flag
191 * dwShareMode [I] Buffer share mode
192 * sa [I] Security attributes
193 * dwFlags [I] Type of buffer to create
194 * lpScreenBufferData [I] Reserved
197 * Should call SetLastError
200 * Success: Handle to new console screen buffer
201 * Failure: INVALID_HANDLE_VALUE
203 HANDLE32 WINAPI
CreateConsoleScreenBuffer( DWORD dwDesiredAccess
,
204 DWORD dwShareMode
, LPSECURITY_ATTRIBUTES sa
,
205 DWORD dwFlags
, LPVOID lpScreenBufferData
)
207 FIXME(console
, "(%ld,%ld,%p,%ld,%p): stub\n",dwDesiredAccess
,
208 dwShareMode
, sa
, dwFlags
, lpScreenBufferData
);
213 /***********************************************************************
214 * GetConsoleScreenBufferInfo (KERNEL32.190)
216 BOOL32 WINAPI
GetConsoleScreenBufferInfo( HANDLE32 hConsoleOutput
,
217 LPCONSOLE_SCREEN_BUFFER_INFO csbi
)
221 csbi
->dwCursorPosition
.x
= 0;
222 csbi
->dwCursorPosition
.y
= 0;
223 csbi
->wAttributes
= 0;
224 csbi
->srWindow
.Left
= 0;
225 csbi
->srWindow
.Right
= 79;
226 csbi
->srWindow
.Top
= 0;
227 csbi
->srWindow
.Bottom
= 23;
228 csbi
->dwMaximumWindowSize
.x
= 80;
229 csbi
->dwMaximumWindowSize
.y
= 24;
234 /******************************************************************************
235 * SetConsoleActiveScreenBuffer [KERNEL32.623] Sets buffer to current console
241 BOOL32 WINAPI
SetConsoleActiveScreenBuffer(
242 HANDLE32 hConsoleOutput
) /* [in] Handle to console screen buffer */
244 FIXME(console
, "(%x): stub\n", hConsoleOutput
);
249 /***********************************************************************
250 * GetLargestConsoleWindowSize (KERNEL32.226)
252 DWORD WINAPI
GetLargestConsoleWindowSize( HANDLE32 hConsoleOutput
)
254 return (DWORD
)MAKELONG(dummyinfo
.dwMaximumWindowSize
.x
,dummyinfo
.dwMaximumWindowSize
.y
);
257 /***********************************************************************
258 * FreeConsole (KERNEL32.267)
260 BOOL32 WINAPI
FreeConsole(VOID
)
263 PDB32
*pdb
= PROCESS_Current();
268 console
= (CONSOLE
*)pdb
->console
;
270 if (console
== NULL
) {
271 SetLastError(ERROR_INVALID_PARAMETER
);
275 HANDLE_CloseAll( pdb
, &console
->header
);
277 K32OBJ_DecCount( &console
->header
);
285 * It looks like the openpty that comes with glibc in RedHat 5.0
286 * is buggy (second call returns what looks like a dup of 0 and 1
287 * instead of a new pty), this is a generic replacement.
289 static int wine_openpty(int *master
, int *slave
, char *name
,
290 struct termios
*term
, struct winsize
*winsize
)
296 strcpy (pts_name
, "/dev/ptyXY");
298 for (ptr1
= "pqrstuvwxyzPQRST"; *ptr1
!= 0; ptr1
++) {
300 for (ptr2
= "0123456789abcdef"; *ptr2
!= 0; ptr2
++) {
303 if ((fdm
= open(pts_name
, O_RDWR
)) < 0) {
310 if ((fds
= open(pts_name
, O_RDWR
)) < 0) {
318 tcsetattr(*slave
, TCSANOW
, term
);
320 ioctl(*slave
, TIOCSWINSZ
, winsize
);
322 strcpy(name
, pts_name
);
329 static BOOL32
wine_createConsole(int *master
, int *slave
, int *pid
)
337 if (tcgetattr(0, &term
) < 0) return FALSE
;
338 term
.c_lflag
|= ICANON
;
339 term
.c_lflag
&= ~ECHO
;
340 if (wine_openpty(master
, slave
, NULL
, &term
, NULL
) < 0) return FALSE
;
342 if ((*pid
=fork()) == 0) {
343 tcsetattr(*slave
, TCSADRAIN
, &term
);
344 sprintf(buf
, "-Sxx%d", *master
);
345 execlp("xterm", "xterm", buf
, NULL
);
346 ERR(console
, "error creating AllocConsole xterm\n");
350 /* most xterms like to print their window ID when used with -S;
351 * read it and continue before the user has a chance...
352 * NOTE: this is the reason we started xterm with ECHO off,
353 * we'll turn it back on below
356 for (i
=0; c
!='\n'; (status
=read(*slave
, &c
, 1)), i
++) {
357 if (status
== -1 && c
== '\0') {
358 /* wait for xterm to be created */
362 WARN(console
, "can't read xterm WID\n");
367 term
.c_lflag
|= ECHO
;
368 tcsetattr(*master
, TCSADRAIN
, &term
);
374 /***********************************************************************
375 * CONSOLE_GetConsoleHandle
376 * returns a 16-bit style console handle
377 * note: only called from _lopen
379 HFILE32
CONSOLE_GetConsoleHandle(VOID
)
381 PDB32
*pdb
= PROCESS_Current();
382 HFILE32 handle
= HFILE_ERROR32
;
385 if (pdb
->console
!= NULL
) {
386 CONSOLE
*console
= (CONSOLE
*)pdb
->console
;
387 handle
= (HFILE32
)HANDLE_Alloc(pdb
, &console
->header
, 0, TRUE
);
393 /***********************************************************************
394 * AllocConsole (KERNEL32.103)
396 * creates an xterm with a pty to our program
398 BOOL32 WINAPI
AllocConsole(VOID
)
404 PDB32
*pdb
= PROCESS_Current();
406 HANDLE32 hIn
, hOut
, hErr
;
408 SYSTEM_LOCK(); /* FIXME: really only need to lock the process */
410 SetLastError(ERROR_CANNOT_MAKE
); /* this might not be the right
411 error, but it's a good guess :) */
413 console
= (CONSOLE
*)pdb
->console
;
415 /* don't create a console if we already have one */
416 if (console
!= NULL
) {
417 SetLastError(ERROR_ACCESS_DENIED
);
422 if (!(console
= (CONSOLE
*)HeapAlloc( SystemHeap
, 0, sizeof(*console
))))
428 console
->header
.type
= K32OBJ_CONSOLE
;
429 console
->header
.refcount
= 1;
431 console
->title
= NULL
;
433 if (wine_createConsole(&master
, &slave
, &pid
) == FALSE
) {
434 K32OBJ_DecCount(&console
->header
);
439 /* save the pid and other info for future use */
440 console
->master
= master
;
441 console
->slave
= slave
;
444 if ((hIn
= HANDLE_Alloc(pdb
,&console
->header
, 0, TRUE
)) == INVALID_HANDLE_VALUE32
)
446 K32OBJ_DecCount(&console
->header
);
451 if ((hOut
= HANDLE_Alloc(pdb
,&console
->header
, 0, TRUE
)) == INVALID_HANDLE_VALUE32
)
454 K32OBJ_DecCount(&console
->header
);
460 if ((hErr
= HANDLE_Alloc(pdb
,&console
->header
, 0, TRUE
)) == INVALID_HANDLE_VALUE32
)
464 K32OBJ_DecCount(&console
->header
);
469 /* associate this console with the process */
470 if (pdb
->console
) K32OBJ_DecCount( pdb
->console
);
471 pdb
->console
= (K32OBJ
*)console
;
473 /* NT resets the STD_*_HANDLEs on console alloc */
474 SetStdHandle(STD_INPUT_HANDLE
, hIn
);
475 SetStdHandle(STD_OUTPUT_HANDLE
, hOut
);
476 SetStdHandle(STD_ERROR_HANDLE
, hErr
);
478 SetLastError(ERROR_SUCCESS
);
480 SetConsoleTitle32A("Wine Console");
485 /******************************************************************************
486 * GetConsoleCP [KERNEL32.295] Returns the OEM code page for the console
491 UINT32 WINAPI
GetConsoleCP(VOID
)
497 /***********************************************************************
498 * GetConsoleOutputCP (KERNEL32.189)
500 UINT32 WINAPI
GetConsoleOutputCP(VOID
)
502 return GetConsoleCP();
505 /***********************************************************************
506 * GetConsoleMode (KERNEL32.188)
508 BOOL32 WINAPI
GetConsoleMode(HANDLE32 hcon
,LPDWORD mode
)
510 *mode
= ENABLE_PROCESSED_INPUT
|
517 /******************************************************************************
518 * SetConsoleMode [KERNEL32.628] Sets input mode of console's input buffer
521 * hcon [I] Handle to console input or screen buffer
522 * mode [I] Input or output mode to set
528 BOOL32 WINAPI
SetConsoleMode( HANDLE32 hcon
, DWORD mode
)
530 FIXME(console
,"(%08x,%08lx): stub\n",hcon
,mode
);
535 /***********************************************************************
536 * GetConsoleTitleA (KERNEL32.191)
538 DWORD WINAPI
GetConsoleTitle32A(LPSTR title
,DWORD size
)
540 PDB32
*pdb
= PROCESS_Current();
541 CONSOLE
*console
= (CONSOLE
*)pdb
->console
;
543 if(console
&& console
->title
)
545 lstrcpyn32A(title
,console
->title
,size
);
546 return strlen(title
);
552 /******************************************************************************
553 * GetConsoleTitle32W [KERNEL32.192] Retrieves title string for console
556 * title [O] Address of buffer for title
557 * size [I] Size of buffer
560 * Success: Length of string copied
563 DWORD WINAPI
GetConsoleTitle32W( LPWSTR title
, DWORD size
)
565 PDB32
*pdb
= PROCESS_Current();
566 CONSOLE
*console
= (CONSOLE
*)pdb
->console
;
567 if(console
&& console
->title
)
569 lstrcpynAtoW(title
,console
->title
,size
);
570 return (lstrlen32W(title
));
576 /***********************************************************************
577 * WriteConsoleA (KERNEL32.729)
579 BOOL32 WINAPI
WriteConsole32A( HANDLE32 hConsoleOutput
,
581 DWORD nNumberOfCharsToWrite
,
582 LPDWORD lpNumberOfCharsWritten
,
585 /* FIXME: should I check if this is a console handle? */
586 return WriteFile(hConsoleOutput
, lpBuffer
, nNumberOfCharsToWrite
,
587 lpNumberOfCharsWritten
, NULL
);
591 /***********************************************************************
592 * WriteConsoleOutputA (KERNEL32.732)
594 BOOL32 WINAPI
WriteConsoleOutput32A( HANDLE32 hConsoleOutput
,
595 LPCHAR_INFO lpBuffer
,
598 LPSMALL_RECT lpWriteRegion
)
600 FIXME(console
, "(...):stub\n");
604 /***********************************************************************
605 * WriteConsoleW (KERNEL32.577)
607 BOOL32 WINAPI
WriteConsole32W( HANDLE32 hConsoleOutput
,
609 DWORD nNumberOfCharsToWrite
,
610 LPDWORD lpNumberOfCharsWritten
,
614 LPSTR xstring
=HeapAlloc( GetProcessHeap(), 0, nNumberOfCharsToWrite
);
616 lstrcpynWtoA( xstring
, lpBuffer
,nNumberOfCharsToWrite
);
618 /* FIXME: should I check if this is a console handle? */
619 ret
= WriteFile(hConsoleOutput
, xstring
, nNumberOfCharsToWrite
,
620 lpNumberOfCharsWritten
, NULL
);
621 HeapFree( GetProcessHeap(), 0, xstring
);
626 /***********************************************************************
627 * ReadConsoleA (KERNEL32.419)
629 BOOL32 WINAPI
ReadConsole32A( HANDLE32 hConsoleInput
,
631 DWORD nNumberOfCharsToRead
,
632 LPDWORD lpNumberOfCharsRead
,
635 return ReadFile(hConsoleInput
, lpBuffer
, nNumberOfCharsToRead
,
636 lpNumberOfCharsRead
, NULL
);
639 fgets(lpBuffer
,nNumberOfCharsToRead
, CONSOLE_console
.conIO
);
640 if (ferror(CONSOLE_console
.conIO
) {
644 *lpNumberOfCharsRead
= strlen(lpBuffer
);
650 /***********************************************************************
651 * ReadConsoleW (KERNEL32.427)
653 BOOL32 WINAPI
ReadConsole32W( HANDLE32 hConsoleInput
,
655 DWORD nNumberOfCharsToRead
,
656 LPDWORD lpNumberOfCharsRead
,
660 LPSTR buf
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0,
661 nNumberOfCharsToRead
);
662 ret
= ReadFile(hConsoleInput
, buf
, nNumberOfCharsToRead
,
663 lpNumberOfCharsRead
, NULL
);
664 lstrcpynAtoW(lpBuffer
,buf
,nNumberOfCharsToRead
);
665 *lpNumberOfCharsRead
= strlen(buf
);
666 HeapFree( GetProcessHeap(), 0, buf
);
670 LPSTR buf
= (LPSTR
)HEAP_xalloc(GetProcessHeap(), 0,
671 nNumberOfCharsToRead
);
672 fgets(buf
, nNumberOfCharsToRead
, CONSOLE_console
.conIO
);
674 if (ferror(CONSOLE_console
.conIO
) {
675 HeapFree( GetProcessHeap(), 0, buf
);
680 lstrcpynAtoW(lpBuffer
,buf
,nNumberOfCharsToRead
);
681 *lpNumberOfCharsRead
= strlen(buf
);
682 HeapFree( GetProcessHeap(), 0, buf
);
689 /******************************************************************************
690 * ReadConsoleInputA [KERNEL32.569] Reads data from a console
693 * hConsoleInput [I] Handle to console input buffer
694 * lpBuffer [O] Address of buffer for read data
695 * nLength [I] Number of records to read
696 * lpNumberOfEventsRead [O] Address of number of records read
702 BOOL32 WINAPI
ReadConsoleInputA( HANDLE32 hConsoleInput
,
703 LPINPUT_RECORD lpBuffer
,
704 DWORD nLength
, LPDWORD lpNumberOfEventsRead
)
706 FIXME(console
, "(%d,%p,%ld,%p): stub\n",hConsoleInput
, lpBuffer
, nLength
,
707 lpNumberOfEventsRead
);
708 return ReadConsole32A(hConsoleInput
, lpBuffer
, nLength
,
709 lpNumberOfEventsRead
, 0);
713 /***********************************************************************
714 * SetConsoleTitle32A (KERNEL32.476)
716 BOOL32 WINAPI
SetConsoleTitle32A(LPCSTR title
)
718 PDB32
*pdb
= PROCESS_Current();
721 char titleformat
[]="\033]2;%s\a"; /*this should work for xterms*/
725 TRACE(console
,"(%s)\n",title
);
727 console
= (CONSOLE
*)pdb
->console
;
730 if(console
->title
) /* Free old title, if there is one */
731 HeapFree( SystemHeap
, 0, console
->title
);
732 console
->title
= (LPSTR
)HeapAlloc(SystemHeap
, 0,strlen(title
)+1);
733 if(console
->title
) strcpy(console
->title
,title
);
735 titlestring
= HeapAlloc(GetProcessHeap(), 0,strlen(title
)+strlen(titleformat
)+1);
739 sprintf(titlestring
,titleformat
,title
);
741 CONSOLE_Write((K32OBJ
*)console
,titlestring
,strlen(titlestring
),&written
,NULL
);
742 if (written
== strlen(titlestring
))
744 HeapFree( GetProcessHeap(), 0, titlestring
);
749 /******************************************************************************
750 * SetConsoleTitle32W [KERNEL32.477] Sets title bar string for console
753 * title [I] Address of new title
756 * This should not be calling the A version
762 BOOL32 WINAPI
SetConsoleTitle32W( LPCWSTR title
)
766 LPSTR titleA
= HEAP_strdupWtoA( GetProcessHeap(), 0, title
);
767 ret
= SetConsoleTitle32A(titleA
);
768 HeapFree( GetProcessHeap(), 0, titleA
);
773 /***********************************************************************
774 * FlushConsoleInputBuffer (KERNEL32.132)
776 BOOL32 WINAPI
FlushConsoleInputBuffer(HANDLE32 hConsoleInput
)
778 FIXME(console
,"(%d): stub\n",hConsoleInput
);
783 /******************************************************************************
784 * SetConsoleCursorPosition [KERNEL32.627]
785 * Sets the cursor position in console
788 * hConsoleOutput [I] Handle of console screen buffer
789 * dwCursorPosition [I] New cursor position coordinates
793 BOOL32 WINAPI
SetConsoleCursorPosition( HANDLE32 hConsoleOutput
,
794 COORD dwCursorPosition
)
796 TRACE(console
, "%d (%d x %d)\n", hConsoleOutput
, dwCursorPosition
.x
,
798 /* x are columns, y rows */
799 fprintf(stderr
,"\r");
800 /* note: 0x1B == ESC */
801 fprintf(stdout
,"%c[%d;%dH", 0x1B, dwCursorPosition
.y
, dwCursorPosition
.x
);
806 /***********************************************************************
807 * GetNumberOfConsoleInputEvents (KERNEL32.246)
809 BOOL32 WINAPI
GetNumberOfConsoleInputEvents(HANDLE32 hcon
,LPDWORD nrofevents
)
812 FIXME(console
,"(%x): stub\n", hcon
);
816 /***********************************************************************
817 * GetNumberOfConsoleMouseButtons (KERNEL32.358)
819 BOOL32 WINAPI
GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons
)
821 FIXME(console
,"(%p): stub\n", nrofbuttons
);
827 /***********************************************************************
828 * PeekConsoleInputA (KERNEL32.550)
830 BOOL32 WINAPI
PeekConsoleInput32A(HANDLE32 hConsoleInput
,
831 LPINPUT_RECORD pirBuffer
,
838 FIXME(console
,"(%d,%p,%ld,%p): stub\n",hConsoleInput
, pirBuffer
,
839 cInRecords
, lpcRead
);
844 /***********************************************************************
845 * PeekConsoleInputW (KERNEL32.551)
847 BOOL32 WINAPI
PeekConsoleInput32W(HANDLE32 hConsoleInput
,
848 LPINPUT_RECORD pirBuffer
,
855 FIXME(console
,"(%d,%p,%ld,%p): stub\n", hConsoleInput
, pirBuffer
,
856 cInRecords
, lpcRead
);
861 /******************************************************************************
862 * GetConsoleCursorInfo32 [KERNEL32.296] Gets size and visibility of console
865 * hcon [I] Handle to console screen buffer
866 * cinfo [O] Address of cursor information
872 BOOL32 WINAPI
GetConsoleCursorInfo32( HANDLE32 hcon
,
873 LPCONSOLE_CURSOR_INFO cinfo
)
875 FIXME(console
, "(%x,%p): stub\n", hcon
, cinfo
);
876 if (!cinfo
) return FALSE
;
877 cinfo
->dwSize
= 10; /* 10% of character box is cursor. */
878 cinfo
->bVisible
= TRUE
; /* Cursor is visible. */
883 /******************************************************************************
884 * SetConsoleCursorInfo32 [KERNEL32.626] Sets size and visibility of cursor
890 BOOL32 WINAPI
SetConsoleCursorInfo32(
891 HANDLE32 hcon
, /* [in] Handle to console screen buffer */
892 LPCONSOLE_CURSOR_INFO cinfo
) /* [in] Address of cursor information */
894 FIXME(console
, "(%x,%ld,%i): stub\n", hcon
,cinfo
->dwSize
,cinfo
->bVisible
);
899 /******************************************************************************
900 * SetConsoleWindowInfo [KERNEL32.634] Sets size and position of console
906 BOOL32 WINAPI
SetConsoleWindowInfo(
907 HANDLE32 hcon
, /* [in] Handle to console screen buffer */
908 BOOL32 bAbsolute
, /* [in] Coordinate type flag */
909 LPSMALL_RECT window
) /* [in] Address of new window rectangle */
911 FIXME(console
, "(%x,%d,%p): stub\n", hcon
, bAbsolute
, window
);
916 /******************************************************************************
917 * SetConsoleTextAttribute32 [KERNEL32.631] Sets colors for text
919 * Sets the foreground and background color attributes of characters
920 * written to the screen buffer.
926 BOOL32 WINAPI
SetConsoleTextAttribute32(HANDLE32 hConsoleOutput
,WORD wAttr
)
934 if( attrib
>= BACKGROUND_INTENSITY
)
935 attrib
-= BACKGROUND_INTENSITY
; /* Background intensity is ignored */
936 if( attrib
>= BACKGROUND_RED
)
938 attrib
-= BACKGROUND_RED
;
939 if( attrib
>= BACKGROUND_GREEN
)
941 attrib
-= BACKGROUND_GREEN
;
942 if( attrib
>= BACKGROUND_BLUE
)
944 attrib
-= BACKGROUND_BLUE
;
945 backcolor
= 47; /* White background */
948 backcolor
= 43; /* Yellow background */
950 else if( attrib
>= BACKGROUND_BLUE
)
952 attrib
-= BACKGROUND_BLUE
;
953 backcolor
= 45; /* Magenta background */
956 backcolor
= 41; /* Red Background */
958 else if( attrib
>= BACKGROUND_GREEN
)
960 attrib
-= BACKGROUND_GREEN
;
961 if( attrib
>= BACKGROUND_BLUE
)
963 attrib
-= BACKGROUND_BLUE
;
964 backcolor
= 46; /* Cyan background */
967 backcolor
= 42; /* Green background */
969 else if( attrib
>= BACKGROUND_BLUE
)
971 attrib
-= BACKGROUND_BLUE
;
972 backcolor
= 44; /* Blue background */
975 backcolor
= 40; /* Black background */
976 if( attrib
>= FOREGROUND_INTENSITY
)
978 attrib
-= FOREGROUND_INTENSITY
;
979 boldtext
= 1; /* Bold attribute is on */
981 if( attrib
>= FOREGROUND_RED
)
983 attrib
-= FOREGROUND_RED
;
984 if( attrib
>= FOREGROUND_GREEN
)
986 attrib
-= FOREGROUND_GREEN
;
987 if( attrib
>= FOREGROUND_BLUE
)
989 attrib
-= FOREGROUND_BLUE
;
990 forecolor
= 37; /* White foreground */
993 forecolor
= 33; /* Yellow foreground */
995 else if( attrib
>= FOREGROUND_BLUE
)
997 attrib
-= FOREGROUND_BLUE
;
998 forecolor
= 35; /* Magenta foreground */
1001 forecolor
= 31; /* Red foreground */
1003 else if( attrib
>= FOREGROUND_GREEN
)
1005 attrib
-= FOREGROUND_GREEN
;
1006 if( attrib
>= FOREGROUND_BLUE
)
1008 attrib
-= FOREGROUND_BLUE
;
1009 forecolor
= 36; /* Cyan foreground */
1012 forecolor
= 32; /* Green foreground */
1014 else if( attrib
>= FOREGROUND_BLUE
)
1016 attrib
-= FOREGROUND_BLUE
;
1017 forecolor
= 34; /* Blue foreground */
1020 forecolor
= 30; /* Black foreground */
1022 fprintf(stdout
,"%c[%d;%d;%dm",0x1B,boldtext
,forecolor
,backcolor
);
1027 /******************************************************************************
1028 * SetConsoleScreenBufferSize [KERNEL32.630] Changes size of console
1031 * hConsoleOutput [I] Handle to console screen buffer
1032 * dwSize [I] New size in character rows and cols
1038 BOOL32 WINAPI
SetConsoleScreenBufferSize( HANDLE32 hConsoleOutput
,
1041 FIXME(console
, "(%d,%dx%d): stub\n",hConsoleOutput
,dwSize
.x
,dwSize
.y
);
1046 /******************************************************************************
1047 * FillConsoleOutputCharacterA [KERNEL32.242]
1050 * hConsoleOutput [I] Handle to screen buffer
1051 * cCharacter [I] Character to write
1052 * nLength [I] Number of cells to write to
1053 * dwCoord [I] Coords of first cell
1054 * lpNumCharsWritten [O] Pointer to number of cells written
1060 BOOL32 WINAPI
FillConsoleOutputCharacterA(
1061 HANDLE32 hConsoleOutput
,
1065 LPDWORD lpNumCharsWritten
)
1068 SetConsoleCursorPosition(hConsoleOutput
,dwCoord
);
1069 for(count
=0;count
<nLength
;count
++)
1070 putc(cCharacter
,stdout
);
1071 *lpNumCharsWritten
= nLength
;
1076 /******************************************************************************
1077 * FillConsoleOutputCharacterW [KERNEL32.243] Writes characters to console
1080 * hConsoleOutput [I] Handle to screen buffer
1081 * cCharacter [I] Character to write
1082 * nLength [I] Number of cells to write to
1083 * dwCoord [I] Coords of first cell
1084 * lpNumCharsWritten [O] Pointer to number of cells written
1090 BOOL32 WINAPI
FillConsoleOutputCharacterW(HANDLE32 hConsoleOutput
,
1094 LPDWORD lpNumCharsWritten
)
1097 SetConsoleCursorPosition(hConsoleOutput
,dwCoord
);
1098 for(count
=0;count
<nLength
;count
++)
1099 putc(cCharacter
,stdout
);
1100 *lpNumCharsWritten
= nLength
;
1105 /******************************************************************************
1106 * FillConsoleOutputAttribute [KERNEL32.241] Sets attributes for console
1109 * hConsoleOutput [I] Handle to screen buffer
1110 * wAttribute [I] Color attribute to write
1111 * nLength [I] Number of cells to write to
1112 * dwCoord [I] Coords of first cell
1113 * lpNumAttrsWritten [O] Pointer to number of cells written
1119 BOOL32 WINAPI
FillConsoleOutputAttribute( HANDLE32 hConsoleOutput
,
1120 WORD wAttribute
, DWORD nLength
, COORD dwCoord
,
1121 LPDWORD lpNumAttrsWritten
)
1123 FIXME(console
, "(%d,%d,%ld,%dx%d,%p): stub\n", hConsoleOutput
,
1124 wAttribute
,nLength
,dwCoord
.x
,dwCoord
.y
,lpNumAttrsWritten
);
1125 *lpNumAttrsWritten
= nLength
;