1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-17 10:26:15 +00:00

Add internal function __collcmp once instead of adding it statically

to many places in the libc
This commit is contained in:
Andrey A. Chernov 1996-08-12 03:40:37 +00:00
parent 072acff80a
commit 2eecfbac3a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=17530
3 changed files with 65 additions and 2 deletions

View File

@ -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 \

View File

@ -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 */

61
lib/libc/locale/collcmp.c Normal file
View File

@ -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 <ctype.h>
#include <string.h>
#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);
}