2000-02-18 03:38:33 +08:00
|
|
|
/* fhandler_console.cc
|
|
|
|
|
2006-01-04 01:44:26 +08:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
2010-01-15 02:46:02 +08:00
|
|
|
2006, 2008, 2009, 2010 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2008-04-08 00:15:45 +08:00
|
|
|
#include "miscfuncs.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2009-03-24 20:18:34 +08:00
|
|
|
#include <wchar.h>
|
2000-07-28 01:30:51 +08:00
|
|
|
#include <wingdi.h>
|
|
|
|
#include <winuser.h>
|
2002-06-26 13:29:41 +08:00
|
|
|
#include <winnls.h>
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <ctype.h>
|
2000-09-08 10:56:55 +08:00
|
|
|
#include <sys/cygwin.h>
|
2006-07-03 23:29:10 +08:00
|
|
|
#include <cygwin/kd.h>
|
2000-08-22 11:58:47 +08:00
|
|
|
#include "cygerrno.h"
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2001-10-01 12:10:07 +08:00
|
|
|
#include "path.h"
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
#include "fhandler.h"
|
2001-04-19 05:10:15 +08:00
|
|
|
#include "dtable.h"
|
|
|
|
#include "cygheap.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "sigproc.h"
|
|
|
|
#include "pinfo.h"
|
2000-09-08 00:23:51 +08:00
|
|
|
#include "shared_info.h"
|
2004-05-16 12:18:50 +08:00
|
|
|
#include "cygtls.h"
|
2008-03-11 01:23:50 +08:00
|
|
|
#include "tls_pbuf.h"
|
2006-01-03 09:15:29 +08:00
|
|
|
#include "registry.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2008-03-11 01:23:50 +08:00
|
|
|
/* Don't make this bigger than NT_MAX_PATH as long as the temporary buffer
|
|
|
|
is allocated using tmp_pathbuf!!! */
|
|
|
|
#define CONVERT_LIMIT NT_MAX_PATH
|
2001-04-09 08:44:25 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/*
|
|
|
|
* Scroll the screen context.
|
|
|
|
* x1, y1 - ul corner
|
|
|
|
* x2, y2 - dr corner
|
|
|
|
* xn, yn - new ul corner
|
|
|
|
* Negative values represents current screen dimensions
|
|
|
|
*/
|
|
|
|
|
2002-10-08 14:16:16 +08:00
|
|
|
#define srTop (dev_state->info.winTop + dev_state->scroll_region.Top)
|
|
|
|
#define srBottom ((dev_state->scroll_region.Bottom < 0) ? dev_state->info.winBottom : dev_state->info.winTop + dev_state->scroll_region.Bottom)
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
#define use_tty ISSTATE (myself, PID_USETTY)
|
|
|
|
|
2009-05-30 13:51:41 +08:00
|
|
|
const char *get_nonascii_key (INPUT_RECORD&, char *);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2009-05-04 11:51:16 +08:00
|
|
|
const unsigned fhandler_console::MAX_WRITE_CHARS = 16384;
|
|
|
|
|
2002-10-15 04:25:52 +08:00
|
|
|
static console_state NO_COPY *shared_console_info;
|
2002-10-08 14:16:16 +08:00
|
|
|
|
|
|
|
dev_console NO_COPY *fhandler_console::dev_state;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2009-09-30 17:23:45 +08:00
|
|
|
static void
|
|
|
|
beep ()
|
|
|
|
{
|
|
|
|
reg_key r (HKEY_CURRENT_USER, KEY_ALL_ACCESS, "AppEvents", "Schemes", "Apps",
|
|
|
|
".Default", ".Default", ".Current", NULL);
|
|
|
|
if (r.created ())
|
|
|
|
{
|
|
|
|
char *buf = NULL;
|
|
|
|
UINT len = GetWindowsDirectory (buf, 0);
|
|
|
|
buf = (char *) alloca (len += sizeof ("\\media\\ding.wav"));
|
|
|
|
UINT res = GetWindowsDirectory (buf, len);
|
|
|
|
if (res && res <= len)
|
|
|
|
r.set_string ("", strcat (buf, "\\media\\ding.wav"));
|
|
|
|
}
|
|
|
|
MessageBeep (MB_OK);
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Allocate and initialize the shared record for the current console.
|
|
|
|
Returns a pointer to shared_console_info. */
|
2002-10-08 14:16:16 +08:00
|
|
|
tty_min *
|
|
|
|
fhandler_console::get_tty_stuff (int flags = 0)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-10-09 12:08:05 +08:00
|
|
|
if (dev_state)
|
2002-10-08 14:16:16 +08:00
|
|
|
return &shared_console_info->tty_min_state;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-10-15 15:03:45 +08:00
|
|
|
shared_console_info =
|
2002-10-08 14:16:16 +08:00
|
|
|
(console_state *) open_shared (NULL, 0, cygheap->console_h,
|
2002-10-15 04:25:52 +08:00
|
|
|
sizeof (*shared_console_info),
|
2010-03-10 05:26:55 +08:00
|
|
|
SH_SHARED_CONSOLE);
|
2002-10-09 12:08:05 +08:00
|
|
|
dev_state = &shared_console_info->dev_state;
|
|
|
|
|
2002-07-14 04:00:27 +08:00
|
|
|
ProtectHandleINH (cygheap->console_h);
|
2002-10-08 14:16:16 +08:00
|
|
|
if (!shared_console_info->tty_min_state.ntty)
|
2001-08-07 13:15:59 +08:00
|
|
|
{
|
2002-10-08 14:16:16 +08:00
|
|
|
shared_console_info->tty_min_state.setntty (TTY_CONSOLE);
|
|
|
|
shared_console_info->tty_min_state.setsid (myself->sid);
|
2003-12-11 14:12:41 +08:00
|
|
|
myself->set_ctty (&shared_console_info->tty_min_state, flags, NULL);
|
2002-10-08 14:16:16 +08:00
|
|
|
|
|
|
|
dev_state->scroll_region.Bottom = -1;
|
|
|
|
dev_state->dwLastCursorPosition.X = -1;
|
|
|
|
dev_state->dwLastCursorPosition.Y = -1;
|
2009-12-16 22:56:10 +08:00
|
|
|
dev_state->dwLastMousePosition.X = -1;
|
|
|
|
dev_state->dwLastMousePosition.Y = -1;
|
|
|
|
dev_state->dwLastButtonState = 0; /* none pressed */
|
|
|
|
dev_state->last_button_code = 3; /* released */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->underline_color = FOREGROUND_GREEN | FOREGROUND_BLUE;
|
|
|
|
dev_state->dim_color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
|
|
|
|
dev_state->meta_mask = LEFT_ALT_PRESSED;
|
|
|
|
/* Set the mask that determines if an input keystroke is modified by
|
|
|
|
META. We set this based on the keyboard layout language loaded
|
|
|
|
for the current thread. The left <ALT> key always generates
|
|
|
|
META, but the right <ALT> key only generates META if we are using
|
|
|
|
an English keyboard because many "international" keyboards
|
|
|
|
replace common shell symbols ('[', '{', etc.) with accented
|
|
|
|
language-specific characters (umlaut, accent grave, etc.). On
|
|
|
|
these keyboards right <ALT> (called AltGr) is used to produce the
|
|
|
|
shell symbols and should not be interpreted as META. */
|
|
|
|
if (PRIMARYLANGID (LOWORD (GetKeyboardLayout (0))) == LANG_ENGLISH)
|
|
|
|
dev_state->meta_mask |= RIGHT_ALT_PRESSED;
|
2005-04-23 01:03:38 +08:00
|
|
|
dev_state->set_default_attr ();
|
2010-04-12 03:11:17 +08:00
|
|
|
dev_state->backspace_keycode = CERASE;
|
2006-04-22 02:53:05 +08:00
|
|
|
shared_console_info->tty_min_state.sethwnd ((HWND) INVALID_HANDLE_VALUE);
|
2001-08-07 13:15:59 +08:00
|
|
|
}
|
2002-10-08 14:16:16 +08:00
|
|
|
|
|
|
|
return &shared_console_info->tty_min_state;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2001-04-29 07:48:28 +08:00
|
|
|
void
|
|
|
|
set_console_ctty ()
|
|
|
|
{
|
2005-07-07 04:05:03 +08:00
|
|
|
fhandler_console::get_tty_stuff ();
|
2001-04-29 07:48:28 +08:00
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Return the tty structure associated with a given tty number. If the
|
|
|
|
tty number is < 0, just return a dummy record. */
|
|
|
|
tty_min *
|
|
|
|
tty_list::get_tty (int n)
|
|
|
|
{
|
|
|
|
static tty_min nada;
|
|
|
|
if (n == TTY_CONSOLE)
|
2002-10-08 14:16:16 +08:00
|
|
|
return fhandler_console::get_tty_stuff ();
|
2000-02-18 03:38:33 +08:00
|
|
|
else if (n >= 0)
|
|
|
|
return &cygwin_shared->tty.ttys[n];
|
|
|
|
else
|
|
|
|
return &nada;
|
|
|
|
}
|
|
|
|
|
2008-03-11 00:22:38 +08:00
|
|
|
inline DWORD
|
2008-02-06 01:37:10 +08:00
|
|
|
dev_console::con_to_str (char *d, int dlen, WCHAR w)
|
2003-10-16 22:08:28 +08:00
|
|
|
{
|
2009-09-28 20:10:32 +08:00
|
|
|
return sys_cp_wcstombs (cygheap->locale.wctomb, cygheap->locale.charset,
|
|
|
|
d, dlen, &w, 1);
|
2003-10-16 22:08:28 +08:00
|
|
|
}
|
|
|
|
|
2008-02-06 01:37:10 +08:00
|
|
|
inline UINT
|
|
|
|
dev_console::get_console_cp ()
|
2003-10-16 22:08:28 +08:00
|
|
|
{
|
2009-09-28 20:10:32 +08:00
|
|
|
/* The alternate charset is always 437, just as in the Linux console. */
|
|
|
|
return alternate_charset_active ? 437 : 0;
|
2008-02-06 01:37:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline DWORD
|
2009-09-28 20:10:32 +08:00
|
|
|
dev_console::str_to_con (mbtowc_p f_mbtowc, const char *charset,
|
2009-04-07 20:13:37 +08:00
|
|
|
PWCHAR d, const char *s, DWORD sz)
|
2008-02-06 01:37:10 +08:00
|
|
|
{
|
2009-04-07 20:13:37 +08:00
|
|
|
return sys_cp_mbstowcs (f_mbtowc, charset, d, CONVERT_LIMIT, s, sz);
|
2003-10-16 22:08:28 +08:00
|
|
|
}
|
|
|
|
|
2003-12-08 06:37:12 +08:00
|
|
|
bool
|
|
|
|
fhandler_console::set_raw_win32_keyboard_mode (bool new_mode)
|
2001-02-27 17:14:35 +08:00
|
|
|
{
|
2003-12-08 06:37:12 +08:00
|
|
|
bool old_mode = dev_state->raw_win32_keyboard_mode;
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->raw_win32_keyboard_mode = new_mode;
|
|
|
|
syscall_printf ("raw keyboard mode %sabled", dev_state->raw_win32_keyboard_mode ? "en" : "dis");
|
2001-02-27 17:14:35 +08:00
|
|
|
return old_mode;
|
|
|
|
};
|
|
|
|
|
2000-07-30 00:24:59 +08:00
|
|
|
void
|
|
|
|
fhandler_console::set_cursor_maybe ()
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO now;
|
|
|
|
|
2001-04-09 08:44:25 +08:00
|
|
|
if (!GetConsoleScreenBufferInfo (get_output_handle (), &now))
|
2000-07-30 00:24:59 +08:00
|
|
|
return;
|
|
|
|
|
2002-10-08 14:16:16 +08:00
|
|
|
if (dev_state->dwLastCursorPosition.X != now.dwCursorPosition.X ||
|
|
|
|
dev_state->dwLastCursorPosition.Y != now.dwCursorPosition.Y)
|
2000-07-30 00:24:59 +08:00
|
|
|
{
|
|
|
|
SetConsoleCursorPosition (get_output_handle (), now.dwCursorPosition);
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->dwLastCursorPosition = now.dwCursorPosition;
|
2000-07-30 00:24:59 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-19 12:43:58 +08:00
|
|
|
void
|
|
|
|
fhandler_console::send_winch_maybe ()
|
|
|
|
{
|
2002-10-08 14:16:16 +08:00
|
|
|
SHORT y = dev_state->info.dwWinSize.Y;
|
|
|
|
SHORT x = dev_state->info.dwWinSize.X;
|
2005-04-23 01:03:38 +08:00
|
|
|
dev_state->fillin_info (get_output_handle ());
|
2002-09-19 11:30:20 +08:00
|
|
|
|
2002-10-08 14:16:16 +08:00
|
|
|
if (y != dev_state->info.dwWinSize.Y || x != dev_state->info.dwWinSize.X)
|
2002-12-27 13:31:30 +08:00
|
|
|
{
|
|
|
|
extern fhandler_tty_master *tty_master;
|
2003-01-25 09:17:51 +08:00
|
|
|
dev_state->scroll_region.Top = 0;
|
|
|
|
dev_state->scroll_region.Bottom = -1;
|
2002-12-27 13:31:30 +08:00
|
|
|
if (tty_master)
|
|
|
|
tty_master->set_winsize (true);
|
|
|
|
else
|
|
|
|
tc->kill_pgrp (SIGWINCH);
|
|
|
|
}
|
2002-08-19 12:43:58 +08:00
|
|
|
}
|
|
|
|
|
2009-12-16 22:56:10 +08:00
|
|
|
/* Check whether a mouse event is to be reported as an escape sequence */
|
|
|
|
bool
|
|
|
|
fhandler_console::mouse_aware (MOUSE_EVENT_RECORD& mouse_event)
|
|
|
|
{
|
|
|
|
if (! dev_state->use_mouse)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Adjust mouse position by window scroll buffer offset
|
|
|
|
and remember adjusted position in state for use by read() */
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO now;
|
|
|
|
if (GetConsoleScreenBufferInfo (get_output_handle (), &now))
|
|
|
|
{
|
|
|
|
dev_state->dwMousePosition.X = mouse_event.dwMousePosition.X - now.srWindow.Left;
|
|
|
|
dev_state->dwMousePosition.Y = mouse_event.dwMousePosition.Y - now.srWindow.Top;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Cannot adjust position by window scroll buffer offset */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check whether adjusted mouse position can be reported */
|
|
|
|
if (dev_state->dwMousePosition.X > 0xFF - ' ' - 1
|
|
|
|
|| dev_state->dwMousePosition.Y > 0xFF - ' ' - 1)
|
|
|
|
{
|
|
|
|
/* Mouse position out of reporting range */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((mouse_event.dwEventFlags == 0 || mouse_event.dwEventFlags == DOUBLE_CLICK)
|
|
|
|
&& mouse_event.dwButtonState != dev_state->dwLastButtonState)
|
|
|
|
|| mouse_event.dwEventFlags == MOUSE_WHEELED
|
|
|
|
|| (mouse_event.dwEventFlags == MOUSE_MOVED
|
|
|
|
&& (dev_state->dwMousePosition.X != dev_state->dwLastMousePosition.X
|
|
|
|
|| dev_state->dwMousePosition.Y != dev_state->dwLastMousePosition.Y)
|
|
|
|
&& ((dev_state->use_mouse >= 2 && mouse_event.dwButtonState)
|
|
|
|
|| dev_state->use_mouse >= 3));
|
|
|
|
}
|
|
|
|
|
2002-12-14 12:01:32 +08:00
|
|
|
void __stdcall
|
|
|
|
fhandler_console::read (void *pv, size_t& buflen)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
HANDLE h = get_io_handle ();
|
|
|
|
|
|
|
|
#define buf ((char *) pv)
|
|
|
|
|
|
|
|
int ch;
|
|
|
|
set_input_state ();
|
2000-03-12 14:29:54 +08:00
|
|
|
|
|
|
|
int copied_chars = get_readahead_into_buffer (buf, buflen);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (copied_chars)
|
2002-12-14 12:01:32 +08:00
|
|
|
{
|
|
|
|
buflen = copied_chars;
|
|
|
|
return;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
HANDLE w4[2];
|
|
|
|
DWORD nwait;
|
2001-02-27 17:14:35 +08:00
|
|
|
char tmp[60];
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
w4[0] = h;
|
2004-05-16 12:18:50 +08:00
|
|
|
if (&_my_tls != _main_tls)
|
2000-03-12 12:44:37 +08:00
|
|
|
nwait = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
w4[1] = signal_arrived;
|
|
|
|
nwait = 2;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-12-27 11:50:29 +08:00
|
|
|
termios ti = tc->ti;
|
2000-02-18 03:38:33 +08:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
int bgres;
|
2001-01-17 22:57:09 +08:00
|
|
|
if ((bgres = bg_check (SIGTTIN)) <= bg_eof)
|
2002-12-14 12:01:32 +08:00
|
|
|
{
|
|
|
|
buflen = bgres;
|
|
|
|
return;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-07-30 00:24:59 +08:00
|
|
|
set_cursor_maybe (); /* to make cursor appear on the screen immediately */
|
2000-02-18 03:38:33 +08:00
|
|
|
switch (WaitForMultipleObjects (nwait, w4, FALSE, INFINITE))
|
|
|
|
{
|
|
|
|
case WAIT_OBJECT_0:
|
|
|
|
break;
|
|
|
|
case WAIT_OBJECT_0 + 1:
|
2001-03-05 14:28:25 +08:00
|
|
|
goto sig_exit;
|
2000-02-18 03:38:33 +08:00
|
|
|
default:
|
2002-12-14 12:01:32 +08:00
|
|
|
goto err;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2000-07-10 23:30:04 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
DWORD nread;
|
|
|
|
INPUT_RECORD input_rec;
|
2000-12-16 11:11:02 +08:00
|
|
|
const char *toadd = NULL;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2008-02-06 01:37:10 +08:00
|
|
|
if (!ReadConsoleInputW (h, &input_rec, 1, &nread))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2000-10-21 12:53:49 +08:00
|
|
|
syscall_printf ("ReadConsoleInput failed, %E");
|
2002-12-14 12:01:32 +08:00
|
|
|
goto err; /* seems to be failure */
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-12-16 11:11:02 +08:00
|
|
|
/* check the event that occurred */
|
|
|
|
switch (input_rec.EventType)
|
|
|
|
{
|
|
|
|
case KEY_EVENT:
|
2001-02-27 17:14:35 +08:00
|
|
|
#define virtual_key_code (input_rec.Event.KeyEvent.wVirtualKeyCode)
|
|
|
|
#define control_key_state (input_rec.Event.KeyEvent.dwControlKeyState)
|
|
|
|
|
2003-09-27 10:36:50 +08:00
|
|
|
dev_state->nModifiers = 0;
|
|
|
|
|
2001-02-27 17:14:35 +08:00
|
|
|
#ifdef DEBUGGING
|
2001-03-03 11:56:34 +08:00
|
|
|
/* allow manual switching to/from raw mode via ctrl-alt-scrolllock */
|
|
|
|
if (input_rec.Event.KeyEvent.bKeyDown &&
|
|
|
|
virtual_key_code == VK_SCROLL &&
|
2008-09-11 12:34:24 +08:00
|
|
|
((control_key_state & (LEFT_ALT_PRESSED | LEFT_CTRL_PRESSED)) == (LEFT_ALT_PRESSED | LEFT_CTRL_PRESSED))
|
2001-03-03 11:56:34 +08:00
|
|
|
)
|
|
|
|
{
|
2002-10-08 14:16:16 +08:00
|
|
|
set_raw_win32_keyboard_mode (!dev_state->raw_win32_keyboard_mode);
|
2001-03-03 11:56:34 +08:00
|
|
|
continue;
|
|
|
|
}
|
2001-02-27 17:14:35 +08:00
|
|
|
#endif
|
|
|
|
|
2002-10-08 14:16:16 +08:00
|
|
|
if (dev_state->raw_win32_keyboard_mode)
|
2001-03-03 11:56:34 +08:00
|
|
|
{
|
2001-04-09 08:44:25 +08:00
|
|
|
__small_sprintf (tmp, "\033{%u;%u;%u;%u;%u;%luK",
|
|
|
|
input_rec.Event.KeyEvent.bKeyDown,
|
|
|
|
input_rec.Event.KeyEvent.wRepeatCount,
|
|
|
|
input_rec.Event.KeyEvent.wVirtualKeyCode,
|
|
|
|
input_rec.Event.KeyEvent.wVirtualScanCode,
|
|
|
|
input_rec.Event.KeyEvent.uChar.UnicodeChar,
|
|
|
|
input_rec.Event.KeyEvent.dwControlKeyState);
|
2001-03-03 11:56:34 +08:00
|
|
|
toadd = tmp;
|
|
|
|
nread = strlen (toadd);
|
|
|
|
break;
|
|
|
|
}
|
2001-02-27 17:14:35 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
#define ich (input_rec.Event.KeyEvent.uChar.AsciiChar)
|
2000-07-10 23:30:04 +08:00
|
|
|
#define wch (input_rec.Event.KeyEvent.uChar.UnicodeChar)
|
2001-06-23 04:08:06 +08:00
|
|
|
#define ALT_PRESSED (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)
|
|
|
|
#define CTRL_PRESSED (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-04-09 05:19:33 +08:00
|
|
|
/* Ignore key up events, except for left alt events with non-zero character
|
|
|
|
*/
|
|
|
|
if (!input_rec.Event.KeyEvent.bKeyDown &&
|
|
|
|
/*
|
|
|
|
Event for left alt, with a non-zero character, comes from
|
|
|
|
"alt + numerics" key sequence.
|
|
|
|
e.g. <left-alt> 0233 => é
|
|
|
|
*/
|
|
|
|
!(wch != 0
|
|
|
|
// ?? experimentally determined on an XP system
|
|
|
|
&& virtual_key_code == VK_MENU
|
|
|
|
// left alt -- see http://www.microsoft.com/hwdev/tech/input/Scancode.asp
|
|
|
|
&& input_rec.Event.KeyEvent.wVirtualScanCode == 0x38))
|
|
|
|
continue;
|
|
|
|
|
2003-09-27 10:36:50 +08:00
|
|
|
if (control_key_state & SHIFT_PRESSED)
|
|
|
|
dev_state->nModifiers |= 1;
|
|
|
|
if (control_key_state & RIGHT_ALT_PRESSED)
|
|
|
|
dev_state->nModifiers |= 2;
|
|
|
|
if (control_key_state & CTRL_PRESSED)
|
|
|
|
dev_state->nModifiers |= 4;
|
|
|
|
if (control_key_state & LEFT_ALT_PRESSED)
|
|
|
|
dev_state->nModifiers |= 8;
|
|
|
|
|
2009-05-30 13:51:41 +08:00
|
|
|
if (input_rec.Event.KeyEvent.wVirtualScanCode == 14)
|
2009-06-03 19:07:38 +08:00
|
|
|
{
|
2010-04-12 03:11:17 +08:00
|
|
|
char c = dev_state->backspace_keycode;
|
2009-12-26 01:38:46 +08:00
|
|
|
nread = 0;
|
|
|
|
if (control_key_state & ALT_PRESSED) {
|
|
|
|
if (dev_state->metabit)
|
|
|
|
c |= 0x80;
|
|
|
|
else
|
|
|
|
tmp[nread++] = '\e';
|
|
|
|
}
|
|
|
|
tmp[nread++] = c;
|
|
|
|
tmp[nread] = 0;
|
|
|
|
toadd = tmp;
|
2009-06-03 19:07:38 +08:00
|
|
|
}
|
2009-06-04 17:57:34 +08:00
|
|
|
/* Allow Ctrl-Space to emit ^@ */
|
|
|
|
else if (input_rec.Event.KeyEvent.wVirtualKeyCode == VK_SPACE
|
|
|
|
&& (control_key_state & CTRL_PRESSED))
|
|
|
|
toadd = "";
|
2009-05-30 13:51:41 +08:00
|
|
|
else if (wch == 0
|
2000-12-16 11:11:02 +08:00
|
|
|
/* arrow/function keys */
|
2009-05-30 13:51:41 +08:00
|
|
|
|| (input_rec.Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
|
2000-12-16 11:11:02 +08:00
|
|
|
{
|
|
|
|
toadd = get_nonascii_key (input_rec, tmp);
|
|
|
|
if (!toadd)
|
2003-09-27 10:36:50 +08:00
|
|
|
{
|
|
|
|
dev_state->nModifiers = 0;
|
|
|
|
continue;
|
|
|
|
}
|
2000-12-16 11:11:02 +08:00
|
|
|
nread = strlen (toadd);
|
|
|
|
}
|
2001-03-03 11:56:34 +08:00
|
|
|
else
|
|
|
|
{
|
2008-03-11 00:22:38 +08:00
|
|
|
nread = dev_state->con_to_str (tmp + 1, 59, wch);
|
2001-06-23 04:08:06 +08:00
|
|
|
/* Determine if the keystroke is modified by META. The tricky
|
|
|
|
part is to distinguish whether the right Alt key should be
|
|
|
|
recognized as Alt, or as AltGr. */
|
2009-12-19 23:37:10 +08:00
|
|
|
bool meta =
|
|
|
|
/* Alt but not AltGr (= left ctrl + right alt)? */
|
|
|
|
(control_key_state & ALT_PRESSED) != 0
|
2007-02-23 01:35:14 +08:00
|
|
|
&& ((control_key_state & CTRL_PRESSED) == 0
|
2009-12-19 23:37:10 +08:00
|
|
|
/* but also allow Alt-AltGr: */
|
|
|
|
|| (control_key_state & ALT_PRESSED) == ALT_PRESSED
|
2008-02-06 01:37:10 +08:00
|
|
|
|| (wch <= 0x1f || wch == 0x7f));
|
2001-06-23 04:08:06 +08:00
|
|
|
if (!meta)
|
2009-09-30 17:23:45 +08:00
|
|
|
{
|
|
|
|
/* Determine if the character is in the current multibyte
|
|
|
|
charset. The test is easy. If the multibyte sequence
|
|
|
|
is > 1 and the first byte is ASCII CAN, the character
|
|
|
|
has been translated into the ASCII CAN + UTF-8 replacement
|
|
|
|
sequence. If so, just ignore the keypress.
|
|
|
|
FIXME: Is there a better solution? */
|
|
|
|
if (nread > 1 && tmp[1] == 0x18)
|
|
|
|
beep ();
|
|
|
|
else
|
|
|
|
toadd = tmp + 1;
|
|
|
|
}
|
2009-11-11 04:02:20 +08:00
|
|
|
else if (dev_state->metabit)
|
2006-07-03 23:29:10 +08:00
|
|
|
{
|
2009-11-11 04:02:20 +08:00
|
|
|
tmp[1] |= 0x80;
|
|
|
|
toadd = tmp + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tmp[0] = '\033';
|
|
|
|
tmp[1] = cyg_tolower (tmp[1]);
|
|
|
|
toadd = tmp;
|
|
|
|
nread++;
|
|
|
|
dev_state->nModifiers &= ~4;
|
2000-12-16 11:11:02 +08:00
|
|
|
}
|
2001-03-03 11:56:34 +08:00
|
|
|
}
|
2000-12-16 11:11:02 +08:00
|
|
|
#undef ich
|
|
|
|
#undef wch
|
2001-06-23 04:08:06 +08:00
|
|
|
#undef ALT_PRESSED
|
|
|
|
#undef CTRL_PRESSED
|
2000-12-16 11:11:02 +08:00
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-12-16 11:11:02 +08:00
|
|
|
case MOUSE_EVENT:
|
2002-08-19 12:43:58 +08:00
|
|
|
send_winch_maybe ();
|
2009-12-16 22:56:10 +08:00
|
|
|
{
|
|
|
|
MOUSE_EVENT_RECORD& mouse_event = input_rec.Event.MouseEvent;
|
|
|
|
/* As a unique guard for mouse report generation,
|
|
|
|
call mouse_aware() which is common with select(), so the result
|
|
|
|
of select() and the actual read() will be consistent on the
|
|
|
|
issue of whether input (i.e. a mouse escape sequence) will
|
|
|
|
be available or not */
|
|
|
|
if (mouse_aware (mouse_event))
|
|
|
|
{
|
|
|
|
/* Note: Reported mouse position was already retrieved by
|
|
|
|
mouse_aware() and adjusted by window scroll buffer offset */
|
|
|
|
|
|
|
|
/* Treat the double-click event like a regular button press */
|
|
|
|
if (mouse_event.dwEventFlags == DOUBLE_CLICK)
|
|
|
|
{
|
|
|
|
syscall_printf ("mouse: double-click -> click");
|
|
|
|
mouse_event.dwEventFlags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This code assumes Windows never reports multiple button
|
|
|
|
events at the same time. */
|
|
|
|
int b = 0;
|
|
|
|
char sz[32];
|
|
|
|
|
|
|
|
if (mouse_event.dwEventFlags == MOUSE_WHEELED)
|
|
|
|
{
|
|
|
|
if (mouse_event.dwButtonState & 0xFF800000)
|
|
|
|
{
|
|
|
|
b = 0x41;
|
|
|
|
strcpy (sz, "wheel down");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
b = 0x40;
|
|
|
|
strcpy (sz, "wheel up");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Ignore unimportant mouse buttons */
|
|
|
|
mouse_event.dwButtonState &= 0x7;
|
|
|
|
|
|
|
|
if (mouse_event.dwEventFlags == MOUSE_MOVED)
|
|
|
|
{
|
|
|
|
b = dev_state->last_button_code;
|
|
|
|
}
|
|
|
|
else if (mouse_event.dwButtonState < dev_state->dwLastButtonState)
|
|
|
|
{
|
|
|
|
b = 3;
|
|
|
|
strcpy (sz, "btn up");
|
|
|
|
}
|
|
|
|
else if ((mouse_event.dwButtonState & 1) != (dev_state->dwLastButtonState & 1))
|
|
|
|
{
|
|
|
|
b = 0;
|
|
|
|
strcpy (sz, "btn1 down");
|
|
|
|
}
|
|
|
|
else if ((mouse_event.dwButtonState & 2) != (dev_state->dwLastButtonState & 2))
|
|
|
|
{
|
|
|
|
b = 2;
|
|
|
|
strcpy (sz, "btn2 down");
|
|
|
|
}
|
|
|
|
else if ((mouse_event.dwButtonState & 4) != (dev_state->dwLastButtonState & 4))
|
|
|
|
{
|
|
|
|
b = 1;
|
|
|
|
strcpy (sz, "btn3 down");
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_state->last_button_code = b;
|
|
|
|
|
|
|
|
if (mouse_event.dwEventFlags == MOUSE_MOVED)
|
|
|
|
{
|
|
|
|
b += 32;
|
|
|
|
strcpy (sz, "move");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Remember the modified button state */
|
|
|
|
dev_state->dwLastButtonState = mouse_event.dwButtonState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remember mouse position */
|
|
|
|
dev_state->dwLastMousePosition.X = dev_state->dwMousePosition.X;
|
|
|
|
dev_state->dwLastMousePosition.Y = dev_state->dwMousePosition.Y;
|
|
|
|
|
|
|
|
/* Remember the modifiers */
|
|
|
|
dev_state->nModifiers = 0;
|
|
|
|
if (mouse_event.dwControlKeyState & SHIFT_PRESSED)
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->nModifiers |= 0x4;
|
2009-12-16 22:56:10 +08:00
|
|
|
if (mouse_event.dwControlKeyState & (RIGHT_ALT_PRESSED|LEFT_ALT_PRESSED))
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->nModifiers |= 0x8;
|
2009-12-16 22:56:10 +08:00
|
|
|
if (mouse_event.dwControlKeyState & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED))
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->nModifiers |= 0x10;
|
2001-03-03 11:56:34 +08:00
|
|
|
|
2009-12-16 22:56:10 +08:00
|
|
|
/* Indicate the modifiers */
|
|
|
|
b |= dev_state->nModifiers;
|
2001-03-03 11:56:34 +08:00
|
|
|
|
2009-12-16 22:56:10 +08:00
|
|
|
/* We can now create the code. */
|
|
|
|
sprintf (tmp, "\033[M%c%c%c", b + ' ', dev_state->dwMousePosition.X + ' ' + 1, dev_state->dwMousePosition.Y + ' ' + 1);
|
|
|
|
syscall_printf ("mouse: %s at (%d,%d)", sz, dev_state->dwMousePosition.X, dev_state->dwMousePosition.Y);
|
2000-12-16 11:11:02 +08:00
|
|
|
|
2009-12-16 22:56:10 +08:00
|
|
|
toadd = tmp;
|
|
|
|
nread = 6;
|
|
|
|
}
|
|
|
|
}
|
2000-12-16 11:11:02 +08:00
|
|
|
break;
|
|
|
|
|
2002-08-19 12:43:58 +08:00
|
|
|
case FOCUS_EVENT:
|
2009-12-16 22:56:10 +08:00
|
|
|
if (dev_state->use_focus) {
|
|
|
|
if (input_rec.Event.FocusEvent.bSetFocus)
|
|
|
|
sprintf (tmp, "\033[I");
|
|
|
|
else
|
|
|
|
sprintf (tmp, "\033[O");
|
|
|
|
|
|
|
|
toadd = tmp;
|
|
|
|
nread = 3;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-12-16 11:11:02 +08:00
|
|
|
case WINDOW_BUFFER_SIZE_EVENT:
|
2002-08-19 12:43:58 +08:00
|
|
|
send_winch_maybe ();
|
|
|
|
/* fall through */
|
2000-12-16 11:11:02 +08:00
|
|
|
default:
|
|
|
|
continue;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2001-03-05 14:28:25 +08:00
|
|
|
if (toadd)
|
|
|
|
{
|
2002-12-27 11:50:29 +08:00
|
|
|
line_edit_status res = line_edit (toadd, nread, ti);
|
2002-12-06 00:24:52 +08:00
|
|
|
if (res == line_edit_signalled)
|
2001-03-05 14:28:25 +08:00
|
|
|
goto sig_exit;
|
2002-12-06 00:24:52 +08:00
|
|
|
else if (res == line_edit_input_done)
|
2001-03-05 14:28:25 +08:00
|
|
|
break;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
while (buflen)
|
|
|
|
if ((ch = get_readahead ()) < 0)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf[copied_chars++] = (unsigned char)(ch & 0xff);
|
|
|
|
buflen--;
|
|
|
|
}
|
|
|
|
#undef buf
|
|
|
|
|
2002-12-14 12:01:32 +08:00
|
|
|
buflen = copied_chars;
|
|
|
|
return;
|
|
|
|
|
|
|
|
err:
|
|
|
|
__seterrno ();
|
2003-09-05 09:55:01 +08:00
|
|
|
buflen = (size_t) -1;
|
2002-12-14 12:01:32 +08:00
|
|
|
return;
|
2001-03-05 14:28:25 +08:00
|
|
|
|
2003-09-09 11:11:31 +08:00
|
|
|
sig_exit:
|
2001-03-05 14:28:25 +08:00
|
|
|
set_sig_errno (EINTR);
|
2003-09-05 09:55:01 +08:00
|
|
|
buflen = (size_t) -1;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-09-08 00:23:51 +08:00
|
|
|
void
|
|
|
|
fhandler_console::set_input_state ()
|
|
|
|
{
|
2004-04-10 21:45:10 +08:00
|
|
|
if (tc->rstcons ())
|
2000-09-08 00:23:51 +08:00
|
|
|
input_tcsetattr (0, &tc->ti);
|
|
|
|
}
|
|
|
|
|
2003-12-08 06:37:12 +08:00
|
|
|
bool
|
2005-04-23 01:03:38 +08:00
|
|
|
dev_console::fillin_info (HANDLE h)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-12-08 06:37:12 +08:00
|
|
|
bool ret;
|
2000-02-18 03:38:33 +08:00
|
|
|
CONSOLE_SCREEN_BUFFER_INFO linfo;
|
|
|
|
|
2005-04-23 01:03:38 +08:00
|
|
|
if ((ret = GetConsoleScreenBufferInfo (h, &linfo)))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2005-04-23 01:03:38 +08:00
|
|
|
info.winTop = linfo.srWindow.Top;
|
|
|
|
info.winBottom = linfo.srWindow.Bottom;
|
|
|
|
info.dwWinSize.Y = 1 + linfo.srWindow.Bottom - linfo.srWindow.Top;
|
|
|
|
info.dwWinSize.X = 1 + linfo.srWindow.Right - linfo.srWindow.Left;
|
|
|
|
info.dwBufferSize = linfo.dwSize;
|
|
|
|
info.dwCursorPosition = linfo.dwCursorPosition;
|
|
|
|
info.wAttributes = linfo.wAttributes;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-04-23 01:03:38 +08:00
|
|
|
memset (&info, 0, sizeof info);
|
|
|
|
info.dwWinSize.Y = 25;
|
|
|
|
info.dwWinSize.X = 80;
|
|
|
|
info.winBottom = 24;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_console::scroll_screen (int x1, int y1, int x2, int y2, int xn, int yn)
|
|
|
|
{
|
|
|
|
SMALL_RECT sr1, sr2;
|
|
|
|
CHAR_INFO fill;
|
|
|
|
COORD dest;
|
|
|
|
|
2005-07-07 04:05:03 +08:00
|
|
|
dev_state->fillin_info (get_output_handle ());
|
2002-10-08 14:16:16 +08:00
|
|
|
sr1.Left = x1 >= 0 ? x1 : dev_state->info.dwWinSize.X - 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (y1 == 0)
|
2002-10-08 14:16:16 +08:00
|
|
|
sr1.Top = dev_state->info.winTop;
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
2002-10-08 14:16:16 +08:00
|
|
|
sr1.Top = y1 > 0 ? y1 : dev_state->info.winBottom;
|
|
|
|
sr1.Right = x2 >= 0 ? x2 : dev_state->info.dwWinSize.X - 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (y2 == 0)
|
2002-10-08 14:16:16 +08:00
|
|
|
sr1.Bottom = dev_state->info.winTop;
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
2002-10-08 14:16:16 +08:00
|
|
|
sr1.Bottom = y2 > 0 ? y2 : dev_state->info.winBottom;
|
2000-02-18 03:38:33 +08:00
|
|
|
sr2.Top = srTop;
|
|
|
|
sr2.Left = 0;
|
|
|
|
sr2.Bottom = srBottom;
|
2002-10-08 14:16:16 +08:00
|
|
|
sr2.Right = dev_state->info.dwWinSize.X - 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (sr1.Bottom > sr2.Bottom && sr1.Top <= sr2.Bottom)
|
|
|
|
sr1.Bottom = sr2.Bottom;
|
2002-10-08 14:16:16 +08:00
|
|
|
dest.X = xn >= 0 ? xn : dev_state->info.dwWinSize.X - 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (yn == 0)
|
2002-10-08 14:16:16 +08:00
|
|
|
dest.Y = dev_state->info.winTop;
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
2002-10-08 14:16:16 +08:00
|
|
|
dest.Y = yn > 0 ? yn : dev_state->info.winBottom;
|
2000-02-18 03:38:33 +08:00
|
|
|
fill.Char.AsciiChar = ' ';
|
2002-10-08 14:16:16 +08:00
|
|
|
fill.Attributes = dev_state->current_win32_attr;
|
2000-02-18 03:38:33 +08:00
|
|
|
ScrollConsoleScreenBuffer (get_output_handle (), &sr1, &sr2, dest, &fill);
|
|
|
|
|
|
|
|
/* ScrollConsoleScreenBuffer on Windows 95 is buggy - when scroll distance
|
|
|
|
* is more than half of screen, filling doesn't work as expected */
|
|
|
|
|
2008-09-11 12:34:24 +08:00
|
|
|
if (sr1.Top == sr1.Bottom)
|
|
|
|
/* nothing to do */;
|
|
|
|
else if (dest.Y <= sr1.Top) /* forward scroll */
|
|
|
|
clear_screen (0, 1 + dest.Y + sr1.Bottom - sr1.Top, sr2.Right, sr2.Bottom);
|
|
|
|
else /* reverse scroll */
|
|
|
|
clear_screen (0, sr1.Top, sr2.Right, dest.Y - 1);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
fhandler_console::open (int flags, mode_t)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
HANDLE h;
|
|
|
|
|
2010-10-24 02:07:08 +08:00
|
|
|
tcinit (get_tty_stuff (flags), false);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-09-22 11:38:57 +08:00
|
|
|
set_io_handle (NULL);
|
|
|
|
set_output_handle (NULL);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-07-02 03:03:26 +08:00
|
|
|
set_flags ((flags & ~O_TEXT) | O_BINARY);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Open the input handle as handle_ */
|
2002-09-19 23:12:48 +08:00
|
|
|
h = CreateFile ("CONIN$", GENERIC_READ | GENERIC_WRITE,
|
2010-01-15 02:46:02 +08:00
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE, sec_none_cloexec (flags),
|
2002-09-19 23:12:48 +08:00
|
|
|
OPEN_EXISTING, 0, 0);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (h == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
set_io_handle (h);
|
2004-04-10 21:45:10 +08:00
|
|
|
uninterruptible_io (true); // Handled explicitly in read code
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-09-19 23:12:48 +08:00
|
|
|
h = CreateFile ("CONOUT$", GENERIC_READ | GENERIC_WRITE,
|
2010-01-15 02:46:02 +08:00
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE, sec_none_cloexec (flags),
|
2002-09-19 23:12:48 +08:00
|
|
|
OPEN_EXISTING, 0, 0);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (h == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
set_output_handle (h);
|
|
|
|
|
2005-04-23 01:03:38 +08:00
|
|
|
if (dev_state->fillin_info (get_output_handle ()))
|
|
|
|
{
|
|
|
|
dev_state->current_win32_attr = dev_state->info.wAttributes;
|
|
|
|
if (!dev_state->default_color)
|
|
|
|
dev_state->default_color = dev_state->info.wAttributes;
|
|
|
|
dev_state->set_default_attr ();
|
|
|
|
}
|
2001-02-27 17:14:35 +08:00
|
|
|
|
2004-04-10 21:45:10 +08:00
|
|
|
tc->rstcons (false);
|
2001-04-24 10:07:58 +08:00
|
|
|
set_open_status ();
|
2005-11-14 12:28:45 +08:00
|
|
|
cygheap->manage_console_count ("fhandler_console::open", 1);
|
2008-06-12 23:57:23 +08:00
|
|
|
|
|
|
|
DWORD cflags;
|
|
|
|
if (GetConsoleMode (get_io_handle (), &cflags))
|
|
|
|
SetConsoleMode (get_io_handle (),
|
|
|
|
ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT | cflags);
|
|
|
|
|
2003-12-30 09:57:16 +08:00
|
|
|
debug_printf ("opened conin$ %p, conout$ %p", get_io_handle (),
|
|
|
|
get_output_handle ());
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-07-05 11:16:46 +08:00
|
|
|
fhandler_console::close ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
CloseHandle (get_io_handle ());
|
|
|
|
CloseHandle (get_output_handle ());
|
2005-11-14 12:28:45 +08:00
|
|
|
if (!hExeced)
|
|
|
|
cygheap->manage_console_count ("fhandler_console::close", -1);
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-14 13:36:16 +08:00
|
|
|
/* Special console dup to duplicate input and output handles. */
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
int
|
2005-09-29 03:22:25 +08:00
|
|
|
fhandler_console::dup (fhandler_base *child)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
fhandler_console *fhc = (fhandler_console *) child;
|
|
|
|
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
if (!fhc->open (get_flags () & ~O_NOCTTY, 0))
|
2000-02-18 03:38:33 +08:00
|
|
|
system_printf ("error opening console, %E");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_console::ioctl (unsigned int cmd, void *buf)
|
|
|
|
{
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case TIOCGWINSZ:
|
|
|
|
int st;
|
|
|
|
|
2005-04-23 01:03:38 +08:00
|
|
|
st = dev_state->fillin_info (get_output_handle ());
|
2000-02-18 03:38:33 +08:00
|
|
|
if (st)
|
|
|
|
{
|
|
|
|
/* *not* the buffer size, the actual screen size... */
|
|
|
|
/* based on Left Top Right Bottom of srWindow */
|
2002-10-08 14:16:16 +08:00
|
|
|
((struct winsize *) buf)->ws_row = dev_state->info.dwWinSize.Y;
|
|
|
|
((struct winsize *) buf)->ws_col = dev_state->info.dwWinSize.X;
|
2000-02-18 03:38:33 +08:00
|
|
|
syscall_printf ("WINSZ: (row=%d,col=%d)",
|
|
|
|
((struct winsize *) buf)->ws_row,
|
|
|
|
((struct winsize *) buf)->ws_col);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
syscall_printf ("WINSZ failed");
|
|
|
|
__seterrno ();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
case TIOCSWINSZ:
|
2005-07-07 04:05:03 +08:00
|
|
|
bg_check (SIGTTOU);
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
2006-07-03 23:29:10 +08:00
|
|
|
case KDGKBMETA:
|
|
|
|
*(int *) buf = (dev_state->metabit) ? K_METABIT : K_ESCPREFIX;
|
|
|
|
return 0;
|
|
|
|
case KDSKBMETA:
|
|
|
|
if ((int) buf == K_METABIT)
|
|
|
|
dev_state->metabit = TRUE;
|
|
|
|
else if ((int) buf == K_ESCPREFIX)
|
|
|
|
dev_state->metabit = FALSE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2003-09-27 10:36:50 +08:00
|
|
|
case TIOCLINUX:
|
2009-05-07 01:16:33 +08:00
|
|
|
if (*(unsigned char *) buf == 6)
|
2003-09-27 10:36:50 +08:00
|
|
|
{
|
2009-05-07 01:16:33 +08:00
|
|
|
*(unsigned char *) buf = (unsigned char) dev_state->nModifiers;
|
2003-09-27 10:36:50 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return fhandler_base::ioctl (cmd, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_console::tcflush (int queue)
|
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
if (queue == TCIFLUSH
|
|
|
|
|| queue == TCIOFLUSH)
|
|
|
|
{
|
|
|
|
if (!FlushConsoleInputBuffer (get_io_handle ()))
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_console::output_tcsetattr (int, struct termios const *t)
|
|
|
|
{
|
|
|
|
/* All the output bits we can ignore */
|
|
|
|
|
|
|
|
DWORD flags = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
|
|
|
|
|
|
|
|
int res = SetConsoleMode (get_output_handle (), flags) ? 0 : -1;
|
|
|
|
syscall_printf ("%d = tcsetattr (,%x) (ENABLE FLAGS %x) (lflag %x oflag %x)",
|
|
|
|
res, t, flags, t->c_lflag, t->c_oflag);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_console::input_tcsetattr (int, struct termios const *t)
|
|
|
|
{
|
|
|
|
/* Ignore the optional_actions stuff, since all output is emitted
|
|
|
|
instantly */
|
|
|
|
|
|
|
|
DWORD oflags;
|
|
|
|
|
|
|
|
if (!GetConsoleMode (get_io_handle (), &oflags))
|
|
|
|
oflags = 0;
|
|
|
|
DWORD flags = 0;
|
|
|
|
|
2002-06-05 12:01:43 +08:00
|
|
|
#if 0
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Enable/disable LF -> CRLF conversions */
|
2004-04-10 21:45:10 +08:00
|
|
|
rbinary ((t->c_iflag & INLCR) ? false : true);
|
2002-06-05 12:01:43 +08:00
|
|
|
#endif
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* There's some disparity between what we need and what's
|
|
|
|
available. We've got ECHO and ICANON, they've
|
|
|
|
got ENABLE_ECHO_INPUT and ENABLE_LINE_INPUT. */
|
|
|
|
|
|
|
|
tc->ti = *t;
|
|
|
|
|
|
|
|
if (t->c_lflag & ECHO)
|
|
|
|
{
|
|
|
|
flags |= ENABLE_ECHO_INPUT;
|
|
|
|
}
|
|
|
|
if (t->c_lflag & ICANON)
|
|
|
|
{
|
|
|
|
flags |= ENABLE_LINE_INPUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & ENABLE_ECHO_INPUT
|
|
|
|
&& !(flags & ENABLE_LINE_INPUT))
|
|
|
|
{
|
|
|
|
/* This is illegal, so turn off the echo here, and fake it
|
|
|
|
when we read the characters */
|
|
|
|
|
|
|
|
flags &= ~ENABLE_ECHO_INPUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t->c_lflag & ISIG)
|
|
|
|
{
|
|
|
|
flags |= ENABLE_PROCESSED_INPUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_tty)
|
|
|
|
{
|
|
|
|
flags = 0; // ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
|
|
|
|
tc->ti.c_iflag = 0;
|
|
|
|
tc->ti.c_lflag = 0;
|
|
|
|
}
|
|
|
|
|
2000-12-16 11:11:02 +08:00
|
|
|
flags |= ENABLE_WINDOW_INPUT | ENABLE_MOUSE_INPUT;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
int res;
|
|
|
|
if (flags == oflags)
|
|
|
|
res = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = SetConsoleMode (get_io_handle (), flags) ? 0 : -1;
|
|
|
|
if (res < 0)
|
|
|
|
__seterrno ();
|
|
|
|
syscall_printf ("%d = tcsetattr (,%x) enable flags %p, c_lflag %p iflag %p",
|
|
|
|
res, t, flags, t->c_lflag, t->c_iflag);
|
|
|
|
}
|
|
|
|
|
2004-04-10 21:45:10 +08:00
|
|
|
tc->rstcons (false);
|
2000-02-18 03:38:33 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_console::tcsetattr (int a, struct termios const *t)
|
|
|
|
{
|
|
|
|
int res = output_tcsetattr (a, t);
|
|
|
|
if (res != 0)
|
|
|
|
return res;
|
|
|
|
return input_tcsetattr (a, t);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fhandler_console::tcgetattr (struct termios *t)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
*t = tc->ti;
|
|
|
|
|
|
|
|
t->c_cflag |= CS8;
|
|
|
|
|
|
|
|
DWORD flags;
|
|
|
|
|
|
|
|
if (!GetConsoleMode (get_io_handle (), &flags))
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
res = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (flags & ENABLE_ECHO_INPUT)
|
|
|
|
t->c_lflag |= ECHO;
|
|
|
|
|
|
|
|
if (flags & ENABLE_LINE_INPUT)
|
|
|
|
t->c_lflag |= ICANON;
|
|
|
|
|
|
|
|
if (flags & ENABLE_PROCESSED_INPUT)
|
|
|
|
t->c_lflag |= ISIG;
|
|
|
|
|
|
|
|
/* What about ENABLE_WINDOW_INPUT
|
|
|
|
and ENABLE_MOUSE_INPUT ? */
|
|
|
|
|
|
|
|
/* All the output bits we can ignore */
|
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
syscall_printf ("%d = tcgetattr (%p) enable flags %p, t->lflag %p, t->iflag %p",
|
|
|
|
res, t, flags, t->c_lflag, t->c_iflag);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2001-10-14 01:23:35 +08:00
|
|
|
fhandler_console::fhandler_console () :
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
fhandler_termios ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2008-02-07 02:24:50 +08:00
|
|
|
trunc_buf.len = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2008-02-07 02:24:50 +08:00
|
|
|
|
2001-02-27 17:14:35 +08:00
|
|
|
void
|
2005-04-23 01:03:38 +08:00
|
|
|
dev_console::set_color (HANDLE h)
|
2001-02-27 17:14:35 +08:00
|
|
|
{
|
2005-04-23 01:03:38 +08:00
|
|
|
WORD win_fg = fg;
|
|
|
|
WORD win_bg = bg;
|
|
|
|
if (reverse)
|
2001-03-03 11:56:34 +08:00
|
|
|
{
|
2001-02-27 17:14:35 +08:00
|
|
|
WORD save_fg = win_fg;
|
2001-03-03 11:56:34 +08:00
|
|
|
win_fg = (win_bg & BACKGROUND_RED ? FOREGROUND_RED : 0) |
|
|
|
|
(win_bg & BACKGROUND_GREEN ? FOREGROUND_GREEN : 0) |
|
|
|
|
(win_bg & BACKGROUND_BLUE ? FOREGROUND_BLUE : 0) |
|
2004-12-16 21:19:08 +08:00
|
|
|
(win_bg & BACKGROUND_INTENSITY ? FOREGROUND_INTENSITY : 0);
|
2001-03-03 11:56:34 +08:00
|
|
|
win_bg = (save_fg & FOREGROUND_RED ? BACKGROUND_RED : 0) |
|
|
|
|
(save_fg & FOREGROUND_GREEN ? BACKGROUND_GREEN : 0) |
|
|
|
|
(save_fg & FOREGROUND_BLUE ? BACKGROUND_BLUE : 0) |
|
2004-12-16 21:19:08 +08:00
|
|
|
(save_fg & FOREGROUND_INTENSITY ? BACKGROUND_INTENSITY : 0);
|
2001-02-27 17:14:35 +08:00
|
|
|
}
|
2006-11-23 18:08:04 +08:00
|
|
|
|
|
|
|
/* apply attributes */
|
2005-04-23 01:03:38 +08:00
|
|
|
if (underline)
|
|
|
|
win_fg = underline_color;
|
2001-02-27 17:14:35 +08:00
|
|
|
/* emulate blink with bright background */
|
2005-04-23 01:03:38 +08:00
|
|
|
if (blink)
|
2002-10-08 14:16:16 +08:00
|
|
|
win_bg |= BACKGROUND_INTENSITY;
|
2005-04-23 01:03:38 +08:00
|
|
|
if (intensity == INTENSITY_INVISIBLE)
|
2001-02-27 17:14:35 +08:00
|
|
|
win_fg = win_bg;
|
2008-09-11 12:34:24 +08:00
|
|
|
else if (intensity != INTENSITY_BOLD)
|
|
|
|
/* nothing to do */;
|
2006-11-23 18:08:04 +08:00
|
|
|
/* apply foreground intensity only in non-reverse mode! */
|
2008-09-11 12:34:24 +08:00
|
|
|
else if (reverse)
|
|
|
|
win_bg |= BACKGROUND_INTENSITY;
|
|
|
|
else
|
|
|
|
win_fg |= FOREGROUND_INTENSITY;
|
2006-11-23 18:08:04 +08:00
|
|
|
|
2005-04-23 01:03:38 +08:00
|
|
|
current_win32_attr = win_fg | win_bg;
|
|
|
|
if (h)
|
|
|
|
SetConsoleTextAttribute (h, current_win32_attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FOREGROUND_ATTR_MASK (FOREGROUND_RED | FOREGROUND_GREEN | \
|
|
|
|
FOREGROUND_BLUE | FOREGROUND_INTENSITY)
|
|
|
|
#define BACKGROUND_ATTR_MASK (BACKGROUND_RED | BACKGROUND_GREEN | \
|
|
|
|
BACKGROUND_BLUE | BACKGROUND_INTENSITY)
|
|
|
|
void
|
|
|
|
dev_console::set_default_attr ()
|
|
|
|
{
|
|
|
|
blink = underline = reverse = false;
|
|
|
|
intensity = INTENSITY_NORMAL;
|
|
|
|
fg = default_color & FOREGROUND_ATTR_MASK;
|
|
|
|
bg = default_color & BACKGROUND_ATTR_MASK;
|
|
|
|
set_color (NULL);
|
2001-02-27 17:14:35 +08:00
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/*
|
|
|
|
* Clear the screen context from x1/y1 to x2/y2 cell.
|
|
|
|
* Negative values represents current screen dimensions
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
fhandler_console::clear_screen (int x1, int y1, int x2, int y2)
|
|
|
|
{
|
|
|
|
COORD tlc;
|
|
|
|
DWORD done;
|
|
|
|
int num;
|
|
|
|
|
2005-07-07 04:05:03 +08:00
|
|
|
dev_state->fillin_info (get_output_handle ());
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
if (x1 < 0)
|
2002-10-08 14:16:16 +08:00
|
|
|
x1 = dev_state->info.dwWinSize.X - 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (y1 < 0)
|
2002-10-08 14:16:16 +08:00
|
|
|
y1 = dev_state->info.winBottom;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (x2 < 0)
|
2002-10-08 14:16:16 +08:00
|
|
|
x2 = dev_state->info.dwWinSize.X - 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (y2 < 0)
|
2002-10-08 14:16:16 +08:00
|
|
|
y2 = dev_state->info.winBottom;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-10-08 14:16:16 +08:00
|
|
|
num = abs (y1 - y2) * dev_state->info.dwBufferSize.X + abs (x1 - x2) + 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-10-08 14:16:16 +08:00
|
|
|
if ((y2 * dev_state->info.dwBufferSize.X + x2) > (y1 * dev_state->info.dwBufferSize.X + x1))
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
tlc.X = x1;
|
|
|
|
tlc.Y = y1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tlc.X = x2;
|
|
|
|
tlc.Y = y2;
|
|
|
|
}
|
|
|
|
FillConsoleOutputCharacterA (get_output_handle (), ' ',
|
|
|
|
num,
|
|
|
|
tlc,
|
|
|
|
&done);
|
|
|
|
FillConsoleOutputAttribute (get_output_handle (),
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->current_win32_attr,
|
2000-02-18 03:38:33 +08:00
|
|
|
num,
|
|
|
|
tlc,
|
|
|
|
&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2003-12-08 06:37:12 +08:00
|
|
|
fhandler_console::cursor_set (bool rel_to_top, int x, int y)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
COORD pos;
|
|
|
|
|
2005-07-07 04:05:03 +08:00
|
|
|
dev_state->fillin_info (get_output_handle ());
|
2002-10-08 14:16:16 +08:00
|
|
|
if (y > dev_state->info.winBottom)
|
|
|
|
y = dev_state->info.winBottom;
|
2000-02-18 03:38:33 +08:00
|
|
|
else if (y < 0)
|
|
|
|
y = 0;
|
|
|
|
else if (rel_to_top)
|
2002-10-08 14:16:16 +08:00
|
|
|
y += dev_state->info.winTop;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2002-10-08 14:16:16 +08:00
|
|
|
if (x > dev_state->info.dwWinSize.X)
|
|
|
|
x = dev_state->info.dwWinSize.X - 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
else if (x < 0)
|
|
|
|
x = 0;
|
|
|
|
|
|
|
|
pos.X = x;
|
|
|
|
pos.Y = y;
|
|
|
|
SetConsoleCursorPosition (get_output_handle (), pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_console::cursor_rel (int x, int y)
|
|
|
|
{
|
2005-07-07 04:05:03 +08:00
|
|
|
dev_state->fillin_info (get_output_handle ());
|
2002-10-08 14:16:16 +08:00
|
|
|
x += dev_state->info.dwCursorPosition.X;
|
|
|
|
y += dev_state->info.dwCursorPosition.Y;
|
2003-12-08 06:37:12 +08:00
|
|
|
cursor_set (false, x, y);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fhandler_console::cursor_get (int *x, int *y)
|
|
|
|
{
|
2005-04-23 01:03:38 +08:00
|
|
|
dev_state->fillin_info (get_output_handle ());
|
2002-10-08 14:16:16 +08:00
|
|
|
*y = dev_state->info.dwCursorPosition.Y;
|
|
|
|
*x = dev_state->info.dwCursorPosition.X;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2009-12-19 23:37:10 +08:00
|
|
|
/* VT100 line drawing graphics mode maps `abcdefghijklmnopqrstuvwxyz{|}~ to
|
|
|
|
graphical characters */
|
2009-12-19 23:40:31 +08:00
|
|
|
static wchar_t __vt100_conv [31] = {
|
2009-12-19 23:37:10 +08:00
|
|
|
0x25C6, /* Black Diamond */
|
|
|
|
0x2592, /* Medium Shade */
|
|
|
|
0x2409, /* Symbol for Horizontal Tabulation */
|
|
|
|
0x240C, /* Symbol for Form Feed */
|
|
|
|
0x240D, /* Symbol for Carriage Return */
|
|
|
|
0x240A, /* Symbol for Line Feed */
|
|
|
|
0x00B0, /* Degree Sign */
|
|
|
|
0x00B1, /* Plus-Minus Sign */
|
|
|
|
0x2424, /* Symbol for Newline */
|
|
|
|
0x240B, /* Symbol for Vertical Tabulation */
|
|
|
|
0x2518, /* Box Drawings Light Up And Left */
|
|
|
|
0x2510, /* Box Drawings Light Down And Left */
|
|
|
|
0x250C, /* Box Drawings Light Down And Right */
|
|
|
|
0x2514, /* Box Drawings Light Up And Right */
|
|
|
|
0x253C, /* Box Drawings Light Vertical And Horizontal */
|
|
|
|
0x23BA, /* Horizontal Scan Line-1 */
|
|
|
|
0x23BB, /* Horizontal Scan Line-3 */
|
|
|
|
0x2500, /* Box Drawings Light Horizontal */
|
|
|
|
0x23BC, /* Horizontal Scan Line-7 */
|
|
|
|
0x23BD, /* Horizontal Scan Line-9 */
|
|
|
|
0x251C, /* Box Drawings Light Vertical And Right */
|
|
|
|
0x2524, /* Box Drawings Light Vertical And Left */
|
|
|
|
0x2534, /* Box Drawings Light Up And Horizontal */
|
|
|
|
0x252C, /* Box Drawings Light Down And Horizontal */
|
|
|
|
0x2502, /* Box Drawings Light Vertical */
|
|
|
|
0x2264, /* Less-Than Or Equal To */
|
|
|
|
0x2265, /* Greater-Than Or Equal To */
|
|
|
|
0x03C0, /* Greek Small Letter Pi */
|
|
|
|
0x2260, /* Not Equal To */
|
|
|
|
0x00A3, /* Pound Sign */
|
|
|
|
0x00B7, /* Middle Dot */
|
|
|
|
};
|
|
|
|
|
2009-05-04 11:51:16 +08:00
|
|
|
inline
|
|
|
|
bool fhandler_console::write_console (PWCHAR buf, DWORD len, DWORD& done)
|
|
|
|
{
|
2010-03-31 00:17:34 +08:00
|
|
|
if (dev_state->iso_2022_G1
|
|
|
|
? dev_state->vt100_graphics_mode_G1
|
|
|
|
: dev_state->vt100_graphics_mode_G0)
|
2009-12-19 23:37:10 +08:00
|
|
|
for (DWORD i = 0; i < len; i ++)
|
|
|
|
if (buf[i] >= (unsigned char) '`' && buf[i] <= (unsigned char) '~')
|
|
|
|
buf[i] = __vt100_conv[buf[i] - (unsigned char) '`'];
|
|
|
|
|
2009-05-04 11:51:16 +08:00
|
|
|
while (len > 0)
|
|
|
|
{
|
|
|
|
DWORD nbytes = len > MAX_WRITE_CHARS ? MAX_WRITE_CHARS : len;
|
|
|
|
if (!WriteConsoleW (get_output_handle (), buf, nbytes, &done, 0))
|
|
|
|
{
|
|
|
|
__seterrno ();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
len -= done;
|
|
|
|
buf += done;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
#define BAK 1
|
|
|
|
#define ESC 2
|
|
|
|
#define NOR 0
|
|
|
|
#define IGN 4
|
2008-02-07 02:24:50 +08:00
|
|
|
#if 1
|
2000-02-18 03:38:33 +08:00
|
|
|
#define ERR 5
|
|
|
|
#else
|
|
|
|
#define ERR NOR
|
|
|
|
#endif
|
|
|
|
#define DWN 6
|
|
|
|
#define BEL 7
|
|
|
|
#define TAB 8 /* We should't let the console deal with these */
|
|
|
|
#define CR 13
|
|
|
|
#define LF 10
|
2009-12-19 23:37:10 +08:00
|
|
|
#define SO 14
|
|
|
|
#define SI 15
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
static const char base_chars[256] =
|
|
|
|
{
|
|
|
|
/*00 01 02 03 04 05 06 07 */ IGN, ERR, ERR, NOR, NOR, NOR, NOR, BEL,
|
2009-12-19 23:37:10 +08:00
|
|
|
/*08 09 0A 0B 0C 0D 0E 0F */ BAK, TAB, DWN, ERR, ERR, CR, SO, SI,
|
2000-02-18 03:38:33 +08:00
|
|
|
/*10 11 12 13 14 15 16 17 */ NOR, NOR, ERR, ERR, ERR, ERR, ERR, ERR,
|
|
|
|
/*18 19 1A 1B 1C 1D 1E 1F */ NOR, NOR, ERR, ESC, ERR, ERR, ERR, ERR,
|
|
|
|
/* ! " # $ % & ' */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
2008-02-06 01:37:10 +08:00
|
|
|
/*( ) * + , - . / */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
2000-02-18 03:38:33 +08:00
|
|
|
/*0 1 2 3 4 5 6 7 */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*8 9 : ; < = > ? */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*@ A B C D E F G */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*H I J K L M N O */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*P Q R S T U V W */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*X Y Z [ \ ] ^ _ */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*` a b c d e f g */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*h i j k l m n o */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*p q r s t u v w */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*x y z { | } ~ 7F */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*80 81 82 83 84 85 86 87 */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*88 89 8A 8B 8C 8D 8E 8F */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*90 91 92 93 94 95 96 97 */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*98 99 9A 9B 9C 9D 9E 9F */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*A0 A1 A2 A3 A4 A5 A6 A7 */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*A8 A9 AA AB AC AD AE AF */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*B0 B1 B2 B3 B4 B5 B6 B7 */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*B8 B9 BA BB BC BD BE BF */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*C0 C1 C2 C3 C4 C5 C6 C7 */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*C8 C9 CA CB CC CD CE CF */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*D0 D1 D2 D3 D4 D5 D6 D7 */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*D8 D9 DA DB DC DD DE DF */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*E0 E1 E2 E3 E4 E5 E6 E7 */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*E8 E9 EA EB EC ED EE EF */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*F0 F1 F2 F3 F4 F5 F6 F7 */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR,
|
|
|
|
/*F8 F9 FA FB FC FD FE FF */ NOR, NOR, NOR, NOR, NOR, NOR, NOR, NOR };
|
|
|
|
|
|
|
|
void
|
2001-02-27 17:14:35 +08:00
|
|
|
fhandler_console::char_command (char c)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
char buf[40];
|
|
|
|
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'm': /* Set Graphics Rendition */
|
2005-04-23 01:03:38 +08:00
|
|
|
for (int i = 0; i <= dev_state->nargs_; i++)
|
2002-10-08 14:16:16 +08:00
|
|
|
switch (dev_state->args_[i])
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
case 0: /* normal color */
|
2005-04-23 01:03:38 +08:00
|
|
|
dev_state->set_default_attr ();
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 1: /* bold */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->intensity = INTENSITY_BOLD;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
2009-12-15 20:46:40 +08:00
|
|
|
case 2: /* dim */
|
|
|
|
dev_state->intensity = INTENSITY_DIM;
|
|
|
|
break;
|
|
|
|
case 4: /* underlined */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->underline = 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 5: /* blink mode */
|
2003-12-08 06:37:12 +08:00
|
|
|
dev_state->blink = true;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 7: /* reverse */
|
2003-12-08 06:37:12 +08:00
|
|
|
dev_state->reverse = true;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 8: /* invisible */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->intensity = INTENSITY_INVISIBLE;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
2004-05-29 03:50:07 +08:00
|
|
|
case 10: /* end alternate charset */
|
|
|
|
dev_state->alternate_charset_active = false;
|
2003-10-15 16:23:26 +08:00
|
|
|
break;
|
2004-05-29 03:50:07 +08:00
|
|
|
case 11: /* start alternate charset */
|
|
|
|
dev_state->alternate_charset_active = true;
|
2003-10-15 16:23:26 +08:00
|
|
|
break;
|
2009-12-15 20:46:40 +08:00
|
|
|
case 22:
|
|
|
|
case 28:
|
|
|
|
dev_state->intensity = INTENSITY_NORMAL;
|
|
|
|
break;
|
2001-03-03 11:56:34 +08:00
|
|
|
case 24:
|
2003-12-08 06:37:12 +08:00
|
|
|
dev_state->underline = false;
|
2001-03-03 11:56:34 +08:00
|
|
|
break;
|
2009-12-15 20:46:40 +08:00
|
|
|
case 25:
|
|
|
|
dev_state->blink = false;
|
|
|
|
break;
|
2001-03-03 11:56:34 +08:00
|
|
|
case 27:
|
2003-12-08 06:37:12 +08:00
|
|
|
dev_state->reverse = false;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 30: /* BLACK foreground */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->fg = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 31: /* RED foreground */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->fg = FOREGROUND_RED;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 32: /* GREEN foreground */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->fg = FOREGROUND_GREEN;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 33: /* YELLOW foreground */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->fg = FOREGROUND_RED | FOREGROUND_GREEN;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 34: /* BLUE foreground */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->fg = FOREGROUND_BLUE;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 35: /* MAGENTA foreground */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->fg = FOREGROUND_RED | FOREGROUND_BLUE;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 36: /* CYAN foreground */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->fg = FOREGROUND_BLUE | FOREGROUND_GREEN;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 37: /* WHITE foreg */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->fg = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
2001-03-03 11:56:34 +08:00
|
|
|
case 39:
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->fg = dev_state->default_color & FOREGROUND_ATTR_MASK;
|
2001-03-03 11:56:34 +08:00
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
case 40: /* BLACK background */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->bg = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 41: /* RED background */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->bg = BACKGROUND_RED;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 42: /* GREEN background */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->bg = BACKGROUND_GREEN;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 43: /* YELLOW background */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->bg = BACKGROUND_RED | BACKGROUND_GREEN;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 44: /* BLUE background */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->bg = BACKGROUND_BLUE;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 45: /* MAGENTA background */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->bg = BACKGROUND_RED | BACKGROUND_BLUE;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 46: /* CYAN background */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->bg = BACKGROUND_BLUE | BACKGROUND_GREEN;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 47: /* WHITE background */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->bg = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
2001-03-03 11:56:34 +08:00
|
|
|
case 49:
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->bg = dev_state->default_color & BACKGROUND_ATTR_MASK;
|
2001-03-03 11:56:34 +08:00
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2005-04-23 01:03:38 +08:00
|
|
|
dev_state->set_color (get_output_handle ());
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case 'l':
|
2002-10-08 14:16:16 +08:00
|
|
|
if (!dev_state->saw_question_mark)
|
2001-04-09 08:44:25 +08:00
|
|
|
{
|
2002-10-08 14:16:16 +08:00
|
|
|
switch (dev_state->args_[0])
|
2001-03-31 17:19:32 +08:00
|
|
|
{
|
|
|
|
case 4: /* Insert mode */
|
2003-12-08 06:37:12 +08:00
|
|
|
dev_state->insert_mode = (c == 'h') ? true : false;
|
2002-10-08 14:16:16 +08:00
|
|
|
syscall_printf ("insert mode %sabled", dev_state->insert_mode ? "en" : "dis");
|
2001-03-31 17:19:32 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-10-08 14:16:16 +08:00
|
|
|
switch (dev_state->args_[0])
|
2000-12-16 11:11:02 +08:00
|
|
|
{
|
2001-03-30 19:10:13 +08:00
|
|
|
case 47: /* Save/Restore screen */
|
|
|
|
if (c == 'h') /* save */
|
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO now;
|
|
|
|
COORD cob = { 0, 0 };
|
|
|
|
|
|
|
|
if (!GetConsoleScreenBufferInfo (get_output_handle (), &now))
|
2001-04-09 08:44:25 +08:00
|
|
|
break;
|
2001-03-30 19:10:13 +08:00
|
|
|
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->savebufsiz.X = now.srWindow.Right - now.srWindow.Left + 1;
|
|
|
|
dev_state->savebufsiz.Y = now.srWindow.Bottom - now.srWindow.Top + 1;
|
2001-03-30 19:10:13 +08:00
|
|
|
|
2002-10-08 14:16:16 +08:00
|
|
|
if (dev_state->savebuf)
|
|
|
|
cfree (dev_state->savebuf);
|
2007-11-27 05:30:49 +08:00
|
|
|
dev_state->savebuf = (PCHAR_INFO) cmalloc_abort (HEAP_1_BUF, sizeof (CHAR_INFO) *
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->savebufsiz.X * dev_state->savebufsiz.Y);
|
2001-03-30 19:10:13 +08:00
|
|
|
|
2008-02-06 01:37:10 +08:00
|
|
|
ReadConsoleOutputW (get_output_handle (), dev_state->savebuf,
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->savebufsiz, cob, &now.srWindow);
|
2001-03-30 19:10:13 +08:00
|
|
|
}
|
2002-05-28 09:55:40 +08:00
|
|
|
else /* restore */
|
2001-03-30 19:10:13 +08:00
|
|
|
{
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO now;
|
|
|
|
COORD cob = { 0, 0 };
|
|
|
|
|
|
|
|
if (!GetConsoleScreenBufferInfo (get_output_handle (), &now))
|
2001-04-09 08:44:25 +08:00
|
|
|
break;
|
2001-03-30 19:10:13 +08:00
|
|
|
|
2002-10-08 14:16:16 +08:00
|
|
|
if (!dev_state->savebuf)
|
2001-04-09 08:44:25 +08:00
|
|
|
break;
|
2001-03-30 19:10:13 +08:00
|
|
|
|
2008-02-06 01:37:10 +08:00
|
|
|
WriteConsoleOutputW (get_output_handle (), dev_state->savebuf,
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->savebufsiz, cob, &now.srWindow);
|
2001-03-30 19:10:13 +08:00
|
|
|
|
2002-10-08 14:16:16 +08:00
|
|
|
cfree (dev_state->savebuf);
|
|
|
|
dev_state->savebuf = NULL;
|
|
|
|
dev_state->savebufsiz.X = dev_state->savebufsiz.Y = 0;
|
2001-03-30 19:10:13 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-04-12 03:11:17 +08:00
|
|
|
case 67: /* DECBKM ("DEC Backarrow Key Mode") */
|
|
|
|
dev_state->backspace_keycode = (c == 'h' ? CTRL('H') : CERASE);
|
|
|
|
break;
|
|
|
|
|
2009-12-16 22:56:10 +08:00
|
|
|
case 1000: /* Mouse tracking */
|
|
|
|
dev_state->use_mouse = (c == 'h') ? 1 : 0;
|
|
|
|
syscall_printf ("mouse support set to mode %d", dev_state->use_mouse);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1002: /* Mouse button event tracking */
|
|
|
|
dev_state->use_mouse = (c == 'h') ? 2 : 0;
|
|
|
|
syscall_printf ("mouse support set to mode %d", dev_state->use_mouse);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1003: /* Mouse any event tracking */
|
|
|
|
dev_state->use_mouse = (c == 'h') ? 3 : 0;
|
|
|
|
syscall_printf ("mouse support set to mode %d", dev_state->use_mouse);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1004: /* Focus in/out event reporting */
|
|
|
|
dev_state->use_focus = (c == 'h') ? true : false;
|
|
|
|
syscall_printf ("focus reporting set to %d", dev_state->use_focus);
|
2000-12-16 11:11:02 +08:00
|
|
|
break;
|
|
|
|
|
2001-03-03 11:56:34 +08:00
|
|
|
case 2000: /* Raw keyboard mode */
|
2003-12-08 06:37:12 +08:00
|
|
|
set_raw_win32_keyboard_mode ((c == 'h') ? true : false);
|
2001-03-03 11:56:34 +08:00
|
|
|
break;
|
|
|
|
|
2000-12-16 11:11:02 +08:00
|
|
|
default: /* Ignore */
|
2002-10-08 14:16:16 +08:00
|
|
|
syscall_printf ("unknown h/l command: %d", dev_state->args_[0]);
|
2000-12-16 11:11:02 +08:00
|
|
|
break;
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'J':
|
2002-10-08 14:16:16 +08:00
|
|
|
switch (dev_state->args_[0])
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
case 0: /* Clear to end of screen */
|
|
|
|
cursor_get (&x, &y);
|
|
|
|
clear_screen (x, y, -1, -1);
|
|
|
|
break;
|
|
|
|
case 1: /* Clear from beginning of screen to cursor */
|
|
|
|
cursor_get (&x, &y);
|
|
|
|
clear_screen (0, 0, x, y);
|
|
|
|
break;
|
|
|
|
case 2: /* Clear screen */
|
|
|
|
clear_screen (0, 0, -1, -1);
|
2003-12-08 06:37:12 +08:00
|
|
|
cursor_set (true, 0,0);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto bad_escape;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'A':
|
2002-10-08 14:16:16 +08:00
|
|
|
cursor_rel (0, -(dev_state->args_[0] ? dev_state->args_[0] : 1));
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'B':
|
2002-10-08 14:16:16 +08:00
|
|
|
cursor_rel (0, dev_state->args_[0] ? dev_state->args_[0] : 1);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'C':
|
2002-10-08 14:16:16 +08:00
|
|
|
cursor_rel (dev_state->args_[0] ? dev_state->args_[0] : 1, 0);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'D':
|
2002-10-08 14:16:16 +08:00
|
|
|
cursor_rel (-(dev_state->args_[0] ? dev_state->args_[0] : 1),0);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'K':
|
2002-10-08 14:16:16 +08:00
|
|
|
switch (dev_state->args_[0])
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
case 0: /* Clear to end of line */
|
|
|
|
cursor_get (&x, &y);
|
|
|
|
clear_screen (x, y, -1, y);
|
|
|
|
break;
|
|
|
|
case 2: /* Clear line */
|
|
|
|
cursor_get (&x, &y);
|
|
|
|
clear_screen (0, y, -1, y);
|
|
|
|
break;
|
|
|
|
case 1: /* Clear from bol to cursor */
|
|
|
|
cursor_get (&x, &y);
|
|
|
|
clear_screen (0, y, x, y);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto bad_escape;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'H':
|
|
|
|
case 'f':
|
2003-12-08 06:37:12 +08:00
|
|
|
cursor_set (true, (dev_state->args_[1] ? dev_state->args_[1] : 1) - 1,
|
2002-10-08 14:16:16 +08:00
|
|
|
(dev_state->args_[0] ? dev_state->args_[0] : 1) - 1);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'G': /* hpa - position cursor at column n - 1 */
|
|
|
|
cursor_get (&x, &y);
|
2003-12-08 06:37:12 +08:00
|
|
|
cursor_set (false, (dev_state->args_[0] ? dev_state->args_[0] - 1 : 0), y);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'd': /* vpa - position cursor at line n */
|
|
|
|
cursor_get (&x, &y);
|
2003-12-08 06:37:12 +08:00
|
|
|
cursor_set (true, x, (dev_state->args_[0] ? dev_state->args_[0] - 1 : 0));
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 's': /* Save cursor position */
|
2002-10-08 14:16:16 +08:00
|
|
|
cursor_get (&dev_state->savex, &dev_state->savey);
|
|
|
|
dev_state->savey -= dev_state->info.winTop;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'u': /* Restore cursor position */
|
2003-12-08 06:37:12 +08:00
|
|
|
cursor_set (true, dev_state->savex, dev_state->savey);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'I': /* TAB */
|
|
|
|
cursor_get (&x, &y);
|
2003-12-08 06:37:12 +08:00
|
|
|
cursor_set (false, 8 * (x / 8 + 1), y);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'L': /* AL - insert blank lines */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->args_[0] = dev_state->args_[0] ? dev_state->args_[0] : 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
cursor_get (&x, &y);
|
2002-10-08 14:16:16 +08:00
|
|
|
scroll_screen (0, y, -1, -1, 0, y + dev_state->args_[0]);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'M': /* DL - delete lines */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->args_[0] = dev_state->args_[0] ? dev_state->args_[0] : 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
cursor_get (&x, &y);
|
2002-10-08 14:16:16 +08:00
|
|
|
scroll_screen (0, y + dev_state->args_[0], -1, -1, 0, y);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case '@': /* IC - insert chars */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->args_[0] = dev_state->args_[0] ? dev_state->args_[0] : 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
cursor_get (&x, &y);
|
2002-10-08 14:16:16 +08:00
|
|
|
scroll_screen (x, y, -1, y, x + dev_state->args_[0], y);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'P': /* DC - delete chars */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->args_[0] = dev_state->args_[0] ? dev_state->args_[0] : 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
cursor_get (&x, &y);
|
2002-10-08 14:16:16 +08:00
|
|
|
scroll_screen (x + dev_state->args_[0], y, -1, y, x, y);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'S': /* SF - Scroll forward */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->args_[0] = dev_state->args_[0] ? dev_state->args_[0] : 1;
|
|
|
|
scroll_screen (0, dev_state->args_[0], -1, -1, 0, 0);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'T': /* SR - Scroll down */
|
2005-04-23 01:03:38 +08:00
|
|
|
dev_state->fillin_info (get_output_handle ());
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->args_[0] = dev_state->args_[0] ? dev_state->args_[0] : 1;
|
|
|
|
scroll_screen (0, 0, -1, -1, 0, dev_state->info.winTop + dev_state->args_[0]);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'X': /* ec - erase chars */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->args_[0] = dev_state->args_[0] ? dev_state->args_[0] : 1;
|
2000-02-18 03:38:33 +08:00
|
|
|
cursor_get (&x, &y);
|
2002-10-08 14:16:16 +08:00
|
|
|
scroll_screen (x + dev_state->args_[0], y, -1, y, x, y);
|
|
|
|
scroll_screen (x, y, -1, y, x + dev_state->args_[0], y);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'Z': /* Back tab */
|
|
|
|
cursor_get (&x, &y);
|
2003-12-08 06:37:12 +08:00
|
|
|
cursor_set (false, ((8 * (x / 8 + 1)) - 8), y);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'b': /* Repeat char #1 #2 times */
|
2002-10-08 14:16:16 +08:00
|
|
|
if (dev_state->insert_mode)
|
2001-03-31 17:19:32 +08:00
|
|
|
{
|
2001-04-09 08:44:25 +08:00
|
|
|
cursor_get (&x, &y);
|
2002-10-08 14:16:16 +08:00
|
|
|
scroll_screen (x, y, -1, y, x + dev_state->args_[1], y);
|
2001-03-31 17:19:32 +08:00
|
|
|
}
|
2002-10-08 14:16:16 +08:00
|
|
|
while (dev_state->args_[1]--)
|
|
|
|
WriteFile (get_output_handle (), &dev_state->args_[0], 1, (DWORD *) &x, 0);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'c': /* u9 - Terminal enquire string */
|
2009-12-19 23:37:10 +08:00
|
|
|
if (dev_state->saw_greater_than_sign)
|
|
|
|
/* Generate Secondary Device Attribute report, using 67 = ASCII 'C'
|
|
|
|
to indicate Cygwin (convention used by Rxvt, Urxvt, Screen, Mintty),
|
|
|
|
and cygwin version for terminal version. */
|
|
|
|
__small_sprintf (buf, "\033[>67;%d%02d;0c", CYGWIN_VERSION_DLL_MAJOR, CYGWIN_VERSION_DLL_MINOR);
|
|
|
|
else
|
|
|
|
strcpy (buf, "\033[?6c");
|
|
|
|
/* The generated report needs to be injected for read-ahead into the
|
|
|
|
fhandler_console object associated with standard input.
|
|
|
|
The current call does not work. */
|
2000-02-18 03:38:33 +08:00
|
|
|
puts_readahead (buf);
|
|
|
|
break;
|
|
|
|
case 'n':
|
2002-10-08 14:16:16 +08:00
|
|
|
switch (dev_state->args_[0])
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
case 6: /* u7 - Cursor position request */
|
|
|
|
cursor_get (&x, &y);
|
2002-10-08 14:16:16 +08:00
|
|
|
y -= dev_state->info.winTop;
|
|
|
|
/* x -= dev_state->info.winLeft; // not available yet */
|
2000-02-18 03:38:33 +08:00
|
|
|
__small_sprintf (buf, "\033[%d;%dR", y + 1, x + 1);
|
|
|
|
puts_readahead (buf);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto bad_escape;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'r': /* Set Scroll region */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->scroll_region.Top = dev_state->args_[0] ? dev_state->args_[0] - 1 : 0;
|
|
|
|
dev_state->scroll_region.Bottom = dev_state->args_[1] ? dev_state->args_[1] - 1 : -1;
|
2003-12-08 06:37:12 +08:00
|
|
|
cursor_set (true, 0, 0);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case 'g': /* TAB set/clear */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
bad_escape:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-24 20:18:34 +08:00
|
|
|
/* This gets called when we found an invalid input character. We just
|
|
|
|
print a half filled square (UTF 0x2592). We have no chance to figure
|
|
|
|
out the "meaning" of the input char anyway. */
|
2009-05-04 11:51:16 +08:00
|
|
|
inline void
|
2009-03-24 20:18:34 +08:00
|
|
|
fhandler_console::write_replacement_char ()
|
2008-02-07 02:24:50 +08:00
|
|
|
{
|
2009-03-24 20:18:34 +08:00
|
|
|
static const wchar_t replacement_char = 0x2592; /* Half filled square */
|
2008-02-07 02:24:50 +08:00
|
|
|
DWORD done;
|
2009-03-24 20:18:34 +08:00
|
|
|
WriteConsoleW (get_output_handle (), &replacement_char, 1, &done, 0);
|
2008-02-07 02:24:50 +08:00
|
|
|
}
|
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
const unsigned char *
|
|
|
|
fhandler_console::write_normal (const unsigned char *src,
|
|
|
|
const unsigned char *end)
|
|
|
|
{
|
|
|
|
/* Scan forward to see what a char which needs special treatment */
|
|
|
|
DWORD done;
|
2008-02-07 02:24:50 +08:00
|
|
|
DWORD buf_len;
|
|
|
|
const unsigned char *found = src;
|
2009-03-24 20:18:34 +08:00
|
|
|
size_t ret;
|
|
|
|
mbstate_t ps;
|
2008-02-06 01:37:10 +08:00
|
|
|
UINT cp = dev_state->get_console_cp ();
|
2009-09-28 20:10:32 +08:00
|
|
|
const char *charset;
|
2009-04-07 20:13:37 +08:00
|
|
|
mbtowc_p f_mbtowc;
|
2009-03-24 20:18:34 +08:00
|
|
|
|
|
|
|
if (cp)
|
2009-09-28 20:10:32 +08:00
|
|
|
{
|
|
|
|
/* The alternate charset is always 437, just as in the Linux console. */
|
|
|
|
f_mbtowc = __cp_mbtowc;
|
|
|
|
charset = "CP437";
|
|
|
|
}
|
2009-04-07 20:13:37 +08:00
|
|
|
else
|
|
|
|
{
|
2009-09-28 20:10:32 +08:00
|
|
|
f_mbtowc = cygheap->locale.mbtowc;
|
2009-05-15 03:49:37 +08:00
|
|
|
charset = cygheap->locale.charset;
|
2009-04-07 20:13:37 +08:00
|
|
|
}
|
2008-02-07 02:24:50 +08:00
|
|
|
|
2008-02-16 01:53:11 +08:00
|
|
|
/* First check if we have cached lead bytes of a former try to write
|
2008-02-07 02:24:50 +08:00
|
|
|
a truncated multibyte sequence. If so, process it. */
|
|
|
|
if (trunc_buf.len)
|
|
|
|
{
|
2009-03-24 20:18:34 +08:00
|
|
|
const unsigned char *nfound;
|
2008-02-07 02:24:50 +08:00
|
|
|
int cp_len = min (end - src, 4 - trunc_buf.len);
|
|
|
|
memcpy (trunc_buf.buf + trunc_buf.len, src, cp_len);
|
2009-03-24 20:18:34 +08:00
|
|
|
memset (&ps, 0, sizeof ps);
|
|
|
|
switch (ret = f_mbtowc (_REENT, NULL, (const char *) trunc_buf.buf,
|
|
|
|
trunc_buf.len + cp_len, charset, &ps))
|
2008-03-11 00:22:38 +08:00
|
|
|
{
|
2009-03-24 20:18:34 +08:00
|
|
|
case -2:
|
|
|
|
/* Still truncated multibyte sequence? Keep in trunc_buf. */
|
2008-02-07 02:24:50 +08:00
|
|
|
trunc_buf.len += cp_len;
|
|
|
|
return end;
|
2009-03-24 20:18:34 +08:00
|
|
|
case -1:
|
|
|
|
/* Give up, print replacement chars for trunc_buf... */
|
|
|
|
for (int i = 0; i < trunc_buf.len; ++i)
|
|
|
|
write_replacement_char ();
|
|
|
|
/* ... mark trunc_buf as unused... */
|
|
|
|
trunc_buf.len = 0;
|
|
|
|
/* ... and proceed. */
|
|
|
|
nfound = NULL;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
nfound = trunc_buf.buf + 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
nfound = trunc_buf.buf + ret;
|
|
|
|
break;
|
2008-02-07 02:24:50 +08:00
|
|
|
}
|
2008-03-11 00:22:38 +08:00
|
|
|
/* Valid multibyte sequence? Process. */
|
|
|
|
if (nfound)
|
2008-02-07 02:24:50 +08:00
|
|
|
{
|
2009-04-07 20:13:37 +08:00
|
|
|
buf_len = dev_state->str_to_con (f_mbtowc, charset, write_buf,
|
2008-03-11 01:23:50 +08:00
|
|
|
(const char *) trunc_buf.buf,
|
2008-02-07 02:24:50 +08:00
|
|
|
nfound - trunc_buf.buf);
|
2009-05-04 11:51:16 +08:00
|
|
|
if (!write_console (write_buf, buf_len, done))
|
|
|
|
{
|
|
|
|
debug_printf ("multibyte sequence write failed, handle %p", get_output_handle ());
|
|
|
|
return 0;
|
|
|
|
}
|
2008-02-07 02:24:50 +08:00
|
|
|
found = src + (nfound - trunc_buf.buf - trunc_buf.len);
|
2008-03-11 00:22:38 +08:00
|
|
|
trunc_buf.len = 0;
|
|
|
|
return found;
|
2008-02-07 02:24:50 +08:00
|
|
|
}
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2009-03-24 20:18:34 +08:00
|
|
|
memset (&ps, 0, sizeof ps);
|
2008-02-06 01:37:10 +08:00
|
|
|
while (found < end
|
|
|
|
&& found - src < CONVERT_LIMIT
|
|
|
|
&& base_chars[*found] == NOR)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2009-03-24 20:18:34 +08:00
|
|
|
switch (ret = f_mbtowc (_REENT, NULL, (const char *) found,
|
|
|
|
end - found, charset, &ps))
|
|
|
|
{
|
|
|
|
case -2:
|
|
|
|
/* Truncated multibyte sequence. Stick to it until the next write. */
|
2008-02-07 02:24:50 +08:00
|
|
|
trunc_buf.len = end - found;
|
|
|
|
memcpy (trunc_buf.buf, found, trunc_buf.len);
|
|
|
|
return end;
|
2009-03-24 20:18:34 +08:00
|
|
|
case -1:
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
found++;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
found += ret;
|
|
|
|
break;
|
2008-02-06 01:37:10 +08:00
|
|
|
}
|
2009-03-24 20:18:34 +08:00
|
|
|
if (ret == (size_t) -1) /* Invalid multibyte sequence. */
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2001-04-09 08:44:25 +08:00
|
|
|
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Print all the base ones out */
|
|
|
|
if (found != src)
|
|
|
|
{
|
2001-04-09 08:44:25 +08:00
|
|
|
DWORD len = found - src;
|
2009-04-07 20:13:37 +08:00
|
|
|
buf_len = dev_state->str_to_con (f_mbtowc, charset, write_buf,
|
|
|
|
(const char *) src, len);
|
2008-02-06 01:37:10 +08:00
|
|
|
if (!buf_len)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2008-02-06 01:37:10 +08:00
|
|
|
debug_printf ("conversion error, handle %p",
|
|
|
|
get_output_handle ());
|
|
|
|
__seterrno ();
|
|
|
|
return 0;
|
|
|
|
}
|
2001-04-09 08:44:25 +08:00
|
|
|
|
2008-02-06 01:37:10 +08:00
|
|
|
if (dev_state->insert_mode)
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
cursor_get (&x, &y);
|
|
|
|
scroll_screen (x, y, -1, y, x + buf_len, y);
|
|
|
|
}
|
2001-04-09 08:44:25 +08:00
|
|
|
|
2009-05-04 11:51:16 +08:00
|
|
|
if (!write_console (write_buf, buf_len, done))
|
2008-02-06 01:37:10 +08:00
|
|
|
{
|
2009-05-04 11:51:16 +08:00
|
|
|
debug_printf ("write failed, handle %p", get_output_handle ());
|
|
|
|
return 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2008-02-07 02:24:50 +08:00
|
|
|
if (len >= CONVERT_LIMIT)
|
|
|
|
return found;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2001-04-09 08:44:25 +08:00
|
|
|
|
2008-02-07 02:24:50 +08:00
|
|
|
if (found < end)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
int x, y;
|
2008-02-07 02:24:50 +08:00
|
|
|
switch (base_chars[*found])
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2010-03-31 00:17:34 +08:00
|
|
|
case SO: /* Shift Out: Invoke G1 character set (ISO 2022) */
|
|
|
|
dev_state->iso_2022_G1 = true;
|
2009-12-19 23:37:10 +08:00
|
|
|
break;
|
2010-03-31 00:17:34 +08:00
|
|
|
case SI: /* Shift In: Invoke G0 character set (ISO 2022) */
|
|
|
|
dev_state->iso_2022_G1 = false;
|
2009-12-19 23:37:10 +08:00
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
case BEL:
|
2006-01-03 09:15:29 +08:00
|
|
|
beep ();
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case ESC:
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->state_ = gotesc;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
2002-06-01 06:35:57 +08:00
|
|
|
case DWN:
|
2000-02-18 03:38:33 +08:00
|
|
|
cursor_get (&x, &y);
|
|
|
|
if (y >= srBottom)
|
|
|
|
{
|
2002-10-08 14:16:16 +08:00
|
|
|
if (y >= dev_state->info.winBottom && !dev_state->scroll_region.Top)
|
2008-02-06 01:37:10 +08:00
|
|
|
WriteConsoleW (get_output_handle (), L"\n", 1, &done, 0);
|
2002-06-01 06:35:57 +08:00
|
|
|
else
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
scroll_screen (0, srTop + 1, -1, srBottom, 0, srTop);
|
|
|
|
y--;
|
|
|
|
}
|
|
|
|
}
|
2003-12-08 06:37:12 +08:00
|
|
|
cursor_set (false, ((tc->ti.c_oflag & ONLCR) ? 0 : x), y + 1);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case BAK:
|
|
|
|
cursor_rel (-1, 0);
|
|
|
|
break;
|
|
|
|
case IGN:
|
|
|
|
cursor_rel (1, 0);
|
|
|
|
break;
|
|
|
|
case CR:
|
|
|
|
cursor_get (&x, &y);
|
2003-12-08 06:37:12 +08:00
|
|
|
cursor_set (false, 0, y);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case ERR:
|
2009-09-28 20:10:32 +08:00
|
|
|
/* Don't print chars marked as ERR chars, except for a ASCII CAN
|
|
|
|
sequence which is printed as singlebyte chars from the UTF
|
|
|
|
Basic Latin and Latin 1 Supplement plains. */
|
|
|
|
if (*found == 0x18)
|
2009-03-25 20:29:04 +08:00
|
|
|
{
|
|
|
|
write_replacement_char ();
|
|
|
|
if (found + 1 < end)
|
|
|
|
{
|
|
|
|
ret = __utf8_mbtowc (_REENT, NULL, (const char *) found + 1,
|
|
|
|
end - found - 1, NULL, &ps);
|
|
|
|
if (ret != (size_t) -1)
|
|
|
|
while (ret-- > 0)
|
|
|
|
{
|
|
|
|
WCHAR w = *(found + 1);
|
|
|
|
WriteConsoleW (get_output_handle (), &w, 1, &done, 0);
|
|
|
|
found++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case TAB:
|
|
|
|
cursor_get (&x, &y);
|
2003-12-08 06:37:12 +08:00
|
|
|
cursor_set (false, 8 * (x / 8 + 1), y);
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
2008-02-07 02:24:50 +08:00
|
|
|
case NOR:
|
2009-03-24 20:18:34 +08:00
|
|
|
write_replacement_char ();
|
2008-02-07 02:24:50 +08:00
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2008-02-07 02:24:50 +08:00
|
|
|
found++;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2008-02-07 02:24:50 +08:00
|
|
|
return found;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2009-07-25 04:54:33 +08:00
|
|
|
ssize_t __stdcall
|
2000-02-18 03:38:33 +08:00
|
|
|
fhandler_console::write (const void *vsrc, size_t len)
|
|
|
|
{
|
|
|
|
/* Run and check for ansi sequences */
|
|
|
|
unsigned const char *src = (unsigned char *) vsrc;
|
|
|
|
unsigned const char *end = src + len;
|
2008-03-11 01:23:50 +08:00
|
|
|
/* This might look a bit far fetched, but using the TLS path buffer allows
|
|
|
|
to allocate a big buffer without using the stack too much. Doing it here
|
|
|
|
in write instead of in write_normal should be faster, too. */
|
|
|
|
tmp_pathbuf tp;
|
|
|
|
write_buf = tp.w_get ();
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
debug_printf ("%x, %d", vsrc, len);
|
|
|
|
|
|
|
|
while (src < end)
|
|
|
|
{
|
|
|
|
debug_printf ("at %d(%c) state is %d", *src, isprint (*src) ? *src : ' ',
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->state_);
|
|
|
|
switch (dev_state->state_)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
case normal:
|
|
|
|
src = write_normal (src, end);
|
2000-10-23 11:35:50 +08:00
|
|
|
if (!src) /* write_normal failed */
|
2000-02-18 03:38:33 +08:00
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
case gotesc:
|
2009-12-19 23:37:10 +08:00
|
|
|
if (*src == '[') /* CSI Control Sequence Introducer */
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->state_ = gotsquare;
|
2003-12-08 06:37:12 +08:00
|
|
|
dev_state->saw_question_mark = false;
|
2009-12-19 23:37:10 +08:00
|
|
|
dev_state->saw_greater_than_sign = false;
|
2002-10-08 14:16:16 +08:00
|
|
|
for (dev_state->nargs_ = 0; dev_state->nargs_ < MAXARGS; dev_state->nargs_++)
|
|
|
|
dev_state->args_[dev_state->nargs_] = 0;
|
|
|
|
dev_state->nargs_ = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2009-12-19 23:37:10 +08:00
|
|
|
else if (*src == ']') /* OSC Operating System Command */
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->rarg = 0;
|
|
|
|
dev_state->my_title_buf[0] = '\0';
|
|
|
|
dev_state->state_ = gotrsquare;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2009-12-19 23:37:10 +08:00
|
|
|
else if (*src == '(') /* Designate G0 character set */
|
|
|
|
{
|
|
|
|
dev_state->state_ = gotparen;
|
|
|
|
}
|
|
|
|
else if (*src == ')') /* Designate G1 character set */
|
|
|
|
{
|
|
|
|
dev_state->state_ = gotrparen;
|
|
|
|
}
|
|
|
|
else if (*src == 'M') /* Reverse Index (scroll down) */
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2005-04-23 01:03:38 +08:00
|
|
|
dev_state->fillin_info (get_output_handle ());
|
2002-10-08 14:16:16 +08:00
|
|
|
scroll_screen (0, 0, -1, -1, 0, dev_state->info.winTop + 1);
|
|
|
|
dev_state->state_ = normal;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2009-12-19 23:37:10 +08:00
|
|
|
else if (*src == 'c') /* RIS Full Reset */
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2005-04-23 01:03:38 +08:00
|
|
|
dev_state->set_default_attr ();
|
2010-03-31 00:17:34 +08:00
|
|
|
dev_state->vt100_graphics_mode_G0 = false;
|
|
|
|
dev_state->vt100_graphics_mode_G1 = false;
|
|
|
|
dev_state->iso_2022_G1 = false;
|
2000-02-18 03:38:33 +08:00
|
|
|
clear_screen (0, 0, -1, -1);
|
2003-12-08 06:37:12 +08:00
|
|
|
cursor_set (true, 0, 0);
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->state_ = normal;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2009-12-19 23:37:10 +08:00
|
|
|
else if (*src == '8') /* DECRC Restore cursor position */
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-12-08 06:37:12 +08:00
|
|
|
cursor_set (true, dev_state->savex, dev_state->savey);
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->state_ = normal;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2009-12-19 23:37:10 +08:00
|
|
|
else if (*src == '7') /* DECSC Save cursor position */
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-10-08 14:16:16 +08:00
|
|
|
cursor_get (&dev_state->savex, &dev_state->savey);
|
|
|
|
dev_state->savey -= dev_state->info.winTop;
|
|
|
|
dev_state->state_ = normal;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2009-12-19 23:37:10 +08:00
|
|
|
else if (*src == 'R') /* ? */
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->state_ = normal;
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
|
|
|
{
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->state_ = normal;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
src++;
|
|
|
|
break;
|
|
|
|
case gotarg1:
|
|
|
|
if (isdigit (*src))
|
|
|
|
{
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->args_[dev_state->nargs_] = dev_state->args_[dev_state->nargs_] * 10 + *src - '0';
|
2000-02-18 03:38:33 +08:00
|
|
|
src++;
|
|
|
|
}
|
|
|
|
else if (*src == ';')
|
|
|
|
{
|
|
|
|
src++;
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->nargs_++;
|
|
|
|
if (dev_state->nargs_ >= MAXARGS)
|
|
|
|
dev_state->nargs_--;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->state_ = gotcommand;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case gotcommand:
|
2001-02-27 17:14:35 +08:00
|
|
|
char_command (*src++);
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->state_ = normal;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
|
|
|
case gotrsquare:
|
2001-04-09 08:44:25 +08:00
|
|
|
if (isdigit (*src))
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->rarg = dev_state->rarg * 10 + (*src - '0');
|
|
|
|
else if (*src == ';' && (dev_state->rarg == 2 || dev_state->rarg == 0))
|
|
|
|
dev_state->state_ = gettitle;
|
2000-02-18 03:38:33 +08:00
|
|
|
else
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->state_ = eattitle;
|
2000-02-18 03:38:33 +08:00
|
|
|
src++;
|
|
|
|
break;
|
|
|
|
case eattitle:
|
|
|
|
case gettitle:
|
|
|
|
{
|
2002-10-08 14:16:16 +08:00
|
|
|
int n = strlen (dev_state->my_title_buf);
|
2002-11-15 02:02:05 +08:00
|
|
|
if (*src < ' ')
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2002-10-08 14:16:16 +08:00
|
|
|
if (*src == '\007' && dev_state->state_ == gettitle)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (old_title)
|
2002-10-08 14:16:16 +08:00
|
|
|
strcpy (old_title, dev_state->my_title_buf);
|
|
|
|
set_console_title (dev_state->my_title_buf);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->state_ = normal;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
else if (n < TITLESIZE)
|
|
|
|
{
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->my_title_buf[n++] = *src;
|
|
|
|
dev_state->my_title_buf[n] = '\0';
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
src++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case gotsquare:
|
|
|
|
if (*src == ';')
|
|
|
|
{
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->state_ = gotarg1;
|
|
|
|
dev_state->nargs_++;
|
2000-02-18 03:38:33 +08:00
|
|
|
src++;
|
|
|
|
}
|
|
|
|
else if (isalpha (*src))
|
2002-11-15 12:35:13 +08:00
|
|
|
dev_state->state_ = gotcommand;
|
2000-02-18 03:38:33 +08:00
|
|
|
else if (*src != '@' && !isalpha (*src) && !isdigit (*src))
|
|
|
|
{
|
2000-12-15 12:42:20 +08:00
|
|
|
if (*src == '?')
|
2003-12-08 06:37:12 +08:00
|
|
|
dev_state->saw_question_mark = true;
|
2009-12-19 23:37:10 +08:00
|
|
|
else if (*src == '>')
|
|
|
|
dev_state->saw_greater_than_sign = true;
|
2000-02-18 03:38:33 +08:00
|
|
|
/* ignore any extra chars between [ and first arg or command */
|
|
|
|
src++;
|
|
|
|
}
|
|
|
|
else
|
2002-10-08 14:16:16 +08:00
|
|
|
dev_state->state_ = gotarg1;
|
2000-02-18 03:38:33 +08:00
|
|
|
break;
|
2010-03-31 00:17:34 +08:00
|
|
|
case gotparen: /* Designate G0 Character Set (ISO 2022) */
|
2009-12-19 23:37:10 +08:00
|
|
|
if (*src == '0')
|
2010-03-31 00:17:34 +08:00
|
|
|
dev_state->vt100_graphics_mode_G0 = true;
|
2009-12-19 23:37:10 +08:00
|
|
|
else
|
2010-03-31 00:17:34 +08:00
|
|
|
dev_state->vt100_graphics_mode_G0 = false;
|
2009-12-19 23:37:10 +08:00
|
|
|
dev_state->state_ = normal;
|
|
|
|
src++;
|
|
|
|
break;
|
2010-03-31 00:17:34 +08:00
|
|
|
case gotrparen: /* Designate G1 Character Set (ISO 2022) */
|
2009-12-19 23:37:10 +08:00
|
|
|
if (*src == '0')
|
2010-03-31 00:17:34 +08:00
|
|
|
dev_state->vt100_graphics_mode_G1 = true;
|
2009-12-19 23:37:10 +08:00
|
|
|
else
|
2010-03-31 00:17:34 +08:00
|
|
|
dev_state->vt100_graphics_mode_G1 = false;
|
2009-12-19 23:37:10 +08:00
|
|
|
dev_state->state_ = normal;
|
|
|
|
src++;
|
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
2000-07-30 00:24:59 +08:00
|
|
|
|
2010-10-03 03:08:21 +08:00
|
|
|
syscall_printf ("%d = fhandler_console::write (...)", len);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
int vk;
|
|
|
|
const char *val[4];
|
2001-10-13 09:35:15 +08:00
|
|
|
} keytable[] NO_COPY = {
|
2009-12-21 18:11:27 +08:00
|
|
|
/* NORMAL */ /* SHIFT */ /* CTRL */ /* CTRL-SHIFT */
|
|
|
|
/* Unmodified and Alt-modified keypad keys comply with linux console
|
|
|
|
SHIFT, CTRL, CTRL-SHIFT modifiers comply with xterm modifier usage */
|
|
|
|
{VK_NUMPAD5, {"\033[G", "\033[1;2G", "\033[1;5G", "\033[1;6G"}},
|
|
|
|
{VK_CLEAR, {"\033[G", "\033[1;2G", "\033[1;5G", "\033[1;6G"}},
|
|
|
|
{VK_LEFT, {"\033[D", "\033[1;2D", "\033[1;5D", "\033[1;6D"}},
|
|
|
|
{VK_RIGHT, {"\033[C", "\033[1;2C", "\033[1;5C", "\033[1;6C"}},
|
|
|
|
{VK_UP, {"\033[A", "\033[1;2A", "\033[1;5A", "\033[1;6A"}},
|
|
|
|
{VK_DOWN, {"\033[B", "\033[1;2B", "\033[1;5B", "\033[1;6B"}},
|
|
|
|
{VK_PRIOR, {"\033[5~", "\033[5;2~", "\033[5;5~", "\033[5;6~"}},
|
|
|
|
{VK_NEXT, {"\033[6~", "\033[6;2~", "\033[6;5~", "\033[6;6~"}},
|
|
|
|
{VK_HOME, {"\033[1~", "\033[1;2~", "\033[1;5~", "\033[1;6~"}},
|
|
|
|
{VK_END, {"\033[4~", "\033[4;2~", "\033[4;5~", "\033[4;6~"}},
|
|
|
|
{VK_INSERT, {"\033[2~", "\033[2;2~", "\033[2;5~", "\033[2;6~"}},
|
|
|
|
{VK_DELETE, {"\033[3~", "\033[3;2~", "\033[3;5~", "\033[3;6~"}},
|
|
|
|
/* F1...F12, SHIFT-F1...SHIFT-F10 comply with linux console
|
|
|
|
F6...F12, and all modified F-keys comply with rxvt (compatible extension) */
|
|
|
|
{VK_F1, {"\033[[A", "\033[23~", "\033[11^", "\033[23^"}},
|
|
|
|
{VK_F2, {"\033[[B", "\033[24~", "\033[12^", "\033[24^"}},
|
|
|
|
{VK_F3, {"\033[[C", "\033[25~", "\033[13^", "\033[25^"}},
|
|
|
|
{VK_F4, {"\033[[D", "\033[26~", "\033[14^", "\033[26^"}},
|
|
|
|
{VK_F5, {"\033[[E", "\033[28~", "\033[15^", "\033[28^"}},
|
|
|
|
{VK_F6, {"\033[17~", "\033[29~", "\033[17^", "\033[29^"}},
|
|
|
|
{VK_F7, {"\033[18~", "\033[31~", "\033[18^", "\033[31^"}},
|
|
|
|
{VK_F8, {"\033[19~", "\033[32~", "\033[19^", "\033[32^"}},
|
|
|
|
{VK_F9, {"\033[20~", "\033[33~", "\033[20^", "\033[33^"}},
|
|
|
|
{VK_F10, {"\033[21~", "\033[34~", "\033[21^", "\033[34^"}},
|
|
|
|
{VK_F11, {"\033[23~", "\033[23$", "\033[23^", "\033[23@"}},
|
|
|
|
{VK_F12, {"\033[24~", "\033[24$", "\033[24^", "\033[24@"}},
|
|
|
|
/* CTRL-6 complies with Windows cmd console but should be fixed */
|
2000-02-18 03:38:33 +08:00
|
|
|
{'6', {NULL, NULL, "\036", NULL}},
|
2009-12-21 18:11:27 +08:00
|
|
|
/* Table end marker */
|
|
|
|
{0}
|
2000-02-18 03:38:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const char *
|
2000-07-31 01:58:48 +08:00
|
|
|
get_nonascii_key (INPUT_RECORD& input_rec, char *tmp)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
#define NORMAL 0
|
|
|
|
#define SHIFT 1
|
|
|
|
#define CONTROL 2
|
2009-12-21 18:11:27 +08:00
|
|
|
/*#define CONTROLSHIFT 3*/
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2009-12-21 18:11:27 +08:00
|
|
|
int modifier_index = NORMAL;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (input_rec.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED)
|
|
|
|
modifier_index = SHIFT;
|
2009-12-21 18:11:27 +08:00
|
|
|
if (input_rec.Event.KeyEvent.dwControlKeyState &
|
2000-02-18 03:38:33 +08:00
|
|
|
(LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
|
2009-12-21 18:11:27 +08:00
|
|
|
modifier_index += CONTROL;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
for (int i = 0; keytable[i].vk; i++)
|
|
|
|
if (input_rec.Event.KeyEvent.wVirtualKeyCode == keytable[i].vk)
|
2009-12-21 18:11:27 +08:00
|
|
|
{
|
|
|
|
if ((input_rec.Event.KeyEvent.dwControlKeyState &
|
|
|
|
(LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))
|
|
|
|
&& keytable[i].val[modifier_index] != NULL)
|
|
|
|
{ /* Generic ESC prefixing if Alt is pressed */
|
|
|
|
tmp[0] = '\033';
|
|
|
|
strcpy (tmp + 1, keytable[i].val[modifier_index]);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return keytable[i].val[modifier_index];
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2000-07-31 01:58:48 +08:00
|
|
|
if (input_rec.Event.KeyEvent.uChar.AsciiChar)
|
2000-07-30 03:07:15 +08:00
|
|
|
{
|
2000-07-31 01:58:48 +08:00
|
|
|
tmp[0] = input_rec.Event.KeyEvent.uChar.AsciiChar;
|
|
|
|
tmp[1] = '\0';
|
|
|
|
return tmp;
|
2000-07-30 03:07:15 +08:00
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-07-04 02:05:51 +08:00
|
|
|
int
|
2000-02-18 03:38:33 +08:00
|
|
|
fhandler_console::init (HANDLE f, DWORD a, mode_t bin)
|
|
|
|
{
|
2002-06-05 09:42:28 +08:00
|
|
|
// this->fhandler_termios::init (f, mode, bin);
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Ensure both input and output console handles are open */
|
2002-06-05 09:42:28 +08:00
|
|
|
int flags = 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
a &= GENERIC_READ | GENERIC_WRITE;
|
|
|
|
if (a == GENERIC_READ)
|
2002-06-05 09:42:28 +08:00
|
|
|
flags = O_RDONLY;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (a == GENERIC_WRITE)
|
2002-06-05 09:42:28 +08:00
|
|
|
flags = O_WRONLY;
|
2000-02-18 03:38:33 +08:00
|
|
|
if (a == (GENERIC_READ | GENERIC_WRITE))
|
2002-06-05 09:42:28 +08:00
|
|
|
flags = O_RDWR;
|
* devices.cc: New file.
* devices.gperf: New file.
* devices.shilka: New file.
* cygwin-gperf: New file.
* cygwin-shilka: New file.
* fhandler_fifo.cc: New file.
* fhandler_nodevice.cc : New file. Reorganize headers so that path.h precedes
fhandler.h throughout. Remove device argument and unit arguments from fhandler
constructors throughout. Remove pc arguments to fhandler functions and use
internal pc element instead, throughout. Use dev element in pc throughout.
Use major/minor elements rather than units and device numbers previously in
fhandler class. Use correct methods for fhandler file names rather than
directly accessing file name variables, throughout.
* Makefile.in (DLL_OFILES): Add devices.o, fhandler_fifo.o
* dcrt0.cc (dll_crt0_1): Call device::init.
* devices.h: Renumber devices based on more Linux-like major/minor numbers.
Add more devices. Declare standard device storage.
(device): Declare struct.
* dir.cc (opendir): Use new 'build_fh_name' to construct a fhandler_* type.
* dtable.cc (dtable::get_debugger_info): Ditto.
(cygwin_attach_handle_to_fd): Ditto.
(dtable::release): Remove special FH_SOCKET case in favor of generic
"need_fixup_before" test.
(dtable::init_std_file_from_handle): Use either build_fh_dev or build_fh_name
to build standard fhandler.
(dtable::build_fh_name): Renamed from dtable::build_fhandler_from_name. Move
out of dtable class. Don't accept a path_conv argument. Just build it here
and pass it to:
(build_fh_pc): Renamed from dtable::build_fhandler. Move out of dtable class.
Use intrinsic device type in path_conv to create new fhandler.
(build_fh_dev): Renamed from dtable::build_fhandler. Move out of dtable class.
Simplify arguments to just take new 'device' type and a name. Just return
pointer to fhandler rather than trying to insert into dtable.
(dtable::dup_worker): Accommodate above build_fh name changes.
(dtable::find_fifo): New (currently broken) function.
(handle_to_fn): Use strechr for efficiency.
* dtable.h: Reflect above build_fh name changes and argument differences.
(fhandler_base *&operator []): Return self rather than copy of self.
* fhandler.cc (fhandler_base::operator =): Use pc element to set normalized
path.
(fhandler_base::set_name): Ditto.
(fhandler_base::raw_read): Use method to access name.
(fhandler_base::write): Correctly use get_output_handle rather than get_handle.
(handler_base::device_access_denied): New function.
(fhandler_base::open): Eliminate pc argument and use pc element of
fhandler_base throughout.
(fhandler_base::fstat): Detect if device is based in filesystem and use
fstat_fs to calculate stat, if so.
(fhandler_base::fhandler_base): Eliminate handling of file names and, instead,
just free appropriate component from pc.
(fhandler_base::opendir): Remove path_conv parameter.
* fhandler.h: Remove all device flags.
(fhandler_base::pc): New element.
(fhandler_base::set_name): Change argument to path_conv.
(fhandler_base::error): New function.
(fhandler_base::exists): New function.
(fhandler_base::pc_binmode): New function.
(fhandler_base::dev): New function.
(fhandler_base::open_fs): New function.
(fhandler_base::fstat_fs): New function.
(fhandler_base::fstat_by_name): New function.
(fhandler_base::fstat_by_handle): New function.
(fhandler_base::isfifo): New function.
(fhandler_base::is_slow): New function.
(fhandler_base::is_auto_device): New function.
(fhandler_base::is_fs_special): New function.
(fhandler_base::device_access_denied): New function.
(fhandler_base::operator DWORD&): New operator.
(fhandler_base::get_name): Return normalized path from pc.
(fhandler_base::get_win32_name): Return windows path from pc.
(fhandler_base::isdevice): Renamed from is_device.
(fhandler_base::get_native_name): Return device format.
(fhandler_fifo): New class.
(fhandler_nodevice): New class.
(select_stuff::device_specific): Remove array.
(select_stuff::device_specific_pipe): New class element.
(select_stuff::device_specific_socket): New class element.
(select_stuff::device_specific_serial): New class element.
(select_stuff::select_stuff): Initialize new elements.
* fhandler_disk_file.cc (fhandler_base::fstat_by_handle): Move to base class
from fhandler_disk_file.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_base::fstat_by_name): Ditto.
(fhandler_disk_file::open): Move most functionality into
fhandler_base::open_fs.
(fhandler_base::open_fs): New function.
(fhandler_disk_file::close): Move most functionality into
fhandler_base::close_fs.
(fhandler_base::close_fs): New function.
* fhandler_mem.cc (fhandler_dev_mem::open): Use device name in debugging
output.
* fhandler_socket.cc (fhandler_socket::set_connect_secret): Copy standard
urandom device into appropriate place.
(fhandler_socket::accept): Reflect change in fdsock return value.
* fhandler_tty.cc: See "throughouts" above.
* net.cc: Accommodate fdsock change throughout.
(fdsock): Return success or failure, accept fd argument and device argument.
* path.cc (symlink_info::major): New element.
(symlink_info::minor): New element.
(symlink_info::parse_device): Declare new function.
(fs_info::update): Accommodate changes in path_conv class.
(path_conv::fillin): Ditto.
(path_conv::return_and_clear_normalized_path): Eliminate.
(path_conv::set_normalized_path): New function.
(path_conv::path_conv): Set info in dev element. Use path_conv methods Check
for FH_FS rather than FH_BAD to indicate when to fill in filesystem stuff.
where appropriate rather than direct access. Use set_normalized_path to set
normalized path.
(windows_device_names): Eliminate.
(get_dev): Ditto.
(get_raw_device_number): Ditto.
(get_device_number): Ditto.
(win32_device_name): Call new device name parser to do most of the heavy
lifting.
(mount_info::conv_to_win32_path): Fill in dev field as appropriate.
(symlink_worker): Handle new device files.
(symlink_info::check): Ditto.
(symlink_info::parse_device): Define new function.
* path.h (executable_states): Move here from fhandler.h.
(fs_info): Rename variables to *_storage and create methods for accessing same.
(path_conv): Add dev element, remove devn and unit and adjust inline methods to
accommodate.
(set_normalized_path): Declare new function.
* pinfo.cc (_pinfo::commune_recv): Add broken support for handling fifos.
(_pinfo::commune_send): Ditto.
* pipe.cc (fhandler_pipe::close): check for existence of handle before closing
it.
(handler_pipe::create): Rename from make_pipe. Change arguments to accept
fhandler_pipe array. Accommodate fifos.
(pipe): Rework to deal with fhandler_pipe::create changes.
(_pipe): Ditto.
* select.cc: Use individual device_specific types throughout rather than
indexing with obsolete device number.
(set_bits): Use is_socket call rather than checking device number.
* shared_info.h (CURR_MOUNT_MAGIC): Update.
(conv_to_win32_path): Reflect addition of device argument.
* syscalls.cc (mknod_worker): New function.
(open): Use build_fh_name to build fhandler.
(chown_worker): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(chmod_device): New function.
(chmod): Detect if this is an 'auto' device rather than an on-filesystem device
and handle appropriately. Use chmod_device to set mode of in-filesystem
devices.
(stat_worker): Eliminate path_conv argument. Call build_fh_name to construct
fhandler. Use fh->error() rather than pc->error to detect errors in fhandler
construction.
(access_worker): New function pulled from access. Accommodate in-filesystem
devices.
(access): Use access_worker.
(fpathconf): Detect if this is an 'auto' device rather than an on-filesystem
device and handle appropriately.
(mknod_worker): New function.
(mknod32): New function.
(chroot): Free normalized path -- assuming it was actually cmalloced.
* tty.cc (create_tty_master): Tweak for new device class.
(tty::common_init): Ditto.
* winsup.h (stat_worker): Remove.
(symlink_worker): Declare.
* exceptions.cc (set_process_mask): Just call sig_dispatch_pending and don't
worry about pending_signals since sig_dispatch_pending should always do the
right thing now.
(sig_handle): Reorganize SIGCONT handling to more closely conform to SUSv3.
* pinfo.h: Move __SIG enum to sigproc.h.
(PICOM_FIFO): New enum element.
(_pinfo): Remove 'thread2signal' stuff throughout class.
(_pinfo::commune_send): Make varargs.
(_pinfo::sigtodo): Eliminate.
(_pinfo::thread2signal): Ditto.
* signal.cc (kill_worker): Eliminate call to setthread2signal.
* sigproc.cc (local_sigtodo): Eliminate.
(getlocal_sigtodo): Ditto.
(sigelem): New class.
(pending_signals): New class.
(sigqueue): New variable, start of sigqueue linked list.
(sigcatch_nonmain): Eliminate.
(sigcatch_main): Eliminate.
(sigcatch_nosync): Eliminate.
(sigcomplete_nonmain): Eliminate.
(pending_signals): Eliminate.
(sig_clear): Call signal thread to clear pending signals, unless already in
signal thread.
(sigpending): Call signal thread to get pending signals.
(sig_dispatch_pending): Eliminate use of pending_signals and just check
sigqueue.
(sigproc_terminate): Eliminate all of the obsolete semaphore stuff. Close
signal pipe handle.
(sig_send): Eliminate all of the obsolete semaphore stuff and use pipe to send
signals.
(getevent): Eliminate.
(pending_signals::add): New function.
(pending_signals::del): New function.
(pending_signals::next): New function.
(wait_sig): Eliminate all of the obsolete semaphore stuff. Use pipe to
communicate and maintain a linked list of signals.
* sigproc.h: Move __SIG defines here. Add __SIGPENDING.
(sig_dispatch_pending): Remove "C" specifier.
(sig_handle): Accept a mask argument.
* thread.cc: Remove signal handling considerations throughout.
2003-09-25 08:37:18 +08:00
|
|
|
open (flags | O_BINARY);
|
2000-02-18 03:38:33 +08:00
|
|
|
if (f != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle (f); /* Reopened by open */
|
|
|
|
|
2009-07-04 02:05:51 +08:00
|
|
|
return !tcsetattr (0, &tc->ti);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-07-05 11:16:46 +08:00
|
|
|
fhandler_console::igncr_enabled ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
return tc->ti.c_iflag & IGNCR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-04-10 21:45:10 +08:00
|
|
|
fhandler_console::set_close_on_exec (bool val)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2003-02-04 11:01:17 +08:00
|
|
|
fhandler_base::set_close_on_exec (val);
|
2004-02-03 04:33:09 +08:00
|
|
|
set_no_inheritance (output_handle, val);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void __stdcall
|
|
|
|
set_console_title (char *title)
|
|
|
|
{
|
2009-07-25 16:27:10 +08:00
|
|
|
wchar_t buf[TITLESIZE + 1];
|
|
|
|
sys_mbstowcs (buf, TITLESIZE + 1, title);
|
2006-06-04 04:32:07 +08:00
|
|
|
lock_ttys here (15000);
|
2009-06-04 22:59:47 +08:00
|
|
|
SetConsoleTitleW (buf);
|
|
|
|
debug_printf ("title '%W'", buf);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2000-09-03 12:16:35 +08:00
|
|
|
void
|
2005-11-14 22:15:51 +08:00
|
|
|
fhandler_console::fixup_after_fork_exec (bool execing)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
HANDLE h = get_handle ();
|
|
|
|
HANDLE oh = get_output_handle ();
|
|
|
|
|
2005-11-14 22:15:51 +08:00
|
|
|
if ((execing && close_on_exec ()) || open (O_NOCTTY | get_flags (), 0))
|
2005-11-14 13:36:16 +08:00
|
|
|
cygheap->manage_console_count ("fhandler_console::fixup_after_fork_exec", -1);
|
2005-11-14 12:28:45 +08:00
|
|
|
else
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
if (!get_io_handle ())
|
2010-04-11 02:05:52 +08:00
|
|
|
system_printf ("error opening input console handle for %s after fork/exec, errno %d, %E", get_name (), get_errno ());
|
2000-02-18 03:38:33 +08:00
|
|
|
if (!get_output_handle ())
|
2010-04-11 02:05:52 +08:00
|
|
|
system_printf ("error opening output console handle for %s after fork/exec, errno %d, %E", get_name (), get_errno ());
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2005-11-14 12:28:45 +08:00
|
|
|
if (!close_on_exec ())
|
|
|
|
{
|
|
|
|
CloseHandle (h);
|
|
|
|
CloseHandle (oh);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
2005-12-19 12:34:13 +08:00
|
|
|
|
|
|
|
bool NO_COPY fhandler_console::invisible_console;
|
|
|
|
|
2006-01-08 01:57:26 +08:00
|
|
|
// #define WINSTA_ACCESS (WINSTA_READATTRIBUTES | STANDARD_RIGHTS_READ | STANDARD_RIGHTS_WRITE | WINSTA_CREATEDESKTOP | WINSTA_EXITWINDOWS)
|
2009-07-05 07:51:10 +08:00
|
|
|
#define WINSTA_ACCESS WINSTA_ALL_ACCESS
|
|
|
|
|
2009-07-06 00:49:56 +08:00
|
|
|
/* Create a console in an invisible window station. This should work
|
2009-07-05 07:51:10 +08:00
|
|
|
in all versions of Windows NT except Windows 7 (so far). */
|
|
|
|
bool
|
|
|
|
fhandler_console::create_invisible_console (HWINSTA horig)
|
|
|
|
{
|
|
|
|
HWINSTA h = CreateWindowStationW (NULL, 0, WINSTA_ACCESS, NULL);
|
|
|
|
termios_printf ("%p = CreateWindowStation(NULL), %E", h);
|
|
|
|
BOOL b;
|
|
|
|
if (h)
|
|
|
|
{
|
|
|
|
b = SetProcessWindowStation (h);
|
|
|
|
termios_printf ("SetProcessWindowStation %d, %E", b);
|
|
|
|
}
|
|
|
|
b = AllocConsole (); /* will cause flashing if CreateWindowStation
|
|
|
|
failed */
|
|
|
|
if (!h)
|
|
|
|
SetParent (GetConsoleWindow (), HWND_MESSAGE);
|
|
|
|
if (horig && h && h != horig && SetProcessWindowStation (horig))
|
|
|
|
CloseWindowStation (h);
|
|
|
|
termios_printf ("%d = AllocConsole (), %E", b);
|
|
|
|
invisible_console = true;
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ugly workaround for Windows 7.
|
|
|
|
|
|
|
|
First try to just attach to any console which may have started this
|
|
|
|
app. If that works use this as our "invisible console".
|
|
|
|
|
|
|
|
This will fail if not started from the command prompt. In that case, start
|
|
|
|
a dummy console application in a hidden state so that we can use its console
|
|
|
|
as our invisible console. This probably works everywhere but process
|
2009-07-06 00:49:56 +08:00
|
|
|
creation is slow and to be avoided if possible so the window station method
|
2009-07-05 07:51:10 +08:00
|
|
|
is vastly preferred.
|
|
|
|
|
|
|
|
FIXME: This is not completely thread-safe since it creates two inheritable
|
|
|
|
handles which are known only to this function. If another thread starts
|
|
|
|
a process the new process will inherit these handles. However, since this
|
|
|
|
function is currently only called at startup and during exec, it shouldn't
|
|
|
|
be a big deal. */
|
|
|
|
bool
|
|
|
|
fhandler_console::create_invisible_console_workaround ()
|
|
|
|
{
|
|
|
|
if (!AttachConsole (-1))
|
|
|
|
{
|
|
|
|
bool taskbar;
|
|
|
|
DWORD err = GetLastError ();
|
|
|
|
path_conv helper ("/bin/cygwin-console-helper.exe");
|
|
|
|
HANDLE hello = NULL;
|
|
|
|
HANDLE goodbye = NULL;
|
|
|
|
/* If err == ERROR_PROC_FOUND then this method won't work. But that's
|
2009-07-06 00:49:56 +08:00
|
|
|
ok. The window station method should work ok when AttachConsole doesn't
|
2009-07-05 07:51:10 +08:00
|
|
|
work.
|
|
|
|
|
|
|
|
If the helper doesn't exist or we can't create event handles then we
|
|
|
|
can't use this method. */
|
|
|
|
if (err == ERROR_PROC_NOT_FOUND || !helper.exists ()
|
|
|
|
|| !(hello = CreateEvent (&sec_none, true, false, NULL))
|
|
|
|
|| !(goodbye = CreateEvent (&sec_none, true, false, NULL)))
|
|
|
|
{
|
|
|
|
AllocConsole (); /* This is just sanity check code. We should
|
|
|
|
never actually hit here unless we're running
|
|
|
|
in an environment which lacks the helper
|
|
|
|
app. */
|
|
|
|
taskbar = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
STARTUPINFOW si = {};
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
size_t len = helper.get_wide_win32_path_len ();
|
2009-08-10 23:25:58 +08:00
|
|
|
WCHAR cmd[len + (2 * strlen (" 0xffffffff")) + 1];
|
2009-07-05 07:51:10 +08:00
|
|
|
WCHAR title[] = L"invisible cygwin console";
|
|
|
|
|
|
|
|
helper.get_wide_win32_path (cmd);
|
|
|
|
__small_swprintf (cmd + len, L" %p %p", hello, goodbye);
|
|
|
|
|
|
|
|
si.cb = sizeof (si);
|
|
|
|
si.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
si.wShowWindow = SW_HIDE;
|
|
|
|
si.lpTitle = title;
|
|
|
|
|
|
|
|
/* Create a new hidden process. Use the two event handles as
|
|
|
|
argv[1] and argv[2]. */
|
|
|
|
BOOL x = CreateProcessW (NULL, cmd, &sec_none_nih, &sec_none_nih, true,
|
|
|
|
CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi);
|
|
|
|
if (x)
|
|
|
|
{
|
|
|
|
CloseHandle (pi.hProcess); /* Don't need */
|
|
|
|
CloseHandle (pi.hThread); /* these. */
|
|
|
|
}
|
|
|
|
taskbar = false;
|
|
|
|
/* Wait for subprocess to indicate that it is live. This may not
|
|
|
|
actually be needed but it's hard to say since it is possible that
|
|
|
|
there will be no console for a brief time after the process
|
|
|
|
returns and there is no easy way to determine if/when this happens
|
|
|
|
in Windows. So play it safe. */
|
|
|
|
if (!x || (WaitForSingleObject (hello, 10000) != WAIT_OBJECT_0)
|
|
|
|
|| !AttachConsole (pi.dwProcessId))
|
|
|
|
AllocConsole (); /* Oh well. Watch the flash. */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!taskbar)
|
|
|
|
/* Setting the owner of the console window to HWND_MESSAGE seems to
|
|
|
|
hide it from the taskbar. Don't know if this method is faster than
|
|
|
|
calling ShowWindowAsync but it should guarantee no taskbar presence
|
|
|
|
for the hidden console. */
|
|
|
|
SetParent (GetConsoleWindow (), HWND_MESSAGE);
|
|
|
|
if (hello)
|
|
|
|
CloseHandle (hello);
|
|
|
|
if (goodbye)
|
|
|
|
{
|
|
|
|
SetEvent (goodbye); /* Tell helper process it's ok to exit. */
|
|
|
|
CloseHandle (goodbye);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return invisible_console = true;
|
|
|
|
}
|
2006-01-08 01:57:26 +08:00
|
|
|
|
2005-12-19 12:34:13 +08:00
|
|
|
bool
|
|
|
|
fhandler_console::need_invisible ()
|
|
|
|
{
|
|
|
|
BOOL b = false;
|
2007-02-23 20:01:52 +08:00
|
|
|
if (GetConsoleCP ())
|
2005-12-19 12:34:13 +08:00
|
|
|
invisible_console = false;
|
|
|
|
else
|
|
|
|
{
|
2009-07-05 07:51:10 +08:00
|
|
|
HWINSTA h;
|
2005-12-19 12:34:13 +08:00
|
|
|
/* The intent here is to allocate an "invisible" console if we have no
|
|
|
|
controlling tty or to reuse the existing console if we already have
|
2009-07-06 00:49:56 +08:00
|
|
|
a tty. So, first get the old window station. If there is no controlling
|
|
|
|
terminal, create a new window station and then set it as the current
|
|
|
|
window station. The subsequent AllocConsole will then be allocated
|
2005-12-19 12:34:13 +08:00
|
|
|
invisibly. But, after doing that we have to restore any existing windows
|
|
|
|
station or, strangely, characters will not be displayed in any windows
|
|
|
|
drawn on the current screen. We only do this if we have changed to
|
2009-07-06 00:49:56 +08:00
|
|
|
a new window station and if we had an existing windows station previously.
|
|
|
|
We also close the previously opened window station even though AllocConsole
|
2005-12-19 12:34:13 +08:00
|
|
|
is now "using" it. This doesn't seem to cause any problems.
|
|
|
|
|
|
|
|
Things to watch out for if you make changes in this code:
|
|
|
|
|
|
|
|
- Flashing, black consoles showing up when you start, e.g., ssh in
|
|
|
|
an xterm.
|
|
|
|
- Non-displaying of characters in rxvt or xemacs if you start a
|
|
|
|
process using setsid: bash -lc "setsid rxvt". */
|
|
|
|
|
2009-07-05 07:51:10 +08:00
|
|
|
h = GetProcessWindowStation ();
|
2006-01-08 01:57:26 +08:00
|
|
|
|
|
|
|
USEROBJECTFLAGS oi;
|
|
|
|
DWORD len;
|
2009-07-05 07:51:10 +08:00
|
|
|
if (!h
|
|
|
|
|| !GetUserObjectInformationW (h, UOI_FLAGS, &oi, sizeof (oi), &len)
|
2006-01-08 01:57:26 +08:00
|
|
|
|| !(oi.dwFlags & WSF_VISIBLE))
|
|
|
|
{
|
|
|
|
b = true;
|
|
|
|
debug_printf ("window station is not visible");
|
2009-07-05 07:51:10 +08:00
|
|
|
AllocConsole ();
|
2006-01-08 01:57:26 +08:00
|
|
|
invisible_console = true;
|
|
|
|
}
|
2009-07-05 07:51:10 +08:00
|
|
|
else if (wincap.has_broken_alloc_console ())
|
|
|
|
b = create_invisible_console_workaround ();
|
|
|
|
else
|
|
|
|
b = create_invisible_console (h);
|
2005-12-19 12:34:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
debug_printf ("invisible_console %d", invisible_console);
|
|
|
|
return b;
|
|
|
|
}
|