b1b7c41e0968ad0b69a77e219c552aec8d5b97bb
[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 /*
15  * @implemented
16  */
17 int _mbsicmp(const unsigned char *str1, const unsigned char *str2)
18 {
19         unsigned char *s1 = (unsigned char *)str1;
20         unsigned char *s2 = (unsigned char *)str2;
21
22         unsigned short *short_s1, *short_s2;
23
24         int l1, l2;
25
26         do {
27                 
28                 if (*s1 == 0)
29                         break;  
30
31                 l1 = _ismbblead(*s1);
32                 l2 = _ismbblead(*s2);
33                 if ( !l1 &&  !l2  ) {
34
35                         if (toupper(*s1) != toupper(*s2))
36                                 return toupper(*s1) - toupper(*s2);
37                         else {
38                                 s1 += 1;
39                                 s2 += 1;
40                         }
41                 }
42                 else if ( l1 && l2 ){
43                         short_s1 = (unsigned short *)s1;
44                         short_s2 = (unsigned short *)s2;
45                         if ( _mbctoupper(*short_s1) != _mbctoupper(*short_s2 ))
46                                 return _mbctoupper(*short_s1) - _mbctoupper(*short_s2);
47                         else {
48                                 s1 += 2;
49                                 s2 += 2;
50                         }
51                 }
52                 else
53                         return *s1 - *s2;
54         } while (*s1 != 0);
55         return 0;
56
57   while (toupper(*s1) == toupper(*s2))
58   {
59     if (*s1 == 0)
60       return 0;
61     s1++;
62     s2++;
63   }
64   return toupper(*(unsigned const char *)s1) - toupper(*(unsigned const char *)(s2));
65 }