1
0
mirror of https://github.com/termux/termux-packages synced 2024-06-18 17:19:45 +00:00

gawk: Fix locale support

This commit is contained in:
Tee KOBAYASHI 2023-04-15 13:39:23 +09:00 committed by xtkoba
parent 21432177e5
commit 7879b94395
2 changed files with 92 additions and 0 deletions

View File

@ -3,6 +3,7 @@ TERMUX_PKG_DESCRIPTION="Programming language designed for text processing"
TERMUX_PKG_LICENSE="GPL-3.0"
TERMUX_PKG_MAINTAINER="@termux"
TERMUX_PKG_VERSION=5.2.1
TERMUX_PKG_REVISION=1
TERMUX_PKG_SRCURL=https://mirrors.kernel.org/gnu/gawk/gawk-${TERMUX_PKG_VERSION}.tar.xz
TERMUX_PKG_SHA256=673553b91f9e18cc5792ed51075df8d510c9040f550a6f74e09c9add243a7e4f
TERMUX_PKG_DEPENDS="libandroid-support, libgmp, libmpfr, readline"

View File

@ -0,0 +1,91 @@
https://github.com/termux/termux-packages/issues/15929
--- a/awk.h
+++ b/awk.h
@@ -80,6 +80,11 @@
#ifdef STDC_HEADERS
#include <stdlib.h>
+#if defined __ANDROID__ && defined __TERMUX__
+#undef MB_CUR_MAX
+#define MB_CUR_MAX __ctype_get_mb_cur_max()
+size_t __ctype_get_mb_cur_max(void);
+#endif
#endif /* not STDC_HEADERS */
--- a/support/localeinfo.c
+++ b/support/localeinfo.c
@@ -28,6 +28,11 @@
#include <limits.h>
#include <locale.h>
#include <stdlib.h>
+#if defined __ANDROID__ && defined __TERMUX__
+#undef MB_CUR_MAX
+#define MB_CUR_MAX __ctype_get_mb_cur_max()
+size_t __ctype_get_mb_cur_max(void);
+#endif
#include <string.h>
#include <wctype.h>
--- a/support/regex_internal.h
+++ b/support/regex_internal.h
@@ -23,6 +23,11 @@
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
+#if defined __ANDROID__ && defined __TERMUX__
+#undef MB_CUR_MAX
+#define MB_CUR_MAX __ctype_get_mb_cur_max()
+size_t __ctype_get_mb_cur_max(void);
+#endif
#include <string.h>
#include <langinfo.h>
--- a/main.c
+++ b/main.c
@@ -30,6 +30,15 @@
#include "awk.h"
#include "getopt.h"
+#ifdef __ANDROID__
+static __inline__ char *setlocale_(int category, const char *locale_name) {
+ return setlocale(category, locale_name);
+}
+#define setlocale(category, locale_name) /* */
+#else
+#define setlocale_ setlocale
+#endif
+
#ifdef HAVE_MCHECK_H
#include <mcheck.h>
#endif
@@ -230,6 +239,19 @@
#if defined(LOCALEDEBUG)
const char *initial_locale;
#endif
+#ifdef __ANDROID__
+ locale = getenv("LC_ALL");
+ if (locale == NULL || locale[0] == '\0')
+ locale = getenv("LC_CTYPE");
+ if (locale == NULL || locale[0] == '\0')
+ locale = getenv("LANG");
+ if (locale == NULL)
+ locale = "";
+ if (strcmp(locale, "C") == 0 || strcmp(locale, "POSIX") == 0)
+ setlocale_(LC_CTYPE, "C");
+ else
+ setlocale_(LC_CTYPE, "C.UTF-8");
+#endif
myname = gawk_name(argv[0]);
@@ -384,7 +406,7 @@
else {
gawk_mb_cur_max = 1; /* hands off my data! */
#if defined(LC_ALL)
- setlocale(LC_ALL, "C");
+ setlocale_(LC_ALL, "C");
#endif
}
}