blob: 91b154165eca255126fe6662ceb178411b4b11db [file] [log] [blame]
Alexandre Julliardade697e1995-11-26 13:59:11 +00001/*
2 * Win32 kernel functions
3 *
4 * Copyright 1995 Martin von Loewis and Cameron Heide
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00005 * Copyright 1997 Karl Garrison
Alexandre Julliard03468f71998-02-15 19:40:49 +00006 * Copyright 1998 John Richardson
Marcus Meissner537772a1998-12-09 16:37:04 +00007 * Copyright 1998 Marcus Meissner
8 */
9
10/* FIXME:
Marcus Meissner8bc54b61998-12-14 14:48:09 +000011 * - Completely lacks SCREENBUFFER interface.
12 * - No abstraction for something other than xterm.
Marcus Meissner8bc54b61998-12-14 14:48:09 +000013 * - Output sometimes is buffered (We switched off buffering by ~ICANON ?)
14 */
15/* Reference applications:
16 * - IDA (interactive disassembler) full version 3.75. Works.
17 * - LYNX/W32. Works mostly, some keys crash it.
Alexandre Julliardade697e1995-11-26 13:59:11 +000018 */
19
Patrik Stridvall96336321999-10-24 22:13:47 +000020#include "config.h"
21
Alexandre Julliard84c70f51997-05-09 08:40:27 +000022#include <stdlib.h>
Jeremy Whited3e22d92000-02-10 19:03:02 +000023#include <stdio.h>
Alexandre Julliard03468f71998-02-15 19:40:49 +000024#include <unistd.h>
Alexandre Julliard03468f71998-02-15 19:40:49 +000025#include <termios.h>
David Luyercb40df21999-03-25 15:52:09 +000026#include <string.h>
Alexandre Julliard03468f71998-02-15 19:40:49 +000027#include <sys/ioctl.h>
28#include <sys/types.h>
Marcus Meissnerb02ffc71998-10-11 10:49:46 +000029#include <sys/time.h>
Alexandre Julliard03468f71998-02-15 19:40:49 +000030#include <fcntl.h>
31#include <errno.h>
Howard Abrams13277481999-07-10 13:16:29 +000032#ifdef HAVE_SYS_ERRNO_H
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000033#include <sys/errno.h>
Howard Abrams13277481999-07-10 13:16:29 +000034#endif
Alexandre Julliard03468f71998-02-15 19:40:49 +000035#include <signal.h>
36#include <assert.h>
Marcus Meissnerad7538b1998-12-14 18:15:10 +000037
Jeremy Whited3e22d92000-02-10 19:03:02 +000038#include "windef.h"
Alexandre Julliard24a62ab2000-11-28 22:40:56 +000039#include "winbase.h"
40#include "winnls.h"
Jeremy Whited3e22d92000-02-10 19:03:02 +000041#include "wingdi.h"
Marcus Meissner04c3e1d1999-02-19 10:37:02 +000042#include "wine/winuser16.h"
43#include "wine/keyboard16.h"
Marcus Meissnerad7538b1998-12-14 18:15:10 +000044#include "thread.h"
Alexandre Julliardade697e1995-11-26 13:59:11 +000045#include "winerror.h"
Alexandre Julliardade697e1995-11-26 13:59:11 +000046#include "wincon.h"
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +000047#include "heap.h"
Alexandre Julliardb2340ea1998-12-30 12:10:49 +000048#include "server.h"
Alexandre Julliard5bc78081999-06-22 17:26:53 +000049#include "debugtools.h"
Alexandre Julliardb2340ea1998-12-30 12:10:49 +000050
Dimitrie O. Paun529da542000-11-27 23:54:25 +000051DEFAULT_DEBUG_CHANNEL(console);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000052
Marcus Meissnere75902a2000-08-31 02:05:19 +000053/* Ascii -> VK, generated by calling VkKeyScanA(i) */
54static int vkkeyscan_table[256] = {
55 0,0,0,0,0,0,0,0,8,9,0,0,0,13,0,0,0,0,0,19,145,556,0,0,0,0,0,27,0,0,0,
56 0,32,305,478,307,308,309,311,222,313,304,312,443,188,189,190,191,48,
57 49,50,51,52,53,54,55,56,57,442,186,444,187,446,447,306,321,322,323,
58 324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,
59 341,342,343,344,345,346,219,220,221,310,445,192,65,66,67,68,69,70,71,
60 72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,475,476,477,
61 448,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
62 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
63 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
64 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,400,0,0,0,0,0,0
65};
66
67static int mapvkey_0[256]={
68 0,0,0,0,0,0,0,0,14,15,0,0,0,28,0,0,42,29,56,69,58,0,0,0,0,0,0,1,0,0,
69 0,0,57,73,81,79,71,75,72,77,80,0,0,0,55,82,83,0,11,2,3,4,5,6,7,8,9,
70 10,0,0,0,0,0,0,0,30,48,46,32,18,33,34,35,23,36,37,38,50,49,24,25,16,
71 19,31,20,22,47,17,45,21,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,55,78,0,74,
72 0,53,59,60,61,62,63,64,65,66,67,68,87,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
73 0,0,0,0,0,0,69,70,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
74 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,39,13,51,12,52,53,41,0,0,0,0,0,0,0,0,0,
75 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,26,43,27,40,76,96,0,0,0,0,0,0,0,0,
76 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
77};
78
79static int mapvkey_1[256]={
80 0,27,49,50,51,52,53,54,55,56,57,48,189,187,8,9,81,87,69,82,84,89,85,
81 73,79,80,219,221,13,17,65,83,68,70,71,72,74,75,76,186,222,192,16,220,
82 90,88,67,86,66,78,77,188,190,191,16,106,18,32,20,112,113,114,115,116,
83 117,118,119,120,121,144,145,36,38,33,109,37,223,39,107,35,40,34,45,
84 46,0,0,0,122,123,0,0,0,0,0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
85 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
86 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
87 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
88 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
89 0,0,0,0,0,0,0
90};
Alexandre Julliard03468f71998-02-15 19:40:49 +000091
Zygo Blaxelledc858c1999-02-09 14:14:16 +000092/* FIXME: Should be in an internal header file. OK, so which one?
Alexandre Julliard908464d2000-11-01 03:11:12 +000093 Used by CONSOLE_make_complex. */
94extern int wine_openpty(int *master, int *slave, char *name,
Patrik Stridvall2c684081999-07-31 17:36:48 +000095 struct termios *term, struct winsize *winsize);
Zygo Blaxelledc858c1999-02-09 14:14:16 +000096
Alexandre Julliard62a8b431999-01-19 17:48:23 +000097/****************************************************************************
Alexandre Julliardebe29ef1999-06-26 08:43:26 +000098 * CONSOLE_GetPid
Alexandre Julliard62a8b431999-01-19 17:48:23 +000099 */
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000100static int CONSOLE_GetPid( HANDLE handle )
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000101{
Alexandre Julliard92643002000-08-31 01:59:51 +0000102 int ret = 0;
Alexandre Julliard67a74992001-02-27 02:09:16 +0000103 SERVER_START_REQ( get_console_info )
Alexandre Julliard92643002000-08-31 01:59:51 +0000104 {
Alexandre Julliard92643002000-08-31 01:59:51 +0000105 req->handle = handle;
Alexandre Julliard67a74992001-02-27 02:09:16 +0000106 if (!SERVER_CALL_ERR()) ret = req->pid;
Alexandre Julliard92643002000-08-31 01:59:51 +0000107 }
108 SERVER_END_REQ;
109 return ret;
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000110}
111
Marcus Meissner537772a1998-12-09 16:37:04 +0000112/****************************************************************************
113 * XTERM_string_to_IR [internal]
114 *
115 * Transfers a string read from XTERM to INPUT_RECORDs and adds them to the
116 * queue. Does translation of vt100 style function keys and xterm-mouse clicks.
117 */
118static void
Alexandre Julliarda3960291999-02-26 11:11:13 +0000119CONSOLE_string_to_IR( HANDLE hConsoleInput,unsigned char *buf,int len) {
Marcus Meissner537772a1998-12-09 16:37:04 +0000120 int j,k;
121 INPUT_RECORD ir;
Marcus Meissnera2ca7b91999-02-05 09:32:39 +0000122 DWORD junk;
Marcus Meissner537772a1998-12-09 16:37:04 +0000123
124 for (j=0;j<len;j++) {
125 unsigned char inchar = buf[j];
126
127 if (inchar!=27) { /* no escape -> 'normal' keyboard event */
128 ir.EventType = 1; /* Key_event */
129
Marcus Meissner8bc54b61998-12-14 14:48:09 +0000130 ir.Event.KeyEvent.bKeyDown = 1;
131 ir.Event.KeyEvent.wRepeatCount = 0;
Marcus Meissner537772a1998-12-09 16:37:04 +0000132
Marcus Meissner8bc54b61998-12-14 14:48:09 +0000133 ir.Event.KeyEvent.dwControlKeyState = 0;
Marcus Meissner537772a1998-12-09 16:37:04 +0000134 if (inchar & 0x80) {
135 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
136 inchar &= ~0x80;
137 }
Marcus Meissnere75902a2000-08-31 02:05:19 +0000138 ir.Event.KeyEvent.wVirtualKeyCode = vkkeyscan_table[inchar];
Marcus Meissner8bc54b61998-12-14 14:48:09 +0000139 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0100)
Marcus Meissner537772a1998-12-09 16:37:04 +0000140 ir.Event.KeyEvent.dwControlKeyState|=SHIFT_PRESSED;
Marcus Meissner8bc54b61998-12-14 14:48:09 +0000141 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0200)
142 ir.Event.KeyEvent.dwControlKeyState|=LEFT_CTRL_PRESSED;
143 if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0400)
144 ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED;
Marcus Meissnere75902a2000-08-31 02:05:19 +0000145 ir.Event.KeyEvent.wVirtualScanCode = mapvkey_0[
146 ir.Event.KeyEvent.wVirtualKeyCode & 0x00ff
147 ]; /* VirtualKeyCodes to ScanCode */
Marcus Meissnera2ca7b91999-02-05 09:32:39 +0000148 ir.Event.KeyEvent.uChar.AsciiChar = inchar;
149
Ove Kaaven5d6d5012000-02-03 00:45:04 +0000150 if ((inchar==127)||(inchar=='\b')) { /* backspace */
Marcus Meissnera2ca7b91999-02-05 09:32:39 +0000151 ir.Event.KeyEvent.uChar.AsciiChar = '\b'; /* FIXME: hmm */
152 ir.Event.KeyEvent.wVirtualScanCode = 0x0e;
153 ir.Event.KeyEvent.wVirtualKeyCode = VK_BACK;
Marcus Meissner537772a1998-12-09 16:37:04 +0000154 } else {
Marcus Meissnerc868cd31999-05-29 10:55:08 +0000155 if ((inchar=='\n')||(inchar=='\r')) {
Marcus Meissnera2ca7b91999-02-05 09:32:39 +0000156 ir.Event.KeyEvent.uChar.AsciiChar = '\r';
157 ir.Event.KeyEvent.wVirtualKeyCode = VK_RETURN;
158 ir.Event.KeyEvent.wVirtualScanCode = 0x1c;
Marcus Meissnerc868cd31999-05-29 10:55:08 +0000159 ir.Event.KeyEvent.dwControlKeyState = 0;
Marcus Meissnera2ca7b91999-02-05 09:32:39 +0000160 } else {
161 if (inchar<' ') {
162 /* FIXME: find good values for ^X */
163 ir.Event.KeyEvent.wVirtualKeyCode = 0xdead;
164 ir.Event.KeyEvent.wVirtualScanCode = 0xbeef;
165 }
166 }
Marcus Meissner537772a1998-12-09 16:37:04 +0000167 }
168
Alexandre Julliarda3960291999-02-26 11:11:13 +0000169 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
Marcus Meissner537772a1998-12-09 16:37:04 +0000170 ir.Event.KeyEvent.bKeyDown = 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000171 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
Marcus Meissner537772a1998-12-09 16:37:04 +0000172 continue;
173 }
174 /* inchar is ESC */
175 if ((j==len-1) || (buf[j+1]!='[')) {/* add ESCape on its own */
176 ir.EventType = 1; /* Key_event */
Marcus Meissner8bc54b61998-12-14 14:48:09 +0000177 ir.Event.KeyEvent.bKeyDown = 1;
178 ir.Event.KeyEvent.wRepeatCount = 0;
Marcus Meissner537772a1998-12-09 16:37:04 +0000179
Alexandre Julliard09ddb592000-08-03 22:22:42 +0000180 ir.Event.KeyEvent.wVirtualKeyCode = VK_ESCAPE;
Marcus Meissnere75902a2000-08-31 02:05:19 +0000181 ir.Event.KeyEvent.wVirtualScanCode = mapvkey_0[
182 ir.Event.KeyEvent.wVirtualKeyCode
183 ];
Marcus Meissner537772a1998-12-09 16:37:04 +0000184 ir.Event.KeyEvent.dwControlKeyState = 0;
Marcus Meissner537772a1998-12-09 16:37:04 +0000185 ir.Event.KeyEvent.uChar.AsciiChar = 27;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000186 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
Marcus Meissner537772a1998-12-09 16:37:04 +0000187 ir.Event.KeyEvent.bKeyDown = 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000188 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
Marcus Meissner537772a1998-12-09 16:37:04 +0000189 continue;
190 }
191 for (k=j;k<len;k++) {
192 if (((buf[k]>='A') && (buf[k]<='Z')) ||
193 ((buf[k]>='a') && (buf[k]<='z')) ||
194 (buf[k]=='~')
195 )
196 break;
197 }
198 if (k<len) {
199 int subid,scancode=0;
200
201 ir.EventType = 1; /* Key_event */
202 ir.Event.KeyEvent.bKeyDown = 1;
203 ir.Event.KeyEvent.wRepeatCount = 0;
204 ir.Event.KeyEvent.dwControlKeyState = 0;
205
Marcus Meissner8bc54b61998-12-14 14:48:09 +0000206 ir.Event.KeyEvent.wVirtualKeyCode = 0xad; /* FIXME */
207 ir.Event.KeyEvent.wVirtualScanCode = 0xad; /* FIXME */
Marcus Meissner537772a1998-12-09 16:37:04 +0000208 ir.Event.KeyEvent.uChar.AsciiChar = 0;
209
210 switch (buf[k]) {
211 case '~':
212 sscanf(&buf[j+2],"%d",&subid);
213 switch (subid) {
214 case 2:/*INS */scancode = 0xe052;break;
215 case 3:/*DEL */scancode = 0xe053;break;
216 case 6:/*PGDW*/scancode = 0xe051;break;
217 case 5:/*PGUP*/scancode = 0xe049;break;
218 case 11:/*F1 */scancode = 0x003b;break;
219 case 12:/*F2 */scancode = 0x003c;break;
220 case 13:/*F3 */scancode = 0x003d;break;
221 case 14:/*F4 */scancode = 0x003e;break;
222 case 15:/*F5 */scancode = 0x003f;break;
223 case 17:/*F6 */scancode = 0x0040;break;
224 case 18:/*F7 */scancode = 0x0041;break;
225 case 19:/*F8 */scancode = 0x0042;break;
226 case 20:/*F9 */scancode = 0x0043;break;
227 case 21:/*F10 */scancode = 0x0044;break;
228 case 23:/*F11 */scancode = 0x00d9;break;
229 case 24:/*F12 */scancode = 0x00da;break;
230 /* FIXME: Shift-Fx */
231 default:
Alexandre Julliard15657091999-05-23 10:25:25 +0000232 FIXME("parse ESC[%d~\n",subid);
Marcus Meissner537772a1998-12-09 16:37:04 +0000233 break;
234 }
235 break;
236 case 'A': /* Cursor Up */scancode = 0xe048;break;
237 case 'B': /* Cursor Down */scancode = 0xe050;break;
238 case 'D': /* Cursor Left */scancode = 0xe04b;break;
239 case 'C': /* Cursor Right */scancode = 0xe04d;break;
240 case 'F': /* End */scancode = 0xe04f;break;
241 case 'H': /* Home */scancode = 0xe047;break;
242 case 'M':
243 /* Mouse Button Press (ESCM<button+'!'><x+'!'><y+'!'>) or
244 * Release (ESCM#<x+'!'><y+'!'>
245 */
246 if (k<len-3) {
247 ir.EventType = MOUSE_EVENT;
Alexandre Julliardf818d422000-05-03 17:48:21 +0000248 ir.Event.MouseEvent.dwMousePosition.X = buf[k+2]-'!';
249 ir.Event.MouseEvent.dwMousePosition.Y = buf[k+3]-'!';
Marcus Meissner537772a1998-12-09 16:37:04 +0000250 if (buf[k+1]=='#')
251 ir.Event.MouseEvent.dwButtonState = 0;
252 else
253 ir.Event.MouseEvent.dwButtonState = 1<<(buf[k+1]-' ');
254 ir.Event.MouseEvent.dwEventFlags = 0; /* FIXME */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000255 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk));
Marcus Meissner537772a1998-12-09 16:37:04 +0000256 j=k+3;
257 }
258 break;
Marcus Meissner62de4b91999-05-08 18:32:56 +0000259 case 'c':
260 j=k;
261 break;
Marcus Meissner537772a1998-12-09 16:37:04 +0000262 }
263 if (scancode) {
264 ir.Event.KeyEvent.wVirtualScanCode = scancode;
Marcus Meissnere75902a2000-08-31 02:05:19 +0000265 ir.Event.KeyEvent.wVirtualKeyCode = mapvkey_1[scancode];
Alexandre Julliarda3960291999-02-26 11:11:13 +0000266 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
Marcus Meissner537772a1998-12-09 16:37:04 +0000267 ir.Event.KeyEvent.bKeyDown = 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000268 assert(WriteConsoleInputA( hConsoleInput, &ir, 1, &junk ));
Marcus Meissner537772a1998-12-09 16:37:04 +0000269 j=k;
270 continue;
271 }
272 }
273 }
274}
Alexandre Julliard55443871998-12-31 15:52:06 +0000275
Marcus Meissner537772a1998-12-09 16:37:04 +0000276/****************************************************************************
277 * CONSOLE_get_input (internal)
278 *
279 * Reads (nonblocking) as much input events as possible and stores them
280 * in an internal queue.
Marcus Meissner537772a1998-12-09 16:37:04 +0000281 */
282static void
Alexandre Julliarda3960291999-02-26 11:11:13 +0000283CONSOLE_get_input( HANDLE handle, BOOL blockwait )
Alexandre Julliard55443871998-12-31 15:52:06 +0000284{
Marcus Meissner537772a1998-12-09 16:37:04 +0000285 char *buf = HeapAlloc(GetProcessHeap(),0,1);
Marcus Meissner8bc6e002000-02-20 13:29:25 +0000286 int len = 0, escape_seen = 0;
Marcus Meissner537772a1998-12-09 16:37:04 +0000287
Alexandre Julliard55443871998-12-31 15:52:06 +0000288 while (1)
289 {
290 DWORD res;
291 char inchar;
Marcus Meissner8bc6e002000-02-20 13:29:25 +0000292
293 /* If we have at one time seen escape in this loop, we are
294 * within an Escape sequence, so wait for a bit more input for the
295 * rest of the loop.
296 */
297 if (WaitForSingleObject( handle, escape_seen*10 )) break;
Alexandre Julliard55443871998-12-31 15:52:06 +0000298 if (!ReadFile( handle, &inchar, 1, &res, NULL )) break;
Marcus Meissner03f10f41999-01-26 10:08:36 +0000299 if (!res) /* res 0 but readable means EOF? Hmm. */
300 break;
Marcus Meissner537772a1998-12-09 16:37:04 +0000301 buf = HeapReAlloc(GetProcessHeap(),0,buf,len+1);
302 buf[len++]=inchar;
Marcus Meissner8bc6e002000-02-20 13:29:25 +0000303 if (inchar == 27) {
304 if (len>1) {
305 /* If we spot an ESC, we flush all up to it
306 * since we can be sure that we have a complete
307 * sequence.
308 */
309 CONSOLE_string_to_IR(handle,buf,len-1);
310 buf = HeapReAlloc(GetProcessHeap(),0,buf,1);
311 buf[0] = 27;
312 len = 1;
313 }
314 escape_seen = 1;
315 }
Marcus Meissner537772a1998-12-09 16:37:04 +0000316 }
Alexandre Julliard55443871998-12-31 15:52:06 +0000317 CONSOLE_string_to_IR(handle,buf,len);
Marcus Meissner537772a1998-12-09 16:37:04 +0000318 HeapFree(GetProcessHeap(),0,buf);
319}
320
Alexandre Julliard92643002000-08-31 01:59:51 +0000321
322/******************************************************************************
323 * read_console_input
324 *
325 * Helper function for ReadConsole, ReadConsoleInput and PeekConsoleInput
326 */
327static BOOL read_console_input( HANDLE handle, LPINPUT_RECORD buffer, DWORD count,
328 LPDWORD read, BOOL flush )
329{
330 BOOL ret;
331
332 count = min( count, REQUEST_MAX_VAR_SIZE/sizeof(INPUT_RECORD) );
333
Alexandre Julliard67a74992001-02-27 02:09:16 +0000334 SERVER_START_VAR_REQ( read_console_input, count*sizeof(INPUT_RECORD) )
Alexandre Julliard92643002000-08-31 01:59:51 +0000335 {
Alexandre Julliard92643002000-08-31 01:59:51 +0000336 req->handle = handle;
337 req->flush = flush;
Alexandre Julliard67a74992001-02-27 02:09:16 +0000338 if ((ret = !SERVER_CALL_ERR()))
Alexandre Julliard92643002000-08-31 01:59:51 +0000339 {
340 if (count) memcpy( buffer, server_data_ptr(req), server_data_size(req) );
341 if (read) *read = req->read;
342 }
343 }
Alexandre Julliard67a74992001-02-27 02:09:16 +0000344 SERVER_END_VAR_REQ;
Alexandre Julliard92643002000-08-31 01:59:51 +0000345 return ret;
346}
347
348
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000349/******************************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000350 * SetConsoleCtrlHandler [KERNEL32.@] Adds function to calling process list
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000351 *
352 * PARAMS
353 * func [I] Address of handler function
354 * add [I] Handler to add or remove
355 *
356 * RETURNS
357 * Success: TRUE
358 * Failure: FALSE
James Sutherland577db371998-11-08 15:09:08 +0000359 *
360 * CHANGED
361 * James Sutherland (JamesSutherland@gmx.de)
362 * Added global variables console_ignore_ctrl_c and handlers[]
363 * Does not yet do any error checking, or set LastError if failed.
364 * This doesn't yet matter, since these handlers are not yet called...!
Alexandre Julliardade697e1995-11-26 13:59:11 +0000365 */
James Sutherland577db371998-11-08 15:09:08 +0000366static unsigned int console_ignore_ctrl_c = 0;
367static HANDLER_ROUTINE *handlers[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
Alexandre Julliarda3960291999-02-26 11:11:13 +0000368BOOL WINAPI SetConsoleCtrlHandler( HANDLER_ROUTINE *func, BOOL add )
Alexandre Julliardade697e1995-11-26 13:59:11 +0000369{
James Sutherland577db371998-11-08 15:09:08 +0000370 unsigned int alloc_loop = sizeof(handlers)/sizeof(HANDLER_ROUTINE *);
371 unsigned int done = 0;
Alexandre Julliard15657091999-05-23 10:25:25 +0000372 FIXME("(%p,%i) - no error checking or testing yet\n", func, add);
James Sutherland577db371998-11-08 15:09:08 +0000373 if (!func)
374 {
375 console_ignore_ctrl_c = add;
376 return TRUE;
377 }
378 if (add)
379 {
380 for (;alloc_loop--;)
381 if (!handlers[alloc_loop] && !done)
382 {
383 handlers[alloc_loop] = func;
384 done++;
385 }
386 if (!done)
Alexandre Julliard15657091999-05-23 10:25:25 +0000387 FIXME("Out of space on CtrlHandler table\n");
James Sutherland577db371998-11-08 15:09:08 +0000388 return(done);
389 }
390 else
391 {
392 for (;alloc_loop--;)
393 if (handlers[alloc_loop] == func && !done)
394 {
395 handlers[alloc_loop] = 0;
396 done++;
397 }
398 if (!done)
Alexandre Julliard15657091999-05-23 10:25:25 +0000399 WARN("Attempt to remove non-installed CtrlHandler %p\n",
Huw D M Davies7b06d981998-11-14 17:13:51 +0000400 func);
James Sutherland577db371998-11-08 15:09:08 +0000401 return (done);
402 }
403 return (done);
404}
405
406
407/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +0000408 * GenerateConsoleCtrlEvent [KERNEL32.@] Simulate a CTRL-C or CTRL-BREAK
James Sutherland577db371998-11-08 15:09:08 +0000409 *
410 * PARAMS
411 * dwCtrlEvent [I] Type of event
412 * dwProcessGroupID [I] Process group ID to send event to
413 *
414 * NOTES
415 * Doesn't yet work...!
416 *
417 * RETURNS
418 * Success: True
419 * Failure: False (and *should* [but doesn't] set LastError)
420 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000421BOOL WINAPI GenerateConsoleCtrlEvent( DWORD dwCtrlEvent,
James Sutherland577db371998-11-08 15:09:08 +0000422 DWORD dwProcessGroupID )
423{
424 if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT)
425 {
Alexandre Julliard15657091999-05-23 10:25:25 +0000426 ERR("invalid event %d for PGID %ld\n",
James Sutherland577db371998-11-08 15:09:08 +0000427 (unsigned short)dwCtrlEvent, dwProcessGroupID );
428 return FALSE;
429 }
430 if (dwProcessGroupID == GetCurrentProcessId() )
431 {
Alexandre Julliard15657091999-05-23 10:25:25 +0000432 FIXME("Attempt to send event %d to self - stub\n",
James Sutherland577db371998-11-08 15:09:08 +0000433 (unsigned short)dwCtrlEvent );
434 return FALSE;
435 }
Alexandre Julliard15657091999-05-23 10:25:25 +0000436 FIXME("event %d to external PGID %ld - not implemented yet\n",
James Sutherland577db371998-11-08 15:09:08 +0000437 (unsigned short)dwCtrlEvent, dwProcessGroupID );
438 return FALSE;
Alexandre Julliardade697e1995-11-26 13:59:11 +0000439}
440
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000441
442/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +0000443 * CreateConsoleScreenBuffer [KERNEL32.@] Creates a console screen buffer
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000444 *
445 * PARAMS
446 * dwDesiredAccess [I] Access flag
447 * dwShareMode [I] Buffer share mode
448 * sa [I] Security attributes
449 * dwFlags [I] Type of buffer to create
450 * lpScreenBufferData [I] Reserved
451 *
452 * NOTES
453 * Should call SetLastError
454 *
455 * RETURNS
456 * Success: Handle to new console screen buffer
457 * Failure: INVALID_HANDLE_VALUE
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000458 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000459HANDLE WINAPI CreateConsoleScreenBuffer( DWORD dwDesiredAccess,
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000460 DWORD dwShareMode, LPSECURITY_ATTRIBUTES sa,
461 DWORD dwFlags, LPVOID lpScreenBufferData )
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000462{
Alexandre Julliard15657091999-05-23 10:25:25 +0000463 FIXME("(%ld,%ld,%p,%ld,%p): stub\n",dwDesiredAccess,
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000464 dwShareMode, sa, dwFlags, lpScreenBufferData);
Marcus Meissner537772a1998-12-09 16:37:04 +0000465 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
Alexandre Julliarda3960291999-02-26 11:11:13 +0000466 return INVALID_HANDLE_VALUE;
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000467}
468
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000469
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000470/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000471 * GetConsoleScreenBufferInfo (KERNEL32.@)
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000472 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000473BOOL WINAPI GetConsoleScreenBufferInfo( HANDLE hConsoleOutput,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000474 LPCONSOLE_SCREEN_BUFFER_INFO csbi )
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000475{
Alexandre Julliardf818d422000-05-03 17:48:21 +0000476 csbi->dwSize.X = 80;
477 csbi->dwSize.Y = 24;
478 csbi->dwCursorPosition.X = 0;
479 csbi->dwCursorPosition.Y = 0;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000480 csbi->wAttributes = 0;
481 csbi->srWindow.Left = 0;
482 csbi->srWindow.Right = 79;
483 csbi->srWindow.Top = 0;
484 csbi->srWindow.Bottom = 23;
Alexandre Julliardf818d422000-05-03 17:48:21 +0000485 csbi->dwMaximumWindowSize.X = 80;
486 csbi->dwMaximumWindowSize.Y = 24;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000487 return TRUE;
488}
489
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000490
491/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +0000492 * SetConsoleActiveScreenBuffer [KERNEL32.@] Sets buffer to current console
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000493 *
494 * RETURNS
495 * Success: TRUE
496 * Failure: FALSE
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000497 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000498BOOL WINAPI SetConsoleActiveScreenBuffer(
499 HANDLE hConsoleOutput) /* [in] Handle to console screen buffer */
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000500{
Alexandre Julliard15657091999-05-23 10:25:25 +0000501 FIXME("(%x): stub\n", hConsoleOutput);
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000502 return FALSE;
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000503}
504
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000505
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000506/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000507 * GetLargestConsoleWindowSize (KERNEL32.@)
Alexandre Julliard3bf456b2000-11-25 21:46:30 +0000508 *
Patrik Stridvall697bf652000-12-02 23:44:59 +0000509 * NOTE
510 * This should return a COORD, but calling convention for returning
511 * structures is different between Windows and gcc on i386.
512 *
513 * VERSION: [i386]
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000514 */
Alexandre Julliard3bf456b2000-11-25 21:46:30 +0000515#ifdef __i386__
516#undef GetLargestConsoleWindowSize
517DWORD WINAPI GetLargestConsoleWindowSize( HANDLE hConsoleOutput )
518{
519 COORD c;
520 c.X = 80;
521 c.Y = 24;
522 return *(DWORD *)&c;
523}
Patrik Stridvall697bf652000-12-02 23:44:59 +0000524#endif /* defined(__i386__) */
525
526
527/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000528 * GetLargestConsoleWindowSize (KERNEL32.@)
Patrik Stridvall697bf652000-12-02 23:44:59 +0000529 *
530 * NOTE
531 * This should return a COORD, but calling convention for returning
532 * structures is different between Windows and gcc on i386.
533 *
534 * VERSION: [!i386]
535 */
536#ifndef __i386__
Eric Pouechf1a25322000-04-29 17:16:00 +0000537COORD WINAPI GetLargestConsoleWindowSize( HANDLE hConsoleOutput )
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000538{
Eric Pouechf1a25322000-04-29 17:16:00 +0000539 COORD c;
Alexandre Julliardf818d422000-05-03 17:48:21 +0000540 c.X = 80;
541 c.Y = 24;
Eric Pouechf1a25322000-04-29 17:16:00 +0000542 return c;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000543}
Patrik Stridvall697bf652000-12-02 23:44:59 +0000544#endif /* defined(__i386__) */
545
Alexandre Julliardf818d422000-05-03 17:48:21 +0000546
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000547/***********************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +0000548 * FreeConsole (KERNEL32.@)
Alexandre Julliard03468f71998-02-15 19:40:49 +0000549 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000550BOOL WINAPI FreeConsole(VOID)
Alexandre Julliard03468f71998-02-15 19:40:49 +0000551{
Alexandre Julliard92643002000-08-31 01:59:51 +0000552 BOOL ret;
Alexandre Julliard67a74992001-02-27 02:09:16 +0000553 SERVER_START_REQ( free_console )
Alexandre Julliard92643002000-08-31 01:59:51 +0000554 {
Alexandre Julliard67a74992001-02-27 02:09:16 +0000555 ret = !SERVER_CALL_ERR();
Alexandre Julliard92643002000-08-31 01:59:51 +0000556 }
557 SERVER_END_REQ;
558 return ret;
Alexandre Julliard03468f71998-02-15 19:40:49 +0000559}
560
561
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000562/*************************************************************************
Marcus Meissner537772a1998-12-09 16:37:04 +0000563 * CONSOLE_make_complex [internal]
564 *
565 * Turns a CONSOLE kernel object into a complex one.
566 * (switches from output/input using the terminal where WINE was started to
567 * its own xterm).
568 *
569 * This makes simple commandline tools pipeable, while complex commandline
570 * tools work without getting messed up by debugoutput.
571 *
Andreas Mohra6d83eb2000-12-27 04:02:46 +0000572 * All other functions should work independently from this call.
Marcus Meissner537772a1998-12-09 16:37:04 +0000573 *
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000574 * To test for complex console: pid == 0 -> simple, otherwise complex.
Marcus Meissner537772a1998-12-09 16:37:04 +0000575 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000576static BOOL CONSOLE_make_complex(HANDLE handle)
Alexandre Julliard03468f71998-02-15 19:40:49 +0000577{
578 struct termios term;
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000579 char buf[256];
Alexandre Julliard03468f71998-02-15 19:40:49 +0000580 char c = '\0';
François Gougetabb8c072001-01-09 20:50:51 +0000581 int i,xpid,master,slave;
Marcus Meissner537772a1998-12-09 16:37:04 +0000582
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000583 if (CONSOLE_GetPid( handle )) return TRUE; /* already complex */
Marcus Meissner537772a1998-12-09 16:37:04 +0000584
Alexandre Julliard15657091999-05-23 10:25:25 +0000585 MESSAGE("Console: Making console complex (creating an xterm)...\n");
Alexandre Julliard03468f71998-02-15 19:40:49 +0000586
Marcus Meissner03f10f41999-01-26 10:08:36 +0000587 if (tcgetattr(0, &term) < 0) {
588 /* ignore failure, or we can't run from a script */
589 }
Marcus Meissner537772a1998-12-09 16:37:04 +0000590 term.c_lflag = ~(ECHO|ICANON);
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000591
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000592 if (wine_openpty(&master, &slave, NULL, &term, NULL) < 0)
593 return FALSE;
Alexandre Julliard03468f71998-02-15 19:40:49 +0000594
Marcus Meissner537772a1998-12-09 16:37:04 +0000595 if ((xpid=fork()) == 0) {
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000596 tcsetattr(slave, TCSADRAIN, &term);
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000597 close( slave );
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000598 sprintf(buf, "-Sxx%d", master);
Marcus Meissner537772a1998-12-09 16:37:04 +0000599 /* "-fn vga" for VGA font. Harmless if vga is not present:
600 * xterm: unable to open font "vga", trying "fixed"....
601 */
602 execlp("xterm", "xterm", buf, "-fn","vga",NULL);
Alexandre Julliard15657091999-05-23 10:25:25 +0000603 ERR("error creating AllocConsole xterm\n");
Alexandre Julliard03468f71998-02-15 19:40:49 +0000604 exit(1);
605 }
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000606 close( master );
Alexandre Julliard03468f71998-02-15 19:40:49 +0000607
608 /* most xterms like to print their window ID when used with -S;
609 * read it and continue before the user has a chance...
Alexandre Julliard03468f71998-02-15 19:40:49 +0000610 */
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000611 for (i = 0; i < 10000; i++)
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000612 {
Alexandre Julliarda5a872e2001-03-22 19:35:27 +0000613 if (read( slave, &c, 1 ) == 1)
614 {
615 if (c == '\n') break;
616 }
617 else usleep(100); /* wait for xterm to be created */
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000618 }
619 if (i == 10000)
620 {
621 ERR("can't read xterm WID\n");
Alexandre Julliarda5a872e2001-03-22 19:35:27 +0000622 close( slave );
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000623 return FALSE;
624 }
Alexandre Julliarda5a872e2001-03-22 19:35:27 +0000625
626 wine_server_send_fd( slave );
Alexandre Julliard67a74992001-02-27 02:09:16 +0000627 SERVER_START_REQ( set_console_fd )
Alexandre Julliard92643002000-08-31 01:59:51 +0000628 {
Alexandre Julliarda5a872e2001-03-22 19:35:27 +0000629 req->handle = handle;
630 req->fd_in = slave;
631 req->fd_out = slave;
632 req->pid = xpid;
Alexandre Julliard67a74992001-02-27 02:09:16 +0000633 SERVER_CALL();
Alexandre Julliarda5a872e2001-03-22 19:35:27 +0000634 close( slave );
Alexandre Julliard92643002000-08-31 01:59:51 +0000635 }
636 SERVER_END_REQ;
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000637
638 /* enable mouseclicks */
Marcus Meissner627616b2000-09-02 23:18:31 +0000639 strcpy( buf, "\033[?1002h" );
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000640 WriteFile(handle,buf,strlen(buf),NULL,NULL);
641
642 strcpy( buf, "\033]2;" );
643 if (GetConsoleTitleA( buf + 4, sizeof(buf) - 5 ))
644 {
645 strcat( buf, "\a" );
646 WriteFile(handle,buf,strlen(buf),NULL,NULL);
Alexandre Julliard638f1691999-01-17 16:32:32 +0000647 }
Alexandre Julliard03468f71998-02-15 19:40:49 +0000648 return TRUE;
649
650}
651
652
653/***********************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +0000654 * AllocConsole (KERNEL32.@)
Alexandre Julliard03468f71998-02-15 19:40:49 +0000655 *
656 * creates an xterm with a pty to our program
657 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000658BOOL WINAPI AllocConsole(VOID)
Alexandre Julliard03468f71998-02-15 19:40:49 +0000659{
Alexandre Julliard92643002000-08-31 01:59:51 +0000660 BOOL ret;
Alexandre Julliard039aa421999-06-11 18:31:22 +0000661 HANDLE hStderr;
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000662 int handle_in, handle_out;
Alexandre Julliard03468f71998-02-15 19:40:49 +0000663
Alexandre Julliard039aa421999-06-11 18:31:22 +0000664 TRACE("()\n");
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000665
Alexandre Julliard67a74992001-02-27 02:09:16 +0000666 SERVER_START_REQ( alloc_console )
Alexandre Julliard92643002000-08-31 01:59:51 +0000667 {
Alexandre Julliard92643002000-08-31 01:59:51 +0000668 req->access = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE;
669 req->inherit = FALSE;
Alexandre Julliard67a74992001-02-27 02:09:16 +0000670 ret = !SERVER_CALL_ERR();
Alexandre Julliard92643002000-08-31 01:59:51 +0000671 handle_in = req->handle_in;
672 handle_out = req->handle_out;
673 }
674 SERVER_END_REQ;
675 if (!ret) return FALSE;
676
677 if (!DuplicateHandle( GetCurrentProcess(), handle_out, GetCurrentProcess(), &hStderr,
Alexandre Julliard039aa421999-06-11 18:31:22 +0000678 0, TRUE, DUPLICATE_SAME_ACCESS ))
679 {
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000680 CloseHandle( handle_in );
681 CloseHandle( handle_out );
Alexandre Julliard039aa421999-06-11 18:31:22 +0000682 FreeConsole();
683 return FALSE;
684 }
Alexandre Julliard03468f71998-02-15 19:40:49 +0000685
Alexandre Julliard039aa421999-06-11 18:31:22 +0000686 /* NT resets the STD_*_HANDLEs on console alloc */
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000687 SetStdHandle( STD_INPUT_HANDLE, handle_in );
688 SetStdHandle( STD_OUTPUT_HANDLE, handle_out );
Alexandre Julliard039aa421999-06-11 18:31:22 +0000689 SetStdHandle( STD_ERROR_HANDLE, hStderr );
Alexandre Julliard03468f71998-02-15 19:40:49 +0000690
Alexandre Julliard039aa421999-06-11 18:31:22 +0000691 SetLastError(ERROR_SUCCESS);
692 SetConsoleTitleA("Wine Console");
693 return TRUE;
Alexandre Julliard03468f71998-02-15 19:40:49 +0000694}
695
696
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000697/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +0000698 * GetConsoleCP [KERNEL32.@] Returns the OEM code page for the console
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000699 *
700 * RETURNS
701 * Code page code
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000702 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000703UINT WINAPI GetConsoleCP(VOID)
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000704{
705 return GetACP();
706}
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000707
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000708
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000709/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000710 * GetConsoleOutputCP (KERNEL32.@)
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000711 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000712UINT WINAPI GetConsoleOutputCP(VOID)
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000713{
714 return GetConsoleCP();
715}
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000716
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000717/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000718 * GetConsoleMode (KERNEL32.@)
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000719 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000720BOOL WINAPI GetConsoleMode(HANDLE hcon,LPDWORD mode)
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000721{
Alexandre Julliard9c2370b2000-08-30 00:00:48 +0000722 BOOL ret;
Alexandre Julliard67a74992001-02-27 02:09:16 +0000723 SERVER_START_REQ( get_console_mode )
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000724 {
Alexandre Julliard9c2370b2000-08-30 00:00:48 +0000725 req->handle = hcon;
Alexandre Julliard67a74992001-02-27 02:09:16 +0000726 ret = !SERVER_CALL_ERR();
Alexandre Julliard9c2370b2000-08-30 00:00:48 +0000727 if (ret && mode) *mode = req->mode;
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000728 }
Alexandre Julliard9c2370b2000-08-30 00:00:48 +0000729 SERVER_END_REQ;
Alexandre Julliardebe29ef1999-06-26 08:43:26 +0000730 return ret;
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000731}
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000732
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000733
734/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +0000735 * SetConsoleMode [KERNEL32.@] Sets input mode of console's input buffer
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000736 *
737 * PARAMS
738 * hcon [I] Handle to console input or screen buffer
739 * mode [I] Input or output mode to set
740 *
741 * RETURNS
742 * Success: TRUE
743 * Failure: FALSE
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000744 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000745BOOL WINAPI SetConsoleMode( HANDLE hcon, DWORD mode )
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000746{
Alexandre Julliard9c2370b2000-08-30 00:00:48 +0000747 BOOL ret;
Alexandre Julliard67a74992001-02-27 02:09:16 +0000748 SERVER_START_REQ( set_console_mode )
Alexandre Julliard9c2370b2000-08-30 00:00:48 +0000749 {
Alexandre Julliard9c2370b2000-08-30 00:00:48 +0000750 req->handle = hcon;
751 req->mode = mode;
Alexandre Julliard67a74992001-02-27 02:09:16 +0000752 ret = !SERVER_CALL_ERR();
Alexandre Julliard9c2370b2000-08-30 00:00:48 +0000753 }
754 SERVER_END_REQ;
755 return ret;
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000756}
757
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000758
Ulrich Czekalla637e2002000-05-30 20:06:08 +0000759/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +0000760 * SetConsoleOutputCP [KERNEL32.@] Set the output codepage used by the console
Ulrich Czekalla637e2002000-05-30 20:06:08 +0000761 *
762 * PARAMS
763 * cp [I] code page to set
764 *
765 * RETURNS
766 * Success: TRUE
767 * Failure: FALSE
768 */
769BOOL WINAPI SetConsoleOutputCP( UINT cp )
770{
771 FIXME("stub\n");
772 return TRUE;
773}
774
775
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000776/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000777 * GetConsoleTitleA (KERNEL32.@)
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000778 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000779DWORD WINAPI GetConsoleTitleA(LPSTR title,DWORD size)
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000780{
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000781 DWORD ret = 0;
Alexandre Julliarda3960291999-02-26 11:11:13 +0000782 HANDLE hcon;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000783
Alexandre Julliarda3960291999-02-26 11:11:13 +0000784 if ((hcon = CreateFileA( "CONOUT$", GENERIC_READ, 0, NULL,
785 OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000786 return 0;
Alexandre Julliard67a74992001-02-27 02:09:16 +0000787 SERVER_START_VAR_REQ( get_console_info, REQUEST_MAX_VAR_SIZE )
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000788 {
Alexandre Julliard92643002000-08-31 01:59:51 +0000789 req->handle = hcon;
Alexandre Julliard67a74992001-02-27 02:09:16 +0000790 if (!SERVER_CALL_ERR())
Alexandre Julliard92643002000-08-31 01:59:51 +0000791 {
792 ret = server_data_size(req);
793 size = min( size-1, ret );
794 memcpy( title, server_data_ptr(req), size );
795 title[size] = 0;
796 }
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000797 }
Alexandre Julliard67a74992001-02-27 02:09:16 +0000798 SERVER_END_VAR_REQ;
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000799 CloseHandle( hcon );
800 return ret;
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000801}
802
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000803
804/******************************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000805 * GetConsoleTitleW [KERNEL32.@] Retrieves title string for console
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000806 *
807 * PARAMS
808 * title [O] Address of buffer for title
809 * size [I] Size of buffer
810 *
811 * RETURNS
812 * Success: Length of string copied
813 * Failure: 0
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000814 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000815DWORD WINAPI GetConsoleTitleW( LPWSTR title, DWORD size )
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000816{
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000817 char *tmp;
818 DWORD ret;
819
Alexandre Julliard24a62ab2000-11-28 22:40:56 +0000820 if (!(tmp = HeapAlloc( GetProcessHeap(), 0, size*sizeof(WCHAR) ))) return 0;
821 GetConsoleTitleA( tmp, size*sizeof(WCHAR) );
822 ret = MultiByteToWideChar( CP_ACP, 0, tmp, -1, title, size );
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000823 HeapFree( GetProcessHeap(), 0, tmp );
824 return ret;
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000825}
826
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000827
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000828/***********************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +0000829 * WriteConsoleA (KERNEL32.@)
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000830 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000831BOOL WINAPI WriteConsoleA( HANDLE hConsoleOutput,
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000832 LPCVOID lpBuffer,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000833 DWORD nNumberOfCharsToWrite,
834 LPDWORD lpNumberOfCharsWritten,
835 LPVOID lpReserved )
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000836{
Alexandre Julliard03468f71998-02-15 19:40:49 +0000837 /* FIXME: should I check if this is a console handle? */
838 return WriteFile(hConsoleOutput, lpBuffer, nNumberOfCharsToWrite,
839 lpNumberOfCharsWritten, NULL);
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000840}
841
Alexandre Julliard46ea8b31998-05-03 19:01:20 +0000842
Marcus Meissner8bc54b61998-12-14 14:48:09 +0000843#define CADD(c) \
844 if (bufused==curbufsize-1) \
845 buffer = HeapReAlloc(GetProcessHeap(),0,buffer,(curbufsize+=100));\
846 buffer[bufused++]=c;
847#define SADD(s) { char *x=s;while (*x) {CADD(*x);x++;}}
848
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000849/***********************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +0000850 * WriteConsoleOutputA (KERNEL32.@)
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000851 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000852BOOL WINAPI WriteConsoleOutputA( HANDLE hConsoleOutput,
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000853 LPCHAR_INFO lpBuffer,
854 COORD dwBufferSize,
855 COORD dwBufferCoord,
856 LPSMALL_RECT lpWriteRegion)
857{
Marcus Meissnerb02ffc71998-10-11 10:49:46 +0000858 int i,j,off=0,lastattr=-1;
Guy Albertelli749a2c61999-09-04 11:11:02 +0000859 int offbase;
Marcus Meissner8bc54b61998-12-14 14:48:09 +0000860 char sbuf[20],*buffer=NULL;
861 int bufused=0,curbufsize = 100;
Marcus Meissnerb02ffc71998-10-11 10:49:46 +0000862 DWORD res;
Guy Albertelli749a2c61999-09-04 11:11:02 +0000863 CONSOLE_SCREEN_BUFFER_INFO csbi;
Marcus Meissner537772a1998-12-09 16:37:04 +0000864 const int colormap[8] = {
Marcus Meissnerb02ffc71998-10-11 10:49:46 +0000865 0,4,2,6,
866 1,5,3,7,
867 };
Alexandre Julliard62a8b431999-01-19 17:48:23 +0000868 CONSOLE_make_complex(hConsoleOutput);
Guy Albertelli749a2c61999-09-04 11:11:02 +0000869 buffer = HeapAlloc(GetProcessHeap(),0,curbufsize);
Alexandre Julliardf818d422000-05-03 17:48:21 +0000870 offbase = (dwBufferCoord.Y - 1) * dwBufferSize.X +
871 (dwBufferCoord.X - lpWriteRegion->Left);
Marcus Meissnerb02ffc71998-10-11 10:49:46 +0000872
Guy Albertelli749a2c61999-09-04 11:11:02 +0000873 TRACE("orig rect top = %d, bottom=%d, left=%d, right=%d\n",
Marcus Meissnerb02ffc71998-10-11 10:49:46 +0000874 lpWriteRegion->Top,
875 lpWriteRegion->Bottom,
876 lpWriteRegion->Left,
877 lpWriteRegion->Right
878 );
879
Guy Albertelli749a2c61999-09-04 11:11:02 +0000880 GetConsoleScreenBufferInfo(hConsoleOutput, &csbi);
Marcus Meissner9934a8d2000-02-03 01:03:23 +0000881 sprintf(sbuf,"%c7",27);SADD(sbuf);
Guy Albertelli749a2c61999-09-04 11:11:02 +0000882
883 /* Step 1. Make (Bottom,Right) offset of intersection with
884 Screen Buffer */
Alexandre Julliardf818d422000-05-03 17:48:21 +0000885 lpWriteRegion->Bottom = min(lpWriteRegion->Bottom, csbi.dwSize.Y-1) -
Guy Albertelli749a2c61999-09-04 11:11:02 +0000886 lpWriteRegion->Top;
Alexandre Julliardf818d422000-05-03 17:48:21 +0000887 lpWriteRegion->Right = min(lpWriteRegion->Right, csbi.dwSize.X-1) -
Guy Albertelli749a2c61999-09-04 11:11:02 +0000888 lpWriteRegion->Left;
889
890 /* Step 2. If either offset is negative, then no action
891 should be performed. (Implies that requested rectangle is
892 outside the current screen buffer rectangle.) */
893 if ((lpWriteRegion->Bottom < 0) ||
894 (lpWriteRegion->Right < 0)) {
895 /* readjust (Bottom Right) for rectangle */
896 lpWriteRegion->Bottom += lpWriteRegion->Top;
897 lpWriteRegion->Right += lpWriteRegion->Left;
898
899 TRACE("invisible rect top = %d, bottom=%d, left=%d, right=%d\n",
900 lpWriteRegion->Top,
901 lpWriteRegion->Bottom,
902 lpWriteRegion->Left,
903 lpWriteRegion->Right
904 );
905
906 HeapFree(GetProcessHeap(),0,buffer);
907 return TRUE;
908 }
909
910 /* Step 3. Intersect with source rectangle */
Alexandre Julliardf818d422000-05-03 17:48:21 +0000911 lpWriteRegion->Bottom = lpWriteRegion->Top - dwBufferCoord.Y +
912 min(lpWriteRegion->Bottom + dwBufferCoord.Y, dwBufferSize.Y-1);
913 lpWriteRegion->Right = lpWriteRegion->Left - dwBufferCoord.X +
914 min(lpWriteRegion->Right + dwBufferCoord.X, dwBufferSize.X-1);
Guy Albertelli749a2c61999-09-04 11:11:02 +0000915
916 TRACE("clipped rect top = %d, bottom=%d, left=%d,right=%d\n",
917 lpWriteRegion->Top,
918 lpWriteRegion->Bottom,
919 lpWriteRegion->Left,
920 lpWriteRegion->Right
921 );
922
923 /* Validate above computations made sense, if not then issue
924 error and fudge to single character rectangle */
925 if ((lpWriteRegion->Bottom < lpWriteRegion->Top) ||
926 (lpWriteRegion->Right < lpWriteRegion->Left)) {
927 ERR("Invalid clipped rectangle top = %d, bottom=%d, left=%d,right=%d\n",
928 lpWriteRegion->Top,
929 lpWriteRegion->Bottom,
930 lpWriteRegion->Left,
931 lpWriteRegion->Right
932 );
933 lpWriteRegion->Bottom = lpWriteRegion->Top;
934 lpWriteRegion->Right = lpWriteRegion->Left;
935 }
936
937 /* Now do the real processing and move the characters */
Marcus Meissnerb02ffc71998-10-11 10:49:46 +0000938 for (i=lpWriteRegion->Top;i<=lpWriteRegion->Bottom;i++) {
Alexandre Julliardf818d422000-05-03 17:48:21 +0000939 offbase += dwBufferSize.X;
Marcus Meissner8bc54b61998-12-14 14:48:09 +0000940 sprintf(sbuf,"%c[%d;%dH",27,i+1,lpWriteRegion->Left+1);
941 SADD(sbuf);
942 for (j=lpWriteRegion->Left;j<=lpWriteRegion->Right;j++) {
Guy Albertelli749a2c61999-09-04 11:11:02 +0000943 off = j + offbase;
Marcus Meissner8bc54b61998-12-14 14:48:09 +0000944 if (lastattr!=lpBuffer[off].Attributes) {
Marcus Meissnerb02ffc71998-10-11 10:49:46 +0000945 lastattr = lpBuffer[off].Attributes;
Marcus Meissner8bc54b61998-12-14 14:48:09 +0000946 sprintf(sbuf,"%c[0;%s3%d;4%dm",
Marcus Meissner537772a1998-12-09 16:37:04 +0000947 27,
948 (lastattr & FOREGROUND_INTENSITY)?"1;":"",
949 colormap[lastattr&7],
950 colormap[(lastattr&0x70)>>4]
951 );
952 /* FIXME: BACKGROUND_INTENSITY */
Marcus Meissner8bc54b61998-12-14 14:48:09 +0000953 SADD(sbuf);
954 }
955 CADD(lpBuffer[off].Char.AsciiChar);
Marcus Meissnerb02ffc71998-10-11 10:49:46 +0000956 }
Marcus Meissnerb02ffc71998-10-11 10:49:46 +0000957 }
Marcus Meissner9934a8d2000-02-03 01:03:23 +0000958 sprintf(sbuf,"%c[0m%c8",27,27);SADD(sbuf);
Marcus Meissner8bc54b61998-12-14 14:48:09 +0000959 WriteFile(hConsoleOutput,buffer,bufused,&res,NULL);
960 HeapFree(GetProcessHeap(),0,buffer);
Marcus Meissnerb02ffc71998-10-11 10:49:46 +0000961 return TRUE;
Alexandre Julliard60ce85c1998-02-01 18:33:27 +0000962}
963
964/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000965 * WriteConsoleOutputW (KERNEL32.@)
Eric Pouechc32169c2000-06-24 17:54:07 +0000966 */
967BOOL WINAPI WriteConsoleOutputW( HANDLE hConsoleOutput,
968 LPCHAR_INFO lpBuffer,
969 COORD dwBufferSize,
970 COORD dwBufferCoord,
971 LPSMALL_RECT lpWriteRegion)
972{
973 FIXME("(%d,%p,%dx%d,%dx%d,%p): stub\n", hConsoleOutput, lpBuffer,
974 dwBufferSize.X,dwBufferSize.Y,dwBufferCoord.X,dwBufferCoord.Y,lpWriteRegion);
975
976 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
977 return FALSE;
978}
979
980/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +0000981 * WriteConsoleW (KERNEL32.@)
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000982 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000983BOOL WINAPI WriteConsoleW( HANDLE hConsoleOutput,
Alexandre Julliard44ed71f1997-12-21 19:17:50 +0000984 LPCVOID lpBuffer,
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000985 DWORD nNumberOfCharsToWrite,
986 LPDWORD lpNumberOfCharsWritten,
987 LPVOID lpReserved )
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000988{
Alexandre Julliarda3960291999-02-26 11:11:13 +0000989 BOOL ret;
Hidenori Takeshimae2905ea2000-03-26 14:43:22 +0000990 LPSTR xstring;
991 DWORD n;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000992
Hidenori Takeshimae2905ea2000-03-26 14:43:22 +0000993 n = WideCharToMultiByte(CP_ACP,0,lpBuffer,nNumberOfCharsToWrite,NULL,0,NULL,NULL);
994 xstring=HeapAlloc( GetProcessHeap(), 0, n );
995
996 n = WideCharToMultiByte(CP_ACP,0,lpBuffer,nNumberOfCharsToWrite,xstring,n,NULL,NULL);
Alexandre Julliard03468f71998-02-15 19:40:49 +0000997
998 /* FIXME: should I check if this is a console handle? */
Hidenori Takeshimae2905ea2000-03-26 14:43:22 +0000999 ret= WriteFile(hConsoleOutput, xstring, n,
Alexandre Julliard03468f71998-02-15 19:40:49 +00001000 lpNumberOfCharsWritten, NULL);
Hidenori Takeshimae2905ea2000-03-26 14:43:22 +00001001 /* FIXME: lpNumberOfCharsWritten should be converted to numofchars in UNICODE */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001002 HeapFree( GetProcessHeap(), 0, xstring );
1003 return ret;
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001004}
1005
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001006
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001007/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +00001008 * ReadConsoleA (KERNEL32.@)
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001009 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001010BOOL WINAPI ReadConsoleA( HANDLE hConsoleInput,
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001011 LPVOID lpBuffer,
1012 DWORD nNumberOfCharsToRead,
1013 LPDWORD lpNumberOfCharsRead,
1014 LPVOID lpReserved )
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001015{
Alexandre Julliard908464d2000-11-01 03:11:12 +00001016 DWORD charsread = 0;
Marcus Meissner537772a1998-12-09 16:37:04 +00001017 LPSTR xbuf = (LPSTR)lpBuffer;
Alexandre Julliard03468f71998-02-15 19:40:49 +00001018
Alexandre Julliard15657091999-05-23 10:25:25 +00001019 TRACE("(%d,%p,%ld,%p,%p)\n",
Marcus Meissner537772a1998-12-09 16:37:04 +00001020 hConsoleInput,lpBuffer,nNumberOfCharsToRead,
1021 lpNumberOfCharsRead,lpReserved
1022 );
Marcus Meissnera2ca7b91999-02-05 09:32:39 +00001023
1024 CONSOLE_get_input(hConsoleInput,FALSE);
1025
Alexandre Julliard638f1691999-01-17 16:32:32 +00001026 /* FIXME: should we read at least 1 char? The SDK does not say */
Marcus Meissnera2ca7b91999-02-05 09:32:39 +00001027 while (charsread<nNumberOfCharsToRead)
1028 {
Alexandre Julliard92643002000-08-31 01:59:51 +00001029 INPUT_RECORD ir;
1030 DWORD count;
1031 if (!read_console_input( hConsoleInput, &ir, 1, &count, TRUE )) return FALSE;
1032 if (!count) break;
1033 if (ir.EventType != KEY_EVENT) continue;
1034 if (!ir.Event.KeyEvent.bKeyDown) continue;
1035 *xbuf++ = ir.Event.KeyEvent.uChar.AsciiChar;
1036 charsread++;
Marcus Meissner537772a1998-12-09 16:37:04 +00001037 }
Marcus Meissner537772a1998-12-09 16:37:04 +00001038 if (lpNumberOfCharsRead)
1039 *lpNumberOfCharsRead = charsread;
Marcus Meissner537772a1998-12-09 16:37:04 +00001040 return TRUE;
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001041}
1042
1043/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +00001044 * ReadConsoleW (KERNEL32.@)
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001045 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001046BOOL WINAPI ReadConsoleW( HANDLE hConsoleInput,
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001047 LPVOID lpBuffer,
1048 DWORD nNumberOfCharsToRead,
1049 LPDWORD lpNumberOfCharsRead,
1050 LPVOID lpReserved )
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001051{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001052 BOOL ret;
Marcus Meissner537772a1998-12-09 16:37:04 +00001053 LPSTR buf = (LPSTR)HeapAlloc(GetProcessHeap(), 0, nNumberOfCharsToRead);
Alexandre Julliard03468f71998-02-15 19:40:49 +00001054
Alexandre Julliarda3960291999-02-26 11:11:13 +00001055 ret = ReadConsoleA(
Marcus Meissner537772a1998-12-09 16:37:04 +00001056 hConsoleInput,
1057 buf,
1058 nNumberOfCharsToRead,
1059 lpNumberOfCharsRead,
1060 lpReserved
1061 );
1062 if (ret)
Alexandre Julliard24a62ab2000-11-28 22:40:56 +00001063 MultiByteToWideChar( CP_ACP, 0, buf, -1, lpBuffer, nNumberOfCharsToRead );
1064
Marcus Meissner537772a1998-12-09 16:37:04 +00001065 HeapFree( GetProcessHeap(), 0, buf );
1066 return ret;
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001067}
1068
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001069
1070/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001071 * ReadConsoleInputA [KERNEL32.@] Reads data from a console
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001072 *
1073 * PARAMS
1074 * hConsoleInput [I] Handle to console input buffer
1075 * lpBuffer [O] Address of buffer for read data
1076 * nLength [I] Number of records to read
1077 * lpNumberOfEventsRead [O] Address of number of records read
1078 *
1079 * RETURNS
1080 * Success: TRUE
1081 * Failure: FALSE
1082 */
Alexandre Julliardebe29ef1999-06-26 08:43:26 +00001083BOOL WINAPI ReadConsoleInputA(HANDLE hConsoleInput, LPINPUT_RECORD lpBuffer,
1084 DWORD nLength, LPDWORD lpNumberOfEventsRead)
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001085{
Alexandre Julliard92643002000-08-31 01:59:51 +00001086 if (!nLength)
1087 {
1088 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = 0;
1089 return TRUE;
1090 }
Alexandre Julliard638f1691999-01-17 16:32:32 +00001091
Alexandre Julliard4b461121999-01-31 19:04:30 +00001092 /* loop until we get at least one event */
1093 for (;;)
1094 {
Alexandre Julliard92643002000-08-31 01:59:51 +00001095 DWORD count;
1096 BOOL ret = read_console_input( hConsoleInput, lpBuffer, nLength, &count, TRUE );
1097
1098 if (!ret) return FALSE;
1099 if (count)
Alexandre Julliardebe29ef1999-06-26 08:43:26 +00001100 {
Alexandre Julliard92643002000-08-31 01:59:51 +00001101 if (lpNumberOfEventsRead) *lpNumberOfEventsRead = count;
Alexandre Julliardebe29ef1999-06-26 08:43:26 +00001102 return TRUE;
1103 }
Alexandre Julliard92643002000-08-31 01:59:51 +00001104 CONSOLE_get_input(hConsoleInput,TRUE);
Marcus Meissnera2ca7b91999-02-05 09:32:39 +00001105 /*WaitForSingleObject( hConsoleInput, INFINITE32 );*/
Marcus Meissner537772a1998-12-09 16:37:04 +00001106 }
Marcus Meissner537772a1998-12-09 16:37:04 +00001107}
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001108
Alexandre Julliard4b461121999-01-31 19:04:30 +00001109
1110/***********************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001111 * ReadConsoleInputW (KERNEL32.@)
Alexandre Julliard4b461121999-01-31 19:04:30 +00001112 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001113BOOL WINAPI ReadConsoleInputW( HANDLE handle, LPINPUT_RECORD buffer,
Alexandre Julliard4b461121999-01-31 19:04:30 +00001114 DWORD count, LPDWORD read )
1115{
1116 /* FIXME: Fix this if we get UNICODE input. */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001117 return ReadConsoleInputA( handle, buffer, count, read );
Alexandre Julliard4b461121999-01-31 19:04:30 +00001118}
1119
1120
1121/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +00001122 * FlushConsoleInputBuffer (KERNEL32.@)
Alexandre Julliard4b461121999-01-31 19:04:30 +00001123 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001124BOOL WINAPI FlushConsoleInputBuffer( HANDLE handle )
Alexandre Julliard4b461121999-01-31 19:04:30 +00001125{
Alexandre Julliard92643002000-08-31 01:59:51 +00001126 return read_console_input( handle, NULL, 0, NULL, TRUE );
Alexandre Julliard4b461121999-01-31 19:04:30 +00001127}
1128
1129
1130/***********************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001131 * PeekConsoleInputA (KERNEL32.@)
Alexandre Julliard4b461121999-01-31 19:04:30 +00001132 *
1133 * Gets 'count' first events (or less) from input queue.
1134 *
1135 * Does not need a complex console.
1136 */
Alexandre Julliard92643002000-08-31 01:59:51 +00001137BOOL WINAPI PeekConsoleInputA( HANDLE handle, LPINPUT_RECORD buffer, DWORD count, LPDWORD read )
Alexandre Julliard4b461121999-01-31 19:04:30 +00001138{
Marcus Meissnera2ca7b91999-02-05 09:32:39 +00001139 CONSOLE_get_input(handle,FALSE);
Alexandre Julliard92643002000-08-31 01:59:51 +00001140 if (!count)
1141 {
1142 if (read) *read = 0;
1143 return TRUE;
1144 }
1145 return read_console_input( handle, buffer, count, read, FALSE );
Alexandre Julliard4b461121999-01-31 19:04:30 +00001146}
1147
1148
1149/***********************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001150 * PeekConsoleInputW (KERNEL32.@)
Alexandre Julliard4b461121999-01-31 19:04:30 +00001151 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001152BOOL WINAPI PeekConsoleInputW(HANDLE hConsoleInput,
Alexandre Julliard4b461121999-01-31 19:04:30 +00001153 LPINPUT_RECORD pirBuffer,
1154 DWORD cInRecords,
1155 LPDWORD lpcRead)
1156{
1157 /* FIXME: Hmm. Fix this if we get UNICODE input. */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001158 return PeekConsoleInputA(hConsoleInput,pirBuffer,cInRecords,lpcRead);
Alexandre Julliard4b461121999-01-31 19:04:30 +00001159}
1160
1161
1162/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001163 * WriteConsoleInputA [KERNEL32.@] Write data to a console input buffer
Alexandre Julliard4b461121999-01-31 19:04:30 +00001164 *
1165 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001166BOOL WINAPI WriteConsoleInputA( HANDLE handle, INPUT_RECORD *buffer,
Alexandre Julliardebe29ef1999-06-26 08:43:26 +00001167 DWORD count, LPDWORD written )
Alexandre Julliard4b461121999-01-31 19:04:30 +00001168{
Alexandre Julliard92643002000-08-31 01:59:51 +00001169 BOOL ret = TRUE;
Alexandre Julliard4b461121999-01-31 19:04:30 +00001170
Alexandre Julliardebe29ef1999-06-26 08:43:26 +00001171 if (written) *written = 0;
Alexandre Julliard92643002000-08-31 01:59:51 +00001172 while (count && ret)
Alexandre Julliardebe29ef1999-06-26 08:43:26 +00001173 {
Alexandre Julliard92643002000-08-31 01:59:51 +00001174 DWORD len = min( count, REQUEST_MAX_VAR_SIZE/sizeof(INPUT_RECORD) );
Alexandre Julliard67a74992001-02-27 02:09:16 +00001175 SERVER_START_VAR_REQ( write_console_input, len * sizeof(INPUT_RECORD) )
Alexandre Julliard92643002000-08-31 01:59:51 +00001176 {
Alexandre Julliard92643002000-08-31 01:59:51 +00001177 req->handle = handle;
1178 memcpy( server_data_ptr(req), buffer, len * sizeof(INPUT_RECORD) );
Alexandre Julliard67a74992001-02-27 02:09:16 +00001179 if ((ret = !SERVER_CALL_ERR()))
Alexandre Julliard92643002000-08-31 01:59:51 +00001180 {
1181 if (written) *written += req->written;
1182 count -= len;
1183 buffer += len;
1184 }
1185 }
Alexandre Julliard67a74992001-02-27 02:09:16 +00001186 SERVER_END_VAR_REQ;
Alexandre Julliardebe29ef1999-06-26 08:43:26 +00001187 }
Alexandre Julliard92643002000-08-31 01:59:51 +00001188 return ret;
Alexandre Julliard4b461121999-01-31 19:04:30 +00001189}
1190
Eric Pouechc32169c2000-06-24 17:54:07 +00001191/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001192 * WriteConsoleInputW [KERNEL32.@] Write data to a console input buffer
Eric Pouechc32169c2000-06-24 17:54:07 +00001193 *
1194 */
1195BOOL WINAPI WriteConsoleInputW( HANDLE handle, INPUT_RECORD *buffer,
1196 DWORD count, LPDWORD written )
1197{
1198 FIXME("(%d,%p,%ld,%p): stub!\n", handle, buffer, count, written);
1199
1200 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1201 return FALSE;
1202}
1203
Alexandre Julliard4b461121999-01-31 19:04:30 +00001204
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001205/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +00001206 * SetConsoleTitleA (KERNEL32.@)
Marcus Meissner537772a1998-12-09 16:37:04 +00001207 *
1208 * Sets the console title.
1209 *
1210 * We do not necessarily need to create a complex console for that,
1211 * but should remember the title and set it on creation of the latter.
1212 * (not fixed at this time).
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001213 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001214BOOL WINAPI SetConsoleTitleA(LPCSTR title)
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001215{
Alexandre Julliard92643002000-08-31 01:59:51 +00001216 size_t len = strlen(title);
Alexandre Julliarda3960291999-02-26 11:11:13 +00001217 HANDLE hcon;
Alexandre Julliard62a8b431999-01-19 17:48:23 +00001218 DWORD written;
Alexandre Julliard92643002000-08-31 01:59:51 +00001219 BOOL ret;
Alexandre Julliard62a8b431999-01-19 17:48:23 +00001220
Alexandre Julliarda3960291999-02-26 11:11:13 +00001221 if ((hcon = CreateFileA( "CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL,
1222 OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
Alexandre Julliard62a8b431999-01-19 17:48:23 +00001223 return FALSE;
Alexandre Julliard92643002000-08-31 01:59:51 +00001224
1225 len = min( len, REQUEST_MAX_VAR_SIZE );
Alexandre Julliard67a74992001-02-27 02:09:16 +00001226 SERVER_START_VAR_REQ( set_console_info, len )
Alexandre Julliard92643002000-08-31 01:59:51 +00001227 {
Alexandre Julliard92643002000-08-31 01:59:51 +00001228 req->handle = hcon;
1229 req->mask = SET_CONSOLE_INFO_TITLE;
1230 memcpy( server_data_ptr(req), title, len );
Alexandre Julliard67a74992001-02-27 02:09:16 +00001231 ret = !SERVER_CALL_ERR();
Alexandre Julliard92643002000-08-31 01:59:51 +00001232 }
Alexandre Julliard67a74992001-02-27 02:09:16 +00001233 SERVER_END_VAR_REQ;
Alexandre Julliard92643002000-08-31 01:59:51 +00001234
1235 if (ret && CONSOLE_GetPid( hcon ))
Alexandre Julliard62a8b431999-01-19 17:48:23 +00001236 {
1237 /* only set title for complex console (own xterm) */
1238 WriteFile( hcon, "\033]2;", 4, &written, NULL );
1239 WriteFile( hcon, title, strlen(title), &written, NULL );
1240 WriteFile( hcon, "\a", 1, &written, NULL );
1241 }
Alexandre Julliard96c08d81999-02-28 13:27:56 +00001242 CloseHandle( hcon );
Alexandre Julliard92643002000-08-31 01:59:51 +00001243 return ret;
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001244}
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00001245
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001246
1247/******************************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +00001248 * SetConsoleTitleW [KERNEL32.@] Sets title bar string for console
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001249 *
1250 * PARAMS
1251 * title [I] Address of new title
1252 *
1253 * NOTES
1254 * This should not be calling the A version
1255 *
1256 * RETURNS
1257 * Success: TRUE
1258 * Failure: FALSE
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001259 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001260BOOL WINAPI SetConsoleTitleW( LPCWSTR title )
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001261{
Alexandre Julliarda3960291999-02-26 11:11:13 +00001262 BOOL ret;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001263
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00001264 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
Alexandre Julliarda3960291999-02-26 11:11:13 +00001265 ret = SetConsoleTitleA(titleA);
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +00001266 HeapFree( GetProcessHeap(), 0, titleA );
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001267 return ret;
Alexandre Julliardb1bac321996-12-15 19:45:59 +00001268}
Alexandre Julliarddf2673b1997-03-29 17:20:20 +00001269
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001270/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001271 * SetConsoleCursorPosition [KERNEL32.@]
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001272 * Sets the cursor position in console
1273 *
1274 * PARAMS
1275 * hConsoleOutput [I] Handle of console screen buffer
1276 * dwCursorPosition [I] New cursor position coordinates
1277 *
1278 * RETURNS STD
1279 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001280BOOL WINAPI SetConsoleCursorPosition( HANDLE hcon, COORD pos )
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001281{
Marcus Meissner537772a1998-12-09 16:37:04 +00001282 char xbuf[20];
1283 DWORD xlen;
Alexandre Julliard23946ad1997-06-16 17:43:53 +00001284
Marcus Meissner03f10f41999-01-26 10:08:36 +00001285 /* make console complex only if we change lines, not just in the line */
Alexandre Julliardf818d422000-05-03 17:48:21 +00001286 if (pos.Y)
Marcus Meissner03f10f41999-01-26 10:08:36 +00001287 CONSOLE_make_complex(hcon);
1288
Alexandre Julliardf818d422000-05-03 17:48:21 +00001289 TRACE("%d (%dx%d)\n", hcon, pos.X , pos.Y );
Marcus Meissner537772a1998-12-09 16:37:04 +00001290 /* x are columns, y rows */
Alexandre Julliardf818d422000-05-03 17:48:21 +00001291 if (pos.Y)
Marcus Meissner03f10f41999-01-26 10:08:36 +00001292 /* full screen cursor absolute positioning */
Alexandre Julliardf818d422000-05-03 17:48:21 +00001293 sprintf(xbuf,"%c[%d;%dH", 0x1B, pos.Y+1, pos.X+1);
Marcus Meissner03f10f41999-01-26 10:08:36 +00001294 else
1295 /* relative cursor positioning in line (\r to go to 0) */
Alexandre Julliardf818d422000-05-03 17:48:21 +00001296 sprintf(xbuf,"\r%c[%dC", 0x1B, pos.X);
Marcus Meissner537772a1998-12-09 16:37:04 +00001297 /* FIXME: store internal if we start using own console buffers */
1298 WriteFile(hcon,xbuf,strlen(xbuf),&xlen,NULL);
Marcus Meissner537772a1998-12-09 16:37:04 +00001299 return TRUE;
1300}
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001301
Alexandre Julliard23946ad1997-06-16 17:43:53 +00001302/***********************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +00001303 * GetNumberOfConsoleInputEvents (KERNEL32.@)
Alexandre Julliard23946ad1997-06-16 17:43:53 +00001304 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001305BOOL WINAPI GetNumberOfConsoleInputEvents(HANDLE hcon,LPDWORD nrofevents)
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001306{
Guy L. Albertelliaa9f8dc2000-10-31 00:59:22 +00001307 CONSOLE_get_input (hcon, FALSE);
1308
Alexandre Julliard92643002000-08-31 01:59:51 +00001309 return read_console_input( hcon, NULL, 0, nrofevents, FALSE );
Alexandre Julliard23946ad1997-06-16 17:43:53 +00001310}
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001311
1312/***********************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001313 * GetNumberOfConsoleMouseButtons (KERNEL32.@)
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001314 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001315BOOL WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons)
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001316{
Alexandre Julliard15657091999-05-23 10:25:25 +00001317 FIXME("(%p): stub\n", nrofbuttons);
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001318 *nrofbuttons = 2;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001319 return TRUE;
1320}
1321
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001322/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001323 * GetConsoleCursorInfo [KERNEL32.@] Gets size and visibility of console
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001324 *
1325 * PARAMS
1326 * hcon [I] Handle to console screen buffer
1327 * cinfo [O] Address of cursor information
1328 *
1329 * RETURNS
1330 * Success: TRUE
1331 * Failure: FALSE
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001332 */
Alexandre Julliardebe29ef1999-06-26 08:43:26 +00001333BOOL WINAPI GetConsoleCursorInfo( HANDLE hcon, LPCONSOLE_CURSOR_INFO cinfo )
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001334{
Alexandre Julliard92643002000-08-31 01:59:51 +00001335 BOOL ret;
1336
Alexandre Julliard67a74992001-02-27 02:09:16 +00001337 SERVER_START_REQ( get_console_info )
Alexandre Julliard62a8b431999-01-19 17:48:23 +00001338 {
Alexandre Julliard92643002000-08-31 01:59:51 +00001339 req->handle = hcon;
Alexandre Julliard67a74992001-02-27 02:09:16 +00001340 ret = !SERVER_CALL_ERR();
Alexandre Julliard92643002000-08-31 01:59:51 +00001341 if (ret && cinfo)
1342 {
1343 cinfo->dwSize = req->cursor_size;
1344 cinfo->bVisible = req->cursor_visible;
1345 }
Marcus Meissner537772a1998-12-09 16:37:04 +00001346 }
Alexandre Julliard92643002000-08-31 01:59:51 +00001347 SERVER_END_REQ;
1348 return ret;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001349}
1350
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001351
1352/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001353 * SetConsoleCursorInfo [KERNEL32.@] Sets size and visibility of cursor
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001354 *
1355 * RETURNS
1356 * Success: TRUE
1357 * Failure: FALSE
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001358 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001359BOOL WINAPI SetConsoleCursorInfo(
1360 HANDLE hcon, /* [in] Handle to console screen buffer */
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001361 LPCONSOLE_CURSOR_INFO cinfo) /* [in] Address of cursor information */
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001362{
Marcus Meissner537772a1998-12-09 16:37:04 +00001363 char buf[8];
1364 DWORD xlen;
Alexandre Julliard92643002000-08-31 01:59:51 +00001365 BOOL ret;
Marcus Meissner537772a1998-12-09 16:37:04 +00001366
Alexandre Julliard62a8b431999-01-19 17:48:23 +00001367 CONSOLE_make_complex(hcon);
1368 sprintf(buf,"\033[?25%c",cinfo->bVisible?'h':'l');
Marcus Meissner537772a1998-12-09 16:37:04 +00001369 WriteFile(hcon,buf,strlen(buf),&xlen,NULL);
Alexandre Julliard62a8b431999-01-19 17:48:23 +00001370
Alexandre Julliard67a74992001-02-27 02:09:16 +00001371 SERVER_START_REQ( set_console_info )
Alexandre Julliard92643002000-08-31 01:59:51 +00001372 {
Alexandre Julliard92643002000-08-31 01:59:51 +00001373 req->handle = hcon;
1374 req->cursor_size = cinfo->dwSize;
1375 req->cursor_visible = cinfo->bVisible;
1376 req->mask = SET_CONSOLE_INFO_CURSOR;
Alexandre Julliard67a74992001-02-27 02:09:16 +00001377 ret = !SERVER_CALL_ERR();
Alexandre Julliard92643002000-08-31 01:59:51 +00001378 }
1379 SERVER_END_REQ;
1380 return ret;
Alexandre Julliard44ed71f1997-12-21 19:17:50 +00001381}
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001382
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001383
1384/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001385 * SetConsoleWindowInfo [KERNEL32.@] Sets size and position of console
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001386 *
1387 * RETURNS
1388 * Success: TRUE
1389 * Failure: FALSE
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001390 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001391BOOL WINAPI SetConsoleWindowInfo(
1392 HANDLE hcon, /* [in] Handle to console screen buffer */
1393 BOOL bAbsolute, /* [in] Coordinate type flag */
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001394 LPSMALL_RECT window) /* [in] Address of new window rectangle */
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001395{
Alexandre Julliard15657091999-05-23 10:25:25 +00001396 FIXME("(%x,%d,%p): stub\n", hcon, bAbsolute, window);
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001397 return TRUE;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001398}
1399
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001400
1401/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001402 * SetConsoleTextAttribute [KERNEL32.@] Sets colors for text
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001403 *
1404 * Sets the foreground and background color attributes of characters
1405 * written to the screen buffer.
1406 *
1407 * RETURNS
1408 * Success: TRUE
1409 * Failure: FALSE
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001410 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001411BOOL WINAPI SetConsoleTextAttribute(HANDLE hConsoleOutput,WORD wAttr)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001412{
Marcus Meissner537772a1998-12-09 16:37:04 +00001413 const int colormap[8] = {
1414 0,4,2,6,
1415 1,5,3,7,
1416 };
1417 DWORD xlen;
1418 char buffer[20];
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001419
Alexandre Julliard15657091999-05-23 10:25:25 +00001420 TRACE("(%d,%d)\n",hConsoleOutput,wAttr);
Marcus Meissner537772a1998-12-09 16:37:04 +00001421 sprintf(buffer,"%c[0;%s3%d;4%dm",
1422 27,
1423 (wAttr & FOREGROUND_INTENSITY)?"1;":"",
1424 colormap[wAttr&7],
1425 colormap[(wAttr&0x70)>>4]
1426 );
1427 WriteFile(hConsoleOutput,buffer,strlen(buffer),&xlen,NULL);
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001428 return TRUE;
1429}
1430
1431
1432/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001433 * SetConsoleScreenBufferSize [KERNEL32.@] Changes size of console
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001434 *
1435 * PARAMS
1436 * hConsoleOutput [I] Handle to console screen buffer
1437 * dwSize [I] New size in character rows and cols
1438 *
1439 * RETURNS
1440 * Success: TRUE
1441 * Failure: FALSE
1442 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001443BOOL WINAPI SetConsoleScreenBufferSize( HANDLE hConsoleOutput,
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001444 COORD dwSize )
1445{
Alexandre Julliardf818d422000-05-03 17:48:21 +00001446 FIXME("(%d,%dx%d): stub\n",hConsoleOutput,dwSize.X,dwSize.Y);
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001447 return TRUE;
1448}
1449
1450
1451/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001452 * FillConsoleOutputCharacterA [KERNEL32.@]
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001453 *
1454 * PARAMS
1455 * hConsoleOutput [I] Handle to screen buffer
1456 * cCharacter [I] Character to write
1457 * nLength [I] Number of cells to write to
1458 * dwCoord [I] Coords of first cell
1459 * lpNumCharsWritten [O] Pointer to number of cells written
1460 *
1461 * RETURNS
1462 * Success: TRUE
1463 * Failure: FALSE
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001464 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001465BOOL WINAPI FillConsoleOutputCharacterA(
1466 HANDLE hConsoleOutput,
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001467 BYTE cCharacter,
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001468 DWORD nLength,
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001469 COORD dwCoord,
1470 LPDWORD lpNumCharsWritten)
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001471{
Alexandre Julliard908464d2000-11-01 03:11:12 +00001472 DWORD count;
Marcus Meissner537772a1998-12-09 16:37:04 +00001473 DWORD xlen;
1474
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001475 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
1476 for(count=0;count<nLength;count++)
Marcus Meissner537772a1998-12-09 16:37:04 +00001477 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001478 *lpNumCharsWritten = nLength;
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001479 return TRUE;
1480}
1481
1482
1483/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001484 * FillConsoleOutputCharacterW [KERNEL32.@] Writes characters to console
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001485 *
1486 * PARAMS
1487 * hConsoleOutput [I] Handle to screen buffer
1488 * cCharacter [I] Character to write
1489 * nLength [I] Number of cells to write to
1490 * dwCoord [I] Coords of first cell
1491 * lpNumCharsWritten [O] Pointer to number of cells written
1492 *
1493 * RETURNS
1494 * Success: TRUE
1495 * Failure: FALSE
1496 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001497BOOL WINAPI FillConsoleOutputCharacterW(HANDLE hConsoleOutput,
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001498 WCHAR cCharacter,
1499 DWORD nLength,
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001500 COORD dwCoord,
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001501 LPDWORD lpNumCharsWritten)
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001502{
Alexandre Julliard908464d2000-11-01 03:11:12 +00001503 DWORD count;
Marcus Meissner537772a1998-12-09 16:37:04 +00001504 DWORD xlen;
1505
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001506 SetConsoleCursorPosition(hConsoleOutput,dwCoord);
Marcus Meissner537772a1998-12-09 16:37:04 +00001507 /* FIXME: not quite correct ... but the lower part of UNICODE char comes
1508 * first
1509 */
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001510 for(count=0;count<nLength;count++)
Marcus Meissner537772a1998-12-09 16:37:04 +00001511 WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL);
Alexandre Julliarddadf78f1998-05-17 17:13:43 +00001512 *lpNumCharsWritten = nLength;
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001513 return TRUE;
1514}
1515
1516
1517/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001518 * FillConsoleOutputAttribute [KERNEL32.@] Sets attributes for console
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001519 *
1520 * PARAMS
1521 * hConsoleOutput [I] Handle to screen buffer
1522 * wAttribute [I] Color attribute to write
1523 * nLength [I] Number of cells to write to
1524 * dwCoord [I] Coords of first cell
1525 * lpNumAttrsWritten [O] Pointer to number of cells written
1526 *
1527 * RETURNS
1528 * Success: TRUE
1529 * Failure: FALSE
1530 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001531BOOL WINAPI FillConsoleOutputAttribute( HANDLE hConsoleOutput,
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001532 WORD wAttribute, DWORD nLength, COORD dwCoord,
1533 LPDWORD lpNumAttrsWritten)
1534{
Alexandre Julliard15657091999-05-23 10:25:25 +00001535 FIXME("(%d,%d,%ld,%dx%d,%p): stub\n", hConsoleOutput,
Alexandre Julliardf818d422000-05-03 17:48:21 +00001536 wAttribute,nLength,dwCoord.X,dwCoord.Y,lpNumAttrsWritten);
Alexandre Julliard46ea8b31998-05-03 19:01:20 +00001537 *lpNumAttrsWritten = nLength;
1538 return TRUE;
Alexandre Julliarda69b88b1998-03-15 20:29:56 +00001539}
1540
Alexandre Julliarda845b881998-06-01 10:44:35 +00001541/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001542 * ReadConsoleOutputCharacterA [KERNEL32.@]
Alexandre Julliarda845b881998-06-01 10:44:35 +00001543 *
1544 * BUGS
1545 * Unimplemented
1546 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001547BOOL WINAPI ReadConsoleOutputCharacterA(HANDLE hConsoleOutput,
Alexandre Julliarda845b881998-06-01 10:44:35 +00001548 LPSTR lpstr, DWORD dword, COORD coord, LPDWORD lpdword)
1549{
Alexandre Julliard15657091999-05-23 10:25:25 +00001550 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,lpstr,
Alexandre Julliardf818d422000-05-03 17:48:21 +00001551 dword,coord.X,coord.Y,lpdword);
Alexandre Julliarda845b881998-06-01 10:44:35 +00001552 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1553 return FALSE;
1554}
Alexandre Julliard642d3131998-07-12 19:29:36 +00001555
Eric Pouechc32169c2000-06-24 17:54:07 +00001556/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001557 * ReadConsoleOutputCharacterW [KERNEL32.@]
Eric Pouechc32169c2000-06-24 17:54:07 +00001558 *
1559 * BUGS
1560 * Unimplemented
1561 */
1562BOOL WINAPI ReadConsoleOutputCharacterW(HANDLE hConsoleOutput,
1563 LPWSTR lpstr, DWORD dword, COORD coord, LPDWORD lpdword)
1564{
1565 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,lpstr,
1566 dword,coord.X,coord.Y,lpdword);
1567 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1568 return FALSE;
1569}
1570
Alexandre Julliard642d3131998-07-12 19:29:36 +00001571
1572/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001573 * ScrollConsoleScreenBufferA [KERNEL32.@]
Alexandre Julliard642d3131998-07-12 19:29:36 +00001574 *
1575 * BUGS
1576 * Unimplemented
1577 */
Patrik Stridvall54fe8382000-04-06 20:21:16 +00001578BOOL WINAPI ScrollConsoleScreenBufferA( HANDLE hConsoleOutput,
Alexandre Julliard642d3131998-07-12 19:29:36 +00001579 LPSMALL_RECT lpScrollRect, LPSMALL_RECT lpClipRect,
1580 COORD dwDestOrigin, LPCHAR_INFO lpFill)
1581{
Alexandre Julliard15657091999-05-23 10:25:25 +00001582 FIXME("(%d,%p,%p,%dx%d,%p): stub\n", hConsoleOutput,lpScrollRect,
Alexandre Julliardf818d422000-05-03 17:48:21 +00001583 lpClipRect,dwDestOrigin.X,dwDestOrigin.Y,lpFill);
Alexandre Julliard642d3131998-07-12 19:29:36 +00001584 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1585 return FALSE;
1586}
Eric Pouechc32169c2000-06-24 17:54:07 +00001587
1588/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001589 * ScrollConsoleScreenBufferW [KERNEL32.@]
Eric Pouechc32169c2000-06-24 17:54:07 +00001590 *
1591 * BUGS
1592 * Unimplemented
1593 */
1594BOOL WINAPI ScrollConsoleScreenBufferW( HANDLE hConsoleOutput,
1595 LPSMALL_RECT lpScrollRect, LPSMALL_RECT lpClipRect,
1596 COORD dwDestOrigin, LPCHAR_INFO lpFill)
1597{
1598 FIXME("(%d,%p,%p,%dx%d,%p): stub\n", hConsoleOutput,lpScrollRect,
1599 lpClipRect,dwDestOrigin.X,dwDestOrigin.Y,lpFill);
1600 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1601 return FALSE;
1602}
1603
1604/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001605 * ReadConsoleOutputA [KERNEL32.@]
Eric Pouechc32169c2000-06-24 17:54:07 +00001606 *
1607 * BUGS
1608 * Unimplemented
1609 */
1610BOOL WINAPI ReadConsoleOutputA( HANDLE hConsoleOutput,
1611 LPCHAR_INFO lpBuffer,
1612 COORD dwBufferSize,
1613 COORD dwBufferCoord,
1614 LPSMALL_RECT lpReadRegion )
1615{
1616 FIXME("(%d,%p,%dx%d,%dx%d,%p): stub\n", hConsoleOutput, lpBuffer,
1617 dwBufferSize.X, dwBufferSize.Y, dwBufferSize.X, dwBufferSize.Y,
1618 lpReadRegion);
1619
1620 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1621 return FALSE;
1622}
1623
1624/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001625 * ReadConsoleOutputW [KERNEL32.@]
Eric Pouechc32169c2000-06-24 17:54:07 +00001626 *
1627 * BUGS
1628 * Unimplemented
1629 */
1630BOOL WINAPI ReadConsoleOutputW( HANDLE hConsoleOutput,
1631 LPCHAR_INFO lpBuffer,
1632 COORD dwBufferSize,
1633 COORD dwBufferCoord,
1634 LPSMALL_RECT lpReadRegion )
1635{
1636 FIXME("(%d,%p,%dx%d,%dx%d,%p): stub\n", hConsoleOutput, lpBuffer,
1637 dwBufferSize.X, dwBufferSize.Y, dwBufferSize.X, dwBufferSize.Y,
1638 lpReadRegion);
1639
1640 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1641 return FALSE;
1642}
1643
1644/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001645 * ReadConsoleOutputAttribute [KERNEL32.@]
Eric Pouechc32169c2000-06-24 17:54:07 +00001646 *
1647 * BUGS
1648 * Unimplemented
1649 */
1650BOOL WINAPI ReadConsoleOutputAttribute( HANDLE hConsoleOutput,
1651 LPWORD lpAttribute,
1652 DWORD nLength,
1653 COORD dwReadCoord,
1654 LPDWORD lpNumberOfAttrsRead)
1655{
1656 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput, lpAttribute,
1657 nLength, dwReadCoord.X, dwReadCoord.Y, lpNumberOfAttrsRead);
1658
1659 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1660 return FALSE;
1661}
1662
1663/******************************************************************************
Patrik Stridvalld0a41772001-02-14 23:11:17 +00001664 * SetConsoleCP [KERNEL32.@]
Eric Pouechc32169c2000-06-24 17:54:07 +00001665 *
1666 * BUGS
1667 * Unimplemented
1668 */
1669BOOL WINAPI SetConsoleCP( UINT cp )
1670{
1671 FIXME("(%d): stub\n", cp);
1672
1673 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1674 return FALSE;
1675}
Chris Morganeca7f9f2000-08-18 23:03:22 +00001676
1677/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001678 * SetConsoleInputExeNameW [KERNEL32.@]
Chris Morganeca7f9f2000-08-18 23:03:22 +00001679 *
1680 * BUGS
1681 * Unimplemented
1682 */
1683BOOL WINAPI SetConsoleInputExeNameW( LPCWSTR name )
1684{
1685 FIXME("(%s): stub!\n", debugstr_w(name));
1686
1687 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1688 return TRUE;
1689}
1690
1691/******************************************************************************
Patrik Stridvalldae8de62001-06-13 20:13:18 +00001692 * SetConsoleInputExeNameA [KERNEL32.@]
Chris Morganeca7f9f2000-08-18 23:03:22 +00001693 *
1694 * BUGS
1695 * Unimplemented
1696 */
1697BOOL WINAPI SetConsoleInputExeNameA( LPCSTR name )
1698{
1699 FIXME("(%s): stub!\n", name);
1700
1701 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1702 return TRUE;
1703}
Michael Stefaniuc85d30862001-04-12 21:07:25 +00001704
1705/******************************************************************************
1706 * WriteConsoleOutputAttribute [KERNEL32.@] Sets attributes for some cells in
1707 * the console screen buffer
1708 *
1709 * PARAMS
1710 * hConsoleOutput [I] Handle to screen buffer
1711 * lpAttribute [I] Pointer to buffer with write attributes
1712 * nLength [I] Number of cells to write to
1713 * dwCoord [I] Coords of first cell
1714 * lpNumAttrsWritten [O] Pointer to number of cells written
1715 *
1716 * RETURNS
1717 * Success: TRUE
1718 * Failure: FALSE
1719 *
1720 * BUGS
1721 * Unimplemented
1722 */
1723BOOL WINAPI WriteConsoleOutputAttribute( HANDLE hConsoleOutput,
1724 CONST WORD *lpAttribute, DWORD nLength, COORD dwCoord,
1725 LPDWORD lpNumAttrsWritten)
1726{
1727 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,
1728 lpAttribute,nLength,dwCoord.X,dwCoord.Y,lpNumAttrsWritten);
1729 *lpNumAttrsWritten = nLength;
1730 return TRUE;
1731}
1732
1733/******************************************************************************
1734 * WriteConsoleOutputCharacterA [KERNEL32.@] Copies character to consecutive
1735 * cells in the console screen buffer
1736 *
1737 * PARAMS
1738 * hConsoleOutput [I] Handle to screen buffer
1739 * lpCharacter [I] Pointer to buffer with chars to write
1740 * nLength [I] Number of cells to write to
1741 * dwCoord [I] Coords of first cell
1742 * lpNumCharsWritten [O] Pointer to number of cells written
1743 *
1744 * BUGS
1745 * Unimplemented
1746 */
1747BOOL WINAPI WriteConsoleOutputCharacterA( HANDLE hConsoleOutput,
1748 LPCSTR lpCharacter, DWORD nLength, COORD dwCoord,
1749 LPDWORD lpNumCharsWritten)
1750{
1751 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,
1752 lpCharacter,nLength,dwCoord.X,dwCoord.Y,lpNumCharsWritten);
1753 *lpNumCharsWritten = nLength;
1754 return TRUE;
1755}
1756
1757/******************************************************************************
1758 * WriteConsoleOutputCharacterW [KERNEL32.@] Copies character to consecutive
1759 * cells in the console screen buffer
1760 *
1761 * PARAMS
1762 * hConsoleOutput [I] Handle to screen buffer
1763 * lpCharacter [I] Pointer to buffer with chars to write
1764 * nLength [I] Number of cells to write to
1765 * dwCoord [I] Coords of first cell
1766 * lpNumCharsWritten [O] Pointer to number of cells written
1767 *
1768 * RETURNS
1769 * Success: TRUE
1770 * Failure: FALSE
1771 *
1772 * BUGS
1773 * Unimplemented
1774 */
1775BOOL WINAPI WriteConsoleOutputCharacterW( HANDLE hConsoleOutput,
1776 LPCWSTR lpCharacter, DWORD nLength, COORD dwCoord,
1777 LPDWORD lpNumCharsWritten)
1778{
1779 FIXME("(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,
1780 lpCharacter,nLength,dwCoord.X,dwCoord.Y,lpNumCharsWritten);
1781 *lpNumCharsWritten = nLength;
1782 return TRUE;
1783}