diff options
author | tjr <tjr@FreeBSD.org> | 2002-08-04 12:09:08 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2002-08-04 12:09:08 +0000 |
commit | c7dfca65ec8e30de1b40fcf31c4e140cc8a705e8 (patch) | |
tree | 63912096bfe0d27c0615433761b7eedc4c90e47b | |
parent | fd6d1078a965be3456970e1f7783dd21f7618d82 (diff) | |
download | FreeBSD-src-c7dfca65ec8e30de1b40fcf31c4e140cc8a705e8.zip FreeBSD-src-c7dfca65ec8e30de1b40fcf31c4e140cc8a705e8.tar.gz |
Add the ISO C90 Amd. 1 wctrans(3) and towctrans(3) functions.
-rw-r--r-- | include/wctype.h | 7 | ||||
-rw-r--r-- | lib/libc/locale/Makefile.inc | 5 | ||||
-rw-r--r-- | lib/libc/locale/wctrans.3 | 109 | ||||
-rw-r--r-- | lib/libc/locale/wctrans.c | 84 |
4 files changed, 203 insertions, 2 deletions
diff --git a/include/wctype.h b/include/wctype.h index ab763ca..2dd5e79 100644 --- a/include/wctype.h +++ b/include/wctype.h @@ -41,6 +41,11 @@ typedef _BSD_WINT_T_ wint_t; #undef _BSD_WINT_T_ #endif +#ifndef _WCTRANS_T +typedef int wctrans_t; +#define _WCTRANS_T +#endif + #ifndef _WCTYPE_T typedef long wctype_t; #define _WCTYPE_T @@ -52,6 +57,8 @@ typedef long wctype_t; __BEGIN_DECLS int iswctype(wint_t, wctype_t); +wint_t towctrans(wint_t, wctrans_t); +wctrans_t wctrans(const char *); wctype_t wctype(const char *); #if 0 /* XXX: not implemented */ diff --git a/lib/libc/locale/Makefile.inc b/lib/libc/locale/Makefile.inc index 9111fdd..745154c 100644 --- a/lib/libc/locale/Makefile.inc +++ b/lib/libc/locale/Makefile.inc @@ -9,14 +9,14 @@ SRCS+= ansi.c big5.c btowc.c collate.c collcmp.c euc.c fix_grouping.c frune.c \ ldpart.c lmessages.c lmonetary.c lnumeric.c localeconv.c mbrune.c \ mskanji.c nl_langinfo.c nomacros.c none.c rune.c \ runetype.c setinvalidrune.c setlocale.c setrunelocale.c table.c \ - tolower.c toupper.c utf2.c wctob.c wctype.c + tolower.c toupper.c utf2.c wctob.c wctrans.c wctype.c .if ${LIB} == "c" MAN+= btowc.3 \ ctype.3 digittoint.3 isalnum.3 isalpha.3 isascii.3 isblank.3 iscntrl.3 \ isdigit.3 isgraph.3 islower.3 isprint.3 ispunct.3 isspace.3 \ isupper.3 isxdigit.3 mbrune.3 multibyte.3 nl_langinfo.3 rune.3 \ - setlocale.3 toascii.3 tolower.3 toupper.3 wctype.3 + setlocale.3 toascii.3 tolower.3 toupper.3 wctrans.3 wctype.3 MAN+= euc.4 utf2.4 MLINKS+=btowc.3 wctob.3 @@ -29,5 +29,6 @@ MLINKS+=rune.3 fgetrune.3 rune.3 fputrune.3 rune.3 fungetrune.3 \ rune.3 setinvalidrune.3 rune.3 setrunelocale.3 rune.3 sgetrune.3 \ rune.3 sputrune.3 MLINKS+=setlocale.3 localeconv.3 +MLINKS+=wctrans.3 towctrans.3 MLINKS+=wctype.3 iswctype.3 .endif diff --git a/lib/libc/locale/wctrans.3 b/lib/libc/locale/wctrans.3 new file mode 100644 index 0000000..5f491a6 --- /dev/null +++ b/lib/libc/locale/wctrans.3 @@ -0,0 +1,109 @@ +.\" Copyright (c) 2002 Tim J. Robbins +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd August 4, 2002 +.Dt WCTRANS 3 +.Os +.Sh NAME +.Nm towctrans , +.Nm wctrans +.Nd "wide character mapping functions" +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In wctype.h +.Ft wint_t +.Fn towctrans "wint_t wc" "wctrans_t desc" +.Ft wctrans_t +.Fn wctrans "const char *charclass" +.Sh DESCRIPTION +The +.Fn wctrans +function returns a value of type +.Vt wctrans_t +which represents the requested wide character mapping operation and +may be used as the second argument for calls to +.Fn towctrans . +.Pp +The following character mapping names are recognised: +.Bl -column -offset indent ".Li tolower" ".Li toupper" +.It Li tolower Ta Li toupper +.El +.Pp +The +.Fn towctrans +function transliterates the wide character +.Fa wc +according to the mapping described by +.Fa desc . +.Sh RETURN VALUES +The +.Fn towctrans +function returns the transliterated character if successful, otherwise +it returns the character unchanged and sets +.Va errno . +.Pp +The +.Fn wctrans +function returns non-zero if successful, otherwise it returns zero +and sets +.Va errno . +.Sh ERRORS +The +.Fn towctrans +function will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The supplied +.Fa desc +argument is invalid. +.El +.Pp +The +.Fn wctrans +function will fail if: +.Bl -tag -width Er +.It Bq Er EINVAL +The requested mapping name is invalid. +.El +.Sh SEE ALSO +.Xr tolower 3 , +.Xr toupper 3 , +.Xr wctype 3 +.Sh STANDARDS +The +.Fn towctrans +and +.Fn wctrans +functions conform to +.St -p1003.1-2001 . +.Sh HISTORY +The +.Fn towctrans +and +.Fn wctrans +functions first appeared in +.Fx 5.0 . diff --git a/lib/libc/locale/wctrans.c b/lib/libc/locale/wctrans.c new file mode 100644 index 0000000..d5de6f1 --- /dev/null +++ b/lib/libc/locale/wctrans.c @@ -0,0 +1,84 @@ +/*- + * Copyright (c) 2002 Tim J. Robbins. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <ctype.h> +#include <errno.h> +#include <string.h> +#include <wctype.h> + +enum { + _WCT_ERROR = 0, + _WCT_TOLOWER = 1, + _WCT_TOUPPER = 2 +}; + +/* + * TODO: Supply a macro version of this. + */ +wint_t +towctrans(wint_t wc, wctrans_t desc) +{ + + switch (desc) { + case _WCT_TOLOWER: + wc = tolower(wc); + break; + case _WCT_TOUPPER: + wc = toupper(wc); + break; + case _WCT_ERROR: + default: + errno = EINVAL; + break; + } + + return (wc); +} + +wctrans_t +wctrans(const char *charclass) +{ + struct { + const char *name; + wctrans_t trans; + } ccls[] = { + { "tolower", _WCT_TOLOWER }, + { "toupper", _WCT_TOUPPER }, + { NULL, _WCT_ERROR }, /* Default */ + }; + int i; + + i = 0; + while (ccls[i].name != NULL && strcmp(ccls[i].name, charclass) != 0) + i++; + + if (ccls[i].trans == _WCT_ERROR) + errno = EINVAL; + return (ccls[i].trans); +} |