2001-01-11 00:59:25 +01:00
|
|
|
/*
|
|
|
|
* msvcrt.dll console functions
|
|
|
|
*
|
|
|
|
* Copyright 2000 Jon Griffiths
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
2001-01-11 00:59:25 +01:00
|
|
|
* Note: init and free don't need MT locking since they are called at DLL
|
2011-08-02 22:20:32 +02:00
|
|
|
* (de)attachment time, which is synchronised for us
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2004-06-25 03:19:15 +02:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
#include "msvcrt.h"
|
2010-11-07 19:11:38 +01:00
|
|
|
#include "winnls.h"
|
2001-01-11 00:59:25 +01:00
|
|
|
#include "wincon.h"
|
2002-02-21 21:22:00 +01:00
|
|
|
#include "mtdll.h"
|
2002-01-22 01:57:16 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
/* MT */
|
2020-11-19 11:33:51 +01:00
|
|
|
#define LOCK_CONSOLE _lock(_CONIO_LOCK)
|
|
|
|
#define UNLOCK_CONSOLE _unlock(_CONIO_LOCK)
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2021-03-12 14:02:39 +01:00
|
|
|
static HANDLE MSVCRT_console_in;
|
|
|
|
static HANDLE MSVCRT_console_out;
|
2020-11-30 14:37:09 +01:00
|
|
|
static int __MSVCRT_console_buffer = EOF;
|
2020-11-30 14:37:05 +01:00
|
|
|
static wchar_t __MSVCRT_console_buffer_w = WEOF;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2021-03-12 14:02:39 +01:00
|
|
|
/* INTERNAL: Initialise console handles, _CONIO_LOCK must be held */
|
|
|
|
static HANDLE msvcrt_input_console(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2021-03-12 14:02:39 +01:00
|
|
|
if (!MSVCRT_console_in)
|
|
|
|
{
|
|
|
|
MSVCRT_console_in = CreateFileA("CONIN$", GENERIC_WRITE|GENERIC_READ,
|
|
|
|
FILE_SHARE_WRITE|FILE_SHARE_READ,
|
|
|
|
NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
if (MSVCRT_console_in == INVALID_HANDLE_VALUE)
|
|
|
|
WARN("Input console handle initialization failed!\n");
|
|
|
|
}
|
|
|
|
return MSVCRT_console_in;
|
|
|
|
}
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2021-03-12 14:02:39 +01:00
|
|
|
static HANDLE msvcrt_output_console(void)
|
|
|
|
{
|
|
|
|
if (!MSVCRT_console_out)
|
|
|
|
{
|
|
|
|
MSVCRT_console_out = CreateFileA("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE,
|
|
|
|
NULL, OPEN_EXISTING, 0, NULL);
|
|
|
|
if (MSVCRT_console_out == INVALID_HANDLE_VALUE)
|
|
|
|
WARN("Output console handle initialization failed!\n");
|
|
|
|
}
|
|
|
|
return MSVCRT_console_out;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* INTERNAL: Free console handles */
|
2001-04-10 23:16:07 +02:00
|
|
|
void msvcrt_free_console(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
TRACE(":Closing console handles\n");
|
|
|
|
CloseHandle(MSVCRT_console_in);
|
|
|
|
CloseHandle(MSVCRT_console_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _cputs (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _cputs(const char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
DWORD count;
|
2015-06-14 14:31:01 +02:00
|
|
|
int len, retval = -1;
|
|
|
|
|
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL)) return -1;
|
|
|
|
len = strlen(str);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
LOCK_CONSOLE;
|
2021-03-12 14:02:39 +01:00
|
|
|
if (WriteConsoleA(msvcrt_output_console(), str, len, &count, NULL)
|
2015-06-14 14:31:01 +02:00
|
|
|
&& count == len)
|
2001-01-11 00:59:25 +01:00
|
|
|
retval = 0;
|
|
|
|
UNLOCK_CONSOLE;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-11-02 22:03:28 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _cputws (MSVCRT.@)
|
|
|
|
*/
|
2020-11-27 14:16:49 +01:00
|
|
|
int CDECL _cputws(const wchar_t* str)
|
2010-11-02 22:03:28 +01:00
|
|
|
{
|
|
|
|
DWORD count;
|
2015-06-14 14:31:08 +02:00
|
|
|
int len, retval = -1;
|
|
|
|
|
|
|
|
if (!MSVCRT_CHECK_PMT(str != NULL)) return -1;
|
2020-12-03 19:10:54 +01:00
|
|
|
len = wcslen(str);
|
2010-11-02 22:03:28 +01:00
|
|
|
|
|
|
|
LOCK_CONSOLE;
|
2021-03-12 14:02:39 +01:00
|
|
|
if (WriteConsoleW(msvcrt_output_console(), str, len, &count, NULL)
|
2015-06-14 14:31:08 +02:00
|
|
|
&& count == len)
|
2010-11-02 22:03:28 +01:00
|
|
|
retval = 0;
|
|
|
|
UNLOCK_CONSOLE;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-05-23 20:04:36 +02:00
|
|
|
#define NORMAL_CHAR 0
|
|
|
|
#define ALT_CHAR 1
|
|
|
|
#define CTRL_CHAR 2
|
|
|
|
#define SHIFT_CHAR 3
|
|
|
|
|
2015-06-14 14:31:14 +02:00
|
|
|
static const struct {unsigned short vk; unsigned char ch[4][2];} enh_map[] = {
|
2008-05-23 20:04:36 +02:00
|
|
|
{0x47, {{0xE0, 0x47}, {0x00, 0x97}, {0xE0, 0x77}, {0xE0, 0x47}}},
|
|
|
|
{0x48, {{0xE0, 0x48}, {0x00, 0x98}, {0xE0, 0x8D}, {0xE0, 0x48}}},
|
|
|
|
{0x49, {{0xE0, 0x49}, {0x00, 0x99}, {0xE0, 0x86}, {0xE0, 0x49}}},
|
|
|
|
{0x4B, {{0xE0, 0x4B}, {0x00, 0x9B}, {0xE0, 0x73}, {0xE0, 0x4B}}},
|
|
|
|
{0x4D, {{0xE0, 0x4D}, {0x00, 0x9D}, {0xE0, 0x74}, {0xE0, 0x4D}}},
|
|
|
|
{0x4F, {{0xE0, 0x4F}, {0x00, 0x9F}, {0xE0, 0x75}, {0xE0, 0x4F}}},
|
|
|
|
{0x50, {{0xE0, 0x50}, {0x00, 0xA0}, {0xE0, 0x91}, {0xE0, 0x50}}},
|
|
|
|
{0x51, {{0xE0, 0x51}, {0x00, 0xA1}, {0xE0, 0x76}, {0xE0, 0x51}}},
|
|
|
|
{0x52, {{0xE0, 0x52}, {0x00, 0xA2}, {0xE0, 0x92}, {0xE0, 0x52}}},
|
|
|
|
{0x53, {{0xE0, 0x53}, {0x00, 0xA3}, {0xE0, 0x93}, {0xE0, 0x53}}},
|
|
|
|
};
|
|
|
|
|
2015-06-14 14:31:14 +02:00
|
|
|
static BOOL handle_enhanced_keys(INPUT_RECORD *ir, unsigned char *ch1, unsigned char *ch2)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2018-07-26 00:05:52 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(enh_map); i++)
|
2015-06-14 14:31:14 +02:00
|
|
|
{
|
|
|
|
if (ir->Event.KeyEvent.wVirtualScanCode == enh_map[i].vk)
|
|
|
|
{
|
|
|
|
unsigned idx;
|
|
|
|
|
|
|
|
if (ir->Event.KeyEvent.dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))
|
|
|
|
idx = ALT_CHAR;
|
|
|
|
else if (ir->Event.KeyEvent.dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED) )
|
|
|
|
idx = CTRL_CHAR;
|
|
|
|
else if (ir->Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED)
|
|
|
|
idx = SHIFT_CHAR;
|
|
|
|
else
|
|
|
|
idx = NORMAL_CHAR;
|
|
|
|
|
|
|
|
*ch1 = enh_map[i].ch[idx][0];
|
|
|
|
*ch2 = enh_map[i].ch[idx][1];
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unmapped char keyState=%x vk=%x\n",
|
|
|
|
ir->Event.KeyEvent.dwControlKeyState, ir->Event.KeyEvent.wVirtualScanCode);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
2015-06-11 17:54:13 +02:00
|
|
|
* _getch_nolock (MSVCR80.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2015-06-11 17:54:13 +02:00
|
|
|
int CDECL _getch_nolock(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-11-30 14:37:09 +01:00
|
|
|
int retval = EOF;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2020-11-30 14:37:09 +01:00
|
|
|
if (__MSVCRT_console_buffer != EOF)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
retval = __MSVCRT_console_buffer;
|
2020-11-30 14:37:09 +01:00
|
|
|
__MSVCRT_console_buffer = EOF;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
INPUT_RECORD ir;
|
|
|
|
DWORD count;
|
|
|
|
DWORD mode = 0;
|
|
|
|
|
2021-03-12 14:02:39 +01:00
|
|
|
GetConsoleMode(msvcrt_input_console(), &mode);
|
2001-01-11 00:59:25 +01:00
|
|
|
if(mode)
|
2021-03-12 14:02:39 +01:00
|
|
|
SetConsoleMode(msvcrt_input_console(), 0);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
|
|
|
do {
|
2021-03-12 14:02:39 +01:00
|
|
|
if (ReadConsoleInputA(msvcrt_input_console(), &ir, 1, &count))
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
/* Only interested in ASCII chars */
|
|
|
|
if (ir.EventType == KEY_EVENT &&
|
2008-05-23 20:04:36 +02:00
|
|
|
ir.Event.KeyEvent.bKeyDown)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2015-06-14 14:31:14 +02:00
|
|
|
unsigned char ch1, ch2;
|
|
|
|
|
2008-05-23 20:04:36 +02:00
|
|
|
if (ir.Event.KeyEvent.uChar.AsciiChar)
|
|
|
|
{
|
|
|
|
retval = ir.Event.KeyEvent.uChar.AsciiChar;
|
|
|
|
break;
|
|
|
|
}
|
2015-06-14 14:31:14 +02:00
|
|
|
|
|
|
|
if (handle_enhanced_keys(&ir, &ch1, &ch2))
|
2008-05-23 20:04:36 +02:00
|
|
|
{
|
2015-06-14 14:31:14 +02:00
|
|
|
retval = ch1;
|
|
|
|
__MSVCRT_console_buffer = ch2;
|
2008-05-23 20:04:36 +02:00
|
|
|
break;
|
|
|
|
}
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
} while(1);
|
|
|
|
if (mode)
|
2021-03-12 14:02:39 +01:00
|
|
|
SetConsoleMode(msvcrt_input_console(), mode);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-06-11 17:54:13 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _getch (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _getch(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
LOCK_CONSOLE;
|
|
|
|
ret = _getch_nolock();
|
|
|
|
UNLOCK_CONSOLE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-06-14 14:31:14 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _getwch_nolock (MSVCR80.@)
|
|
|
|
*/
|
2020-11-27 14:16:49 +01:00
|
|
|
wchar_t CDECL _getwch_nolock(void)
|
2015-06-14 14:31:14 +02:00
|
|
|
{
|
2020-11-30 14:37:05 +01:00
|
|
|
wchar_t retval = WEOF;
|
2015-06-14 14:31:14 +02:00
|
|
|
|
2020-11-30 14:37:05 +01:00
|
|
|
if (__MSVCRT_console_buffer_w != WEOF)
|
2015-06-14 14:31:14 +02:00
|
|
|
{
|
|
|
|
retval = __MSVCRT_console_buffer_w;
|
2020-11-30 14:37:05 +01:00
|
|
|
__MSVCRT_console_buffer_w = WEOF;
|
2015-06-14 14:31:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
INPUT_RECORD ir;
|
|
|
|
DWORD count;
|
|
|
|
DWORD mode = 0;
|
|
|
|
|
2021-03-12 14:02:39 +01:00
|
|
|
GetConsoleMode(msvcrt_input_console(), &mode);
|
2015-06-14 14:31:14 +02:00
|
|
|
if(mode)
|
2021-03-12 14:02:39 +01:00
|
|
|
SetConsoleMode(msvcrt_input_console(), 0);
|
2015-06-14 14:31:14 +02:00
|
|
|
|
|
|
|
do {
|
2021-03-12 14:02:39 +01:00
|
|
|
if (ReadConsoleInputW(msvcrt_input_console(), &ir, 1, &count))
|
2015-06-14 14:31:14 +02:00
|
|
|
{
|
|
|
|
/* Only interested in ASCII chars */
|
|
|
|
if (ir.EventType == KEY_EVENT &&
|
|
|
|
ir.Event.KeyEvent.bKeyDown)
|
|
|
|
{
|
|
|
|
unsigned char ch1, ch2;
|
|
|
|
|
|
|
|
if (ir.Event.KeyEvent.uChar.UnicodeChar)
|
|
|
|
{
|
|
|
|
retval = ir.Event.KeyEvent.uChar.UnicodeChar;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handle_enhanced_keys(&ir, &ch1, &ch2))
|
|
|
|
{
|
|
|
|
retval = ch1;
|
|
|
|
__MSVCRT_console_buffer_w = ch2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
} while(1);
|
|
|
|
if (mode)
|
2021-03-12 14:02:39 +01:00
|
|
|
SetConsoleMode(msvcrt_input_console(), mode);
|
2015-06-14 14:31:14 +02:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _getwch (MSVCRT.@)
|
|
|
|
*/
|
2020-11-27 14:16:49 +01:00
|
|
|
wchar_t CDECL _getwch(void)
|
2015-06-14 14:31:14 +02:00
|
|
|
{
|
2020-11-27 14:16:49 +01:00
|
|
|
wchar_t ret;
|
2015-06-14 14:31:14 +02:00
|
|
|
|
|
|
|
LOCK_CONSOLE;
|
|
|
|
ret = _getwch_nolock();
|
|
|
|
UNLOCK_CONSOLE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
2015-06-11 17:54:28 +02:00
|
|
|
* _putch_nolock (MSVCR80.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2015-06-11 17:54:28 +02:00
|
|
|
int CDECL _putch_nolock(int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
DWORD count;
|
2021-03-12 14:02:39 +01:00
|
|
|
if (WriteConsoleA(msvcrt_output_console(), &c, 1, &count, NULL) && count == 1)
|
2015-06-11 17:54:28 +02:00
|
|
|
return c;
|
2020-11-30 14:37:09 +01:00
|
|
|
return EOF;
|
2015-06-11 17:54:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _putch (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _putch(int c)
|
|
|
|
{
|
|
|
|
LOCK_CONSOLE;
|
|
|
|
c = _putch_nolock(c);
|
|
|
|
UNLOCK_CONSOLE;
|
|
|
|
return c;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
2015-06-14 14:30:51 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _putwch_nolock (MSVCR80.@)
|
|
|
|
*/
|
2020-11-27 14:16:49 +01:00
|
|
|
wchar_t CDECL _putwch_nolock(wchar_t c)
|
2015-06-14 14:30:51 +02:00
|
|
|
{
|
|
|
|
DWORD count;
|
2021-03-12 14:02:39 +01:00
|
|
|
if (WriteConsoleW(msvcrt_output_console(), &c, 1, &count, NULL) && count==1)
|
2015-06-14 14:30:51 +02:00
|
|
|
return c;
|
2020-11-30 14:37:05 +01:00
|
|
|
return WEOF;
|
2015-06-14 14:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _putwch (MSVCRT.@)
|
|
|
|
*/
|
2020-11-27 14:16:49 +01:00
|
|
|
wchar_t CDECL _putwch(wchar_t c)
|
2015-06-14 14:30:51 +02:00
|
|
|
{
|
|
|
|
LOCK_CONSOLE;
|
|
|
|
c = _putwch_nolock(c);
|
|
|
|
UNLOCK_CONSOLE;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
2015-06-11 17:54:39 +02:00
|
|
|
* _getche_nolock (MSVCR80.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2015-06-11 17:54:39 +02:00
|
|
|
int CDECL _getche_nolock(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
int retval;
|
2015-06-11 17:54:39 +02:00
|
|
|
retval = _getch_nolock();
|
2020-11-30 14:37:09 +01:00
|
|
|
if (retval != EOF)
|
2015-06-11 17:54:39 +02:00
|
|
|
retval = _putch_nolock(retval);
|
2001-01-11 00:59:25 +01:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-06-11 17:54:39 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _getche (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _getche(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
LOCK_CONSOLE;
|
|
|
|
ret = _getche_nolock();
|
|
|
|
UNLOCK_CONSOLE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-06-14 14:31:23 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _getwche_nolock (MSVCR80.@)
|
|
|
|
*/
|
2020-11-27 14:16:49 +01:00
|
|
|
wchar_t CDECL _getwche_nolock(void)
|
2015-06-14 14:31:23 +02:00
|
|
|
{
|
2020-11-27 14:16:49 +01:00
|
|
|
wchar_t wch;
|
2015-06-14 14:31:23 +02:00
|
|
|
wch = _getch_nolock();
|
2020-11-30 14:37:05 +01:00
|
|
|
if (wch == WEOF)
|
2015-06-14 14:31:23 +02:00
|
|
|
return wch;
|
|
|
|
return _putwch_nolock(wch);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _getwche (MSVCRT.@)
|
|
|
|
*/
|
2020-11-27 14:16:49 +01:00
|
|
|
wchar_t CDECL _getwche(void)
|
2015-06-14 14:31:23 +02:00
|
|
|
{
|
2020-11-27 14:16:49 +01:00
|
|
|
wchar_t ret;
|
2015-06-14 14:31:23 +02:00
|
|
|
|
|
|
|
LOCK_CONSOLE;
|
|
|
|
ret = _getwche_nolock();
|
|
|
|
UNLOCK_CONSOLE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _cgets (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
char* CDECL _cgets(char* str)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
char *buf = str + 2;
|
2005-10-29 12:29:24 +02:00
|
|
|
DWORD got;
|
|
|
|
DWORD conmode = 0;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", str);
|
2001-01-11 00:59:25 +01:00
|
|
|
str[1] = 0; /* Length */
|
|
|
|
LOCK_CONSOLE;
|
2021-03-12 14:02:39 +01:00
|
|
|
GetConsoleMode(msvcrt_input_console(), &conmode);
|
|
|
|
SetConsoleMode(msvcrt_input_console(), ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT|ENABLE_PROCESSED_INPUT);
|
2005-10-29 12:29:24 +02:00
|
|
|
|
2021-03-12 14:02:39 +01:00
|
|
|
if(ReadConsoleA(msvcrt_input_console(), buf, str[0], &got, NULL)) {
|
2005-10-29 12:29:24 +02:00
|
|
|
if(buf[got-2] == '\r') {
|
|
|
|
buf[got-2] = 0;
|
|
|
|
str[1] = got-2;
|
|
|
|
}
|
|
|
|
else if(got == 1 && buf[got-1] == '\n') {
|
|
|
|
buf[0] = 0;
|
|
|
|
str[1] = 0;
|
|
|
|
}
|
|
|
|
else if(got == str[0] && buf[got-1] == '\r') {
|
|
|
|
buf[got-1] = 0;
|
|
|
|
str[1] = got-1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
str[1] = got;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
buf = NULL;
|
2021-03-12 14:02:39 +01:00
|
|
|
SetConsoleMode(msvcrt_input_console(), conmode);
|
2001-01-11 00:59:25 +01:00
|
|
|
UNLOCK_CONSOLE;
|
2005-10-29 12:29:24 +02:00
|
|
|
return buf;
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2015-06-11 17:54:44 +02:00
|
|
|
* _ungetch_nolock (MSVCRT.@)
|
2001-01-11 00:59:25 +01:00
|
|
|
*/
|
2015-06-11 17:54:44 +02:00
|
|
|
int CDECL _ungetch_nolock(int c)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2020-11-30 14:37:09 +01:00
|
|
|
int retval = EOF;
|
|
|
|
if (c != EOF && __MSVCRT_console_buffer == EOF)
|
2001-01-11 00:59:25 +01:00
|
|
|
retval = __MSVCRT_console_buffer = c;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2015-06-11 17:54:44 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _ungetch (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _ungetch(int c)
|
|
|
|
{
|
|
|
|
LOCK_CONSOLE;
|
|
|
|
c = _ungetch_nolock(c);
|
|
|
|
UNLOCK_CONSOLE;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2015-06-14 14:31:32 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _ungetwch_nolock (MSVCR80.@)
|
|
|
|
*/
|
2020-11-27 14:16:49 +01:00
|
|
|
wchar_t CDECL _ungetwch_nolock(wchar_t c)
|
2015-06-14 14:31:32 +02:00
|
|
|
{
|
2020-11-30 14:37:05 +01:00
|
|
|
wchar_t retval = WEOF;
|
|
|
|
if (c != WEOF && __MSVCRT_console_buffer_w == WEOF)
|
2015-06-14 14:31:32 +02:00
|
|
|
retval = __MSVCRT_console_buffer_w = c;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _ungetwch (MSVCRT.@)
|
|
|
|
*/
|
2020-11-27 14:16:49 +01:00
|
|
|
wchar_t CDECL _ungetwch(wchar_t c)
|
2015-06-14 14:31:32 +02:00
|
|
|
{
|
|
|
|
LOCK_CONSOLE;
|
|
|
|
c = _ungetwch_nolock(c);
|
|
|
|
UNLOCK_CONSOLE;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _kbhit (MSVCRT.@)
|
|
|
|
*/
|
2006-06-13 11:21:19 +02:00
|
|
|
int CDECL _kbhit(void)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
LOCK_CONSOLE;
|
2020-11-30 14:37:09 +01:00
|
|
|
if (__MSVCRT_console_buffer != EOF)
|
2001-01-11 00:59:25 +01:00
|
|
|
retval = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FIXME: There has to be a faster way than this in Win32.. */
|
|
|
|
INPUT_RECORD *ir = NULL;
|
|
|
|
DWORD count = 0, i;
|
|
|
|
|
2021-03-12 14:02:39 +01:00
|
|
|
GetNumberOfConsoleInputEvents(msvcrt_input_console(), &count);
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2020-12-01 13:51:32 +01:00
|
|
|
if (count && (ir = malloc(count * sizeof(INPUT_RECORD))) &&
|
2021-03-12 14:02:39 +01:00
|
|
|
PeekConsoleInputA(msvcrt_input_console(), ir, count, &count))
|
2001-01-11 00:59:25 +01:00
|
|
|
for(i = 0; i < count - 1; i++)
|
|
|
|
{
|
|
|
|
if (ir[i].EventType == KEY_EVENT &&
|
|
|
|
ir[i].Event.KeyEvent.bKeyDown &&
|
|
|
|
ir[i].Event.KeyEvent.uChar.AsciiChar)
|
|
|
|
{
|
|
|
|
retval = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-12-01 13:51:32 +01:00
|
|
|
free(ir);
|
2001-01-11 00:59:25 +01:00
|
|
|
}
|
|
|
|
UNLOCK_CONSOLE;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-04-20 14:42:26 +02:00
|
|
|
static int puts_clbk_console_a(void *ctx, int len, const char *str)
|
|
|
|
{
|
|
|
|
LOCK_CONSOLE;
|
2021-03-12 14:02:39 +01:00
|
|
|
if(!WriteConsoleA(msvcrt_output_console(), str, len, NULL, NULL))
|
2011-04-20 14:42:26 +02:00
|
|
|
len = -1;
|
|
|
|
UNLOCK_CONSOLE;
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2020-11-27 14:16:49 +01:00
|
|
|
static int puts_clbk_console_w(void *ctx, int len, const wchar_t *str)
|
2011-04-20 14:42:26 +02:00
|
|
|
{
|
|
|
|
LOCK_CONSOLE;
|
2021-03-12 14:02:39 +01:00
|
|
|
if(!WriteConsoleW(msvcrt_output_console(), str, len, NULL, NULL))
|
2011-04-20 14:42:26 +02:00
|
|
|
len = -1;
|
|
|
|
UNLOCK_CONSOLE;
|
|
|
|
return len;
|
|
|
|
}
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2010-11-07 19:11:38 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _vcprintf (MSVCRT.@)
|
|
|
|
*/
|
|
|
|
int CDECL _vcprintf(const char* format, __ms_va_list valist)
|
|
|
|
{
|
2015-11-03 19:40:36 +01:00
|
|
|
return pf_printf_a(puts_clbk_console_a, NULL, format, NULL, 0, arg_clbk_valist, NULL, &valist);
|
2010-11-07 19:11:38 +01:00
|
|
|
}
|
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* _cprintf (MSVCRT.@)
|
|
|
|
*/
|
2017-11-02 10:19:18 +01:00
|
|
|
int WINAPIV _cprintf(const char* format, ...)
|
2001-01-11 00:59:25 +01:00
|
|
|
{
|
2010-11-07 19:11:38 +01:00
|
|
|
int retval;
|
2009-01-02 21:43:58 +01:00
|
|
|
__ms_va_list valist;
|
2001-01-11 00:59:25 +01:00
|
|
|
|
2009-01-02 21:43:58 +01:00
|
|
|
__ms_va_start( valist, format );
|
2010-11-07 19:11:38 +01:00
|
|
|
retval = _vcprintf(format, valist);
|
|
|
|
__ms_va_end(valist);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _vcwprintf (MSVCRT.@)
|
|
|
|
*/
|
2020-11-27 14:16:49 +01:00
|
|
|
int CDECL _vcwprintf(const wchar_t* format, __ms_va_list valist)
|
2010-11-07 19:11:38 +01:00
|
|
|
{
|
2015-11-03 19:40:36 +01:00
|
|
|
return pf_printf_w(puts_clbk_console_w, NULL, format, NULL, 0, arg_clbk_valist, NULL, &valist);
|
2010-11-07 19:11:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _cwprintf (MSVCRT.@)
|
|
|
|
*/
|
2020-11-27 14:16:49 +01:00
|
|
|
int WINAPIV _cwprintf(const wchar_t* format, ...)
|
2010-11-07 19:11:38 +01:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
__ms_va_list valist;
|
|
|
|
|
|
|
|
__ms_va_start( valist, format );
|
|
|
|
retval = _vcwprintf(format, valist);
|
2009-01-02 21:43:58 +01:00
|
|
|
__ms_va_end(valist);
|
2010-11-07 19:11:38 +01:00
|
|
|
|
2001-01-11 00:59:25 +01:00
|
|
|
return retval;
|
|
|
|
}
|
2017-01-31 19:01:03 +01:00
|
|
|
|
2018-01-03 09:07:41 +01:00
|
|
|
#if _MSVCR_VER>=140
|
|
|
|
|
2017-01-31 19:01:03 +01:00
|
|
|
/*********************************************************************
|
2018-01-03 09:07:41 +01:00
|
|
|
* __conio_common_vcprintf (UCRTBASE.@)
|
2017-01-31 19:01:03 +01:00
|
|
|
*/
|
2020-11-30 14:37:24 +01:00
|
|
|
int CDECL __conio_common_vcprintf(unsigned __int64 options, const char* format,
|
2020-11-26 19:19:18 +01:00
|
|
|
_locale_t locale, __ms_va_list valist)
|
2017-01-31 19:01:03 +01:00
|
|
|
{
|
|
|
|
if (options & ~UCRTBASE_PRINTF_MASK)
|
|
|
|
FIXME("options %s not handled\n", wine_dbgstr_longlong(options));
|
|
|
|
return pf_printf_a(puts_clbk_console_a, NULL, format, locale,
|
|
|
|
options & UCRTBASE_PRINTF_MASK, arg_clbk_valist, NULL, &valist);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*********************************************************************
|
2018-01-03 09:07:41 +01:00
|
|
|
* __conio_common_vcwprintf (UCRTBASE.@)
|
2017-01-31 19:01:03 +01:00
|
|
|
*/
|
2020-11-30 14:37:24 +01:00
|
|
|
int CDECL __conio_common_vcwprintf(unsigned __int64 options, const wchar_t* format,
|
2020-11-26 19:19:18 +01:00
|
|
|
_locale_t locale, __ms_va_list valist)
|
2017-01-31 19:01:03 +01:00
|
|
|
{
|
|
|
|
if (options & ~UCRTBASE_PRINTF_MASK)
|
|
|
|
FIXME("options %s not handled\n", wine_dbgstr_longlong(options));
|
|
|
|
return pf_printf_w(puts_clbk_console_w, NULL, format, locale,
|
|
|
|
options & UCRTBASE_PRINTF_MASK, arg_clbk_valist, NULL, &valist);
|
|
|
|
}
|
2018-01-03 09:07:41 +01:00
|
|
|
|
|
|
|
#endif /* _MSVCR_VER>=140 */
|