home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / fed0217s.zip / source / _ctype.cpp next >
C/C++ Source or Header  |  2000-12-13  |  4KB  |  177 lines

  1. /*
  2. ** Module   :_CTYPE.CPP
  3. ** Abstract : NLS support routines
  4. **
  5. ** Copyright (C) Sergey I. Yevtushenko
  6. **
  7. ** Log: Sat  03/05/1997       Updated
  8. */
  9.  
  10. #define INCL_DOSNLS
  11. #include <os2.h>
  12.  
  13. #include <_ctype.h>
  14. #include <version.h>
  15.  
  16. void __nls_init(void)
  17. {
  18.     COUNTRYCODE Country;
  19.     COUNTRYINFO CtryInfo = {0};
  20.     ULONG ulLen;
  21.     unsigned i;
  22.     APIRET rc;
  23.  
  24.     for(i = 0; i < 256; i++)
  25.     {
  26.         toupper_cvt_table[i] = (char)i;
  27.         tolower_cvt_table[i] = (char)i;
  28.         collate_cvt_table[i] = (char)i;
  29.     }
  30.  
  31.     for(i = 'a'; i <= 'z'; i++)
  32.     {
  33.         toupper_cvt_table[i] = (char)(i - 'a' + 'A');
  34.     }
  35.  
  36.     for(i = 'A'; i <= 'Z'; i++)
  37.     {
  38.         tolower_cvt_table[i] = (char)(i - 'A' + 'a');
  39.     }
  40.  
  41.     Country.country  = 0;
  42.     Country.codepage = 0;
  43.  
  44.     rc = DosMapCase(256,
  45.                     &Country,
  46.                     toupper_cvt_table);
  47.  
  48.     DD_TRACE("DosMapCase",rc);
  49.  
  50.     if(rc)
  51.         return;
  52.  
  53.     rc = DosQueryCollate(256,
  54.                          &Country,
  55.                          collate_cvt_table,
  56.                          &ulLen);
  57.  
  58.     DD_TRACE("DosQueryCollate",rc);
  59.  
  60.     rc = DosQueryCtryInfo(sizeof(CtryInfo), &Country,
  61.                           &CtryInfo, &ulLen);
  62.  
  63.     DD_TRACE("DosQueryCtryInfo",rc);
  64.  
  65.     if(!rc)
  66.     {
  67.         iDateFmt = CtryInfo.fsDateFmt;
  68.       //  cDateSep = CtryInfo.szDateSeparator[0];
  69.     }
  70.     for(i = 128; i < 256; i++)
  71.     {
  72.         if((unsigned char)toupper_cvt_table[i] > (unsigned char)0x7F)
  73.             tolower_cvt_table[(unsigned char)toupper_cvt_table[i]] = (char)i;
  74.     }
  75.     for(i = 128; i < 256; i++)
  76.     {
  77.         __r_ctype[i] = (tolower_cvt_table[i] != toupper_cvt_table[i]) ?
  78.                         (IS_AL | IS_IS) :
  79.                         (IS_PU);
  80.     }
  81. }
  82.  
  83. int __nstrcmp(char *s0, char *s1, char *cvt_tbl)
  84. {
  85.     if(!s0 || !s1)
  86.         return (s0) ? 1:-1;
  87.  
  88.     while(*s0 || *s1)
  89.     {
  90.         if(collate_cvt_table[cvt_tbl[*s0]] == collate_cvt_table[cvt_tbl[*s1]])
  91.         {
  92.             s0++;
  93.             s1++;
  94.             continue;
  95.         }
  96.  
  97.         if(collate_cvt_table[cvt_tbl[*s0]] > collate_cvt_table[cvt_tbl[*s1]])
  98.             return 1;
  99.         if(collate_cvt_table[cvt_tbl[*s0]] < collate_cvt_table[cvt_tbl[*s1]])
  100.             return -1;
  101.     }
  102.     return 0;
  103. }
  104.  
  105. int __cstrcmp(char *s0, char *s1)
  106. {
  107.     if(!s0 || !s1)
  108.         return (s0) ? 1:-1;
  109.     while(*s0 || *s1)
  110.     {
  111.         if(__to_lower(*s0) == __to_lower(*s1))
  112.         {
  113.             *s0++;
  114.             *s1++;
  115.             continue;
  116.         }
  117.  
  118.         if(__to_lower(*s0) > __to_lower(*s1))
  119.             return 1;
  120.         if(__to_lower(*s0) < __to_lower(*s1))
  121.             return -1;
  122.     }
  123.     return 0;
  124. }
  125.  
  126. int __cnstrcmp(char *s0, char *s1, int n)
  127. {
  128.     if(!s0 || !s1 || n <= 0)
  129.         return (s0) ? 1:-1;
  130.  
  131.     while(n--)
  132.     {
  133.         if(__to_lower(*s0) == __to_lower(*s1))
  134.         {
  135.             *s0++;
  136.             *s1++;
  137.             continue;
  138.         }
  139.  
  140.         if(__to_lower(*s0) > __to_lower(*s1))
  141.             return 1;
  142.         if(__to_lower(*s0) < __to_lower(*s1))
  143.             return -1;
  144.     }
  145.     return 0;
  146. }
  147.  
  148. char* __cstrchr(char* s0, int chr)
  149. {
  150.     if(!s0)
  151.         return 0;
  152.  
  153.     chr = __to_lower(chr);
  154.  
  155.     while(*s0)
  156.     {
  157.         if(__to_lower(*s0) == chr)
  158.             return s0;
  159.  
  160.         s0++;
  161.     }
  162.     return 0;
  163. }
  164.  
  165. #ifdef __GNUC__
  166. extern "C" void __rtti_user(void);
  167. void __rtti_user(void) {}
  168. extern "C" void __rtti_si(void);
  169. void __rtti_si(void) {}
  170. extern "C" void __rtti_class(void);
  171. void __rtti_class(void) {}
  172. extern "C" void __eh_pc(void);
  173. void __eh_pc(void){}
  174. //extern "C" void terminate(void)
  175. void terminate(void) {}
  176. #endif
  177.