From 956383bed878377c60fa07ec47955f81a6ee5833 Mon Sep 17 00:00:00 2001 From: ache Date: Mon, 12 Aug 1996 18:38:49 +0000 Subject: There is so many places where range comparation (using collate) needed (much more than I think initially), so I forced to add new user-visible non-standard function to libc. --- lib/libc/locale/collcmp.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/libc/locale/collcmp.c b/lib/libc/locale/collcmp.c index 15dba54..fefa52d 100644 --- a/lib/libc/locale/collcmp.c +++ b/lib/libc/locale/collcmp.c @@ -26,36 +26,47 @@ #include #include +#include + +/* will be removed ***************************/ #include "collate.h" int __collcmp (c1, c2) - u_char c1, c2; + unsigned char c1, c2; +{ + return collate_range_cmp (c1, c2); +} +/* will be removed ***************************/ + +int collate_range_cmp (c1, c2) + int c1, c2; { static char s1[2], s2[2]; + c1 &= UCHAR_MAX; + c2 &= UCHAR_MAX; if (c1 == c2) return (0); if ( (isascii(c1) && isascii(c2)) || (!isalpha(c1) && !isalpha(c2)) ) - return (((int)c1) - ((int)c2)); + return (c1 - c2); if (isalpha(c1) && !isalpha(c2)) { if (isupper(c1)) - return ('A' - ((int)c2)); + return ('A' - c2); else - return ('a' - ((int)c2)); + return ('a' - c2); } else if (isalpha(c2) && !isalpha(c1)) { if (isupper(c2)) - return (((int)c1) - 'A'); + return (c1 - 'A'); else - return (((int)c1) - 'a'); + return (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; + s1[0] = c1; + s2[0] = c2; return strcoll(s1, s2); } - -- cgit v1.1