Changeset 2511


Ignore:
Timestamp:
Jan 19, 2006, 3:44:53 AM (19 years ago)
Author:
bird
Message:

Fixes #30: Fixed two locale bugs. First, setlocale called a locale
dependent function for getting ctype flags. Second, all the
is<>() macros / functions was busted for non-ascii chars (-1..-128).

Location:
branches/libc-0.6/src/emx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified branches/libc-0.6/src/emx/ChangeLog.LIBC

    r2510 r2511  
    22
    33TODO: open replace on RAMFS fails with error 32!
     4
     52006-01-18: knut st. osmundsen <bird-gccos2-spam@anduin.net>
     6    - libc:
     7        o #30: Fixed two locale bugs. First, setlocale called a locale
     8          dependent function for getting ctype flags. Second, all the
     9          is<>() macros / functions was busted for non-ascii chars (-1..-128).
    410
    5112005-12-14: knut st. osmundsen <bird-gccos2-spam@anduin.net>
  • TabularUnified branches/libc-0.6/src/emx/include/InnoTekLIBC/locale.h

    r2163 r2511  
    316316/** @} */
    317317
     318#include <ctype.h>
     319
     320/**
     321 * Convert the type info we get from the unicode lib to libc talk.
     322 * ASSUMES that none of the locals differs from the unicode spec
     323 *
     324 * @returns libc ctype flags.
     325 * @param   pUniType    The unicode type info to translate.
     326 * @param   wc          The unicode code point.
     327 */
     328static inline unsigned ___wctype_uni(const UNICTYPE *pUniType, wchar_t wc)
     329{
     330    unsigned    ufType = 0;
     331    /* ASSUMES CT_* << 8 == __* ! */
     332    ufType = ((unsigned)pUniType->itype << 8)
     333           & (__CT_UPPER  | __CT_LOWER  | __CT_DIGIT | __CT_SPACE |
     334              __CT_PUNCT  | __CT_CNTRL  | __CT_BLANK | __CT_XDIGIT |
     335              __CT_ALPHA  | __CT_ALNUM  | __CT_GRAPH | __CT_PRINT |
     336              __CT_NUMBER | __CT_SYMBOL | __CT_ASCII);
     337    if (pUniType->extend & C3_IDEOGRAPH)
     338        ufType |= __CT_IDEOGRAM;
     339    if (ufType & (__CT_XDIGIT | __CT_DIGIT))
     340    {
     341        if (     (unsigned)wc - 0x30U <= (0x39 - 0x30))
     342            ufType |= (unsigned)wc - 0x30;
     343        else if ((unsigned)wc - 0x41U <= (0x46 - 0x41))
     344            ufType |= (unsigned)wc - 0x41 + 0xa;
     345        else
     346        {
     347            unsigned uVal = UniQueryNumericValue(wc);
     348            if (!(uVal & ~0xffU))
     349                ufType |= uVal;
     350        }
     351    }
     352    ufType |= (pUniType->bidi & 0xf << 24);
     353
     354    /** @todo screen width. */
     355    return ufType;
     356}
     357
    318358__END_DECLS
    319359
  • TabularUnified branches/libc-0.6/src/emx/include/_ctype.h

    r2058 r2511  
    166166static __inline__ unsigned __ctype(__ct_rune_t __ch, unsigned __f)
    167167{
    168     return !(__ch & ~0xffU)
    169         ? __libc_GLocaleCtype.aufType[__ch] & __f
     168    return __ch < 256 && __ch >= -128
     169        ? __libc_GLocaleCtype.aufType[__ch & 0xff] & __f
    170170        : 0;
    171171}
     
    178178static __inline__ int __isctype(__ct_rune_t __ch, unsigned __f)
    179179{
    180     return !(__ch & ~0xffU)
    181         ? !!(__libc_GLocaleCtypeDefault.aufType[__ch] & __f)
     180    return __ch <= 255 && __ch >= -128
     181        ? !!(__libc_GLocaleCtypeDefault.aufType[__ch & 0xff] & __f)
    182182        : 0;
    183183}
     
    185185static __inline__ __ct_rune_t __toupper(__ct_rune_t __ch)
    186186{
    187     return !(__ch & ~0xffU)
    188         ? __libc_GLocaleCtype.auchUpper[__ch]
     187    return __ch <= 255 && __ch >= -128
     188        ? __libc_GLocaleCtype.auchUpper[__ch & 0xff]
    189189        : (__ch);
    190190}
     
    192192static __inline__ __ct_rune_t __tolower(__ct_rune_t __ch)
    193193{
    194     return !(__ch & ~0xffU)
    195         ? __libc_GLocaleCtype.auchLower[__ch]
     194    return __ch <= 255 && __ch >= -128
     195        ? __libc_GLocaleCtype.auchLower[__ch & 0xff]
    196196        : __ch;
    197197}
  • TabularUnified branches/libc-0.6/src/emx/src/lib/locale/locale_ctype.c

    r2058 r2511  
    220220unsigned __ctype(__ct_rune_t __ch, unsigned __f)
    221221{
    222     return !((__ch) & ~0xffU)
    223         ? __libc_GLocaleCtype.aufType[(__ch)/* & 0xff*/] & (__f)
     222    return __ch <= 255 && __ch >= -128
     223        ? __libc_GLocaleCtype.aufType[__ch & 0xff] & __f
    224224        : 0;
    225225}
     
    227227int __istype(__ct_rune_t __ch, unsigned __f)
    228228{
    229     return !!__ctype((__ch), (__f));
     229    return !!__ctype(__ch, __f);
    230230}
    231231
    232232__ct_rune_t __toupper(__ct_rune_t __ch)
    233233{
    234     return !((__ch) & ~0xffU)
    235         ? __libc_GLocaleCtype.auchUpper[(__ch)/* & 0xff*/]
    236         : (__ch);
     234    return __ch <= 255 && __ch >= -128
     235        ? __libc_GLocaleCtype.auchUpper[__ch & 0xff]
     236        : __ch;
    237237}
    238238
    239239__ct_rune_t __tolower(__ct_rune_t __ch)
    240240{
    241     return !((__ch) & ~0xffU)
    242         ? __libc_GLocaleCtype.auchLower[(__ch)/* & 0xff*/]
    243         : (__ch);
     241    return __ch <= 255 && __ch >= -128
     242        ? __libc_GLocaleCtype.auchLower[__ch & 0xff]
     243        : __ch;
    244244}
    245245
     
    397397}
    398398
    399 
    400399/**
    401400 * Get unicode type.
     
    404403unsigned ___wctype(__wchar_t wc)
    405404{
    406     unsigned    ufType = 0;
    407405    if (    __libc_GLocaleWCtype.uMask != ~0x7f
    408406        ||  wc <= 127)
    409407    {
    410         UNICTYPE   *pUniType = UniQueryCharType(wc);
     408        UNICTYPE *pUniType = UniQueryCharType(wc);
    411409        if (pUniType)
    412         {
    413             /* ASSUMES CT_* << 8 == __* ! */
    414             ufType = ((unsigned)pUniType->itype << 8)
    415                    & (__CT_UPPER  | __CT_LOWER  | __CT_DIGIT | __CT_SPACE |
    416                       __CT_PUNCT  | __CT_CNTRL  | __CT_BLANK | __CT_XDIGIT |
    417                       __CT_ALPHA  | __CT_ALNUM  | __CT_GRAPH | __CT_PRINT |
    418                       __CT_NUMBER | __CT_SYMBOL | __CT_ASCII);
    419             if (pUniType->extend & C3_IDEOGRAPH)
    420                 ufType |= __CT_IDEOGRAM;
    421             if (ufType & (__CT_XDIGIT | __CT_DIGIT))
    422             {
    423                 if (     (unsigned)wc - 0x30U <= (0x39 - 0x30))
    424                     ufType |= (unsigned)wc - 0x30;
    425                 else if ((unsigned)wc - 0x41U <= (0x46 - 0x41))
    426                     ufType |= (unsigned)wc - 0x41 + 0xa;
    427                 else
    428                 {
    429                     unsigned uVal = UniQueryNumericValue(wc);
    430                     if (!(uVal & ~0xffU))
    431                         ufType |= uVal;
    432                 }
    433             }
    434             ufType |= (pUniType->bidi & 0xf << 24);
    435 
    436             /** @todo screen width. */
    437         }
    438     }
    439     return ufType;
     410            return ___wctype_uni(pUniType, wc);
     411    }
     412    return 0;
    440413}
    441414
  • TabularUnified branches/libc-0.6/src/emx/src/lib/locale/setlocale.c

    r2262 r2511  
    599599        UniChar         uc = 0xffff;
    600600
    601         /* isxxx() do not support MBCS characters at all. */
     601        /* isxxx() does not support MBCS characters at all. */
    602602        if (!pCtype->mbcs || !IS_MBCS_PREFIX(pCtype, i))
    603603        {
     
    609609                if (pUniType)
    610610                {
    611                     ufType = ___wctype(uc);
     611                    ufType = ___wctype_uni(pUniType, uc);
    612612                    if (ufType & __CT_LOWER)
    613613                        uchUpper = Transform(lobj, uobj, UniTransUpper, uc, i);
Note: See TracChangeset for help on using the changeset viewer.