11ab64890Smrg/*
21ab64890Smrg * Copyright 1992, 1993 by TOSHIBA Corp.
31ab64890Smrg *
41ab64890Smrg * Permission to use, copy, modify, and distribute this software and its
51ab64890Smrg * documentation for any purpose and without fee is hereby granted, provided
61ab64890Smrg * that the above copyright notice appear in all copies and that both that
71ab64890Smrg * copyright notice and this permission notice appear in supporting
81ab64890Smrg * documentation, and that the name of TOSHIBA not be used in advertising
91ab64890Smrg * or publicity pertaining to distribution of the software without specific,
101ab64890Smrg * written prior permission. TOSHIBA make no representations about the
111ab64890Smrg * suitability of this software for any purpose.  It is provided "as is"
121ab64890Smrg * without express or implied warranty.
131ab64890Smrg *
141ab64890Smrg * TOSHIBA DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
151ab64890Smrg * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
161ab64890Smrg * TOSHIBA BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
171ab64890Smrg * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
181ab64890Smrg * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
191ab64890Smrg * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
201ab64890Smrg * SOFTWARE.
211ab64890Smrg *
221ab64890Smrg * Author: Katsuhisa Yano	TOSHIBA Corp.
231ab64890Smrg *			   	mopi@osa.ilab.toshiba.co.jp
241ab64890Smrg * Bug fixes: Bruno Haible	XFree86 Inc.
251ab64890Smrg */
261ab64890Smrg
271ab64890Smrg#ifdef HAVE_CONFIG_H
281ab64890Smrg#include <config.h>
291ab64890Smrg#endif
301ab64890Smrg#include <X11/Xlib.h>
311ab64890Smrg#include "XlcPublic.h"
321ab64890Smrg
331ab64890Smrg/* Don't use <ctype.h> here because it is locale dependent. */
341ab64890Smrg
3507fb9b8fSmrg#define set_toupper(ch) do {  \
361ab64890Smrg  if (ch >= 'a' && ch <= 'z') \
3707fb9b8fSmrg    ch = (unsigned char) (ch - 'a' + 'A'); \
3807fb9b8fSmrg} while (0)
391ab64890Smrg
401ab64890Smrg/* Compares two ISO 8859-1 strings, ignoring case of ASCII letters.
411ab64890Smrg   Like strcasecmp in an ASCII locale. */
4261b2299dSmrgint
431ab64890Smrg_XlcCompareISOLatin1(
441ab64890Smrg    const char *str1,
451ab64890Smrg    const char *str2)
461ab64890Smrg{
471ab64890Smrg    unsigned char ch1, ch2;
481ab64890Smrg
491ab64890Smrg    for ( ; ; str1++, str2++) {
509c019ec5Smaya	ch1 = (unsigned char) *str1;
519c019ec5Smaya	ch2 = (unsigned char) *str2;
521ab64890Smrg	if (ch1 == '\0' || ch2 == '\0')
531ab64890Smrg	    break;
541ab64890Smrg	set_toupper(ch1);
551ab64890Smrg	set_toupper(ch2);
561ab64890Smrg	if (ch1 != ch2)
571ab64890Smrg	    break;
581ab64890Smrg    }
591ab64890Smrg
601ab64890Smrg    return ch1 - ch2;
611ab64890Smrg}
621ab64890Smrg
631ab64890Smrg/* Compares two ISO 8859-1 strings, at most len bytes of each, ignoring
641ab64890Smrg   case of ASCII letters. Like strncasecmp in an ASCII locale. */
6561b2299dSmrgint
661ab64890Smrg_XlcNCompareISOLatin1(
671ab64890Smrg    const char *str1,
681ab64890Smrg    const char *str2,
691ab64890Smrg    int len)
701ab64890Smrg{
711ab64890Smrg    unsigned char ch1, ch2;
721ab64890Smrg
731ab64890Smrg    for ( ; ; str1++, str2++, len--) {
741ab64890Smrg	if (len == 0)
751ab64890Smrg	    return 0;
769c019ec5Smaya	ch1 = (unsigned char) *str1;
779c019ec5Smaya	ch2 = (unsigned char) *str2;
781ab64890Smrg	if (ch1 == '\0' || ch2 == '\0')
791ab64890Smrg	    break;
801ab64890Smrg	set_toupper(ch1);
811ab64890Smrg	set_toupper(ch2);
821ab64890Smrg	if (ch1 != ch2)
831ab64890Smrg	    break;
841ab64890Smrg    }
851ab64890Smrg
861ab64890Smrg    return ch1 - ch2;
871ab64890Smrg}
88