Changeset 3056 for trunk


Ignore:
Timestamp:
Apr 8, 2007, 7:12:27 PM (18 years ago)
Author:
bird
Message:

Added a fixed default (C/POSIX) collate locale to avoid unilib strangeness. Made an attempt at adjusting for this strangeness for the non-default locales...

Location:
trunk/libc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libc/include/klibc/locale.h

    r2909 r3056  
    241241/** String collation information. */
    242242extern __LIBC_LOCALECOLLATE         __libc_gLocaleCollate;
     243/** String collation information for the default 'C'/'POSIX' locale. */
     244extern const __LIBC_LOCALECOLLATE   __libc_gLocaleCollateDefault;
    243245/** Character case conversion tables. */
    244246extern __LIBC_LOCALECTYPE           __libc_GLocaleCtype;
  • trunk/libc/src/libc/locale/locale_collate.c

    r3002 r3056  
    7979};
    8080
     81
     82/** String collation information for the 'C'/'POSIX' default locale. */
     83const __LIBC_LOCALECOLLATE __libc_gLocaleCollateDefault =
     84{
     85    .auchWeight =
     86    {
     87          0,   1,   2,   3,   4,   5,   6,   7,   8,   9,
     88         10,  11,  12,  13,  14,  15,  16,  17,  18,  19,
     89         20,  21,  22,  23,  24,  25,  26,  27,  28,  29,
     90         30,  31,  32,  33,  34,  35,  36,  37,  38,  39,
     91         40,  41,  42,  43,  44,  45,  46,  47,  48,  49,
     92         50,  51,  52,  53,  54,  55,  56,  57,  58,  59,
     93         60,  61,  62,  63,  64,  65,  66,  67,  68,  69,
     94         70,  71,  72,  73,  74,  75,  76,  77,  78,  79,
     95         80,  81,  82,  83,  84,  85,  86,  87,  88,  89,
     96         90,  91,  92,  93,  94,  95,  96,  97,  98,  99,
     97        100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
     98        110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
     99        120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
     100        130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
     101        140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
     102        150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
     103        160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
     104        170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
     105        180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
     106        190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
     107        200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
     108        210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
     109        220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
     110        230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
     111        240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
     112        250, 251, 252, 253, 254, 255
     113    },
     114    .au2MBCSPrefixs =
     115    {   /* 01 */
     116        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     117        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     118        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     119        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     120        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     121        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     122        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     123        0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
     124    },
     125#ifdef __OS2__
     126    .uobj = 0,
     127    .lobj = 0,
     128#else
     129/** @todo portable local */
     130#endif
     131    .mbcs = 0
     132};
     133
  • trunk/libc/src/libc/locale/os2/setlocale.c

    r2935 r3056  
    221221static int query_mbcs(UconvObject uobj, char *mbcs, unsigned char *au2MBCSPrefixs);
    222222
    223 static int localeCollateDo(__LIBC_PLOCALECOLLATE pCollate, UconvObject uobj, LocaleObject lobj);
     223static int localeCollateDo(__LIBC_PLOCALECOLLATE pCollate, UconvObject uobj, LocaleObject lobj, const char *pszLocale);
    224224static void localeCollateFree(__LIBC_PLOCALECOLLATE pCollate);
    225225static inline unsigned char Transform(LocaleObject lobj, UconvObject uobj,
     
    384384 * @param   uobj            The UconvObject to use. Collate is responsible for freeing it.
    385385 * @param   lobj            The LocaleObject to use. Collate is responsible for freeing it.
    386  */
    387 static int localeCollateDo(__LIBC_PLOCALECOLLATE pCollate, UconvObject uobj, LocaleObject lobj)
     386 * @param   pszLocale       Pointer to the locale base specifier.
     387 */
     388static int localeCollateDo(__LIBC_PLOCALECOLLATE pCollate, UconvObject uobj, LocaleObject lobj, const char *pszLocale)
    388389{
    389390    int rc;
     
    391392    /* Cleanup in case of some special LC_ALL call. */
    392393    localeCollateFree(pCollate);
     394
     395    /*
     396     * For "C" / "POSIX" we can simply use the static default locale.
     397     */
     398    if (    IS_C_LOCALE(pszLocale)
     399        ||  IS_POSIX_LOCALE(pszLocale))
     400    {
     401        memcpy(pCollate, &__libc_gLocaleCollateDefault, sizeof(*pCollate));
     402        return 0;
     403    }
    393404
    394405    /*
     
    435446                aCW[i].len = sizeof(aCW[i].ucsWeight) / sizeof(aCW[i].ucsWeight[0]);
    436447            }
     448
     449            /* Workaround for bug / undocumented UniStrxfrm feature. See strxfrm.c & mozilla sources. */
     450            aCW[i].len = MIN(aCW[i].len * 2, sizeof(aCW[i].ucsWeight) / sizeof(aCW[i].ucsWeight[0]));
     451            while (!aCW[i].ucsWeight[aCW[i].len - 1])
     452                aCW[i].len--;
    437453        }
    438454
     
    505521 * @param   uobj            The UconvObject to use. Ctype is responsible for freeing it.
    506522 * @param   lobj            The LocaleObject to use. Ctype is responsible for freeing it.
     523 * @param   pszLocale       Pointer to the locale base specifier.
    507524 * @param   pszCodeset      The codeset used.
    508525 */
     
    12211238 * @returns negated errno on failure.
    12221239 * @param   pszCodepage     Pointer to where the codepage specifier starts.
     1240 * @param   pszLocale       Pointer to the locale base specifier.
     1241 * @param   lobj            The locale object handle.
    12231242 * @param   pucsCodepage    Where to store the code page.
    12241243 * @param   cucCodepage     Number of UniChar's in the buffer.
     
    13961415    {
    13971416        case LC_COLLATE:
    1398             rc = localeCollateDo(&pTemp->Collate, uobj, lobj);
     1417            rc = localeCollateDo(&pTemp->Collate, uobj, lobj, pszLocale);
    13991418            fFree = rc != 0;
    14001419            break;
Note: See TracChangeset for help on using the changeset viewer.