From 1087bbb4ffd8b58651631257b6867ba7e9c2c99f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Arg=C3=BCelles?= Date: Thu, 22 Aug 2013 15:57:34 -0500 Subject: [PATCH 1/2] Make wide character support optional Issue #514. FindCursesw modified to make it simpler. Wide character can be disable by passing NO_WIDECHAR=ON. --- src/chat.c | 4 ++++ src/main.c | 1 - src/toxic_windows.h | 1 - src/windows.c | 4 ++++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/chat.c b/src/chat.c index 41dab99..78316a7 100644 --- a/src/chat.c +++ b/src/chat.c @@ -182,7 +182,11 @@ static void chat_onKey(ToxWindow *self, Messenger *m, wint_t key) getmaxyx(self->window, y2, x2); /* Add printable chars to buffer and print on input space */ +#if HAVE_WIDECHAR if (iswprint(key)) { +#else + if (isprint(key)) { +#endif if (ctx->pos != sizeof(ctx->line) - 1) { mvwaddstr(self->window, y, x, wc_to_char(key)); ctx->line[ctx->pos++] = key; diff --git a/src/main.c b/src/main.c index 6c31041..119ab99 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,6 @@ #include "config.h" #endif -#define _XOPEN_SOURCE_EXTENDED #include #include #include diff --git a/src/toxic_windows.h b/src/toxic_windows.h index 243d5c6..4b1abf1 100644 --- a/src/toxic_windows.h +++ b/src/toxic_windows.h @@ -4,7 +4,6 @@ #ifndef _windows_h #define _windows_h -#define _XOPEN_SOURCE_EXTENDED #include #include #include diff --git a/src/windows.c b/src/windows.c index aff86b7..5906de9 100644 --- a/src/windows.c +++ b/src/windows.c @@ -234,7 +234,11 @@ void draw_active_window(Messenger *m) a->onDraw(a, m); /* Handle input */ +#ifdef HAVE_WIDECHAR get_wch(&ch); +#else + ch = getch(); +#endif if (ch == '\t' || ch == KEY_BTAB) set_next_window((int) ch); From 78deb13c459b57a3d833de6236de5b64969def09 Mon Sep 17 00:00:00 2001 From: Sergey 'Jin' Bostandzhyan Date: Fri, 23 Aug 2013 10:50:04 +0300 Subject: [PATCH 2/2] Added check and define for wide char support Try to figure out if wide character support is available and provide the necessary define for toxic. --- build/Makefile.am | 3 ++- configure.ac | 35 ++++++++++++++++++++++++++++++++--- src/chat.c | 4 ++++ src/configdir.c | 4 ++++ src/dhtstatus.c | 4 ++++ src/friendlist.c | 4 ++++ src/prompt.c | 4 ++++ src/windows.c | 4 ++++ 8 files changed, 58 insertions(+), 4 deletions(-) diff --git a/build/Makefile.am b/build/Makefile.am index a4c19ed..4e747ec 100644 --- a/build/Makefile.am +++ b/build/Makefile.am @@ -15,7 +15,8 @@ toxic_SOURCES = $(top_srcdir)/src/main.c \ $(top_srcdir)/src/dhtstatus.h \ $(top_srcdir)/src/dhtstatus.c -toxic_CFLAGS = $(NCURSES_CFLAGS) \ +toxic_CFLAGS = -I$(top_srcdir) \ + $(NCURSES_CFLAGS) \ $(LIBSODIUM_CFLAGS) \ $(LIBTOXCORE_CFLAGS) diff --git a/configure.ac b/configure.ac index df59b53..35b17cd 100644 --- a/configure.ac +++ b/configure.ac @@ -108,11 +108,18 @@ AC_CHECK_FUNCS( # pkg-config based tests PKG_PROG_PKG_CONFIG +NCURSES_WIDECHAR_SUPPORT="yes" if test -n "$PKG_CONFIG"; then if test "$WIN32" != "xyes"; then - PKG_CHECK_MODULES([NCURSES], [ncursesw], [], + PKG_CHECK_MODULES([NCURSES], [ncursesw], + [], [ - AC_MSG_ERROR([required library ncursesw was not found on your system: $NCURSES_PKG_ERRORS]) + NCURSES_WIDECHAR_SUPPORT="no" + PKG_CHECK_MODULES([NCURSES], [ncurses], + [], + [ + AC_MSG_ERROR([required library ncursesw was not found on your system: $NCURSES_PKG_ERRORS]) + ]) ]) fi else @@ -129,6 +136,8 @@ if (test -z "$PKG_CONFIG") || (test "x$WIN32" = "xyes"); then ) if test "x$WIN32" = "xyes"; then + dnl Check if pdcurses provides wide char support + NCURSES_WIDECHAR_SUPPORT="no" AC_CHECK_LIB([pdcurses], [clear], [], [ @@ -153,7 +162,22 @@ if (test -z "$PKG_CONFIG") || (test "x$WIN32" = "xyes"); then AC_CHECK_LIB([ncursesw], [get_wch], [], [ - AC_MSG_ERROR([required library ncurses was not found on your system]) + NCURSES_WIDECHAR_SUPPORT="no" + AC_CHECK_LIB([ncurses], [clear], + [], + [ + unset ac_cv_lib_ncursesw_get_wch + AC_CHECK_LIB([ncurses], [clear], + [], + [ + AC_MSG_ERROR([required library ncurses was not found on your system]) + ], + [ + -ltinfo + ] + ) + ] + ) ], [ -ltinfo @@ -292,6 +316,11 @@ eval PACKAGE_DATADIR="${datadir}/${PACKAGE}" eval PACKAGE_DATADIR="${PACKAGE_DATADIR}" AC_DEFINE_UNQUOTED(PACKAGE_DATADIR, "$PACKAGE_DATADIR", [toxic data directory]) +if test "x$NCURSES_WIDECHAR_SUPPORT" = "xyes"; then + AC_DEFINE([HAVE_WIDECHAR], [1], [ncurses wide char support available]) + AC_DEFINE([_XOPEN_SOURCE_EXTENDED], [1], + [enable X/Open Portability Guide functionality]) +fi AC_CONFIG_FILES([Makefile misc/Makefile diff --git a/src/chat.c b/src/chat.c index 78316a7..30b8d95 100644 --- a/src/chat.c +++ b/src/chat.c @@ -2,6 +2,10 @@ * Toxic -- Tox Curses Client */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include diff --git a/src/configdir.c b/src/configdir.c index a43dd1d..a032546 100644 --- a/src/configdir.c +++ b/src/configdir.c @@ -18,6 +18,10 @@ * */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include diff --git a/src/dhtstatus.c b/src/dhtstatus.c index 84d58f6..8bd98b7 100644 --- a/src/dhtstatus.c +++ b/src/dhtstatus.c @@ -1,3 +1,7 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "dhtstatus.h" #include "string.h" #include "network.h" diff --git a/src/friendlist.c b/src/friendlist.c index 5f1bedf..548c222 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -2,6 +2,10 @@ * Toxic -- Tox Curses Client */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include diff --git a/src/prompt.c b/src/prompt.c index fc21fcb..887c486 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -2,6 +2,10 @@ * Toxic -- Tox Curses Client */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include diff --git a/src/windows.c b/src/windows.c index 5906de9..6ce234e 100644 --- a/src/windows.c +++ b/src/windows.c @@ -1,3 +1,7 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "friendlist.h" #include "prompt.h" #include "dhtstatus.h"