/*static char *SCCSID = "@(#)cmcmpi.c	6.2 90/12/10";                                 */
/****************************************************************************/
/*                                                                          */
/*                       IBM/Microsoft Confidential                         */
/*                                                                          */
/*                 Copyright (c) IBM Corporation  1987, 1990                */
/*                 Copyright (c) Microsoft Corp.  1987, 1990                */
/*                           All Rights Reserved                            */
/*                                                                          */
/****************************************************************************/
/************* START OF SPECIFICATION ********** IBM CONFIDENTIAL ****/
/*                                                                   */
/* SUBROUTINE NAME:  COM_STRCMPI                                     */
/*                                                                   */
/* DESCRIPTIVE NAME:  COMPARES TWO STRINGS WITHOUT REGARD TO CASE    */
/*                                                                   */
/* FUNCTION:                                                         */
/*                                                                   */
/*                                                                   */
/* NOTES:                                                            */
/*                                                                   */
/*                                                                   */
/* ENTRY POINT:  com_strcmpi                                         */
/*   LINKAGE  :                                                      */
/*                                                                   */
/* INPUT:    string1  --- source string pointer (unsigned char ptr)  */
/*           string2  --- target string pointer (unsigned char ptr)  */
/*                                                                   */
/* EXIT:   integer                                                   */
/*       value            meaning                                    */
/*       less than 0      string1 less than string2                  */
/*       0                string1 identical to string2               */
/*       greater than 0   string1 greater than string2               */
/*                                                                   */
/* EXIT-ERROR:                                                       */
/*       none                                                        */
/*                                                                   */
/*                                                                   */
/*                                                                   */
/* EFFECTS:                                                          */
/*                                                                   */
/* INTERNAL REFERENCES:  none                                        */
/*   ROUTINES:                                                       */
/*                                                                   */
/* EXTERNAL REFERENCES:                                              */
/*   ROUTINES:                                                       */
/*             check_dbcs()                                          */
/*                                                                   */
/* RISTRICTION:                                                      */
/*   First character of string1 and string2 must be single byte code */
/*   or first byte of 2 byte code.                                   */
/*                                                                   */
/* RELEASE:                                                          */
/*                                                                   */
/*   VERSION      DATE       AUTHOR      REASON                      */
/*     1.00    06/13/1986    USHI          initial version           */
/*                                                                   */
/*     1.1     03/18/1988    Cora Yang     ptm2128   @@              */
/*                                                                   */
/*                                    1.   to take care of the       */
/*                                         problem of can read past  */
/*                                         NULL termination of input */
/*                                    2.   to make it shorter and    */
/*                                         faster                    */
/*                                                                   */
/*     1.1     03/28/1988    Cora Yang     call check_dbcs instead   */
/*                                         of com_chkdbcs to improve */
/*                                         performance               */
/*                                                                   */
/*     1.2     6/13/89       ScottB        Use DBCS version of       */
/*                                         to do strcmpi function    */
/*                                         ptr b784201               */
/******************* END OF SPECIFICATIONS ***************************/
#include "cmdbcs.h"
#include "comsub.h"
/* #include <ctype.h>    */
/* #include <stdio.h>    */

/* use private toupper routine to avoid 16 bit string routines */
static unsigned short toupper(unsigned char);

int com_strcmpi(str1,str2)
unsigned char *str1; /* source string         */
unsigned char *str2; /* string to be compared */
{                                              /*                          */
int i;
int rc=0;                                      /*                          */

 com_settbl();                                 /* initialize DBCS table    */

 /* loop thru strings checking the upper cases for
    equality. If a double byte character is found,
    the second byte must not be fed to toupper before
    comparison */

 for ( ; *str1 && *str2 ; str1++, str2++) {
         i = com_toupper(*str1) - com_toupper(*str2);   /* ptr b784201 */
         if (i != 0)
                 return(i);
         if ( check_dbcs(*str1) == DBCS ) {             /* @@ if DBCS */
            if ( !(*(str1 +1)) || !(*(str2 +1)) ) {     /* either one reached the end then we are done */
                 if ( !(*(str1 +1)) && !(*(str2 +1)) )  /* @@ both reached the end */
                       return(0);                       /* @@ compared  */
                 else {
                       if ( !(*(str1 +1)) )             /* if str1 reached end */
                          return(-1);                   /* str1 less than str2 */
                       else
                          return(1);                    /* str1 greater than str2 */
                 }

            } else  {
                 str1++;
                 str2++;
            }

            i = *str1 - *str2;
            if (i)
               return(i);
         }
 }

 return(*str1 - *str2);

}                                              /*  ended                   */



