From 378240cb4bb850ae8415951372ef2774772e00d2 Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 12 Aug 1996 03:40:37 +0000 Subject: Add internal function __collcmp once instead of adding it statically to many places in the libc --- lib/libc/locale/Makefile.inc | 3 ++- lib/libc/locale/collate.h | 3 ++- lib/libc/locale/collcmp.c | 61 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 lib/libc/locale/collcmp.c (limited to 'lib') diff --git a/lib/libc/locale/Makefile.inc b/lib/libc/locale/Makefile.inc index 5fd09d2..ffc2b51 100644 --- a/lib/libc/locale/Makefile.inc +++ b/lib/libc/locale/Makefile.inc @@ -5,7 +5,8 @@ SRCS+= ansi.c ctype.c euc.c frune.c isctype.c lconv.c localeconv.c \ mbrune.c none.c rune.c setlocale.c table.c utf2.c setrunelocale.c \ - runetype.c tolower.c toupper.c nomacros.c collate.c setinvalidrune.c + runetype.c tolower.c toupper.c nomacros.c collate.c setinvalidrune.c \ + collcmp.c MAN3+= locale/ctype.3 locale/isalnum.3 locale/isalpha.3 locale/isascii.3 \ locale/isblank.3 locale/iscntrl.3 locale/isdigit.3 locale/isgraph.3 \ diff --git a/lib/libc/locale/collate.h b/lib/libc/locale/collate.h index c7c0b6d..9125a3e 100644 --- a/lib/libc/locale/collate.h +++ b/lib/libc/locale/collate.h @@ -24,7 +24,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: collate.h,v 1.4 1995/01/27 12:51:06 alex Exp alex $ + * $Id: collate.h,v 1.1 1995/02/16 04:24:32 ache Exp $ */ #ifndef COLLATE_H_INCLUDED @@ -64,6 +64,7 @@ void __collate_lookup __P((u_char *, int *, int *, int *)); #ifdef COLLATE_DEBUG void __collate_print_tables __P((void)); #endif +int __collcmp __P((u_char, u_char)); __END_DECLS #endif /* not COLLATE_H_INCLUDED */ diff --git a/lib/libc/locale/collcmp.c b/lib/libc/locale/collcmp.c new file mode 100644 index 0000000..15dba54 --- /dev/null +++ b/lib/libc/locale/collcmp.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) 1996 by Andrey A. Chernov, Moscow, Russia. + * 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 ``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 REGENTS 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 +#include +#include "collate.h" + +int __collcmp (c1, c2) + u_char c1, c2; +{ + static char s1[2], s2[2]; + + if (c1 == c2) + return (0); + if ( (isascii(c1) && isascii(c2)) + || (!isalpha(c1) && !isalpha(c2)) + ) + return (((int)c1) - ((int)c2)); + if (isalpha(c1) && !isalpha(c2)) { + if (isupper(c1)) + return ('A' - ((int)c2)); + else + return ('a' - ((int)c2)); + } else if (isalpha(c2) && !isalpha(c1)) { + if (isupper(c2)) + return (((int)c1) - 'A'); + else + return (((int)c1) - 'a'); + } + if (isupper(c1) && islower(c2)) + return (-1); + else if (islower(c1) && isupper(c2)) + return (1); + s1[0] = (char) c1; + s2[0] = (char) c2; + return strcoll(s1, s2); +} + -- cgit v1.1