collcmp.c revision 17551
117530Sache/* 217530Sache * Copyright (C) 1996 by Andrey A. Chernov, Moscow, Russia. 317530Sache * All rights reserved. 417530Sache * 517530Sache * Redistribution and use in source and binary forms, with or without 617530Sache * modification, are permitted provided that the following conditions 717530Sache * are met: 817530Sache * 1. Redistributions of source code must retain the above copyright 917530Sache * notice, this list of conditions and the following disclaimer. 1017530Sache * 2. Redistributions in binary form must reproduce the above copyright 1117530Sache * notice, this list of conditions and the following disclaimer in the 1217530Sache * documentation and/or other materials provided with the distribution. 1317530Sache * 1417530Sache * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND 1517530Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1617530Sache * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1717530Sache * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 1817530Sache * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1917530Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2017530Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2117530Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2217530Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2317530Sache * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2417530Sache * SUCH DAMAGE. 2517530Sache */ 2617530Sache 2717530Sache#include <ctype.h> 2817530Sache#include <string.h> 2917551Sache#include <locale.h> 3017551Sache 3117551Sache/* will be removed ***************************/ 3217530Sache#include "collate.h" 3317530Sache 3417530Sacheint __collcmp (c1, c2) 3517551Sache unsigned char c1, c2; 3617530Sache{ 3717551Sache return collate_range_cmp (c1, c2); 3817551Sache} 3917551Sache/* will be removed ***************************/ 4017551Sache 4117551Sacheint collate_range_cmp (c1, c2) 4217551Sache int c1, c2; 4317551Sache{ 4417530Sache static char s1[2], s2[2]; 4517530Sache 4617551Sache c1 &= UCHAR_MAX; 4717551Sache c2 &= UCHAR_MAX; 4817530Sache if (c1 == c2) 4917530Sache return (0); 5017530Sache if ( (isascii(c1) && isascii(c2)) 5117530Sache || (!isalpha(c1) && !isalpha(c2)) 5217530Sache ) 5317551Sache return (c1 - c2); 5417530Sache if (isalpha(c1) && !isalpha(c2)) { 5517530Sache if (isupper(c1)) 5617551Sache return ('A' - c2); 5717530Sache else 5817551Sache return ('a' - c2); 5917530Sache } else if (isalpha(c2) && !isalpha(c1)) { 6017530Sache if (isupper(c2)) 6117551Sache return (c1 - 'A'); 6217530Sache else 6317551Sache return (c1 - 'a'); 6417530Sache } 6517530Sache if (isupper(c1) && islower(c2)) 6617530Sache return (-1); 6717530Sache else if (islower(c1) && isupper(c2)) 6817530Sache return (1); 6917551Sache s1[0] = c1; 7017551Sache s2[0] = c2; 7117530Sache return strcoll(s1, s2); 7217530Sache} 73