Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/distrib/utils/libhack We (especially libcurses and nvi) use ...



details:   https://anonhg.NetBSD.org/src/rev/010574925940
branches:  trunk
changeset: 1000543:010574925940
user:      martin <martin%NetBSD.org@localhost>
date:      Sun Jul 28 10:21:18 2019 +0000

description:
We (especially libcurses and nvi) use more multibyte character locale
related symbols nowadays. Update libhack to avoid pulling in full grown
multibyte locale support on small install media.

diffstat:

 distrib/utils/libhack/Makefile.inc  |    3 +-
 distrib/utils/libhack/multibyte.c   |  175 +++++++++++++++++++++++++++++++++++-
 distrib/utils/libhack/nl_langinfo.c |   20 ++++
 distrib/utils/libhack/strcasecmp.c  |   20 ++++
 4 files changed, 216 insertions(+), 2 deletions(-)

diffs (259 lines):

diff -r 60c0e1e088b9 -r 010574925940 distrib/utils/libhack/Makefile.inc
--- a/distrib/utils/libhack/Makefile.inc        Sun Jul 28 10:07:43 2019 +0000
+++ b/distrib/utils/libhack/Makefile.inc        Sun Jul 28 10:21:18 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.30 2019/06/22 22:50:39 christos Exp $
+# $NetBSD: Makefile.inc,v 1.31 2019/07/28 10:21:18 martin Exp $
 #
 # Include this fragment to build libhack.o
 # It is .o and not .a to make sure these are the
@@ -22,6 +22,7 @@
 CPPFLAGS+=     -DLIBHACK
 HACKOBJS+=     getcap.o getgrent.o getnet.o getnetgr.o getpwent.o jemalloc.o \
                localeconv.o multibyte.o perror.o runetable.o setlocale.o \
+               nl_langinfo.o strcasecmp.o \
                strerror.o strsignal.o syslog.o utmp.o fmtcheck.o
 
 .if (${USE_YP} != "no")
diff -r 60c0e1e088b9 -r 010574925940 distrib/utils/libhack/multibyte.c
--- a/distrib/utils/libhack/multibyte.c Sun Jul 28 10:07:43 2019 +0000
+++ b/distrib/utils/libhack/multibyte.c Sun Jul 28 10:21:18 2019 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: multibyte.c,v 1.7 2014/11/15 19:15:51 htodd Exp $      */
+/*      $NetBSD: multibyte.c,v 1.8 2019/07/28 10:21:18 martin Exp $      */
 
 /*
  * Ignore all multibyte sequences, removes all the citrus code.
@@ -7,7 +7,10 @@
  */
 
 #include <stdlib.h>
+#include <string.h>
 #include <wchar.h>
+#include <wctype.h>
+#include <ctype.h>
 
 size_t
 mbrtowc(wchar_t *wc, const char *str, size_t max_sz, mbstate_t *ps)
@@ -145,3 +148,173 @@
 {
        return MB_CUR_MAX;
 }
