Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Win32 kernel functions |
| 3 | * |
| 4 | * Copyright 1995 Martin von Loewis and Cameron Heide |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 5 | * Copyright 1997 Karl Garrison |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 6 | * Copyright 1998 John Richardson |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 7 | * Copyright 1998 Marcus Meissner |
| 8 | */ |
| 9 | |
| 10 | /* FIXME: |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 11 | * - Completely lacks SCREENBUFFER interface. |
| 12 | * - No abstraction for something other than xterm. |
| 13 | * - Key input translation shouldn't use VkKeyScan and MapVirtualKey, since |
| 14 | * they are window (USER) driver dependend. |
| 15 | * - Output sometimes is buffered (We switched off buffering by ~ICANON ?) |
| 16 | */ |
| 17 | /* Reference applications: |
| 18 | * - IDA (interactive disassembler) full version 3.75. Works. |
| 19 | * - LYNX/W32. Works mostly, some keys crash it. |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 22 | #include <stdlib.h> |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 23 | #include <unistd.h> |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 24 | #include <termios.h> |
Marcus Meissner | b02ffc7 | 1998-10-11 10:49:46 +0000 | [diff] [blame] | 25 | #include <strings.h> |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 26 | #include <sys/ioctl.h> |
| 27 | #include <sys/types.h> |
Marcus Meissner | b02ffc7 | 1998-10-11 10:49:46 +0000 | [diff] [blame] | 28 | #include <sys/time.h> |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 29 | #include <unistd.h> |
| 30 | #include <fcntl.h> |
| 31 | #include <errno.h> |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 32 | #include <sys/errno.h> |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 33 | #include <signal.h> |
| 34 | #include <assert.h> |
Marcus Meissner | ad7538b | 1998-12-14 18:15:10 +0000 | [diff] [blame] | 35 | |
Marcus Meissner | 04c3e1d | 1999-02-19 10:37:02 +0000 | [diff] [blame^] | 36 | #include "winbase.h" |
| 37 | #include "wine/winuser16.h" |
| 38 | #include "wine/keyboard16.h" |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 39 | #include "k32obj.h" |
Marcus Meissner | ad7538b | 1998-12-14 18:15:10 +0000 | [diff] [blame] | 40 | #include "thread.h" |
| 41 | #include "async.h" |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 42 | #include "file.h" |
| 43 | #include "process.h" |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 44 | #include "winerror.h" |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 45 | #include "wincon.h" |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 46 | #include "heap.h" |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 47 | #include "debug.h" |
| 48 | |
Alexandre Julliard | b2340ea | 1998-12-30 12:10:49 +0000 | [diff] [blame] | 49 | #include "server/request.h" |
| 50 | #include "server.h" |
| 51 | |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 52 | /* The CONSOLE kernel32 Object */ |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 53 | typedef struct _CONSOLE { |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 54 | K32OBJ header; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 55 | } CONSOLE; |
| 56 | |
Zygo Blaxell | edc858c | 1999-02-09 14:14:16 +0000 | [diff] [blame] | 57 | /* FIXME: Should be in an internal header file. OK, so which one? |
| 58 | Used by CONSOLE_makecomplex. */ |
| 59 | FILE *wine_openpty(int *master, int *slave, char *name, |
| 60 | struct termios *term, struct winsize *winsize); |
| 61 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 62 | /**************************************************************************** |
| 63 | * CONSOLE_GetInfo |
| 64 | */ |
| 65 | static BOOL32 CONSOLE_GetInfo( HANDLE32 handle, struct get_console_info_reply *reply ) |
| 66 | { |
| 67 | struct get_console_info_request req; |
| 68 | |
| 69 | if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, |
| 70 | K32OBJ_CONSOLE, GENERIC_READ )) == -1) |
| 71 | return FALSE; |
| 72 | CLIENT_SendRequest( REQ_GET_CONSOLE_INFO, -1, 1, &req, sizeof(req) ); |
| 73 | return !CLIENT_WaitSimpleReply( reply, sizeof(*reply), NULL ); |
| 74 | } |
| 75 | |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 76 | /**************************************************************************** |
| 77 | * XTERM_string_to_IR [internal] |
| 78 | * |
| 79 | * Transfers a string read from XTERM to INPUT_RECORDs and adds them to the |
| 80 | * queue. Does translation of vt100 style function keys and xterm-mouse clicks. |
| 81 | */ |
| 82 | static void |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 83 | CONSOLE_string_to_IR( HANDLE32 hConsoleInput,unsigned char *buf,int len) { |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 84 | int j,k; |
| 85 | INPUT_RECORD ir; |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 86 | DWORD junk; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 87 | |
| 88 | for (j=0;j<len;j++) { |
| 89 | unsigned char inchar = buf[j]; |
| 90 | |
| 91 | if (inchar!=27) { /* no escape -> 'normal' keyboard event */ |
| 92 | ir.EventType = 1; /* Key_event */ |
| 93 | |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 94 | ir.Event.KeyEvent.bKeyDown = 1; |
| 95 | ir.Event.KeyEvent.wRepeatCount = 0; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 96 | |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 97 | ir.Event.KeyEvent.dwControlKeyState = 0; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 98 | if (inchar & 0x80) { |
| 99 | ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED; |
| 100 | inchar &= ~0x80; |
| 101 | } |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 102 | ir.Event.KeyEvent.wVirtualKeyCode = VkKeyScan16(inchar); |
| 103 | if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0100) |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 104 | ir.Event.KeyEvent.dwControlKeyState|=SHIFT_PRESSED; |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 105 | if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0200) |
| 106 | ir.Event.KeyEvent.dwControlKeyState|=LEFT_CTRL_PRESSED; |
| 107 | if (ir.Event.KeyEvent.wVirtualKeyCode & 0x0400) |
| 108 | ir.Event.KeyEvent.dwControlKeyState|=LEFT_ALT_PRESSED; |
| 109 | ir.Event.KeyEvent.wVirtualScanCode = MapVirtualKey16( |
| 110 | ir.Event.KeyEvent.wVirtualKeyCode & 0x00ff, |
| 111 | 0 /* VirtualKeyCodes to ScanCode */ |
| 112 | ); |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 113 | ir.Event.KeyEvent.uChar.AsciiChar = inchar; |
| 114 | |
| 115 | if (inchar==127) { /* backspace */ |
| 116 | ir.Event.KeyEvent.uChar.AsciiChar = '\b'; /* FIXME: hmm */ |
| 117 | ir.Event.KeyEvent.wVirtualScanCode = 0x0e; |
| 118 | ir.Event.KeyEvent.wVirtualKeyCode = VK_BACK; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 119 | } else { |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 120 | if (inchar=='\n') { |
| 121 | ir.Event.KeyEvent.uChar.AsciiChar = '\r'; |
| 122 | ir.Event.KeyEvent.wVirtualKeyCode = VK_RETURN; |
| 123 | ir.Event.KeyEvent.wVirtualScanCode = 0x1c; |
| 124 | } else { |
| 125 | if (inchar<' ') { |
| 126 | /* FIXME: find good values for ^X */ |
| 127 | ir.Event.KeyEvent.wVirtualKeyCode = 0xdead; |
| 128 | ir.Event.KeyEvent.wVirtualScanCode = 0xbeef; |
| 129 | } |
| 130 | } |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 131 | } |
| 132 | |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 133 | assert(WriteConsoleInput32A( hConsoleInput, &ir, 1, &junk )); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 134 | ir.Event.KeyEvent.bKeyDown = 0; |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 135 | assert(WriteConsoleInput32A( hConsoleInput, &ir, 1, &junk )); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 136 | continue; |
| 137 | } |
| 138 | /* inchar is ESC */ |
| 139 | if ((j==len-1) || (buf[j+1]!='[')) {/* add ESCape on its own */ |
| 140 | ir.EventType = 1; /* Key_event */ |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 141 | ir.Event.KeyEvent.bKeyDown = 1; |
| 142 | ir.Event.KeyEvent.wRepeatCount = 0; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 143 | |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 144 | ir.Event.KeyEvent.wVirtualKeyCode = VkKeyScan16(27); |
| 145 | ir.Event.KeyEvent.wVirtualScanCode = MapVirtualKey16( |
| 146 | ir.Event.KeyEvent.wVirtualKeyCode,0 |
| 147 | ); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 148 | ir.Event.KeyEvent.dwControlKeyState = 0; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 149 | ir.Event.KeyEvent.uChar.AsciiChar = 27; |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 150 | assert(WriteConsoleInput32A( hConsoleInput, &ir, 1, &junk )); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 151 | ir.Event.KeyEvent.bKeyDown = 0; |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 152 | assert(WriteConsoleInput32A( hConsoleInput, &ir, 1, &junk )); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 153 | continue; |
| 154 | } |
| 155 | for (k=j;k<len;k++) { |
| 156 | if (((buf[k]>='A') && (buf[k]<='Z')) || |
| 157 | ((buf[k]>='a') && (buf[k]<='z')) || |
| 158 | (buf[k]=='~') |
| 159 | ) |
| 160 | break; |
| 161 | } |
| 162 | if (k<len) { |
| 163 | int subid,scancode=0; |
| 164 | |
| 165 | ir.EventType = 1; /* Key_event */ |
| 166 | ir.Event.KeyEvent.bKeyDown = 1; |
| 167 | ir.Event.KeyEvent.wRepeatCount = 0; |
| 168 | ir.Event.KeyEvent.dwControlKeyState = 0; |
| 169 | |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 170 | ir.Event.KeyEvent.wVirtualKeyCode = 0xad; /* FIXME */ |
| 171 | ir.Event.KeyEvent.wVirtualScanCode = 0xad; /* FIXME */ |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 172 | ir.Event.KeyEvent.uChar.AsciiChar = 0; |
| 173 | |
| 174 | switch (buf[k]) { |
| 175 | case '~': |
| 176 | sscanf(&buf[j+2],"%d",&subid); |
| 177 | switch (subid) { |
| 178 | case 2:/*INS */scancode = 0xe052;break; |
| 179 | case 3:/*DEL */scancode = 0xe053;break; |
| 180 | case 6:/*PGDW*/scancode = 0xe051;break; |
| 181 | case 5:/*PGUP*/scancode = 0xe049;break; |
| 182 | case 11:/*F1 */scancode = 0x003b;break; |
| 183 | case 12:/*F2 */scancode = 0x003c;break; |
| 184 | case 13:/*F3 */scancode = 0x003d;break; |
| 185 | case 14:/*F4 */scancode = 0x003e;break; |
| 186 | case 15:/*F5 */scancode = 0x003f;break; |
| 187 | case 17:/*F6 */scancode = 0x0040;break; |
| 188 | case 18:/*F7 */scancode = 0x0041;break; |
| 189 | case 19:/*F8 */scancode = 0x0042;break; |
| 190 | case 20:/*F9 */scancode = 0x0043;break; |
| 191 | case 21:/*F10 */scancode = 0x0044;break; |
| 192 | case 23:/*F11 */scancode = 0x00d9;break; |
| 193 | case 24:/*F12 */scancode = 0x00da;break; |
| 194 | /* FIXME: Shift-Fx */ |
| 195 | default: |
| 196 | FIXME(console,"parse ESC[%d~\n",subid); |
| 197 | break; |
| 198 | } |
| 199 | break; |
| 200 | case 'A': /* Cursor Up */scancode = 0xe048;break; |
| 201 | case 'B': /* Cursor Down */scancode = 0xe050;break; |
| 202 | case 'D': /* Cursor Left */scancode = 0xe04b;break; |
| 203 | case 'C': /* Cursor Right */scancode = 0xe04d;break; |
| 204 | case 'F': /* End */scancode = 0xe04f;break; |
| 205 | case 'H': /* Home */scancode = 0xe047;break; |
| 206 | case 'M': |
| 207 | /* Mouse Button Press (ESCM<button+'!'><x+'!'><y+'!'>) or |
| 208 | * Release (ESCM#<x+'!'><y+'!'> |
| 209 | */ |
| 210 | if (k<len-3) { |
| 211 | ir.EventType = MOUSE_EVENT; |
| 212 | ir.Event.MouseEvent.dwMousePosition.x = buf[k+2]-'!'; |
| 213 | ir.Event.MouseEvent.dwMousePosition.y = buf[k+3]-'!'; |
| 214 | if (buf[k+1]=='#') |
| 215 | ir.Event.MouseEvent.dwButtonState = 0; |
| 216 | else |
| 217 | ir.Event.MouseEvent.dwButtonState = 1<<(buf[k+1]-' '); |
| 218 | ir.Event.MouseEvent.dwEventFlags = 0; /* FIXME */ |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 219 | assert(WriteConsoleInput32A( hConsoleInput, &ir, 1, &junk)); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 220 | j=k+3; |
| 221 | } |
| 222 | break; |
| 223 | |
| 224 | } |
| 225 | if (scancode) { |
| 226 | ir.Event.KeyEvent.wVirtualScanCode = scancode; |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 227 | ir.Event.KeyEvent.wVirtualKeyCode = MapVirtualKey16(scancode,1); |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 228 | assert(WriteConsoleInput32A( hConsoleInput, &ir, 1, &junk )); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 229 | ir.Event.KeyEvent.bKeyDown = 0; |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 230 | assert(WriteConsoleInput32A( hConsoleInput, &ir, 1, &junk )); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 231 | j=k; |
| 232 | continue; |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | } |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 237 | |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 238 | /**************************************************************************** |
| 239 | * CONSOLE_get_input (internal) |
| 240 | * |
| 241 | * Reads (nonblocking) as much input events as possible and stores them |
| 242 | * in an internal queue. |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 243 | */ |
| 244 | static void |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 245 | CONSOLE_get_input( HANDLE32 handle, BOOL32 blockwait ) |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 246 | { |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 247 | char *buf = HeapAlloc(GetProcessHeap(),0,1); |
| 248 | int len = 0; |
| 249 | |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 250 | while (1) |
| 251 | { |
| 252 | DWORD res; |
| 253 | char inchar; |
Marcus Meissner | ba8e2a3 | 1999-01-03 16:18:33 +0000 | [diff] [blame] | 254 | if (WaitForSingleObject( handle, 0 )) break; |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 255 | if (!ReadFile( handle, &inchar, 1, &res, NULL )) break; |
Marcus Meissner | 03f10f4 | 1999-01-26 10:08:36 +0000 | [diff] [blame] | 256 | if (!res) /* res 0 but readable means EOF? Hmm. */ |
| 257 | break; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 258 | buf = HeapReAlloc(GetProcessHeap(),0,buf,len+1); |
| 259 | buf[len++]=inchar; |
| 260 | } |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 261 | CONSOLE_string_to_IR(handle,buf,len); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 262 | HeapFree(GetProcessHeap(),0,buf); |
| 263 | } |
| 264 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 265 | /****************************************************************************** |
| 266 | * SetConsoleCtrlHandler [KERNEL32.459] Adds function to calling process list |
| 267 | * |
| 268 | * PARAMS |
| 269 | * func [I] Address of handler function |
| 270 | * add [I] Handler to add or remove |
| 271 | * |
| 272 | * RETURNS |
| 273 | * Success: TRUE |
| 274 | * Failure: FALSE |
James Sutherland | 577db37 | 1998-11-08 15:09:08 +0000 | [diff] [blame] | 275 | * |
| 276 | * CHANGED |
| 277 | * James Sutherland (JamesSutherland@gmx.de) |
| 278 | * Added global variables console_ignore_ctrl_c and handlers[] |
| 279 | * Does not yet do any error checking, or set LastError if failed. |
| 280 | * This doesn't yet matter, since these handlers are not yet called...! |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 281 | */ |
James Sutherland | 577db37 | 1998-11-08 15:09:08 +0000 | [diff] [blame] | 282 | static unsigned int console_ignore_ctrl_c = 0; |
| 283 | static HANDLER_ROUTINE *handlers[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 284 | BOOL32 WINAPI SetConsoleCtrlHandler( HANDLER_ROUTINE *func, BOOL32 add ) |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 285 | { |
James Sutherland | 577db37 | 1998-11-08 15:09:08 +0000 | [diff] [blame] | 286 | unsigned int alloc_loop = sizeof(handlers)/sizeof(HANDLER_ROUTINE *); |
| 287 | unsigned int done = 0; |
| 288 | FIXME(console, "(%p,%i) - no error checking or testing yet\n", func, add); |
| 289 | if (!func) |
| 290 | { |
| 291 | console_ignore_ctrl_c = add; |
| 292 | return TRUE; |
| 293 | } |
| 294 | if (add) |
| 295 | { |
| 296 | for (;alloc_loop--;) |
| 297 | if (!handlers[alloc_loop] && !done) |
| 298 | { |
| 299 | handlers[alloc_loop] = func; |
| 300 | done++; |
| 301 | } |
| 302 | if (!done) |
| 303 | FIXME(console, "Out of space on CtrlHandler table\n"); |
| 304 | return(done); |
| 305 | } |
| 306 | else |
| 307 | { |
| 308 | for (;alloc_loop--;) |
| 309 | if (handlers[alloc_loop] == func && !done) |
| 310 | { |
| 311 | handlers[alloc_loop] = 0; |
| 312 | done++; |
| 313 | } |
| 314 | if (!done) |
Huw D M Davies | 7b06d98 | 1998-11-14 17:13:51 +0000 | [diff] [blame] | 315 | WARN(console, "Attempt to remove non-installed CtrlHandler %p\n", |
| 316 | func); |
James Sutherland | 577db37 | 1998-11-08 15:09:08 +0000 | [diff] [blame] | 317 | return (done); |
| 318 | } |
| 319 | return (done); |
| 320 | } |
| 321 | |
| 322 | |
| 323 | /****************************************************************************** |
| 324 | * GenerateConsoleCtrlEvent [KERNEL32.275] Simulate a CTRL-C or CTRL-BREAK |
| 325 | * |
| 326 | * PARAMS |
| 327 | * dwCtrlEvent [I] Type of event |
| 328 | * dwProcessGroupID [I] Process group ID to send event to |
| 329 | * |
| 330 | * NOTES |
| 331 | * Doesn't yet work...! |
| 332 | * |
| 333 | * RETURNS |
| 334 | * Success: True |
| 335 | * Failure: False (and *should* [but doesn't] set LastError) |
| 336 | */ |
| 337 | BOOL32 WINAPI GenerateConsoleCtrlEvent( DWORD dwCtrlEvent, |
| 338 | DWORD dwProcessGroupID ) |
| 339 | { |
| 340 | if (dwCtrlEvent != CTRL_C_EVENT && dwCtrlEvent != CTRL_BREAK_EVENT) |
| 341 | { |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 342 | ERR( console, "invalid event %d for PGID %ld\n", |
James Sutherland | 577db37 | 1998-11-08 15:09:08 +0000 | [diff] [blame] | 343 | (unsigned short)dwCtrlEvent, dwProcessGroupID ); |
| 344 | return FALSE; |
| 345 | } |
| 346 | if (dwProcessGroupID == GetCurrentProcessId() ) |
| 347 | { |
| 348 | FIXME( console, "Attempt to send event %d to self - stub\n", |
| 349 | (unsigned short)dwCtrlEvent ); |
| 350 | return FALSE; |
| 351 | } |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 352 | FIXME( console,"event %d to external PGID %ld - not implemented yet\n", |
James Sutherland | 577db37 | 1998-11-08 15:09:08 +0000 | [diff] [blame] | 353 | (unsigned short)dwCtrlEvent, dwProcessGroupID ); |
| 354 | return FALSE; |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 355 | } |
| 356 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 357 | |
| 358 | /****************************************************************************** |
| 359 | * CreateConsoleScreenBuffer [KERNEL32.151] Creates a console screen buffer |
| 360 | * |
| 361 | * PARAMS |
| 362 | * dwDesiredAccess [I] Access flag |
| 363 | * dwShareMode [I] Buffer share mode |
| 364 | * sa [I] Security attributes |
| 365 | * dwFlags [I] Type of buffer to create |
| 366 | * lpScreenBufferData [I] Reserved |
| 367 | * |
| 368 | * NOTES |
| 369 | * Should call SetLastError |
| 370 | * |
| 371 | * RETURNS |
| 372 | * Success: Handle to new console screen buffer |
| 373 | * Failure: INVALID_HANDLE_VALUE |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 374 | */ |
| 375 | HANDLE32 WINAPI CreateConsoleScreenBuffer( DWORD dwDesiredAccess, |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 376 | DWORD dwShareMode, LPSECURITY_ATTRIBUTES sa, |
| 377 | DWORD dwFlags, LPVOID lpScreenBufferData ) |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 378 | { |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 379 | FIXME(console, "(%ld,%ld,%p,%ld,%p): stub\n",dwDesiredAccess, |
| 380 | dwShareMode, sa, dwFlags, lpScreenBufferData); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 381 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 382 | return INVALID_HANDLE_VALUE32; |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 383 | } |
| 384 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 385 | |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 386 | /*********************************************************************** |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 387 | * GetConsoleScreenBufferInfo (KERNEL32.190) |
| 388 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 389 | BOOL32 WINAPI GetConsoleScreenBufferInfo( HANDLE32 hConsoleOutput, |
| 390 | LPCONSOLE_SCREEN_BUFFER_INFO csbi ) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 391 | { |
| 392 | csbi->dwSize.x = 80; |
| 393 | csbi->dwSize.y = 24; |
| 394 | csbi->dwCursorPosition.x = 0; |
| 395 | csbi->dwCursorPosition.y = 0; |
| 396 | csbi->wAttributes = 0; |
| 397 | csbi->srWindow.Left = 0; |
| 398 | csbi->srWindow.Right = 79; |
| 399 | csbi->srWindow.Top = 0; |
| 400 | csbi->srWindow.Bottom = 23; |
| 401 | csbi->dwMaximumWindowSize.x = 80; |
| 402 | csbi->dwMaximumWindowSize.y = 24; |
| 403 | return TRUE; |
| 404 | } |
| 405 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 406 | |
| 407 | /****************************************************************************** |
| 408 | * SetConsoleActiveScreenBuffer [KERNEL32.623] Sets buffer to current console |
| 409 | * |
| 410 | * RETURNS |
| 411 | * Success: TRUE |
| 412 | * Failure: FALSE |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 413 | */ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 414 | BOOL32 WINAPI SetConsoleActiveScreenBuffer( |
| 415 | HANDLE32 hConsoleOutput) /* [in] Handle to console screen buffer */ |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 416 | { |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 417 | FIXME(console, "(%x): stub\n", hConsoleOutput); |
| 418 | return FALSE; |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 421 | |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 422 | /*********************************************************************** |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 423 | * GetLargestConsoleWindowSize (KERNEL32.226) |
| 424 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 425 | DWORD WINAPI GetLargestConsoleWindowSize( HANDLE32 hConsoleOutput ) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 426 | { |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 427 | return (DWORD)MAKELONG(80,24); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 430 | /*********************************************************************** |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 431 | * FreeConsole (KERNEL32.267) |
| 432 | */ |
| 433 | BOOL32 WINAPI FreeConsole(VOID) |
| 434 | { |
| 435 | |
| 436 | PDB32 *pdb = PROCESS_Current(); |
| 437 | CONSOLE *console; |
| 438 | |
| 439 | SYSTEM_LOCK(); |
| 440 | |
| 441 | console = (CONSOLE *)pdb->console; |
| 442 | |
| 443 | if (console == NULL) { |
| 444 | SetLastError(ERROR_INVALID_PARAMETER); |
| 445 | return FALSE; |
| 446 | } |
| 447 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 448 | CLIENT_SendRequest( REQ_FREE_CONSOLE, -1, 0 ); |
| 449 | if (CLIENT_WaitReply( NULL, NULL, 0 ) != ERROR_SUCCESS) |
| 450 | { |
| 451 | K32OBJ_DecCount(&console->header); |
| 452 | SYSTEM_UNLOCK(); |
| 453 | return FALSE; |
| 454 | } |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 455 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 456 | HANDLE_CloseAll( pdb, &console->header ); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 457 | K32OBJ_DecCount( &console->header ); |
| 458 | pdb->console = NULL; |
| 459 | SYSTEM_UNLOCK(); |
| 460 | return TRUE; |
| 461 | } |
| 462 | |
| 463 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 464 | /************************************************************************* |
| 465 | * CONSOLE_OpenHandle |
| 466 | * |
| 467 | * Open a handle to the current process console. |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 468 | */ |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 469 | HANDLE32 CONSOLE_OpenHandle( BOOL32 output, DWORD access, LPSECURITY_ATTRIBUTES sa ) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 470 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 471 | struct open_console_request req; |
| 472 | struct open_console_reply reply; |
| 473 | CONSOLE *console; |
| 474 | HANDLE32 handle; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 475 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 476 | req.output = output; |
| 477 | req.access = access; |
| 478 | req.inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle); |
| 479 | CLIENT_SendRequest( REQ_OPEN_CONSOLE, -1, 1, &req, sizeof(req) ); |
| 480 | CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ); |
| 481 | if (reply.handle == -1) return INVALID_HANDLE_VALUE32; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 482 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 483 | SYSTEM_LOCK(); |
| 484 | if (!(console = (CONSOLE*)HeapAlloc( SystemHeap, 0, sizeof(*console)))) |
| 485 | { |
| 486 | SYSTEM_UNLOCK(); |
| 487 | return FALSE; |
| 488 | } |
| 489 | console->header.type = K32OBJ_CONSOLE; |
| 490 | console->header.refcount = 1; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 491 | handle = HANDLE_Alloc( PROCESS_Current(), &console->header, req.access, |
| 492 | req.inherit, reply.handle ); |
| 493 | SYSTEM_UNLOCK(); |
| 494 | K32OBJ_DecCount(&console->header); |
| 495 | return handle; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 498 | |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 499 | /************************************************************************* |
| 500 | * CONSOLE_make_complex [internal] |
| 501 | * |
| 502 | * Turns a CONSOLE kernel object into a complex one. |
| 503 | * (switches from output/input using the terminal where WINE was started to |
| 504 | * its own xterm). |
| 505 | * |
| 506 | * This makes simple commandline tools pipeable, while complex commandline |
| 507 | * tools work without getting messed up by debugoutput. |
| 508 | * |
| 509 | * All other functions should work indedependend from this call. |
| 510 | * |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 511 | * To test for complex console: pid == 0 -> simple, otherwise complex. |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 512 | */ |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 513 | static BOOL32 CONSOLE_make_complex(HANDLE32 handle) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 514 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 515 | struct set_console_fd_request req; |
| 516 | struct get_console_info_reply info; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 517 | struct termios term; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 518 | char buf[256]; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 519 | char c = '\0'; |
| 520 | int status = 0; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 521 | int i,xpid,master,slave; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 522 | DWORD xlen; |
| 523 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 524 | if (!CONSOLE_GetInfo( handle, &info )) return FALSE; |
| 525 | if (info.pid) return TRUE; /* already complex */ |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 526 | |
| 527 | MSG("Console: Making console complex (creating an xterm)...\n"); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 528 | |
Marcus Meissner | 03f10f4 | 1999-01-26 10:08:36 +0000 | [diff] [blame] | 529 | if (tcgetattr(0, &term) < 0) { |
| 530 | /* ignore failure, or we can't run from a script */ |
| 531 | } |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 532 | term.c_lflag = ~(ECHO|ICANON); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 533 | |
| 534 | if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, |
| 535 | K32OBJ_CONSOLE, 0 )) == -1) |
| 536 | return FALSE; |
| 537 | |
| 538 | if (wine_openpty(&master, &slave, NULL, &term, NULL) < 0) |
| 539 | return FALSE; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 540 | |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 541 | if ((xpid=fork()) == 0) { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 542 | tcsetattr(slave, TCSADRAIN, &term); |
| 543 | sprintf(buf, "-Sxx%d", master); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 544 | /* "-fn vga" for VGA font. Harmless if vga is not present: |
| 545 | * xterm: unable to open font "vga", trying "fixed".... |
| 546 | */ |
| 547 | execlp("xterm", "xterm", buf, "-fn","vga",NULL); |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 548 | ERR(console, "error creating AllocConsole xterm\n"); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 549 | exit(1); |
| 550 | } |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 551 | |
| 552 | req.pid = xpid; |
| 553 | CLIENT_SendRequest( REQ_SET_CONSOLE_FD, dup(slave), 1, &req, sizeof(req) ); |
| 554 | CLIENT_WaitReply( NULL, NULL, 0 ); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 555 | |
| 556 | /* most xterms like to print their window ID when used with -S; |
| 557 | * read it and continue before the user has a chance... |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 558 | */ |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 559 | for (i=0; c!='\n'; (status=read(slave, &c, 1)), i++) { |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 560 | if (status == -1 && c == '\0') { |
| 561 | /* wait for xterm to be created */ |
| 562 | usleep(100); |
| 563 | } |
| 564 | if (i > 10000) { |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 565 | ERR(console, "can't read xterm WID\n"); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 566 | kill(xpid, SIGKILL); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 567 | return FALSE; |
| 568 | } |
| 569 | } |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 570 | /* enable mouseclicks */ |
| 571 | sprintf(buf,"%c[?1001s%c[?1000h",27,27); |
Alexandre Julliard | 5544387 | 1998-12-31 15:52:06 +0000 | [diff] [blame] | 572 | WriteFile(handle,buf,strlen(buf),&xlen,NULL); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 573 | |
| 574 | if (GetConsoleTitle32A( buf, sizeof(buf) )) |
| 575 | { |
| 576 | WriteFile(handle,"\033]2;",4,&xlen,NULL); |
| 577 | WriteFile(handle,buf,strlen(buf),&xlen,NULL); |
| 578 | WriteFile(handle,"\a",1,&xlen,NULL); |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 579 | } |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 580 | return TRUE; |
| 581 | |
| 582 | } |
| 583 | |
| 584 | |
| 585 | /*********************************************************************** |
| 586 | * AllocConsole (KERNEL32.103) |
| 587 | * |
| 588 | * creates an xterm with a pty to our program |
| 589 | */ |
| 590 | BOOL32 WINAPI AllocConsole(VOID) |
| 591 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 592 | struct open_console_request req; |
| 593 | struct open_console_reply reply; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 594 | PDB32 *pdb = PROCESS_Current(); |
| 595 | CONSOLE *console; |
| 596 | HANDLE32 hIn, hOut, hErr; |
| 597 | |
| 598 | SYSTEM_LOCK(); /* FIXME: really only need to lock the process */ |
| 599 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 600 | console = (CONSOLE *)pdb->console; |
| 601 | |
Alexandre Julliard | a11d7b1 | 1998-03-01 20:05:02 +0000 | [diff] [blame] | 602 | /* don't create a console if we already have one */ |
| 603 | if (console != NULL) { |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 604 | SetLastError(ERROR_ACCESS_DENIED); |
| 605 | SYSTEM_UNLOCK(); |
| 606 | return FALSE; |
| 607 | } |
| 608 | |
| 609 | if (!(console = (CONSOLE*)HeapAlloc( SystemHeap, 0, sizeof(*console)))) |
| 610 | { |
| 611 | SYSTEM_UNLOCK(); |
| 612 | return FALSE; |
| 613 | } |
| 614 | |
| 615 | console->header.type = K32OBJ_CONSOLE; |
| 616 | console->header.refcount = 1; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 617 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 618 | CLIENT_SendRequest( REQ_ALLOC_CONSOLE, -1, 0 ); |
| 619 | if (CLIENT_WaitReply( NULL, NULL, 0 ) != ERROR_SUCCESS) |
| 620 | { |
| 621 | K32OBJ_DecCount(&console->header); |
| 622 | SYSTEM_UNLOCK(); |
| 623 | return FALSE; |
| 624 | } |
| 625 | |
| 626 | req.output = 0; |
Marcus Meissner | fbc5625 | 1999-01-20 14:46:49 +0000 | [diff] [blame] | 627 | req.access = GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 628 | req.inherit = FALSE; |
| 629 | CLIENT_SendRequest( REQ_OPEN_CONSOLE, -1, 1, &req, sizeof(req) ); |
Alexandre Julliard | 6ebbe3c | 1999-01-01 17:04:00 +0000 | [diff] [blame] | 630 | if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ) != ERROR_SUCCESS) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 631 | { |
| 632 | K32OBJ_DecCount(&console->header); |
| 633 | SYSTEM_UNLOCK(); |
| 634 | return FALSE; |
Alexandre Julliard | b2340ea | 1998-12-30 12:10:49 +0000 | [diff] [blame] | 635 | } |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 636 | if ((hIn = HANDLE_Alloc(pdb,&console->header, req.access, |
| 637 | FALSE, reply.handle)) == INVALID_HANDLE_VALUE32) |
Alexandre Julliard | b2340ea | 1998-12-30 12:10:49 +0000 | [diff] [blame] | 638 | { |
Alexandre Julliard | b2340ea | 1998-12-30 12:10:49 +0000 | [diff] [blame] | 639 | K32OBJ_DecCount(&console->header); |
| 640 | SYSTEM_UNLOCK(); |
| 641 | return FALSE; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 642 | } |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 643 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 644 | req.output = 1; |
| 645 | CLIENT_SendRequest( REQ_OPEN_CONSOLE, -1, 1, &req, sizeof(req) ); |
| 646 | if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL ) != ERROR_SUCCESS) |
| 647 | { |
| 648 | CloseHandle(hIn); |
| 649 | K32OBJ_DecCount(&console->header); |
| 650 | SYSTEM_UNLOCK(); |
| 651 | return FALSE; |
| 652 | } |
| 653 | if ((hOut = HANDLE_Alloc(pdb,&console->header, req.access, |
| 654 | FALSE, reply.handle)) == INVALID_HANDLE_VALUE32) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 655 | { |
| 656 | CloseHandle(hIn); |
| 657 | K32OBJ_DecCount(&console->header); |
| 658 | SYSTEM_UNLOCK(); |
| 659 | return FALSE; |
| 660 | } |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 661 | |
Alexandre Julliard | b2340ea | 1998-12-30 12:10:49 +0000 | [diff] [blame] | 662 | if (!DuplicateHandle( GetCurrentProcess(), hOut, |
| 663 | GetCurrentProcess(), &hErr, |
| 664 | 0, TRUE, DUPLICATE_SAME_ACCESS )) |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 665 | { |
| 666 | CloseHandle(hIn); |
| 667 | CloseHandle(hOut); |
| 668 | K32OBJ_DecCount(&console->header); |
| 669 | SYSTEM_UNLOCK(); |
| 670 | return FALSE; |
| 671 | } |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 672 | |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 673 | if (pdb->console) K32OBJ_DecCount( pdb->console ); |
| 674 | pdb->console = (K32OBJ *)console; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 675 | K32OBJ_IncCount( pdb->console ); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 676 | |
| 677 | /* NT resets the STD_*_HANDLEs on console alloc */ |
| 678 | SetStdHandle(STD_INPUT_HANDLE, hIn); |
| 679 | SetStdHandle(STD_OUTPUT_HANDLE, hOut); |
| 680 | SetStdHandle(STD_ERROR_HANDLE, hErr); |
| 681 | |
| 682 | SetLastError(ERROR_SUCCESS); |
| 683 | SYSTEM_UNLOCK(); |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 684 | SetConsoleTitle32A("Wine Console"); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 685 | return TRUE; |
| 686 | } |
| 687 | |
| 688 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 689 | /****************************************************************************** |
| 690 | * GetConsoleCP [KERNEL32.295] Returns the OEM code page for the console |
| 691 | * |
| 692 | * RETURNS |
| 693 | * Code page code |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 694 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 695 | UINT32 WINAPI GetConsoleCP(VOID) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 696 | { |
| 697 | return GetACP(); |
| 698 | } |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 699 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 700 | |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 701 | /*********************************************************************** |
| 702 | * GetConsoleOutputCP (KERNEL32.189) |
| 703 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 704 | UINT32 WINAPI GetConsoleOutputCP(VOID) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 705 | { |
| 706 | return GetConsoleCP(); |
| 707 | } |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 708 | |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 709 | /*********************************************************************** |
| 710 | * GetConsoleMode (KERNEL32.188) |
| 711 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 712 | BOOL32 WINAPI GetConsoleMode(HANDLE32 hcon,LPDWORD mode) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 713 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 714 | struct get_console_mode_request req; |
| 715 | struct get_console_mode_reply reply; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 716 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 717 | if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hcon, |
| 718 | K32OBJ_CONSOLE, GENERIC_READ )) == -1) |
| 719 | return FALSE; |
| 720 | CLIENT_SendRequest( REQ_GET_CONSOLE_MODE, -1, 1, &req, sizeof(req)); |
| 721 | if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE; |
| 722 | *mode = reply.mode; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 723 | return TRUE; |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 724 | } |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 725 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 726 | |
| 727 | /****************************************************************************** |
| 728 | * SetConsoleMode [KERNEL32.628] Sets input mode of console's input buffer |
| 729 | * |
| 730 | * PARAMS |
| 731 | * hcon [I] Handle to console input or screen buffer |
| 732 | * mode [I] Input or output mode to set |
| 733 | * |
| 734 | * RETURNS |
| 735 | * Success: TRUE |
| 736 | * Failure: FALSE |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 737 | */ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 738 | BOOL32 WINAPI SetConsoleMode( HANDLE32 hcon, DWORD mode ) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 739 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 740 | struct set_console_mode_request req; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 741 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 742 | if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hcon, |
| 743 | K32OBJ_CONSOLE, GENERIC_READ )) == -1) |
| 744 | return FALSE; |
| 745 | req.mode = mode; |
| 746 | CLIENT_SendRequest( REQ_SET_CONSOLE_MODE, -1, 1, &req, sizeof(req)); |
| 747 | return !CLIENT_WaitReply( NULL, NULL, 0 ); |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 748 | } |
| 749 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 750 | |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 751 | /*********************************************************************** |
| 752 | * GetConsoleTitleA (KERNEL32.191) |
| 753 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 754 | DWORD WINAPI GetConsoleTitle32A(LPSTR title,DWORD size) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 755 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 756 | struct get_console_info_request req; |
| 757 | struct get_console_info_reply reply; |
| 758 | int len; |
| 759 | DWORD ret = 0; |
| 760 | HANDLE32 hcon; |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 761 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 762 | if ((hcon = CreateFile32A( "CONOUT$", GENERIC_READ, 0, NULL, |
| 763 | OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE32) |
| 764 | return 0; |
| 765 | if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hcon, |
| 766 | K32OBJ_CONSOLE, GENERIC_READ )) == -1) |
| 767 | { |
| 768 | CloseHandle( hcon ); |
| 769 | return 0; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 770 | } |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 771 | CLIENT_SendRequest( REQ_GET_CONSOLE_INFO, -1, 1, &req, sizeof(req) ); |
| 772 | if (!CLIENT_WaitReply( &len, NULL, 2, &reply, sizeof(reply), title, size )) |
| 773 | { |
| 774 | if (len > sizeof(reply)+size) title[size-1] = 0; |
| 775 | ret = strlen(title); |
| 776 | } |
| 777 | CloseHandle( hcon ); |
| 778 | return ret; |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 779 | } |
| 780 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 781 | |
| 782 | /****************************************************************************** |
| 783 | * GetConsoleTitle32W [KERNEL32.192] Retrieves title string for console |
| 784 | * |
| 785 | * PARAMS |
| 786 | * title [O] Address of buffer for title |
| 787 | * size [I] Size of buffer |
| 788 | * |
| 789 | * RETURNS |
| 790 | * Success: Length of string copied |
| 791 | * Failure: 0 |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 792 | */ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 793 | DWORD WINAPI GetConsoleTitle32W( LPWSTR title, DWORD size ) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 794 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 795 | char *tmp; |
| 796 | DWORD ret; |
| 797 | |
| 798 | if (!(tmp = HeapAlloc( GetProcessHeap(), 0, size ))) return 0; |
| 799 | ret = GetConsoleTitle32A( tmp, size ); |
| 800 | lstrcpyAtoW( title, tmp ); |
| 801 | HeapFree( GetProcessHeap(), 0, tmp ); |
| 802 | return ret; |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 805 | |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 806 | /*********************************************************************** |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 807 | * WriteConsoleA (KERNEL32.729) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 808 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 809 | BOOL32 WINAPI WriteConsole32A( HANDLE32 hConsoleOutput, |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 810 | LPCVOID lpBuffer, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 811 | DWORD nNumberOfCharsToWrite, |
| 812 | LPDWORD lpNumberOfCharsWritten, |
| 813 | LPVOID lpReserved ) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 814 | { |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 815 | /* FIXME: should I check if this is a console handle? */ |
| 816 | return WriteFile(hConsoleOutput, lpBuffer, nNumberOfCharsToWrite, |
| 817 | lpNumberOfCharsWritten, NULL); |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 820 | |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 821 | #define CADD(c) \ |
| 822 | if (bufused==curbufsize-1) \ |
| 823 | buffer = HeapReAlloc(GetProcessHeap(),0,buffer,(curbufsize+=100));\ |
| 824 | buffer[bufused++]=c; |
| 825 | #define SADD(s) { char *x=s;while (*x) {CADD(*x);x++;}} |
| 826 | |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 827 | /*********************************************************************** |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 828 | * WriteConsoleOutputA (KERNEL32.732) |
| 829 | */ |
| 830 | BOOL32 WINAPI WriteConsoleOutput32A( HANDLE32 hConsoleOutput, |
| 831 | LPCHAR_INFO lpBuffer, |
| 832 | COORD dwBufferSize, |
| 833 | COORD dwBufferCoord, |
| 834 | LPSMALL_RECT lpWriteRegion) |
| 835 | { |
Marcus Meissner | b02ffc7 | 1998-10-11 10:49:46 +0000 | [diff] [blame] | 836 | int i,j,off=0,lastattr=-1; |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 837 | char sbuf[20],*buffer=NULL; |
| 838 | int bufused=0,curbufsize = 100; |
Marcus Meissner | b02ffc7 | 1998-10-11 10:49:46 +0000 | [diff] [blame] | 839 | DWORD res; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 840 | const int colormap[8] = { |
Marcus Meissner | b02ffc7 | 1998-10-11 10:49:46 +0000 | [diff] [blame] | 841 | 0,4,2,6, |
| 842 | 1,5,3,7, |
| 843 | }; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 844 | CONSOLE_make_complex(hConsoleOutput); |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 845 | buffer = HeapAlloc(GetProcessHeap(),0,100);; |
| 846 | curbufsize = 100; |
Marcus Meissner | b02ffc7 | 1998-10-11 10:49:46 +0000 | [diff] [blame] | 847 | |
| 848 | TRACE(console,"wr: top = %d, bottom=%d, left=%d,right=%d\n", |
| 849 | lpWriteRegion->Top, |
| 850 | lpWriteRegion->Bottom, |
| 851 | lpWriteRegion->Left, |
| 852 | lpWriteRegion->Right |
| 853 | ); |
| 854 | |
| 855 | for (i=lpWriteRegion->Top;i<=lpWriteRegion->Bottom;i++) { |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 856 | sprintf(sbuf,"%c[%d;%dH",27,i+1,lpWriteRegion->Left+1); |
| 857 | SADD(sbuf); |
| 858 | for (j=lpWriteRegion->Left;j<=lpWriteRegion->Right;j++) { |
| 859 | if (lastattr!=lpBuffer[off].Attributes) { |
Marcus Meissner | b02ffc7 | 1998-10-11 10:49:46 +0000 | [diff] [blame] | 860 | lastattr = lpBuffer[off].Attributes; |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 861 | sprintf(sbuf,"%c[0;%s3%d;4%dm", |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 862 | 27, |
| 863 | (lastattr & FOREGROUND_INTENSITY)?"1;":"", |
| 864 | colormap[lastattr&7], |
| 865 | colormap[(lastattr&0x70)>>4] |
| 866 | ); |
| 867 | /* FIXME: BACKGROUND_INTENSITY */ |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 868 | SADD(sbuf); |
| 869 | } |
| 870 | CADD(lpBuffer[off].Char.AsciiChar); |
| 871 | off++; |
Marcus Meissner | b02ffc7 | 1998-10-11 10:49:46 +0000 | [diff] [blame] | 872 | } |
Marcus Meissner | b02ffc7 | 1998-10-11 10:49:46 +0000 | [diff] [blame] | 873 | } |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 874 | sprintf(sbuf,"%c[0m",27);SADD(sbuf); |
| 875 | WriteFile(hConsoleOutput,buffer,bufused,&res,NULL); |
| 876 | HeapFree(GetProcessHeap(),0,buffer); |
Marcus Meissner | b02ffc7 | 1998-10-11 10:49:46 +0000 | [diff] [blame] | 877 | return TRUE; |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | /*********************************************************************** |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 881 | * WriteConsoleW (KERNEL32.577) |
| 882 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 883 | BOOL32 WINAPI WriteConsole32W( HANDLE32 hConsoleOutput, |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 884 | LPCVOID lpBuffer, |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 885 | DWORD nNumberOfCharsToWrite, |
| 886 | LPDWORD lpNumberOfCharsWritten, |
| 887 | LPVOID lpReserved ) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 888 | { |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 889 | BOOL32 ret; |
| 890 | LPSTR xstring=HeapAlloc( GetProcessHeap(), 0, nNumberOfCharsToWrite ); |
| 891 | |
| 892 | lstrcpynWtoA( xstring, lpBuffer,nNumberOfCharsToWrite); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 893 | |
| 894 | /* FIXME: should I check if this is a console handle? */ |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 895 | ret= WriteFile(hConsoleOutput, xstring, nNumberOfCharsToWrite, |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 896 | lpNumberOfCharsWritten, NULL); |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 897 | HeapFree( GetProcessHeap(), 0, xstring ); |
| 898 | return ret; |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 899 | } |
| 900 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 901 | |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 902 | /*********************************************************************** |
| 903 | * ReadConsoleA (KERNEL32.419) |
| 904 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 905 | BOOL32 WINAPI ReadConsole32A( HANDLE32 hConsoleInput, |
| 906 | LPVOID lpBuffer, |
| 907 | DWORD nNumberOfCharsToRead, |
| 908 | LPDWORD lpNumberOfCharsRead, |
| 909 | LPVOID lpReserved ) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 910 | { |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 911 | int charsread = 0; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 912 | LPSTR xbuf = (LPSTR)lpBuffer; |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 913 | struct read_console_input_request req; |
| 914 | INPUT_RECORD ir; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 915 | |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 916 | if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hConsoleInput, |
| 917 | K32OBJ_CONSOLE, GENERIC_READ )) == -1) |
| 918 | return FALSE; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 919 | TRACE(console,"(%d,%p,%ld,%p,%p)\n", |
| 920 | hConsoleInput,lpBuffer,nNumberOfCharsToRead, |
| 921 | lpNumberOfCharsRead,lpReserved |
| 922 | ); |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 923 | |
| 924 | CONSOLE_get_input(hConsoleInput,FALSE); |
| 925 | |
| 926 | req.count = 1; |
| 927 | req.flush = 1; |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 928 | |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 929 | /* FIXME: should we read at least 1 char? The SDK does not say */ |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 930 | while (charsread<nNumberOfCharsToRead) |
| 931 | { |
| 932 | int len; |
| 933 | |
| 934 | CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) ); |
| 935 | if (CLIENT_WaitReply( &len, NULL, 1, &ir, sizeof(ir) )) |
| 936 | return FALSE; |
| 937 | assert( !(len % sizeof(ir)) ); |
| 938 | if (!len) break; |
| 939 | if (!ir.Event.KeyEvent.bKeyDown) |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 940 | continue; |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 941 | if (ir.EventType != KEY_EVENT) |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 942 | continue; |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 943 | *xbuf++ = ir.Event.KeyEvent.uChar.AsciiChar; |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 944 | charsread++; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 945 | } |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 946 | if (lpNumberOfCharsRead) |
| 947 | *lpNumberOfCharsRead = charsread; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 948 | return TRUE; |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | /*********************************************************************** |
| 952 | * ReadConsoleW (KERNEL32.427) |
| 953 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 954 | BOOL32 WINAPI ReadConsole32W( HANDLE32 hConsoleInput, |
| 955 | LPVOID lpBuffer, |
| 956 | DWORD nNumberOfCharsToRead, |
| 957 | LPDWORD lpNumberOfCharsRead, |
| 958 | LPVOID lpReserved ) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 959 | { |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 960 | BOOL32 ret; |
| 961 | LPSTR buf = (LPSTR)HeapAlloc(GetProcessHeap(), 0, nNumberOfCharsToRead); |
Alexandre Julliard | 03468f7 | 1998-02-15 19:40:49 +0000 | [diff] [blame] | 962 | |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 963 | ret = ReadConsole32A( |
| 964 | hConsoleInput, |
| 965 | buf, |
| 966 | nNumberOfCharsToRead, |
| 967 | lpNumberOfCharsRead, |
| 968 | lpReserved |
| 969 | ); |
| 970 | if (ret) |
| 971 | lstrcpynAtoW(lpBuffer,buf,nNumberOfCharsToRead); |
| 972 | HeapFree( GetProcessHeap(), 0, buf ); |
| 973 | return ret; |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 974 | } |
| 975 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 976 | |
| 977 | /****************************************************************************** |
Alexandre Julliard | 0c0e3be | 1998-12-10 15:49:22 +0000 | [diff] [blame] | 978 | * ReadConsoleInput32A [KERNEL32.569] Reads data from a console |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 979 | * |
| 980 | * PARAMS |
| 981 | * hConsoleInput [I] Handle to console input buffer |
| 982 | * lpBuffer [O] Address of buffer for read data |
| 983 | * nLength [I] Number of records to read |
| 984 | * lpNumberOfEventsRead [O] Address of number of records read |
| 985 | * |
| 986 | * RETURNS |
| 987 | * Success: TRUE |
| 988 | * Failure: FALSE |
| 989 | */ |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 990 | BOOL32 WINAPI ReadConsoleInput32A(HANDLE32 hConsoleInput, |
| 991 | LPINPUT_RECORD lpBuffer, |
| 992 | DWORD nLength, LPDWORD lpNumberOfEventsRead) |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 993 | { |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 994 | struct read_console_input_request req; |
| 995 | int len; |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 996 | |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 997 | if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hConsoleInput, |
| 998 | K32OBJ_CONSOLE, GENERIC_READ )) == -1) |
| 999 | return FALSE; |
| 1000 | req.count = nLength; |
| 1001 | req.flush = 1; |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 1002 | |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 1003 | /* loop until we get at least one event */ |
| 1004 | for (;;) |
| 1005 | { |
| 1006 | CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) ); |
| 1007 | if (CLIENT_WaitReply( &len, NULL, 1, lpBuffer, nLength * sizeof(*lpBuffer) )) |
| 1008 | return FALSE; |
| 1009 | assert( !(len % sizeof(INPUT_RECORD)) ); |
| 1010 | if (len) break; |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 1011 | CONSOLE_get_input(hConsoleInput,TRUE); |
| 1012 | /*WaitForSingleObject( hConsoleInput, INFINITE32 );*/ |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1013 | } |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 1014 | if (lpNumberOfEventsRead) *lpNumberOfEventsRead = len / sizeof(INPUT_RECORD); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1015 | return TRUE; |
| 1016 | } |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1017 | |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 1018 | |
| 1019 | /*********************************************************************** |
| 1020 | * ReadConsoleInput32W (KERNEL32.570) |
| 1021 | */ |
| 1022 | BOOL32 WINAPI ReadConsoleInput32W( HANDLE32 handle, LPINPUT_RECORD buffer, |
| 1023 | DWORD count, LPDWORD read ) |
| 1024 | { |
| 1025 | /* FIXME: Fix this if we get UNICODE input. */ |
| 1026 | return ReadConsoleInput32A( handle, buffer, count, read ); |
| 1027 | } |
| 1028 | |
| 1029 | |
| 1030 | /*********************************************************************** |
| 1031 | * FlushConsoleInputBuffer (KERNEL32.132) |
| 1032 | */ |
| 1033 | BOOL32 WINAPI FlushConsoleInputBuffer( HANDLE32 handle ) |
| 1034 | { |
| 1035 | struct read_console_input_request req; |
| 1036 | int len; |
| 1037 | |
| 1038 | if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, |
| 1039 | K32OBJ_CONSOLE, GENERIC_READ )) == -1) |
| 1040 | return FALSE; |
| 1041 | req.count = -1; /* get all records */ |
| 1042 | req.flush = 1; |
| 1043 | CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) ); |
| 1044 | return !CLIENT_WaitReply( &len, NULL, 0 ); |
| 1045 | } |
| 1046 | |
| 1047 | |
| 1048 | /*********************************************************************** |
| 1049 | * PeekConsoleInputA (KERNEL32.550) |
| 1050 | * |
| 1051 | * Gets 'count' first events (or less) from input queue. |
| 1052 | * |
| 1053 | * Does not need a complex console. |
| 1054 | */ |
| 1055 | BOOL32 WINAPI PeekConsoleInput32A( HANDLE32 handle, LPINPUT_RECORD buffer, |
| 1056 | DWORD count, LPDWORD read ) |
| 1057 | { |
| 1058 | struct read_console_input_request req; |
| 1059 | int len; |
| 1060 | |
| 1061 | if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, |
| 1062 | K32OBJ_CONSOLE, GENERIC_READ )) == -1) |
| 1063 | return FALSE; |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 1064 | |
| 1065 | CONSOLE_get_input(handle,FALSE); |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 1066 | req.count = count; |
| 1067 | req.flush = 0; |
| 1068 | |
| 1069 | CLIENT_SendRequest( REQ_READ_CONSOLE_INPUT, -1, 1, &req, sizeof(req) ); |
| 1070 | if (CLIENT_WaitReply( &len, NULL, 1, buffer, count * sizeof(*buffer) )) |
| 1071 | return FALSE; |
| 1072 | assert( !(len % sizeof(INPUT_RECORD)) ); |
| 1073 | if (read) *read = len / sizeof(INPUT_RECORD); |
| 1074 | return TRUE; |
| 1075 | } |
| 1076 | |
| 1077 | |
| 1078 | /*********************************************************************** |
| 1079 | * PeekConsoleInputW (KERNEL32.551) |
| 1080 | */ |
| 1081 | BOOL32 WINAPI PeekConsoleInput32W(HANDLE32 hConsoleInput, |
| 1082 | LPINPUT_RECORD pirBuffer, |
| 1083 | DWORD cInRecords, |
| 1084 | LPDWORD lpcRead) |
| 1085 | { |
| 1086 | /* FIXME: Hmm. Fix this if we get UNICODE input. */ |
| 1087 | return PeekConsoleInput32A(hConsoleInput,pirBuffer,cInRecords,lpcRead); |
| 1088 | } |
| 1089 | |
| 1090 | |
| 1091 | /****************************************************************************** |
| 1092 | * WriteConsoleInput32A [KERNEL32.730] Write data to a console input buffer |
| 1093 | * |
| 1094 | */ |
| 1095 | BOOL32 WINAPI WriteConsoleInput32A( HANDLE32 handle, INPUT_RECORD *buffer, |
| 1096 | DWORD count, LPDWORD written ) |
| 1097 | { |
| 1098 | struct write_console_input_request req; |
| 1099 | struct write_console_input_reply reply; |
| 1100 | |
| 1101 | if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), handle, |
| 1102 | K32OBJ_CONSOLE, GENERIC_WRITE )) == -1) |
| 1103 | return FALSE; |
| 1104 | req.count = count; |
| 1105 | CLIENT_SendRequest( REQ_WRITE_CONSOLE_INPUT, -1, 2, &req, sizeof(req), |
| 1106 | buffer, count * sizeof(*buffer) ); |
| 1107 | if (CLIENT_WaitSimpleReply( &reply, sizeof(reply), NULL )) return FALSE; |
| 1108 | if (written) *written = reply.written; |
| 1109 | return TRUE; |
| 1110 | } |
| 1111 | |
| 1112 | |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1113 | /*********************************************************************** |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1114 | * SetConsoleTitle32A (KERNEL32.476) |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1115 | * |
| 1116 | * Sets the console title. |
| 1117 | * |
| 1118 | * We do not necessarily need to create a complex console for that, |
| 1119 | * but should remember the title and set it on creation of the latter. |
| 1120 | * (not fixed at this time). |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1121 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1122 | BOOL32 WINAPI SetConsoleTitle32A(LPCSTR title) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1123 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1124 | #if 0 |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1125 | PDB32 *pdb = PROCESS_Current(); |
| 1126 | CONSOLE *console; |
| 1127 | DWORD written; |
| 1128 | char titleformat[]="\033]2;%s\a"; /*this should work for xterms*/ |
| 1129 | LPSTR titlestring; |
| 1130 | BOOL32 ret=FALSE; |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 1131 | |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1132 | TRACE(console,"(%s)\n",title); |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 1133 | |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1134 | console = (CONSOLE *)pdb->console; |
| 1135 | if (!console) |
| 1136 | return FALSE; |
| 1137 | if(console->title) /* Free old title, if there is one */ |
| 1138 | HeapFree( SystemHeap, 0, console->title ); |
| 1139 | console->title = (LPSTR)HeapAlloc(SystemHeap, 0,strlen(title)+1); |
| 1140 | if(console->title) strcpy(console->title,title); |
| 1141 | titlestring = HeapAlloc(GetProcessHeap(), 0,strlen(title)+strlen(titleformat)+1); |
| 1142 | if (!titlestring) { |
| 1143 | K32OBJ_DecCount(&console->header); |
| 1144 | return FALSE; |
| 1145 | } |
| 1146 | |
| 1147 | sprintf(titlestring,titleformat,title); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1148 | #if 0 |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 1149 | /* only set title for complex console (own xterm) */ |
| 1150 | if (console->pid != -1) { |
| 1151 | WriteFile(GetStdHandle(STD_OUTPUT_HANDLE),titlestring,strlen(titlestring),&written,NULL); |
| 1152 | if (written == strlen(titlestring)) |
| 1153 | ret =TRUE; |
| 1154 | } else |
| 1155 | ret = TRUE; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1156 | #endif |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1157 | HeapFree( GetProcessHeap(), 0, titlestring ); |
| 1158 | K32OBJ_DecCount(&console->header); |
| 1159 | return ret; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1160 | |
| 1161 | |
| 1162 | |
| 1163 | #endif |
| 1164 | |
| 1165 | struct set_console_info_request req; |
| 1166 | struct get_console_info_reply info; |
| 1167 | HANDLE32 hcon; |
| 1168 | DWORD written; |
| 1169 | |
| 1170 | if ((hcon = CreateFile32A( "CONOUT$", GENERIC_READ|GENERIC_WRITE, 0, NULL, |
| 1171 | OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE32) |
| 1172 | return FALSE; |
| 1173 | if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hcon, |
| 1174 | K32OBJ_CONSOLE, GENERIC_WRITE )) == -1) |
| 1175 | goto error; |
| 1176 | req.mask = SET_CONSOLE_INFO_TITLE; |
| 1177 | CLIENT_SendRequest( REQ_SET_CONSOLE_INFO, -1, 2, &req, sizeof(req), |
| 1178 | title, strlen(title)+1 ); |
| 1179 | if (CLIENT_WaitReply( NULL, NULL, 0 )) goto error; |
| 1180 | if (CONSOLE_GetInfo( hcon, &info ) && info.pid) |
| 1181 | { |
| 1182 | /* only set title for complex console (own xterm) */ |
| 1183 | WriteFile( hcon, "\033]2;", 4, &written, NULL ); |
| 1184 | WriteFile( hcon, title, strlen(title), &written, NULL ); |
| 1185 | WriteFile( hcon, "\a", 1, &written, NULL ); |
| 1186 | } |
| 1187 | return TRUE; |
| 1188 | error: |
| 1189 | CloseHandle( hcon ); |
| 1190 | return FALSE; |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1191 | } |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1192 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1193 | |
| 1194 | /****************************************************************************** |
| 1195 | * SetConsoleTitle32W [KERNEL32.477] Sets title bar string for console |
| 1196 | * |
| 1197 | * PARAMS |
| 1198 | * title [I] Address of new title |
| 1199 | * |
| 1200 | * NOTES |
| 1201 | * This should not be calling the A version |
| 1202 | * |
| 1203 | * RETURNS |
| 1204 | * Success: TRUE |
| 1205 | * Failure: FALSE |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1206 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1207 | BOOL32 WINAPI SetConsoleTitle32W( LPCWSTR title ) |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1208 | { |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 1209 | BOOL32 ret; |
| 1210 | |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1211 | LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title ); |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 1212 | ret = SetConsoleTitle32A(titleA); |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 1213 | HeapFree( GetProcessHeap(), 0, titleA ); |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 1214 | return ret; |
Alexandre Julliard | b1bac32 | 1996-12-15 19:45:59 +0000 | [diff] [blame] | 1215 | } |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 1216 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1217 | /****************************************************************************** |
| 1218 | * SetConsoleCursorPosition [KERNEL32.627] |
| 1219 | * Sets the cursor position in console |
| 1220 | * |
| 1221 | * PARAMS |
| 1222 | * hConsoleOutput [I] Handle of console screen buffer |
| 1223 | * dwCursorPosition [I] New cursor position coordinates |
| 1224 | * |
| 1225 | * RETURNS STD |
| 1226 | */ |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1227 | BOOL32 WINAPI SetConsoleCursorPosition( HANDLE32 hcon, COORD pos ) |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1228 | { |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1229 | char xbuf[20]; |
| 1230 | DWORD xlen; |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 1231 | |
Marcus Meissner | 03f10f4 | 1999-01-26 10:08:36 +0000 | [diff] [blame] | 1232 | /* make console complex only if we change lines, not just in the line */ |
| 1233 | if (pos.y) |
| 1234 | CONSOLE_make_complex(hcon); |
| 1235 | |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1236 | TRACE(console, "%d (%dx%d)\n", hcon, pos.x , pos.y ); |
| 1237 | /* x are columns, y rows */ |
Marcus Meissner | 03f10f4 | 1999-01-26 10:08:36 +0000 | [diff] [blame] | 1238 | if (pos.y) |
| 1239 | /* full screen cursor absolute positioning */ |
| 1240 | sprintf(xbuf,"%c[%d;%dH", 0x1B, pos.y+1, pos.x+1); |
| 1241 | else |
| 1242 | /* relative cursor positioning in line (\r to go to 0) */ |
| 1243 | sprintf(xbuf,"\r%c[%dC", 0x1B, pos.x); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1244 | /* FIXME: store internal if we start using own console buffers */ |
| 1245 | WriteFile(hcon,xbuf,strlen(xbuf),&xlen,NULL); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1246 | return TRUE; |
| 1247 | } |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1248 | |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 1249 | /*********************************************************************** |
| 1250 | * GetNumberOfConsoleInputEvents (KERNEL32.246) |
| 1251 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1252 | BOOL32 WINAPI GetNumberOfConsoleInputEvents(HANDLE32 hcon,LPDWORD nrofevents) |
| 1253 | { |
Marcus Meissner | a2ca7b9 | 1999-02-05 09:32:39 +0000 | [diff] [blame] | 1254 | CONSOLE_get_input(hcon,FALSE); |
| 1255 | *nrofevents = 1; /* UMM */ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1256 | return TRUE; |
Alexandre Julliard | 23946ad | 1997-06-16 17:43:53 +0000 | [diff] [blame] | 1257 | } |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1258 | |
| 1259 | /*********************************************************************** |
| 1260 | * GetNumberOfConsoleMouseButtons (KERNEL32.358) |
| 1261 | */ |
| 1262 | BOOL32 WINAPI GetNumberOfConsoleMouseButtons(LPDWORD nrofbuttons) |
| 1263 | { |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1264 | FIXME(console,"(%p): stub\n", nrofbuttons); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1265 | *nrofbuttons = 2; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1266 | return TRUE; |
| 1267 | } |
| 1268 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1269 | /****************************************************************************** |
| 1270 | * GetConsoleCursorInfo32 [KERNEL32.296] Gets size and visibility of console |
| 1271 | * |
| 1272 | * PARAMS |
| 1273 | * hcon [I] Handle to console screen buffer |
| 1274 | * cinfo [O] Address of cursor information |
| 1275 | * |
| 1276 | * RETURNS |
| 1277 | * Success: TRUE |
| 1278 | * Failure: FALSE |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1279 | */ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1280 | BOOL32 WINAPI GetConsoleCursorInfo32( HANDLE32 hcon, |
| 1281 | LPCONSOLE_CURSOR_INFO cinfo ) |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1282 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1283 | struct get_console_info_reply reply; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1284 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1285 | if (!CONSOLE_GetInfo( hcon, &reply )) return FALSE; |
| 1286 | if (cinfo) |
| 1287 | { |
| 1288 | cinfo->dwSize = reply.cursor_size; |
| 1289 | cinfo->bVisible = reply.cursor_visible; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1290 | } |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1291 | return TRUE; |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1294 | |
| 1295 | /****************************************************************************** |
| 1296 | * SetConsoleCursorInfo32 [KERNEL32.626] Sets size and visibility of cursor |
| 1297 | * |
| 1298 | * RETURNS |
| 1299 | * Success: TRUE |
| 1300 | * Failure: FALSE |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1301 | */ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1302 | BOOL32 WINAPI SetConsoleCursorInfo32( |
| 1303 | HANDLE32 hcon, /* [in] Handle to console screen buffer */ |
| 1304 | LPCONSOLE_CURSOR_INFO cinfo) /* [in] Address of cursor information */ |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1305 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1306 | struct set_console_info_request req; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1307 | char buf[8]; |
| 1308 | DWORD xlen; |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1309 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1310 | if ((req.handle = HANDLE_GetServerHandle( PROCESS_Current(), hcon, |
| 1311 | K32OBJ_CONSOLE, GENERIC_WRITE )) == -1) |
| 1312 | return FALSE; |
| 1313 | CONSOLE_make_complex(hcon); |
| 1314 | sprintf(buf,"\033[?25%c",cinfo->bVisible?'h':'l'); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1315 | WriteFile(hcon,buf,strlen(buf),&xlen,NULL); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1316 | |
| 1317 | req.cursor_size = cinfo->dwSize; |
| 1318 | req.cursor_visible = cinfo->bVisible; |
| 1319 | req.mask = SET_CONSOLE_INFO_CURSOR; |
| 1320 | CLIENT_SendRequest( REQ_SET_CONSOLE_INFO, -1, 1, &req, sizeof(req) ); |
| 1321 | return !CLIENT_WaitReply( NULL, NULL, 0 ); |
Alexandre Julliard | 44ed71f | 1997-12-21 19:17:50 +0000 | [diff] [blame] | 1322 | } |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 1323 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1324 | |
| 1325 | /****************************************************************************** |
| 1326 | * SetConsoleWindowInfo [KERNEL32.634] Sets size and position of console |
| 1327 | * |
| 1328 | * RETURNS |
| 1329 | * Success: TRUE |
| 1330 | * Failure: FALSE |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 1331 | */ |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1332 | BOOL32 WINAPI SetConsoleWindowInfo( |
| 1333 | HANDLE32 hcon, /* [in] Handle to console screen buffer */ |
| 1334 | BOOL32 bAbsolute, /* [in] Coordinate type flag */ |
| 1335 | LPSMALL_RECT window) /* [in] Address of new window rectangle */ |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 1336 | { |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1337 | FIXME(console, "(%x,%d,%p): stub\n", hcon, bAbsolute, window); |
| 1338 | return TRUE; |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1341 | |
| 1342 | /****************************************************************************** |
| 1343 | * SetConsoleTextAttribute32 [KERNEL32.631] Sets colors for text |
| 1344 | * |
| 1345 | * Sets the foreground and background color attributes of characters |
| 1346 | * written to the screen buffer. |
| 1347 | * |
| 1348 | * RETURNS |
| 1349 | * Success: TRUE |
| 1350 | * Failure: FALSE |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 1351 | */ |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1352 | BOOL32 WINAPI SetConsoleTextAttribute32(HANDLE32 hConsoleOutput,WORD wAttr) |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 1353 | { |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1354 | const int colormap[8] = { |
| 1355 | 0,4,2,6, |
| 1356 | 1,5,3,7, |
| 1357 | }; |
| 1358 | DWORD xlen; |
| 1359 | char buffer[20]; |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1360 | |
Marcus Meissner | 8bc54b6 | 1998-12-14 14:48:09 +0000 | [diff] [blame] | 1361 | TRACE(console,"(%d,%d)\n",hConsoleOutput,wAttr); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1362 | sprintf(buffer,"%c[0;%s3%d;4%dm", |
| 1363 | 27, |
| 1364 | (wAttr & FOREGROUND_INTENSITY)?"1;":"", |
| 1365 | colormap[wAttr&7], |
| 1366 | colormap[(wAttr&0x70)>>4] |
| 1367 | ); |
| 1368 | WriteFile(hConsoleOutput,buffer,strlen(buffer),&xlen,NULL); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1369 | return TRUE; |
| 1370 | } |
| 1371 | |
| 1372 | |
| 1373 | /****************************************************************************** |
| 1374 | * SetConsoleScreenBufferSize [KERNEL32.630] Changes size of console |
| 1375 | * |
| 1376 | * PARAMS |
| 1377 | * hConsoleOutput [I] Handle to console screen buffer |
| 1378 | * dwSize [I] New size in character rows and cols |
| 1379 | * |
| 1380 | * RETURNS |
| 1381 | * Success: TRUE |
| 1382 | * Failure: FALSE |
| 1383 | */ |
| 1384 | BOOL32 WINAPI SetConsoleScreenBufferSize( HANDLE32 hConsoleOutput, |
| 1385 | COORD dwSize ) |
| 1386 | { |
| 1387 | FIXME(console, "(%d,%dx%d): stub\n",hConsoleOutput,dwSize.x,dwSize.y); |
| 1388 | return TRUE; |
| 1389 | } |
| 1390 | |
| 1391 | |
| 1392 | /****************************************************************************** |
| 1393 | * FillConsoleOutputCharacterA [KERNEL32.242] |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1394 | * |
| 1395 | * PARAMS |
| 1396 | * hConsoleOutput [I] Handle to screen buffer |
| 1397 | * cCharacter [I] Character to write |
| 1398 | * nLength [I] Number of cells to write to |
| 1399 | * dwCoord [I] Coords of first cell |
| 1400 | * lpNumCharsWritten [O] Pointer to number of cells written |
| 1401 | * |
| 1402 | * RETURNS |
| 1403 | * Success: TRUE |
| 1404 | * Failure: FALSE |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1405 | */ |
| 1406 | BOOL32 WINAPI FillConsoleOutputCharacterA( |
| 1407 | HANDLE32 hConsoleOutput, |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1408 | BYTE cCharacter, |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1409 | DWORD nLength, |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1410 | COORD dwCoord, |
| 1411 | LPDWORD lpNumCharsWritten) |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1412 | { |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1413 | long count; |
| 1414 | DWORD xlen; |
| 1415 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1416 | SetConsoleCursorPosition(hConsoleOutput,dwCoord); |
| 1417 | for(count=0;count<nLength;count++) |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1418 | WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1419 | *lpNumCharsWritten = nLength; |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1420 | return TRUE; |
| 1421 | } |
| 1422 | |
| 1423 | |
| 1424 | /****************************************************************************** |
| 1425 | * FillConsoleOutputCharacterW [KERNEL32.243] Writes characters to console |
| 1426 | * |
| 1427 | * PARAMS |
| 1428 | * hConsoleOutput [I] Handle to screen buffer |
| 1429 | * cCharacter [I] Character to write |
| 1430 | * nLength [I] Number of cells to write to |
| 1431 | * dwCoord [I] Coords of first cell |
| 1432 | * lpNumCharsWritten [O] Pointer to number of cells written |
| 1433 | * |
| 1434 | * RETURNS |
| 1435 | * Success: TRUE |
| 1436 | * Failure: FALSE |
| 1437 | */ |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1438 | BOOL32 WINAPI FillConsoleOutputCharacterW(HANDLE32 hConsoleOutput, |
| 1439 | WCHAR cCharacter, |
| 1440 | DWORD nLength, |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1441 | COORD dwCoord, |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1442 | LPDWORD lpNumCharsWritten) |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1443 | { |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1444 | long count; |
| 1445 | DWORD xlen; |
| 1446 | |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1447 | SetConsoleCursorPosition(hConsoleOutput,dwCoord); |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1448 | /* FIXME: not quite correct ... but the lower part of UNICODE char comes |
| 1449 | * first |
| 1450 | */ |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1451 | for(count=0;count<nLength;count++) |
Marcus Meissner | 537772a | 1998-12-09 16:37:04 +0000 | [diff] [blame] | 1452 | WriteFile(hConsoleOutput,&cCharacter,1,&xlen,NULL); |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1453 | *lpNumCharsWritten = nLength; |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1454 | return TRUE; |
| 1455 | } |
| 1456 | |
| 1457 | |
| 1458 | /****************************************************************************** |
| 1459 | * FillConsoleOutputAttribute [KERNEL32.241] Sets attributes for console |
| 1460 | * |
| 1461 | * PARAMS |
| 1462 | * hConsoleOutput [I] Handle to screen buffer |
| 1463 | * wAttribute [I] Color attribute to write |
| 1464 | * nLength [I] Number of cells to write to |
| 1465 | * dwCoord [I] Coords of first cell |
| 1466 | * lpNumAttrsWritten [O] Pointer to number of cells written |
| 1467 | * |
| 1468 | * RETURNS |
| 1469 | * Success: TRUE |
| 1470 | * Failure: FALSE |
| 1471 | */ |
| 1472 | BOOL32 WINAPI FillConsoleOutputAttribute( HANDLE32 hConsoleOutput, |
| 1473 | WORD wAttribute, DWORD nLength, COORD dwCoord, |
| 1474 | LPDWORD lpNumAttrsWritten) |
| 1475 | { |
| 1476 | FIXME(console, "(%d,%d,%ld,%dx%d,%p): stub\n", hConsoleOutput, |
| 1477 | wAttribute,nLength,dwCoord.x,dwCoord.y,lpNumAttrsWritten); |
| 1478 | *lpNumAttrsWritten = nLength; |
| 1479 | return TRUE; |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 1482 | /****************************************************************************** |
| 1483 | * ReadConsoleOutputCharacter32A [KERNEL32.573] |
| 1484 | * |
| 1485 | * BUGS |
| 1486 | * Unimplemented |
| 1487 | */ |
| 1488 | BOOL32 WINAPI ReadConsoleOutputCharacter32A(HANDLE32 hConsoleOutput, |
| 1489 | LPSTR lpstr, DWORD dword, COORD coord, LPDWORD lpdword) |
| 1490 | { |
| 1491 | FIXME(console, "(%d,%p,%ld,%dx%d,%p): stub\n", hConsoleOutput,lpstr, |
| 1492 | dword,coord.x,coord.y,lpdword); |
| 1493 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 1494 | return FALSE; |
| 1495 | } |
Alexandre Julliard | 642d313 | 1998-07-12 19:29:36 +0000 | [diff] [blame] | 1496 | |
| 1497 | |
| 1498 | /****************************************************************************** |
| 1499 | * ScrollConsoleScreenBuffer [KERNEL32.612] |
| 1500 | * |
| 1501 | * BUGS |
| 1502 | * Unimplemented |
| 1503 | */ |
| 1504 | BOOL32 WINAPI ScrollConsoleScreenBuffer( HANDLE32 hConsoleOutput, |
| 1505 | LPSMALL_RECT lpScrollRect, LPSMALL_RECT lpClipRect, |
| 1506 | COORD dwDestOrigin, LPCHAR_INFO lpFill) |
| 1507 | { |
| 1508 | FIXME(console, "(%d,%p,%p,%dx%d,%p): stub\n", hConsoleOutput,lpScrollRect, |
| 1509 | lpClipRect,dwDestOrigin.x,dwDestOrigin.y,lpFill); |
| 1510 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED); |
| 1511 | return FALSE; |
| 1512 | } |