mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-23 00:13:09 +00:00
1861448e6c
also rename wchar -> utf8 to avoid conflict with <wchar.h> (requires rebuild of workspace) (unfortunately copying history fails to "502 bad gateway"; had to delete old + add new independently) This was SVN commit r7340.
112 lines
2.6 KiB
C++
112 lines
2.6 KiB
C++
/* Copyright (c) 2010 Wildfire Games
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
* a copy of this software and associated documentation files (the
|
|
* "Software"), to deal in the Software without restriction, including
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
* the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included
|
|
* in all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
#include "precompiled.h"
|
|
#include "lib/sysdep/os/win/wposix/wterminal.h"
|
|
|
|
#include "lib/sysdep/os/win/wposix/wposix_internal.h"
|
|
#include "lib/sysdep/os/win/wposix/crt_posix.h" // _get_osfhandle
|
|
|
|
|
|
int ioctl(int fd, int op, int* data)
|
|
{
|
|
const HANDLE h = HANDLE_from_intptr(_get_osfhandle(fd));
|
|
|
|
switch(op)
|
|
{
|
|
case TIOCMGET:
|
|
/* TIOCM_* mapped directly to MS_*_ON */
|
|
GetCommModemStatus(h, (DWORD*)data);
|
|
break;
|
|
|
|
case TIOCMBIS:
|
|
/* only RTS supported */
|
|
if(*data & TIOCM_RTS)
|
|
EscapeCommFunction(h, SETRTS);
|
|
else
|
|
EscapeCommFunction(h, CLRRTS);
|
|
break;
|
|
|
|
case TIOCMIWAIT:
|
|
static DWORD mask;
|
|
DWORD new_mask = 0;
|
|
if(*data & TIOCM_CD)
|
|
new_mask |= EV_RLSD;
|
|
if(*data & TIOCM_CTS)
|
|
new_mask |= EV_CTS;
|
|
if(new_mask != mask)
|
|
SetCommMask(h, mask = new_mask);
|
|
WaitCommEvent(h, &mask, 0);
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
static HANDLE std_h[2] = { (HANDLE)((char*)0 + 3), (HANDLE)((char*)0 + 7) };
|
|
|
|
|
|
void _get_console()
|
|
{
|
|
AllocConsole();
|
|
}
|
|
|
|
void _hide_console()
|
|
{
|
|
FreeConsole();
|
|
}
|
|
|
|
|
|
int tcgetattr(int fd, struct termios* termios_p)
|
|
{
|
|
if(fd >= 2)
|
|
return -1;
|
|
HANDLE h = std_h[fd];
|
|
|
|
DWORD mode;
|
|
GetConsoleMode(h, &mode);
|
|
termios_p->c_lflag = mode & (ENABLE_ECHO_INPUT|ENABLE_LINE_INPUT);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
int tcsetattr(int fd, int /* optional_actions */, const struct termios* termios_p)
|
|
{
|
|
if(fd >= 2)
|
|
return -1;
|
|
HANDLE h = std_h[fd];
|
|
SetConsoleMode(h, (DWORD)termios_p->c_lflag);
|
|
FlushConsoleInputBuffer(h);
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
int poll(struct pollfd /* fds */[], int /* nfds */, int /* timeout */)
|
|
{
|
|
return -1;
|
|
}
|
|
|