[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Add support for Win32 term-driver for Cygwin
From: |
Rafael Kitover |
Subject: |
[PATCH] Add support for Win32 term-driver for Cygwin |
Date: |
Mon, 26 Aug 2024 16:09:33 +0000 |
Separate the `_NC_WINDOWS` platform macro into `_NC_WINDOWS_NATIVE`, for
MinGW and other native Win32 support, and `_NC_WINDOWS`, to make some
Win32 features available under the Cygwin runtime, in this case the
term-driver.
Make some minor adjustments to allow `./configure --enable-term-driver`
to also work on Cygwin platforms such as Cygwin and MSYS2.
Also, and unrelated, on native Win32, prefer `pwsh.exe`, followed by
`powershell.exe`, followed by `cmd.exe` as the shell, in that order.
Signed-off-by: Rafael Kitover <rkitover@gmail.com>
---
configure | 2 +-
configure.in | 2 +-
include/nc_mingw.h | 4 ++--
include/nc_win32.h | 4 ++--
ncurses/base/lib_getch.c | 6 +++---
ncurses/curses.priv.h | 30 +++++++++++++++++++++++++-----
ncurses/tinfo/lib_napms.c | 2 +-
ncurses/tinfo/lib_print.c | 2 +-
ncurses/tinfo/lib_setup.c | 2 +-
ncurses/tinfo/lib_win32con.c | 2 +-
ncurses/tinfo/lib_win32util.c | 4 ++--
ncurses/tinfo/tinfo_driver.c | 2 +-
ncurses/tinfo/write_entry.c | 2 +-
ncurses/trace/lib_trace.c | 2 +-
ncurses/widechar/widechars.c | 4 ++--
test/dots_termcap.c | 4 ++--
test/dots_xcurses.c | 2 +-
test/ncurses.c | 6 ++++--
test/rain.c | 2 +-
test/test.priv.h | 8 ++++----
test/test_mouse.c | 2 +-
test/widechars.h | 2 +-
22 files changed, 59 insertions(+), 37 deletions(-)
diff --git a/configure b/configure
index 412e5af2..9ca3d3ae 100755
--- a/configure
+++ b/configure
@@ -28138,7 +28138,7 @@ LIB_SUBSETS="${LIB_SUBSETS}base"
if test "$with_term_driver" != no ; then
LIB_SUBSETS="${LIB_SUBSETS}+port_drivers"
case "$cf_cv_system_name" in
- (*mingw32*|*mingw64*)
+ (*mingw32*|*mingw64*|*msys*|*cygwin*)
if test "x$with_exp_win32" = xyes ; then
LIB_SUBSETS="${LIB_SUBSETS}+port_tinfo+port_win32"
else
diff --git a/configure.in b/configure.in
index c332e045..91247301 100644
--- a/configure.in
+++ b/configure.in
@@ -2104,7 +2104,7 @@ LIB_SUBSETS="${LIB_SUBSETS}base"
if test "$with_term_driver" != no ; then
LIB_SUBSETS="${LIB_SUBSETS}+port_drivers"
case "$cf_cv_system_name" in
- (*mingw32*|*mingw64*)
+ (*mingw32*|*mingw64*|*msys*|*cygwin*)
if test "x$with_exp_win32" = xyes ; then
LIB_SUBSETS="${LIB_SUBSETS}+port_tinfo+port_win32"
else
diff --git a/include/nc_mingw.h b/include/nc_mingw.h
index 1bfc4b0d..45bea99a 100644
--- a/include/nc_mingw.h
+++ b/include/nc_mingw.h
@@ -36,7 +36,7 @@
#ifndef NC_MINGW_H
#define NC_MINGW_H 1
-#ifdef _WIN32
+#if defined(_WIN32) || defined(__MSYS__) || defined(__CYGWIN__)
#ifdef WINVER
# if WINVER < 0x0501
@@ -83,6 +83,6 @@ NCURSES_EXPORT(int) _nc_wcwidth(wchar_t);
}
#endif
-#endif /* _WIN32 */
+#endif /* _WIN32|__MSYS__|__CYGWIN__ */
#endif /* NC_MINGW_H */
diff --git a/include/nc_win32.h b/include/nc_win32.h
index e67b8e04..c5c13524 100644
--- a/include/nc_win32.h
+++ b/include/nc_win32.h
@@ -38,8 +38,8 @@
#if defined(_WIN32) || defined(_WIN64)
-#ifndef _NC_WINDOWS
-#define _NC_WINDOWS
+#ifndef _NC_WINDOWS_NATIVE
+#define _NC_WINDOWS_NATIVE
#endif
#ifdef TERMIOS
diff --git a/ncurses/base/lib_getch.c b/ncurses/base/lib_getch.c
index 831ded9d..86bea556 100644
--- a/ncurses/base/lib_getch.c
+++ b/ncurses/base/lib_getch.c
@@ -135,7 +135,7 @@ _nc_use_meta(WINDOW *win)
}
#ifdef USE_TERM_DRIVER
-# if defined(_NC_WINDOWS) && !defined(EXP_WIN32_DRIVER)
+# if defined(_NC_WINDOWS_NATIVE) && !defined(EXP_WIN32_DRIVER)
static HANDLE
_nc_get_handle(int fd)
{
@@ -163,7 +163,7 @@ check_mouse_activity(SCREEN *sp, int delay
EVENTLIST_2nd(_nc_eventlist * evl))
_nc_console_handle(sp->_ifd),
delay EVENTLIST_2nd(evl));
} else
-# elif defined(_NC_WINDOWS)
+# elif defined(_NC_WINDOWS_NATIVE)
/* if we emulate terminfo on console, we have to use the console routine */
if (IsTermInfoOnConsole(sp)) {
HANDLE fd = _nc_get_handle(sp->_ifd);
@@ -315,7 +315,7 @@ fifo_push(SCREEN *sp EVENTLIST_2nd(_nc_eventlist * evl))
&buf);
_nc_set_read_thread(FALSE);
} else
-# elif defined(_NC_WINDOWS)
+# elif defined(_NC_WINDOWS_NATIVE)
if (NC_ISATTY(sp->_ifd) && IsTermInfoOnConsole(sp) && sp->_cbreak)
n = _nc_mingw_console_read(sp,
_nc_get_handle(sp->_ifd),
diff --git a/ncurses/curses.priv.h b/ncurses/curses.priv.h
index b0ab21bf..cc3079a3 100644
--- a/ncurses/curses.priv.h
+++ b/ncurses/curses.priv.h
@@ -104,13 +104,24 @@ extern int errno;
#endif
/* Some Windows related defines */
+
#undef _NC_WINDOWS
-#if (defined(_WIN32) || defined(_WIN64))
+#if (defined(_WIN32) || defined(_WIN64__) || defined(__MSYS__) ||
defined(__CYGWIN__))
#define _NC_WINDOWS
#else
#undef EXP_WIN32_DRIVER
#endif
+#undef _NC_CYGWIN
+#if (defined(__MSYS__) || defined(__CYGWIN__))
+#define _NC_CYGWIN
+#endif
+
+#undef _NC_WINDOWS_NATIVE
+#if (defined(_WIN32) || defined(_WIN64))
+#define _NC_WINDOWS_NATIVE
+#endif
+
#undef _NC_MINGW
#if (defined(__MINGW32__) || defined(__MINGW64__))
#define _NC_MINGW
@@ -203,7 +214,7 @@ extern int errno;
* the path separator in configure doesn't work properly. So, if building
* for MinGW, we enforce the correct Windows PATH separator
*/
-#if defined(_NC_WINDOWS)
+#if defined(_NC_WINDOWS_NATIVE)
# ifdef NCURSES_PATHSEP
# undef NCURSES_PATHSEP
# endif
@@ -228,6 +239,15 @@ extern int errno;
0)
#endif
+/*
+ * The stricmp() function is in MSVCRT, and cannot be called or linked from
+ * Cygwin runtime-dependent binaries currently. Use the POSIX strcaseccmp()
+ * function instead which is pretty much the same.
+ */
+#if defined(_NC_CYGWIN)
+#define stricmp(s1, s2) strcasecmp(s1, s2)
+#endif
+
/*
* Not all platforms have memmove; some have an equivalent bcopy. (Some may
* have neither).
@@ -2188,7 +2208,7 @@ extern NCURSES_EXPORT(int)
_nc_eventlist_timeout(_nc_eventlist *);
*/
#if USE_WIDEC_SUPPORT
-#if defined(_NC_WINDOWS) && !defined(_NC_MSC) && !defined(EXP_WIN32_DRIVER)
+#if defined(_NC_WINDOWS_NATIVE) && !defined(_NC_MSC) &&
!defined(EXP_WIN32_DRIVER)
/*
* MinGW has wide-character functions, but they do not work correctly.
*/
@@ -2202,9 +2222,9 @@ extern int __MINGW_NOTHROW _nc_mbtowc(wchar_t *, const
char *, size_t);
extern int __MINGW_NOTHROW _nc_mblen(const char *, size_t);
#define mblen(s,n) _nc_mblen(s, n)
-#endif /* _NC_WINDOWS && !_NC_MSC */
+#endif /* _NC_WINDOWS_NATIVE && !_NC_MSC */
-#if defined(_NC_WINDOWS) || defined(_NC_MINGW)
+#if defined(_NC_WINDOWS_NATIVE) || defined(_NC_MINGW)
/* see wcwidth.c */
NCURSES_EXPORT(int) mk_wcwidth(wchar_t);
#define wcwidth(ucs) _nc_wcwidth(ucs)
diff --git a/ncurses/tinfo/lib_napms.c b/ncurses/tinfo/lib_napms.c
index 3a9fc316..fa40f6a5 100644
--- a/ncurses/tinfo/lib_napms.c
+++ b/ncurses/tinfo/lib_napms.c
@@ -75,7 +75,7 @@ NCURSES_SP_NAME(napms) (NCURSES_SP_DCLx int ms)
request = remaining;
}
}
-#elif defined(_NC_WINDOWS)
+#elif defined(_NC_WINDOWS_NATIVE)
Sleep((DWORD) ms);
#else
_nc_timed_wait(0, 0, ms, (int *) 0 EVENTLIST_2nd(0));
diff --git a/ncurses/tinfo/lib_print.c b/ncurses/tinfo/lib_print.c
index aa65041c..44cfa635 100644
--- a/ncurses/tinfo/lib_print.c
+++ b/ncurses/tinfo/lib_print.c
@@ -97,7 +97,7 @@ NCURSES_SP_NAME(mcprint) (NCURSES_SP_DCLx char *data, int len)
* kernel will ship the contiguous clist items from the last write
* immediately.
*/
-#ifndef _NC_WINDOWS
+#ifndef _NC_WINDOWS_NATIVE
(void) sleep(0);
#endif
free(mybuf);
diff --git a/ncurses/tinfo/lib_setup.c b/ncurses/tinfo/lib_setup.c
index db93a368..250b80a1 100644
--- a/ncurses/tinfo/lib_setup.c
+++ b/ncurses/tinfo/lib_setup.c
@@ -574,7 +574,7 @@ NCURSES_EXPORT(int)
_nc_unicode_locale(void)
{
int result = 0;
-#if defined(_NC_WINDOWS) && USE_WIDEC_SUPPORT
+#if defined(_NC_WINDOWS_NATIVE) && USE_WIDEC_SUPPORT
result = 1;
#elif HAVE_LANGINFO_CODESET
char *env = nl_langinfo(CODESET);
diff --git a/ncurses/tinfo/lib_win32con.c b/ncurses/tinfo/lib_win32con.c
index 49b6cd6a..4c63147b 100644
--- a/ncurses/tinfo/lib_win32con.c
+++ b/ncurses/tinfo/lib_win32con.c
@@ -40,7 +40,7 @@
MODULE_ID("$Id: lib_win32con.c,v 1.12 2023/02/26 19:55:10 tom Exp $")
-#ifdef _NC_WINDOWS
+#if defined(_NC_WINDOWS)
#ifdef _NC_MINGW
#include <wchar.h>
diff --git a/ncurses/tinfo/lib_win32util.c b/ncurses/tinfo/lib_win32util.c
index b37c19d7..77a01cf1 100644
--- a/ncurses/tinfo/lib_win32util.c
+++ b/ncurses/tinfo/lib_win32util.c
@@ -36,7 +36,7 @@
MODULE_ID("$Id: lib_win32util.c,v 1.3 2023/02/25 20:07:48 tom Exp $")
-#ifdef _NC_WINDOWS
+#ifdef _NC_WINDOWS_NATIVE
#include <io.h>
#ifdef _NC_CHECK_MINTTY
@@ -131,4 +131,4 @@ _nc_gettimeofday(struct timeval *tv, void *tz GCC_UNUSED)
}
#endif // HAVE_GETTIMEOFDAY == 2
-#endif // _NC_WINDOWS
+#endif // _NC_WINDOWS_NATIVE
diff --git a/ncurses/tinfo/tinfo_driver.c b/ncurses/tinfo/tinfo_driver.c
index eb4ecb3d..c4658740 100644
--- a/ncurses/tinfo/tinfo_driver.c
+++ b/ncurses/tinfo/tinfo_driver.c
@@ -1504,7 +1504,7 @@ typedef struct DriverEntry {
static DRIVER_ENTRY DriverTable[] =
{
-#ifdef _NC_WINDOWS
+#ifdef USE_WIN32CON_DRIVER
{"win32console", &_nc_WIN_DRIVER},
#endif
{"tinfo", &_nc_TINFO_DRIVER} /* must be last */
diff --git a/ncurses/tinfo/write_entry.c b/ncurses/tinfo/write_entry.c
index 002b117c..3759b60a 100644
--- a/ncurses/tinfo/write_entry.c
+++ b/ncurses/tinfo/write_entry.c
@@ -192,7 +192,7 @@ make_db_root(const char *path)
if ((rc = stat(path, &statbuf)) == -1) {
rc = mkdir(path
-#ifndef _NC_WINDOWS
+#ifndef _NC_WINDOWS_NATIVE
,0777
#endif
);
diff --git a/ncurses/trace/lib_trace.c b/ncurses/trace/lib_trace.c
index effd3c1c..d05035e4 100644
--- a/ncurses/trace/lib_trace.c
+++ b/ncurses/trace/lib_trace.c
@@ -267,7 +267,7 @@ _nc_va_tracef(const char *fmt, va_list ap)
# if USE_WEAK_SYMBOLS
if ((pthread_self))
# endif
-#ifdef _NC_WINDOWS
+#ifdef _NC_WINDOWS_NATIVE
fprintf(fp, "%#lx:", (long) (intptr_t) pthread_self().p);
#else
fprintf(fp, "%#lx:", (long) (intptr_t) pthread_self());
diff --git a/ncurses/widechar/widechars.c b/ncurses/widechar/widechars.c
index d05ba98a..d7bc6465 100644
--- a/ncurses/widechar/widechars.c
+++ b/ncurses/widechar/widechars.c
@@ -33,7 +33,7 @@
MODULE_ID("$Id: widechars.c,v 1.9 2020/08/29 16:22:03 juergen Exp $")
-#if (defined(_NC_WINDOWS)) && !defined(_NC_MSC)
+#if defined(_NC_MINGW)
/*
* MinGW has wide-character functions, but they do not work correctly.
*/
@@ -148,6 +148,6 @@ _nc_wctomb(char *s, wchar_t wc)
return result;
}
-#endif /* _NC_WINDOWS */
+#endif /* _NC_MINGW */
#endif /* USE_WIDEC_SUPPORT */
diff --git a/test/dots_termcap.c b/test/dots_termcap.c
index 65786c41..c4d1c6b7 100644
--- a/test/dots_termcap.c
+++ b/test/dots_termcap.c
@@ -37,7 +37,7 @@
#define USE_TINFO
#include <test.priv.h>
-#if !defined(_NC_WINDOWS)
+#if !defined(_NC_WINDOWS_NATIVE)
#include <sys/time.h>
#endif
@@ -162,7 +162,7 @@ static void
my_napms(int ms)
{
if (ms > 0) {
-#if defined(_NC_WINDOWS)
+#if defined(_NC_WINDOWS_NATIVE)
Sleep((unsigned int) ms);
#else
struct timeval data;
diff --git a/test/dots_xcurses.c b/test/dots_xcurses.c
index b4b52193..e57aeb5c 100644
--- a/test/dots_xcurses.c
+++ b/test/dots_xcurses.c
@@ -36,7 +36,7 @@
*/
#include <test.priv.h>
-#if !defined(_NC_WINDOWS)
+#if !defined(_NC_WINDOWS_NATIVE)
#include <sys/time.h>
#endif
diff --git a/test/ncurses.c b/test/ncurses.c
index fed8b9be..db688b98 100644
--- a/test/ncurses.c
+++ b/test/ncurses.c
@@ -490,8 +490,10 @@ ShellOut(bool message)
addstr("Shelling out...");
def_prog_mode();
endwin();
-#ifdef _NC_WINDOWS
- system("cmd.exe");
+#ifdef _NC_WINDOWS_NATIVE
+ if (system("pwsh.exe") == -1)
+ if (system("powershell.exe") == -1)
+ system("cmd.exe");
#else
IGNORE_RC(system("sh"));
#endif
diff --git a/test/rain.c b/test/rain.c
index 1b1d81a0..9e3ef1f5 100644
--- a/test/rain.c
+++ b/test/rain.c
@@ -229,7 +229,7 @@ draw_drop(void *arg)
* Find myself in the list of threads so we can count the number of loops.
*/
for (mystats = 0; mystats < MAX_THREADS; ++mystats) {
-#if defined(_NC_WINDOWS) && !defined(__WINPTHREADS_VERSION)
+#if defined(_NC_WINDOWS_NATIVE) && !defined(__WINPTHREADS_VERSION)
if (drop_threads[mystats].myself.p == pthread_self().p)
#else
if (drop_threads[mystats].myself == pthread_self())
diff --git a/test/test.priv.h b/test/test.priv.h
index a572b5c2..0648848f 100644
--- a/test/test.priv.h
+++ b/test/test.priv.h
@@ -1023,12 +1023,12 @@ extern int TABSIZE;
#define EXIT_FAILURE 1
#endif
-#undef _NC_WINDOWS
+#undef _NC_WINDOWS_NATIVE
#if (defined(_WIN32) || defined(_WIN64))
-#define _NC_WINDOWS 1
+#define _NC_WINDOWS_NATIVE 1
#endif
-#if defined(_NC_WINDOWS) || defined(USE_WIN32CON_DRIVER)
+#if defined(_NC_WINDOWS_NATIVE) || defined(USE_WIN32CON_DRIVER)
#if defined(PDCURSES)
#ifdef WINVER
@@ -1160,7 +1160,7 @@ extern char *_nc_strstr(const char *, const char *);
#define InitAndCatch(init,handler) do { init; CATCHALL(handler); } while (0)
#endif
-#if defined(_NC_WINDOWS) || defined(USE_WIN32CON_DRIVER)
+#if defined(_NC_WINDOWS_NATIVE) || defined(USE_WIN32CON_DRIVER)
#define SetupAlarm(opt) (void)opt
#else
#define SetupAlarm(opt) if (opt) alarm((unsigned)opt)
diff --git a/test/test_mouse.c b/test/test_mouse.c
index d6013c74..a489e3be 100644
--- a/test/test_mouse.c
+++ b/test/test_mouse.c
@@ -31,7 +31,7 @@
#include <test.priv.h>
-#if defined(NCURSES_MOUSE_VERSION) && !defined(_NC_WINDOWS)
+#if defined(NCURSES_MOUSE_VERSION) && !defined(_NC_WINDOWS_NATIVE)
static int logoffset = 0;
diff --git a/test/widechars.h b/test/widechars.h
index 2578a925..d9d288fe 100644
--- a/test/widechars.h
+++ b/test/widechars.h
@@ -34,7 +34,7 @@
#if USE_WIDEC_SUPPORT
-#if defined(_NC_WINDOWS) && !defined(_MSC_VER) && !defined(EXP_WIN32_DRIVER)
+#if defined(_NC_MINGW)
/*
* MinGW has wide-character functions, but they do not work correctly.
*/
--
2.46.0.windows.1
- [PATCH] Add support for Win32 term-driver for Cygwin,
Rafael Kitover <=