[w3m-dev 03433] cygwin console on Win9X

* configure (config.h): SUPPORT_WIN9X_CONSOLE_MBCS
* linein.c (inputLineHistSearch): enable_win9x_console_input()
				disable_win9x_console_input()
* main.c (mouse): cygin_mouse_btn_swapped
* terms.c (is_xterm): static
	(isLocalConsole): added
	(cygwin_mouse_btn_swapped): added
	(check_win32_console): deleted
	(check_win9x): added
	(init_win32_console_handle): check ttyslot()
	(enable_win9x_console_input): added
	(disable_win9x_console_input): added
	(read_win32_console_input): delete ifdef MOUSE
	(cmp_tv): deleted
	(subtract_tv): deleted
	(GetConsoleHwnd): added
	(cygwin_version): added
	(select_or_poll_win32_console): deleted
	(check_cygwin_console): added
	(select_win32_console): deleted
	(set_tty): check_cygin_console()
	(term_title): SetConsoleTitle()
	(CYGWIN_ON): added
	(CYGIN_OFF): added
	(mouse_init): NEED_CYGWIN_ON
	(mouse_end): NEED_CYGWIN_OFF
* terms.h (cygwin_mouse_btn_swapped): added
	(enable_win9x_console_input): added
	(disable_win9x_console_input): added
	(NEED_CYGWIN_ON): added
	(NEED_CYGWIN_OFF): added
