Chez Scheme: avoid uselocale on Solaris

Although Solaris 11 and up probably have `uselocale`, just disable its
use in the expeditor on Solaris for simplicity.
This commit is contained in:
Matthew Flatt 2020-10-19 07:36:20 -06:00
parent 7411b7ffa7
commit a86cf525ef

View File

@ -530,6 +530,7 @@ static void s_ee_write_char(wchar_t c) {
} }
#else /* WIN32 */ #else /* WIN32 */
#include <limits.h> #include <limits.h>
#ifdef DISABLE_CURSES #ifdef DISABLE_CURSES
# include "nocurses.h" # include "nocurses.h"
@ -538,13 +539,14 @@ static void s_ee_write_char(wchar_t c) {
# define CHTYPE int # define CHTYPE int
# include </usr/include/curses.h> # include </usr/include/curses.h>
# include </usr/include/term.h> # include </usr/include/term.h>
# define NO_USELOCALE
#elif defined(NETBSD) #elif defined(NETBSD)
# include <ncurses.h> # include <ncurses.h>
# include <ncurses/term.h> # include <ncurses/term.h>
#else /* NETBSD */ #else
# include <curses.h> # include <curses.h>
# include <term.h> # include <term.h>
#endif /* SOLARIS */ #endif
#include <termios.h> #include <termios.h>
#include <signal.h> #include <signal.h>
#include <time.h> #include <time.h>
@ -588,7 +590,9 @@ static void handle_sigwinch(UNUSED int sig) {
#define STDOUT_FD 1 #define STDOUT_FD 1
static IBOOL disable_auto_margin = 0, avoid_last_column = 0; static IBOOL disable_auto_margin = 0, avoid_last_column = 0;
#ifndef NO_USELOCALE
static locale_t term_locale; static locale_t term_locale;
#endif
static mbstate_t term_in_mbs; static mbstate_t term_in_mbs;
static mbstate_t term_out_mbs; static mbstate_t term_out_mbs;
@ -643,7 +647,9 @@ static IBOOL s_ee_init_term(void) {
sigaction(SIGWINCH, &act, (struct sigaction *)0); sigaction(SIGWINCH, &act, (struct sigaction *)0);
#endif #endif
#ifndef NO_USELOCALE
term_locale = newlocale(LC_ALL_MASK, "", NULL); term_locale = newlocale(LC_ALL_MASK, "", NULL);
#endif
memset(&term_out_mbs, 0, sizeof(term_out_mbs)); memset(&term_out_mbs, 0, sizeof(term_out_mbs));
memset(&term_in_mbs, 0, sizeof(term_in_mbs)); memset(&term_in_mbs, 0, sizeof(term_in_mbs));
@ -659,7 +665,6 @@ static IBOOL s_ee_init_term(void) {
only if blockp is false */ only if blockp is false */
static ptr s_ee_read_char(IBOOL blockp) { static ptr s_ee_read_char(IBOOL blockp) {
ptr msg; int fd = STDIN_FD; int n; char buf[1]; wchar_t wch; size_t sz; ptr msg; int fd = STDIN_FD; int n; char buf[1]; wchar_t wch; size_t sz;
locale_t old_locale;
#ifdef PTHREADS #ifdef PTHREADS
ptr tc = get_thread_context(); ptr tc = get_thread_context();
#endif #endif
@ -697,9 +702,13 @@ static ptr s_ee_read_char(IBOOL blockp) {
if (buf[0] == '\0') { if (buf[0] == '\0') {
return Schar('\0'); return Schar('\0');
} else { } else {
old_locale = uselocale(term_locale); #ifndef NO_USELOCALE
locale_t old_locale = uselocale(term_locale);
#endif
sz = mbrtowc(&wch, buf, 1, &term_out_mbs); sz = mbrtowc(&wch, buf, 1, &term_out_mbs);
#ifndef NO_USELOCALE
uselocale(old_locale); uselocale(old_locale);
#endif
if (sz == 1) { if (sz == 1) {
return Schar(wch); return Schar(wch);
} }
@ -1041,16 +1050,21 @@ static ptr s_ee_get_clipboard(void) {
} }
static void s_ee_write_char(wchar_t wch) { static void s_ee_write_char(wchar_t wch) {
locale_t old; char buf[MB_LEN_MAX]; size_t n; char buf[MB_LEN_MAX]; size_t n;
#ifndef NO_USELOCALE
locale_t old = uselocale(term_locale);
#endif
old = uselocale(term_locale);
n = wcrtomb(buf, wch, &term_in_mbs); n = wcrtomb(buf, wch, &term_in_mbs);
if (n == (size_t)-1) { if (n == (size_t)-1) {
putchar('?'); putchar('?');
} else { } else {
fwrite(buf, 1, n, stdout); fwrite(buf, 1, n, stdout);
} }
#ifndef NO_USELOCALE
uselocale(old); uselocale(old);
#endif
} }
#endif /* WIN32 */ #endif /* WIN32 */