+
+wint_t
+fgetwc(FILE *stream)
+{
+       return fgetc(stream);
+}
+
+wint_t
+fputwc(wchar_t wc, FILE *stream)
+{
+       return fputc(wc & 0xFF, stream);
+}
+ 
+wint_t __fputwc_unlock(wchar_t wc, FILE *stream);
+wint_t
+__fputwc_unlock(wchar_t wc, FILE *stream)
+{
+       return __sputc(wc & 0xFF, stream);
+}
+
+#define        MAPSINGLE(CT)   \
+       int     \
+       isw##CT(wint_t wc)      \
+       {       \
+               return is##CT(wc & 0xFF);       \
+       }
+
+MAPSINGLE(alnum)
+MAPSINGLE(alpha)
+MAPSINGLE(blank)
+MAPSINGLE(cntrl)
+MAPSINGLE(digit)
+MAPSINGLE(graph)
+MAPSINGLE(lower)
+MAPSINGLE(print)
+MAPSINGLE(punct)
+MAPSINGLE(space)
+MAPSINGLE(upper)
+MAPSINGLE(xdigit)
+
+int
+iswspace_l(wint_t wc, locale_t loc)
+{
+       return iswspace(wc);
+}
+
+struct wct_entry_hack {
+       const char *name;
+       int (*predicate)(wint_t);
+};
+
+#define        WCTENTRY(T)     { .name= #T , .predicate= isw##T },
+static const struct wct_entry_hack my_wcts[] = {
+       { .name = NULL },
+       WCTENTRY(alnum)
+       WCTENTRY(alpha)
+       WCTENTRY(blank)
+       WCTENTRY(cntrl)
+       WCTENTRY(digit)
+       WCTENTRY(graph)
+       WCTENTRY(lower)
+       WCTENTRY(print)
+       WCTENTRY(punct)
+       WCTENTRY(space)
+       WCTENTRY(upper)
+       WCTENTRY(xdigit)
+};
+
+wctype_t
+wctype(const char *charclass)
+{
+
+       for (size_t i = 1; i < __arraycount(my_wcts); i++)
+               if (strcmp(charclass, my_wcts[i].name) == 0)
+                       return (wctype_t)i;
+
+       return (wctype_t)0;
+}
+
+int
+iswctype(wint_t wc, wctype_t charclass)
+{
+       size_t ndx = (size_t)charclass;
+
+       if (ndx < 1 || ndx >= __arraycount(my_wcts))
+               return 0;
+
+       return my_wcts[ndx].predicate(wc);
+}
+
+size_t
+wcslen(const wchar_t *s)
+{
+       size_t l;
+
+       if (s == NULL)
+               return 0;
+
+       while (*s) {
+               s++;
+               l++;
+       }
+
+       return l;
+}
+
+int
+wcswidth(const wchar_t *pwcs, size_t n)
+{
+       int cols;
+
+       if (pwcs == NULL)
+               return 0;
+
+       if (*pwcs == 0)
+               return 0;
+
+       for (cols = 0; *pwcs && n > 0; cols++)
+               if (!isprint(*pwcs & 0xFF))
+                       return -1;
+       return cols;
+}
+
+int
+wcwidth(wchar_t wc)
+{
+       if (wc == 0)
+               return 0;
+       if (!isprint(wc & 0xFF))
+               return -1;
+       return 1;
+}
+
+wchar_t *
+wmemchr(const wchar_t *s, wchar_t c, size_t n)
+{
+
+       if (s == NULL)
+               return NULL;
+       while (*s != 0 && *s != c)
+               s++;
+       if (*s != 0)
+               return __UNCONST(s);
+       return NULL;
+}
+
+wchar_t *
+wmemcpy(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n)
+{
+       wchar_t *p;
+
+       for (p = s1; n > 0; n--)
+               *p++ = *s2++;
+
+       return s1;
+}
+
+wint_t
+towlower(wint_t wc)
+{
+       return tolower(wc & 0xFF);
+}
+
+wint_t
+towupper(wint_t wc)
+{
+       return toupper(wc & 0xFF);
+}
+
+
diff -r 60c0e1e088b9 -r 010574925940 distrib/utils/libhack/nl_langinfo.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/distrib/utils/libhack/nl_langinfo.c       Sun Jul 28 10:21:18 2019 +0000
@@ -0,0 +1,20 @@
+/*     $NetBSD: nl_langinfo.c,v 1.1 2019/07/28 10:21:18 martin Exp $   */
+
+/*
+ * Written by Martin Husemann <martin%NetBSD.org@localhost>
+ * Public domain.
+ */
+
+#include <langinfo.h>
+
+/*
+ * Cheap and dirty nl_langinfo() - implements just enough
+ * for our libcurses in crunched environments.
+ */
+char *
+nl_langinfo(nl_item what)
+{
+       if (what == CODESET)
+               return "ASCII";
+       return "";
+}
diff -r 60c0e1e088b9 -r 010574925940 distrib/utils/libhack/strcasecmp.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/distrib/utils/libhack/strcasecmp.c        Sun Jul 28 10:21:18 2019 +0000
@@ -0,0 +1,20 @@
+/*     $NetBSD: strcasecmp.c,v 1.1 2019/07/28 10:21:18 martin Exp $    */
+
+/*
+ * Written by Martin Husemann <martin%NetBSD.org@localhost>
+ * Public domain.
+ */
+
+#include <strings.h>
+
+/*
+ * Cheap and dirty strcasecmp() - implements just enough
+ * for our libcurses in crunched environments: since we
+ * know all compared strings are fixed, uppercase, and plain ASCII,
+ * just use strcmp()
+ */
+int
+strcasecmp(const char *s1, const char *s2)
+{
+       return strcmp(s1, s2);
+}



Home | Main Index | Thread Index | Old Index