update for HEAD-2003021201
[reactos.git] / lib / msvcrt / mbstring / mbsicoll.c
1 /*
2  * COPYRIGHT:   See COPYING in the top level directory
3  * PROJECT:     ReactOS system libraries
4  * FILE:        lib/msvcrt/mbstring/mbsicoll.c
5  * PURPOSE:     
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 colldif(unsigned short c1, unsigned short c2);
15 int _mbsicoll(const unsigned char *str1, const unsigned char *str2)
16 {
17         unsigned char *s1 = (unsigned char *)str1;
18         unsigned char *s2 = (unsigned char *)str2;
19
20         unsigned short *short_s1, *short_s2;
21
22         int l1, l2;
23
24         while ( *s1 != 0 ) {
25                 
26                 if (*s1 == 0)
27                         break;  
28
29                 l1 = _ismbblead(*s1);
30                 l2 = _ismbblead(*s2);
31                 if ( !l1 &&  !l2  ) {
32
33                         if (toupper(*s1) != toupper(*s2))
34                                 return colldif(*s1, *s2);
35                         else {
36                                 s1 += 1;
37                                 s2 += 1;
38                         }
39                 }
40                 else if ( l1 && l2 ){
41                         short_s1 = (unsigned short *)s1;
42                         short_s2 = (unsigned short *)s2;
43                         if ( _mbctoupper(*short_s1) != _mbctoupper(*short_s2 ))
44                                 return colldif(*short_s1, *short_s2);
45                         else {
46                                 s1 += 2;
47                                 s2 += 2;
48
49                         }
50                 }
51                 else
52                         return colldif(*s1, *s2);
53         } ;
54         return 0;
55 }