From: WATANABE Katsuyuki <katsuyuki_1.watanabe@toppan.co.jp>
This commit is contained in:
Fumitoshi UKAI
2002-11-15 15:36:48 +00:00
parent 8b70770b0d
commit 7eb27d5b8b
7 changed files with 185 additions and 178 deletions
+36 -1
View File
@@ -1,3 +1,38 @@
2002-11-16 WATANABE Katsuyuki <katsuyuki_1.watanabe@toppan.co.jp>
* [w3m-dev 03433] cygwin console on Win9X
* configure (config.h): SUPPORT_WIN9X_CONSOLE_MBCS
* linein.c (inputLineHistSearch): enable_win9x_console_input()
disable_win9x_console_input()
* main.c (mouse): cygin_mouse_btn_swapped
* terms.c (is_xterm): static
(isLocalConsole): added
(cygwin_mouse_btn_swapped): added
(check_win32_console): deleted
(check_win9x): added
(init_win32_console_handle): check ttyslot()
(enable_win9x_console_input): added
(disable_win9x_console_input): added
(read_win32_console_input): delete ifdef MOUSE
(cmp_tv): deleted
(subtract_tv): deleted
(GetConsoleHwnd): added
(cygwin_version): added
(select_or_poll_win32_console): deleted
(check_cygwin_console): added
(select_win32_console): deleted
(set_tty): check_cygin_console()
(term_title): SetConsoleTitle()
(CYGWIN_ON): added
(CYGIN_OFF): added
(mouse_init): NEED_CYGWIN_ON
(mouse_end): NEED_CYGWIN_OFF
* terms.h (cygwin_mouse_btn_swapped): added
(enable_win9x_console_input): added
(disable_win9x_console_input): added
(NEED_CYGWIN_ON): added
(NEED_CYGWIN_OFF): added
2002-11-16 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp> 2002-11-16 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
* [w3m-dev 03432] Re: tab browser * [w3m-dev 03432] Re: tab browser
@@ -4691,4 +4726,4 @@ a * [w3m-dev 03276] compile error on EWS4800
* release-0-2-1 * release-0-2-1
* import w3m-0.2.1 * import w3m-0.2.1
$Id: ChangeLog,v 1.516 2002/11/15 15:23:45 ukai Exp $ $Id: ChangeLog,v 1.517 2002/11/15 15:36:48 ukai Exp $
Vendored
+4 -1
View File
@@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
# $Id: configure,v 1.86 2002/11/12 12:44:49 ukai Exp $ # $Id: configure,v 1.87 2002/11/15 15:36:48 ukai Exp $
# Configuration. # Configuration.
# #
@@ -2502,6 +2502,9 @@ $def_ipv6_ss_family
#if defined( __CYGWIN__ ) #if defined( __CYGWIN__ )
#define SUPPORT_NETBIOS_SHARE 1 #define SUPPORT_NETBIOS_SHARE 1
#if LANG == JA
#define SUPPORT_WIN9X_CONSOLE_MBCS 1
#endif
#endif #endif
#if defined(__DJGPP__) #if defined(__DJGPP__)
+8 -10
View File
@@ -1,4 +1,4 @@
/* $Id: linein.c,v 1.24 2002/11/08 16:10:01 ukai Exp $ */ /* $Id: linein.c,v 1.25 2002/11/15 15:36:48 ukai Exp $ */
#include "fm.h" #include "fm.h"
#include "local.h" #include "local.h"
#include "myctype.h" #include "myctype.h"
@@ -139,6 +139,9 @@ inputLineHistSearch(char *prompt, char *def_str, int flag, Hist *hist,
CLen = CPos = 0; CLen = CPos = 0;
} }
#ifdef SUPPORT_WIN9X_CONSOLE_MBCS
enable_win9x_console_input();
#endif
i_cont = TRUE; i_cont = TRUE;
i_broken = FALSE; i_broken = FALSE;
i_quote = FALSE; i_quote = FALSE;
@@ -287,6 +290,10 @@ inputLineHistSearch(char *prompt, char *def_str, int flag, Hist *hist,
if (need_redraw) if (need_redraw)
displayBuffer(Currentbuf, B_FORCE_REDRAW); displayBuffer(Currentbuf, B_FORCE_REDRAW);
#ifdef SUPPORT_WIN9X_CONSOLE_MBCS
disable_win9x_console_input();
#endif
if (i_broken) if (i_broken)
return NULL; return NULL;
@@ -443,15 +450,6 @@ _esc(void)
case 'D': case 'D':
_mvL(); _mvL();
break; break;
#if defined(__CYGWIN__) && defined(USE_MOUSE)
case 'M':
if ((is_xterm & (NEED_XTERM_ON | NEED_XTERM_OFF)) == NEED_XTERM_ON) {
getch();
getch();
getch();
}
break;
#endif
} }
break; break;
case CTRL_I: case CTRL_I:
+9 -1
View File
@@ -1,4 +1,4 @@
/* $Id: main.c,v 1.133 2002/11/15 15:21:07 ukai Exp $ */ /* $Id: main.c,v 1.134 2002/11/15 15:36:48 ukai Exp $ */
#define MAINPROGRAM #define MAINPROGRAM
#include "fm.h" #include "fm.h"
#include <signal.h> #include <signal.h>
@@ -4895,6 +4895,14 @@ mouse()
int btn, x, y; int btn, x, y;
btn = (unsigned char)getch() - 32; btn = (unsigned char)getch() - 32;
#if defined(__CYGWIN__)
if (cygwin_mouse_btn_swapped) {
if (btn == MOUSE_BTN2_DOWN)
btn = MOUSE_BTN3_DOWN;
else if (btn == MOUSE_BTN3_DOWN)
btn = MOUSE_BTN2_DOWN;
}
#endif
x = (unsigned char)getch() - 33; x = (unsigned char)getch() - 33;
if (x < 0) if (x < 0)
x += 0x100; x += 0x100;
+9 -1
View File
@@ -1,4 +1,4 @@
/* $Id: menu.c,v 1.17 2002/11/11 15:33:38 ukai Exp $ */ /* $Id: menu.c,v 1.18 2002/11/15 15:36:48 ukai Exp $ */
/* /*
* w3m menu.c * w3m menu.c
*/ */
@@ -1142,6 +1142,14 @@ mMouse(char c)
int btn, x, y; int btn, x, y;
btn = (unsigned char)getch() - 32; btn = (unsigned char)getch() - 32;
#if defined(__CYGWIN__)
if (cygwin_mouse_btn_swapped) {
if (btn == MOUSE_BTN2_DOWN)
btn = MOUSE_BTN3_DOWN;
else if (btn == MOUSE_BTN3_DOWN)
btn = MOUSE_BTN2_DOWN;
}
#endif
x = (unsigned char)getch() - 33; x = (unsigned char)getch() - 33;
if (x < 0) if (x < 0)
x += 0x100; x += 0x100;
+101 -153
View File
@@ -1,4 +1,4 @@
/* $Id: terms.c,v 1.34 2002/11/06 03:50:49 ukai Exp $ */ /* $Id: terms.c,v 1.35 2002/11/15 15:36:48 ukai Exp $ */
/* /*
* An original curses library for EUC-kanji by Akinori ITO, December 1989 * An original curses library for EUC-kanji by Akinori ITO, December 1989
* revised by Akinori ITO, January 1995 * revised by Akinori ITO, January 1995
@@ -33,10 +33,7 @@ static int cwidth = 8, cheight = 16;
static int xpix, ypix, nbs, obs = 0; static int xpix, ypix, nbs, obs = 0;
#endif /* use_SYSMOUSE */ #endif /* use_SYSMOUSE */
#ifndef __CYGWIN__ static int is_xterm = 0;
static
#endif
int is_xterm = 0;
void mouse_init(), mouse_end(); void mouse_init(), mouse_end();
int mouseActive = 0; int mouseActive = 0;
@@ -61,9 +58,14 @@ extern int CodePage;
#if defined(__CYGWIN__) #if defined(__CYGWIN__)
#include <windows.h> #include <windows.h>
static HANDLE hConIn; #include <sys/cygwin.h>
static int isWinConsole = 0;
static int isLocalConsole = 0;
int cygwin_mouse_btn_swapped = 0;
#if defined(SUPPORT_WIN9X_CONSOLE_MBCS)
static HANDLE hConIn = INVALID_HANDLE_VALUE;
static int isWin95; static int isWin95;
static int isWinConsole;
static char *ConInV; static char *ConInV;
static int iConIn, nConIn, nConInMax; static int iConIn, nConIn, nConInMax;
#ifdef USE_MOUSE #ifdef USE_MOUSE
@@ -71,25 +73,10 @@ static MOUSE_EVENT_RECORD lastConMouse;
#endif #endif
void void
check_win32_console(void) check_win9x(void)
{
char *tty;
tty = ttyname(1);
if (!strncmp(tty, "/dev/con", 8)) {
isWinConsole = TRUE;
}
else {
isWinConsole = FALSE;
}
}
void
init_win32_console_handle(void)
{ {
OSVERSIONINFO winVersionInfo; OSVERSIONINFO winVersionInfo;
check_win32_console();
winVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); winVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&winVersionInfo) == 0) { if (GetVersionEx(&winVersionInfo) == 0) {
fprintf(stderr, "can't get Windows version information.\n"); fprintf(stderr, "can't get Windows version information.\n");
@@ -97,20 +84,36 @@ init_win32_console_handle(void)
} }
if (winVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { if (winVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
isWin95 = 1; isWin95 = 1;
if (ttyslot() != -1) {
isLocalConsole = 0;
} }
hConIn = INVALID_HANDLE_VALUE;
if (isWin95) {
if (isWinConsole) {
if (isatty(0)) {
hConIn = GetStdHandle(STD_INPUT_HANDLE);
} }
else { else {
hConIn = CreateFile("CONIN$", GENERIC_READ, isWin95 = 0;
FILE_SHARE_READ, }
}
void
enable_win9x_console_input(void)
{
if (isWin95 && isWinConsole && isLocalConsole &&
hConIn == INVALID_HANDLE_VALUE) {
hConIn = CreateFile("CONIN$", GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL); NULL, OPEN_EXISTING, 0, NULL);
if (hConIn != INVALID_HANDLE_VALUE) {
getch();
} }
} }
} }
void
disable_win9x_console_input(void)
{
if (hConIn != INVALID_HANDLE_VALUE) {
CloseHandle(hConIn);
hConIn = INVALID_HANDLE_VALUE;
}
} }
static void static void
@@ -143,44 +146,6 @@ read_win32_console_input(void)
} }
break; break;
#ifdef USE_MOUSE
case MOUSE_EVENT:
if ((lastConMouse.dwButtonState ^ rec.Event.MouseEvent.
dwButtonState) & ~(~0 << 5)) {
int down;
MOUSE_EVENT_RECORD *mer;
INPUT_RECORD dummy;
expand_win32_console_input_buffer(6);
mer = &rec.Event.MouseEvent;
ConInV[nConIn] = '\033';
ConInV[nConIn + 1] = '[';
ConInV[nConIn + 2] = 'M';
if (~(mer->dwButtonState) & lastConMouse.
dwButtonState & ~(~0 << 5))
ConInV[nConIn + 3] = MOUSE_BTN_UP + ' ';
else if (!
(down =
mer->dwButtonState & ~lastConMouse.
dwButtonState & ~(~0 << 5)))
break;
else
ConInV[nConIn + 3] = (down & (1 << 0) ? MOUSE_BTN1_DOWN :
down & (1 << 1) ? MOUSE_BTN3_DOWN :
down & (1 << 2) ? MOUSE_BTN2_DOWN :
down & (1 << 3) ?
MOUSE_BTN4_DOWN_XTERM :
MOUSE_BTN5_DOWN_XTERM) + ' ';
ConInV[nConIn + 4] = mer->dwMousePosition.X + '!';
ConInV[nConIn + 5] = mer->dwMousePosition.Y + '!';
nConIn += 6;
lastConMouse = *mer;
ReadConsoleInput(hConIn, &rec, 1, &nevents);
return 6;
}
#endif
default: default:
break; break;
} }
@@ -220,92 +185,64 @@ read_win32_console(char *s, int n)
return n; return n;
} }
static int #endif /* SUPPORT_WIN9X_CONSOLE_MBCS */
cmp_tv(const struct timeval *tv_a, const struct timeval *tv_b)
HWND GetConsoleHwnd(void)
{ {
return ((tv_a->tv_sec < tv_b->tv_sec) ? -1 : #define MY_BUFSIZE 1024
(tv_a->tv_sec > tv_b->tv_sec) ? 1 : HWND hwndFound;
(tv_a->tv_usec < tv_b->tv_usec) ? -1 : char pszNewWindowTitle[MY_BUFSIZE];
(tv_a->tv_usec > tv_b->tv_usec) ? 1 : 0); char pszOldWindowTitle[MY_BUFSIZE];
GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
wsprintf(pszNewWindowTitle,"%d/%d",
GetTickCount(),
GetCurrentProcessId());
SetConsoleTitle(pszNewWindowTitle);
Sleep(40);
hwndFound = FindWindow(NULL, pszNewWindowTitle);
SetConsoleTitle(pszOldWindowTitle);
return(hwndFound);
} }
static int unsigned long
subtract_tv(struct timeval *dst, const struct timeval *src) cygwin_version(void)
{ {
if ((dst->tv_usec -= src->tv_usec) < 0) { struct per_process *p;
--(dst->tv_sec);
dst->tv_usec += 1000000; p = (struct per_process *)cygwin_internal(CW_USER_DATA);
if (p != NULL) {
return (p->dll_major * 1000) + p->dll_minor;
}
return 0;
} }
return ((dst->tv_sec -= src->tv_sec) < 0 ? -1 : void
!dst->tv_sec ? (dst->tv_usec < check_cygwin_console(void)
0 ? -1 : !dst->tv_usec ? 0 : 1) : 1);
}
int
select_or_poll_win32_console(int n, fd_set * rfds, fd_set * wfds,
fd_set * efds, struct timeval *tout)
{ {
int m; char *term = getenv("TERM");
DWORD nevents; HANDLE hWnd;
if ((m = select(n, rfds, wfds, efds, tout)) < 0) if (strncmp(term, "cygwin", 6) == 0) {
return m; isWinConsole = 1;
if (iConIn < nConIn) {
FD_SET(tty, rfds);
++m;
} }
else { if (isWinConsole) {
iConIn = nConIn = 0; hWnd = GetConsoleHwnd();
if (hWnd != INVALID_HANDLE_VALUE) {
while (GetNumberOfConsoleInputEvents(hConIn, &nevents) && nevents) if (IsWindowVisible(hWnd)) {
read_win32_console_input(); isLocalConsole = 1;
if (nConIn) {
FD_SET(tty, rfds);
++m;
}
}
return m;
}
int
select_win32_console(int n, fd_set * rfds, fd_set * wfds, fd_set * efds,
struct timeval *tout)
{
static struct timeval polltv = { 0, 1000000 / CLOCKS_PER_SEC };
int m;
struct timeval tv;
if (hConIn == INVALID_HANDLE_VALUE || tty < 0 || tty >= n || !rfds
|| !FD_ISSET(tty, rfds))
return select(n, rfds, wfds, efds, tout);
FD_CLR(tty, rfds);
if (tout) {
while (cmp_tv(tout, &polltv) > 0) {
tv = polltv;
if ((m = select_or_poll_win32_console(n, rfds, wfds, efds, &tv)))
return m;
subtract_tv(tout, &polltv);
}
return select_or_poll_win32_console(n, rfds, wfds, efds, tout);
}
else
for (;;) {
tv = polltv;
if ((m = select_or_poll_win32_console(n, rfds, wfds, efds, &tv)))
return m;
} }
} }
#ifdef SUPPORT_WIN9X_CONSOLE_MBCS
check_win9x();
#endif #endif
}
if (cygwin_version() <= 1003015) {
/* cygwin DLL 1.3.15 or earler */
cygwin_mouse_btn_swapped = 1;
}
}
#endif /* __CYGWIN__ */
char *getenv(const char *); char *getenv(const char *);
MySignalHandler reset_exit(SIGNAL_ARG), error_dump(SIGNAL_ARG); MySignalHandler reset_exit(SIGNAL_ARG), error_dump(SIGNAL_ARG);
@@ -499,7 +436,7 @@ static struct w3m_term_info {
{W3M_TERM_INFO("mlterm", XTERM_TITLE, (NEED_XTERM_ON|NEED_XTERM_OFF))}, {W3M_TERM_INFO("mlterm", XTERM_TITLE, (NEED_XTERM_ON|NEED_XTERM_OFF))},
{W3M_TERM_INFO("screen", SCREEN_TITLE, 0)}, {W3M_TERM_INFO("screen", SCREEN_TITLE, 0)},
#ifdef __CYGWIN__ #ifdef __CYGWIN__
{W3M_TERM_INFO("cygwin", NULL, NEED_XTERM_ON)}, {W3M_TERM_INFO("cygwin", XTERM_TITLE, (NEED_CYGWIN_ON|NEED_CYGWIN_OFF))},
#endif #endif
{W3M_TERM_INFO(NULL, NULL, 0)} {W3M_TERM_INFO(NULL, NULL, 0)}
}; };
@@ -522,7 +459,7 @@ set_tty(void)
} }
ttyf = fdopen(tty, "w"); ttyf = fdopen(tty, "w");
#ifdef __CYGWIN__ #ifdef __CYGWIN__
init_win32_console_handle(); check_cygwin_console();
#endif #endif
TerminalGet(tty, &d_ioval); TerminalGet(tty, &d_ioval);
if (displayTitleTerm != NULL) { if (displayTitleTerm != NULL) {
@@ -1872,9 +1809,18 @@ term_title(char *s)
{ {
if (!fmInitialized) if (!fmInitialized)
return; return;
if (title_str != NULL) if (title_str != NULL) {
#ifdef __CYGWIN__
if (isLocalConsole) {
char buff[1024];
snprintf(buff, sizeof(buff), "w3m: %s", s);
SetConsoleTitle(buff);
}
else if (!isWinConsole)
#endif
fprintf(ttyf, title_str, s); fprintf(ttyf, title_str, s);
} }
}
char char
getch(void) getch(void)
@@ -1882,7 +1828,7 @@ getch(void)
char c; char c;
while ( while (
#ifdef __CYGWIN__ #ifdef SUPPORT_WIN9X_CONSOLE_MBCS
read_win32_console(&c, 1) read_win32_console(&c, 1)
#else #else
read(tty, &c, 1) read(tty, &c, 1)
@@ -2020,13 +1966,7 @@ sleep_till_anykey(int sec, int purge)
FD_ZERO(&rfd); FD_ZERO(&rfd);
FD_SET(tty, &rfd); FD_SET(tty, &rfd);
if ( if (select(tty + 1, &rfd, 0, 0, &tim) > 0 && purge) {
#ifdef __CYGWIN__
select_win32_console(tty + 1, &rfd, 0, 0, &tim)
#else
select(tty + 1, &rfd, 0, 0, &tim)
#endif
> 0 && purge) {
c = getch(); c = getch();
if (c == ESC_CODE) if (c == ESC_CODE)
skip_escseq(); skip_escseq();
@@ -2042,6 +1982,8 @@ sleep_till_anykey(int sec, int purge)
#define XTERM_ON {fputs("\033[?1001s\033[?1000h",ttyf); flush_tty();} #define XTERM_ON {fputs("\033[?1001s\033[?1000h",ttyf); flush_tty();}
#define XTERM_OFF {fputs("\033[?1000l\033[?1001r",ttyf); flush_tty();} #define XTERM_OFF {fputs("\033[?1000l\033[?1001r",ttyf); flush_tty();}
#define CYGWIN_ON {fputs("\033[?1000h",ttyf); flush_tty();}
#define CYGWIN_OFF {fputs("\033[?1000l",ttyf); flush_tty();}
#ifdef USE_GPM #ifdef USE_GPM
/* Linux console with GPM support */ /* Linux console with GPM support */
@@ -2167,6 +2109,9 @@ mouse_init()
if (is_xterm & NEED_XTERM_ON) { if (is_xterm & NEED_XTERM_ON) {
XTERM_ON; XTERM_ON;
} }
else if (is_xterm & NEED_CYGWIN_ON) {
CYGWIN_ON;
}
mouseActive = 1; mouseActive = 1;
} }
@@ -2178,6 +2123,9 @@ mouse_end()
if (is_xterm & NEED_XTERM_OFF) { if (is_xterm & NEED_XTERM_OFF) {
XTERM_OFF; XTERM_OFF;
} }
else if (is_xterm & NEED_CYGWIN_OFF) {
CYGWIN_OFF;
}
mouseActive = 0; mouseActive = 0;
} }
+8 -1
View File
@@ -1,4 +1,4 @@
/* $Id: terms.h,v 1.6 2002/11/11 15:33:40 ukai Exp $ */ /* $Id: terms.h,v 1.7 2002/11/15 15:36:48 ukai Exp $ */
#ifndef TERMS_H #ifndef TERMS_H
#define TERMS_H #define TERMS_H
@@ -40,6 +40,13 @@ extern int LINES, COLS;
#ifdef __CYGWIN__ #ifdef __CYGWIN__
extern int is_xterm; extern int is_xterm;
extern int cygwin_mouse_btn_swapped;
#ifdef SUPPORT_WIN9X_CONSOLE_MBCS
void enable_win9x_console_input(void);
void disable_win9x_console_input(void);
#endif
#define NEED_CYGWIN_ON (1<<2)
#define NEED_CYGWIN_OFF (1<<3)
#endif #endif
#define NEED_XTERM_ON (1) #define NEED_XTERM_ON (1)
#define NEED_XTERM_OFF (1<<1) #define NEED_XTERM_OFF (1<<1)