collcmp.c revision 17599
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. 2517599Sache * 2617599Sache * $Id$ 2717530Sache */ 2817530Sache 2917530Sache#include <ctype.h> 3017530Sache#include <string.h> 3117556Sache#include <limits.h> 3217551Sache#include <locale.h> 3317551Sache 3417551Sacheint collate_range_cmp (c1, c2) 3517551Sache int c1, c2; 3617551Sache{ 3717576Sache int as1, as2, al1, al2; 3817530Sache static char s1[2], s2[2]; 3917530Sache 4017551Sache c1 &= UCHAR_MAX; 4117551Sache c2 &= UCHAR_MAX; 4217530Sache if (c1 == c2) 4317530Sache return (0); 4417576Sache 4517576Sache as1 = isascii(c1); 4617576Sache as2 = isascii(c2); 4717576Sache al1 = isalpha(c1); 4817576Sache al2 = isalpha(c2); 4917576Sache 5017576Sache if (as1 || as2 || al1 || al2) { 5117576Sache if ((as1 && as2) || (!al1 && !al2)) 5217576Sache return (c1 - c2); 5317576Sache if (al1 && !al2) { 5417576Sache if (isupper(c1)) 5517576Sache return ('A' - c2); 5617576Sache else 5717576Sache return ('a' - c2); 5817576Sache } else if (al2 && !al1) { 5917576Sache if (isupper(c2)) 6017576Sache return (c1 - 'A'); 6117576Sache else 6217576Sache return (c1 - 'a'); 6317576Sache } 6417530Sache } 6517576Sache 6617551Sache s1[0] = c1; 6717551Sache s2[0] = c2; 6817530Sache return strcoll(s1, s2); 6917530Sache} 70