branch update for HEAD-2003021201
[reactos.git] / lib / crtdll / mbstring / mbsicmp.c
1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS system libraries
4  * FILE:        lib/crtdll/mbstring/mbsicmp.c
5  * PURPOSE:     Duplicates a multi byte string
6  * PROGRAMER:   Boudewijn Dekker
7  * UPDATE HISTORY:
8  *              12/04/99: Created
9  */
10 #include <msvcrt/mbstring.h>
11 #include <msvcrt/mbctype.h>
12 #include <msvcrt/ctype.h>
13
14 int _mbsicmp(const unsigned char *str1, const unsigned char *str2)
15 {
16         unsigned char *s1 = (unsigned char *)str1;
17         unsigned char *s2 = (unsigned char *)str2;
18
19         unsigned short *short_s1, *short_s2;
20
21         int l1, l2;
22
23         do {
24                 
25                 if (*s1 == 0)
26                         break;  
27
28                 l1 = _ismbblead(*s1);
29                 l2 = _ismbblead(*s2);
30                 if ( !l1 &&  !l2  ) {
31
32                         if (toupper(*s1) != toupper(*s2))
33                                 return toupper(*s1) - toupper(*s2);
34                         else {
35                                 s1 += 1;
36                                 s2 += 1;
37                         }
38                 }
39                 else if ( l1 && l2 ){
40                         short_s1 = (unsigned short *)s1;
41                         short_s2 = (unsigned short *)s2;
42                         if ( _mbctoupper(*short_s1) != _mbctoupper(*short_s2 ))
43                                 return _mbctoupper(*short_s1) - _mbctoupper(*short_s2);
44                         else {
45                                 s1 += 2;
46                                 s2 += 2;
47                         }
48                 }
49                 else
50                         return *s1 - *s2;
51         } while (*s1 != 0);
52         return 0;
53
54   while (toupper(*s1) == toupper(*s2))
55   {
56     if (*s1 == 0)
57       return 0;
58     s1++;
59     s2++;
60   }
61   return toupper(*(unsigned const char *)s1) - toupper(*(unsigned const char *)(s2));
62 }