Module Name: src Committed By: martin Date: Sun Jul 28 10:21:18 UTC 2019
Modified Files: src/distrib/utils/libhack: Makefile.inc multibyte.c Added Files: src/distrib/utils/libhack: nl_langinfo.c strcasecmp.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.30 -r1.31 src/distrib/utils/libhack/Makefile.inc cvs rdiff -u -r1.7 -r1.8 src/distrib/utils/libhack/multibyte.c cvs rdiff -u -r0 -r1.1 src/distrib/utils/libhack/nl_langinfo.c \ src/distrib/utils/libhack/strcasecmp.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/utils/libhack/Makefile.inc diff -u src/distrib/utils/libhack/Makefile.inc:1.30 src/distrib/utils/libhack/Makefile.inc:1.31 --- src/distrib/utils/libhack/Makefile.inc:1.30 Sat Jun 22 22:50:39 2019 +++ src/distrib/utils/libhack/Makefile.inc Sun Jul 28 10:21:18 2019 @@ -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+= -DSMALL 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") Index: src/distrib/utils/libhack/multibyte.c diff -u src/distrib/utils/libhack/multibyte.c:1.7 src/distrib/utils/libhack/multibyte.c:1.8 --- src/distrib/utils/libhack/multibyte.c:1.7 Sat Nov 15 19:15:51 2014 +++ src/distrib/utils/libhack/multibyte.c Sun Jul 28 10:21:18 2019 @@ -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 @@ _mb_cur_max_l(locale_t loc) { 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); +} + + Added files: Index: src/distrib/utils/libhack/nl_langinfo.c diff -u /dev/null src/distrib/utils/libhack/nl_langinfo.c:1.1 --- /dev/null Sun Jul 28 10:21:18 2019 +++ src/distrib/utils/libhack/nl_langinfo.c Sun Jul 28 10:21:18 2019 @@ -0,0 +1,20 @@ +/* $NetBSD: nl_langinfo.c,v 1.1 2019/07/28 10:21:18 martin Exp $ */ + +/* + * Written by Martin Husemann <mar...@netbsd.org> + * 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 ""; +} Index: src/distrib/utils/libhack/strcasecmp.c diff -u /dev/null src/distrib/utils/libhack/strcasecmp.c:1.1 --- /dev/null Sun Jul 28 10:21:18 2019 +++ src/distrib/utils/libhack/strcasecmp.c Sun Jul 28 10:21:18 2019 @@ -0,0 +1,20 @@ +/* $NetBSD: strcasecmp.c,v 1.1 2019/07/28 10:21:18 martin Exp $ */ + +/* + * Written by Martin Husemann <mar...@netbsd.org> + * 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); +}