Changeset 2161 for trunk


Ignore:
Timestamp:
Jul 3, 2005, 2:31:40 AM (20 years ago)
Author:
bird
Message:

o Fixed serveral bugs in the C/POSIX locale
o Implemented the LC_MESSAGES locale.

Location:
trunk/src/emx
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/ChangeLog.LIBC

    • Property cvs2svn:cvs-rev changed from 1.84 to 1.85
    r2160 r2161  
    99        o Added %m (GLIBC extension) to the printf familiy. %m means
    1010          priting strerror(errno), it takes no arguments.
     11        o Fixed serveral bugs in the C/POSIX locale
     12        o Implemented the LC_MESSAGES locale.
    1113
    12142005-07-01: knut st. osmundsen <bird-gccos2-spam@anduin.net>
  • trunk/src/emx/src/lib/locale/locale_lconv.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r2160 r2161  
    4242        "",                             //*mon_grouping;          /** monetary size of grouping */
    4343        "",                             //*positive_sign;         /** non-negative values sign */
    44         "-",                            //*negative_sign;         /** negative values sign */
     44        "" ,                            //*negative_sign;         /** negative values sign */
    4545        CHAR_MAX,                       //int_frac_digits;        /** number of fractional digits - int currency */
    4646        CHAR_MAX,                       //frac_digits;            /** number of fractional digits - local currency */
     
    6363};
    6464
     65
     66/* Locale information structure for the 'C'/'POSIX' locale. */
     67const __LIBC_LOCALELCONV       __libc_gLocaleLconvDefault =
     68{
     69    .s =
     70    {
     71        ".",                            //*decimal_point;         /** non-monetary decimal point */
     72        "",                             //*thousands_sep;         /** non-monetary thousands separator */
     73        "",                             //*grouping;              /** non-monetary size of grouping */
     74        "",                             //*int_curr_symbol;       /** international currency symbol and separator */
     75        "",                             //*currency_symbol;       /** local currency symbol */
     76        "",                             //*mon_decimal_point;     /** monetary decimal point */
     77        "",                             //*mon_thousands_sep;     /** monetary thousands separator */
     78        "",                             //*mon_grouping;          /** monetary size of grouping */
     79        "",                             //*positive_sign;         /** non-negative values sign */
     80        "" ,                            //*negative_sign;         /** negative values sign */
     81        CHAR_MAX,                       //int_frac_digits;        /** number of fractional digits - int currency */
     82        CHAR_MAX,                       //frac_digits;            /** number of fractional digits - local currency */
     83        CHAR_MAX,                       //p_cs_precedes;          /** (non-neg curr sym) 1-precedes, 0-succeeds */
     84        CHAR_MAX,                       //p_sep_by_space;         /** (non-neg curr sym) 1-space, 0-no space */
     85        CHAR_MAX,                       //n_cs_precedes;          /** (neg curr sym) 1-precedes, 0-succeeds */
     86        CHAR_MAX,                       //n_sep_by_space;         /** (neg curr sym) 1-space, 0-no space */
     87        CHAR_MAX,                       //p_sign_posn;            /** positioning of non-negative monetary sign */
     88        CHAR_MAX,                       //n_sign_posn;            /** positioning of negative monetary sign */
     89        CHAR_MAX,                       //int_p_cs_precedes;
     90        CHAR_MAX,                       //int_p_sep_by_space;
     91        CHAR_MAX,                       //int_n_cs_precedes;
     92        CHAR_MAX,                       //int_n_sep_by_space;
     93        CHAR_MAX,                       //int_p_sign_posn;
     94        CHAR_MAX                        //int_n_sign_posn;
     95    },
     96
     97    .fNumericConsts = 1,
     98    .fMonetaryConsts = 1
     99};
     100
  • trunk/src/emx/src/lib/locale/locale_time.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r2160 r2161  
    3434  .swdays =  { "Sun",   "Mon",   "Tue",    "Wed",      "Thu",     "Fri",   "Sat" },
    3535  .lwdays =  { "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" },
    36   .date_time_fmt = "%a %b %d %H:%M:%S %Y",
     36  .date_time_fmt = "%a %b %e %H:%M:%S %Y",
    3737  .date_fmt = "%m/%d/%y",
    3838  .time_fmt = "%H:%M:%S",
    3939  .am =       "AM",
    4040  .pm =       "PM",
     41  .ampm_fmt = "%I:%M:%S %p",
     42  .era =      "",
     43  .era_date_fmt = "",
     44  .era_date_time_fmt = "",
     45  .era_time_fmt = "",
     46  .alt_digits = "",
     47  .datesep =  "/", //?
     48  .timesep =  ":", //?
     49  .listsep =  "",  //??????
    4150  .fConsts = 1
    4251};
    4352
     53
     54/** Date / time formatting rules for the C/POSIX locale. */
     55const __LIBC_LOCALETIME __libc_gLocaleTimeDefault =
     56{
     57  .smonths = { "Jan",    "Feb",     "Mar",  "Apr",  "May","Jun", "Jul", "Aug",   "Sep",      "Oct",    "Nov",     "Dec"},
     58  .lmonths = { "January","February","March","April","May","June","July","August","September","October","November","December" },
     59  .swdays =  { "Sun",   "Mon",   "Tue",    "Wed",      "Thu",     "Fri",   "Sat" },
     60  .lwdays =  { "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" },
     61  .date_time_fmt = "%a %b %e %H:%M:%S %Y",
     62  .date_fmt = "%m/%d/%y",
     63  .time_fmt = "%H:%M:%S",
     64  .am =       "AM",
     65  .pm =       "PM",
     66  .ampm_fmt = "%I:%M:%S %p",
     67  .era =      "",
     68  .era_date_fmt = "",
     69  .era_date_time_fmt = "",
     70  .era_time_fmt = "",
     71  .alt_digits = "",
     72  .datesep =  "/", //?
     73  .timesep =  ":", //?
     74  .listsep =  "",  //??????
     75  .fConsts = 1
     76};
     77
  • trunk/src/emx/src/lib/locale/nl_langinfo.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2160 r2161  
    101101
    102102        case YESSTR:
    103             return ""; ///@todo LC_MESSAGE
     103            return __libc_gLocaleMsg.pszYesStr;
    104104        case NOSTR:
    105             return ""; ///@todo LC_MESSAGE
     105            return __libc_gLocaleMsg.pszNoStr;
    106106
    107107        case CRNCYSTR:
     
    130130
    131131        case YESEXPR:
    132             return ""; ///@todo LC_MESSAGE
     132            return __libc_gLocaleMsg.pszYesExpr;
    133133        case NOEXPR:
    134             return ""; ///@todo LC_MESSAGE
     134            return __libc_gLocaleMsg.pszNoExpr;
    135135
    136136        case DATESEP:
  • trunk/src/emx/src/lib/locale/setlocale.c

    • Property cvs2svn:cvs-rev changed from 1.20 to 1.21
    r2160 r2161  
    135135    /** Numeric and monetary data. */
    136136    __LIBC_LOCALELCONV          Lconv;
     137    /** Messages data. */
     138    __LIBC_LOCALEMSG            Msg;
    137139};
    138140
     
    228230static int query_item(LocaleObject lobj, UconvObject uobj, LocaleItem iItem, char **ppszOut);
    229231static int query_array(LocaleObject lobj, UconvObject uobj, int cElements, LocaleItem iFirst, char **papszOut);
    230 static int localeTimeDo(__LIBC_PLOCALETIME pTime, UconvObject uobj, LocaleObject lobj);
     232static int localeTimeDo(__LIBC_PLOCALETIME pTime, UconvObject uobj, LocaleObject lobj, const char *pszLocale);
    231233static void localeTimeFree(__LIBC_PLOCALETIME pTime);
    232234static void localeNumericFree(__LIBC_PLOCALELCONV pLconv);
     
    514516
    515517    /*
    516      * For "C" / "POSIX" we can just use the static default locale.
     518     * For "C" / "POSIX" we can simply use the static default locale.
    517519     */
    518520    if (    IS_C_LOCALE(pszLocale)
     
    766768 * @returns 0 on success.
    767769 * @returns negated errno on failure.
    768  * @param   pTime   The time structure to operate on.
    769  * @param   uobj    The UconvObject to use.
    770  * @param   lobj    The LocaleObject to use.
    771  */
    772 static int localeTimeDo(__LIBC_PLOCALETIME pTime, UconvObject uobj, LocaleObject lobj)
     770 * @param   pTime       The time structure to operate on.
     771 * @param   uobj        The UconvObject to use.
     772 * @param   lobj        The LocaleObject to use.
     773 * @param   pszLocale   Pointer to the locale base specifier.
     774 */
     775static int localeTimeDo(__LIBC_PLOCALETIME pTime, UconvObject uobj, LocaleObject lobj, const char *pszLocale)
    773776{
    774777    int         rc;
     
    776779    /* free old stuff. */
    777780    localeTimeFree(pTime);
     781
     782    /*
     783     * For "C" / "POSIX" we can simply use the static default locale.
     784     */
     785    if (    IS_C_LOCALE(pszLocale)
     786        ||  IS_POSIX_LOCALE(pszLocale))
     787    {
     788        memcpy(pTime, &__libc_gLocaleTimeDefault, sizeof(*pTime));
     789        return 0;
     790    }
    778791
    779792    /* query the items. */
     
    899912{
    900913    int     rc;
     914
    901915    /* free any old stuff. */
    902916    localeNumericFree(pLconv);
    903917
    904     if (    !IS_C_LOCALE(pszLocale)
    905         &&  !IS_POSIX_LOCALE(pszLocale))
    906     {
    907         /*
    908          * Convert the stuff.
    909          */
     918    /*
     919     * For "C" / "POSIX" we can simply use the static default locale.
     920     */
     921    if (    IS_C_LOCALE(pszLocale)
     922        ||  IS_POSIX_LOCALE(pszLocale))
     923    {
     924#define COPY(m) do { pLconv->m = __libc_gLocaleLconvDefault.m; } while (0)
     925        pLconv->fNumericConsts        = 1;
     926        COPY(s.decimal_point);
     927        COPY(s.thousands_sep);
     928        COPY(s.grouping);
     929#undef COPY
     930        return 0;
     931    }
     932
     933    /*
     934     * Convert the stuff.
     935     */
    910936#define CONVERT_UCS(field) \
    911937    do  { rc = convert_ucs(uobj, pULconv->field, &pLconv->s.field); if (rc) return rc; } while (0)
    912         CONVERT_UCS(decimal_point);
    913         CONVERT_UCS(thousands_sep);
     938    CONVERT_UCS(decimal_point);
     939    CONVERT_UCS(thousands_sep);
    914940#undef CONVERT_UCS
    915941
    916         return localeConvertGrouping(pULconv->grouping, &pLconv->s.grouping);
    917     }
    918     else
    919     {
    920         /* the C/POSIX locale */
    921         LIBCLOG_MSG2("POSIX '%s'\n", pszLocale);
    922         pLconv->fNumericConsts        = 1;
    923         pLconv->s.decimal_point       = ".";
    924         pLconv->s.thousands_sep       = ",";
    925         pLconv->s.grouping            = "";
    926         return 0;
    927     }
     942    return localeConvertGrouping(pULconv->grouping, &pLconv->s.grouping);
    928943}
    929944
     
    943958{
    944959    int rc;
     960
    945961    /* free any old stuff. */
    946962    localeMonetaryFree(pLconv);
    947963
    948     if (    !IS_C_LOCALE(pszLocale)
    949         &&  !IS_POSIX_LOCALE(pszLocale))
    950     {
    951         /*
    952          * Convert the stuff.
    953          */
     964    /*
     965     * For "C" / "POSIX" we can simply use the static default locale.
     966     */
     967    if (    IS_C_LOCALE(pszLocale)
     968        ||  IS_POSIX_LOCALE(pszLocale))
     969    {
     970#define COPY(m) do { pLconv->m = __libc_gLocaleLconvDefault.m; } while (0)
     971        COPY(s.int_curr_symbol);
     972        COPY(s.currency_symbol);
     973        COPY(s.mon_decimal_point);
     974        COPY(s.mon_thousands_sep);
     975        COPY(s.positive_sign);
     976        COPY(s.negative_sign);
     977        COPY(pszCrncyStr);
     978        COPY(s.mon_grouping);
     979        COPY(s.int_frac_digits);
     980        COPY(s.frac_digits);
     981        COPY(s.p_cs_precedes);
     982        COPY(s.p_sep_by_space);
     983        COPY(s.n_cs_precedes);
     984        COPY(s.n_sep_by_space);
     985        COPY(s.p_sign_posn);
     986        COPY(s.n_sign_posn);
     987        COPY(s.int_p_cs_precedes);
     988        COPY(s.int_n_cs_precedes);
     989        COPY(s.int_p_sep_by_space);
     990        COPY(s.int_n_sep_by_space);
     991        COPY(s.int_p_sign_posn);
     992        COPY(s.int_n_sign_posn);
     993        pLconv->fMonetaryConsts = 1;
     994#undef COPY
     995        return 0;
     996    }
     997    /*
     998     * Convert the stuff.
     999     */
     1000#define FIXMAX(val) \
     1001    ( (val) != 0xff ? (val) : CHAR_MAX ) /* (assumes CHAR_MAX == 0x7f) */
    9541002#define CONVERT_UCS(field) \
    9551003    do  { rc = convert_ucs(uobj, pULconv->field, &pLconv->s.field); if (rc) return rc; } while (0)
    9561004
    957         if (pszModifier && IS_EURO(pszModifier))
    958         {
    959             /** @todo check for specs on a standard EURO grouping and stuff. */
    960             pLconv->s.currency_symbol = strdup("EUR");
    961             pLconv->s.int_curr_symbol = strdup("EUR");
    962         }
    963         else
    964         {
    965             CONVERT_UCS(int_curr_symbol);
    966             CONVERT_UCS(currency_symbol);
    967         }
    968         CONVERT_UCS(mon_decimal_point);
    969         CONVERT_UCS(mon_thousands_sep);
    970         CONVERT_UCS(positive_sign);
    971         CONVERT_UCS(negative_sign);
    972         pLconv->s.int_frac_digits   = pULconv->int_frac_digits;
    973         pLconv->s.frac_digits       = pULconv->frac_digits;
    974         pLconv->s.p_cs_precedes     = pULconv->p_cs_precedes;
    975         pLconv->s.p_sep_by_space    = pULconv->p_sep_by_space;
    976         pLconv->s.n_cs_precedes     = pULconv->n_cs_precedes;
    977         pLconv->s.n_sep_by_space    = pULconv->n_sep_by_space;
    978         pLconv->s.p_sign_posn       = pULconv->p_sign_posn;
    979         pLconv->s.n_sign_posn       = pULconv->n_sign_posn;
    980         /* we fake the international variants here. */
    981         pLconv->s.int_p_cs_precedes = pULconv->p_cs_precedes;
    982         pLconv->s.int_n_cs_precedes = pULconv->n_cs_precedes;
    983         pLconv->s.int_p_sep_by_space= pULconv->p_sep_by_space;
    984         pLconv->s.int_n_sep_by_space= pULconv->n_sep_by_space;
    985         pLconv->s.int_p_sign_posn   = pULconv->p_sign_posn;
    986         pLconv->s.int_n_sign_posn   = pULconv->n_sign_posn;
    987 
     1005    if (pszModifier && IS_EURO(pszModifier))
     1006    {
     1007        /** @todo check for specs on a standard EURO grouping and stuff. */
     1008        pLconv->s.currency_symbol = strdup("EUR");
     1009        pLconv->s.int_curr_symbol = strdup("EUR");
     1010    }
     1011    else
     1012    {
     1013        CONVERT_UCS(int_curr_symbol);
     1014        CONVERT_UCS(currency_symbol);
     1015    }
     1016    CONVERT_UCS(mon_decimal_point);
     1017    CONVERT_UCS(mon_thousands_sep);
     1018    CONVERT_UCS(positive_sign);
     1019    CONVERT_UCS(negative_sign);
     1020
     1021    pLconv->s.int_frac_digits   = FIXMAX(pULconv->int_frac_digits);
     1022    pLconv->s.frac_digits       = FIXMAX(pULconv->frac_digits);
     1023    pLconv->s.p_cs_precedes     = FIXMAX(pULconv->p_cs_precedes);
     1024    pLconv->s.p_sep_by_space    = FIXMAX(pULconv->p_sep_by_space);
     1025    pLconv->s.n_cs_precedes     = FIXMAX(pULconv->n_cs_precedes);
     1026    pLconv->s.n_sep_by_space    = FIXMAX(pULconv->n_sep_by_space);
     1027    pLconv->s.p_sign_posn       = FIXMAX(pULconv->p_sign_posn);
     1028    pLconv->s.n_sign_posn       = FIXMAX(pULconv->n_sign_posn);
     1029    /* we fake the international variants here. */
     1030    pLconv->s.int_p_cs_precedes = pLconv->s.p_cs_precedes;
     1031    pLconv->s.int_n_cs_precedes = pLconv->s.n_cs_precedes;
     1032    pLconv->s.int_p_sep_by_space= pLconv->s.p_sep_by_space;
     1033    pLconv->s.int_n_sep_by_space= pLconv->s.n_sep_by_space;
     1034    pLconv->s.int_p_sign_posn   = pLconv->s.p_sign_posn;
     1035    pLconv->s.int_n_sign_posn   = pLconv->s.n_sign_posn;
     1036
     1037#undef FIXMAX
    9881038#undef CONVERT_UCS
    9891039
    990         /*
    991          * Extra stuff (which I don't know which member corresponds to).
    992          */
    993         if ((rc = query_item(lobj, uobj, CRNCYSTR, &pLconv->pszCrncyStr)))
    994             return rc;
    995 
    996         return localeConvertGrouping(pULconv->mon_grouping, &pLconv->s.mon_grouping);
    997     }
    998     else
    999     {
    1000         /*
    1001          * The C/POSIX locale.
    1002          */
    1003         pLconv->fMonetaryConsts = 1;
    1004         pLconv->s.int_curr_symbol = pLconv->s.currency_symbol = pLconv->s.mon_decimal_point
    1005             = pLconv->s.mon_thousands_sep = pLconv->s.positive_sign = pLconv->s.negative_sign
    1006             = pLconv->pszCrncyStr = pLconv->s.mon_grouping = "";
    1007         pLconv->s.int_frac_digits   = -1;
    1008         pLconv->s.frac_digits       = -1;
    1009         pLconv->s.p_cs_precedes     = -1;
    1010         pLconv->s.p_sep_by_space    = -1;
    1011         pLconv->s.n_cs_precedes     = -1;
    1012         pLconv->s.n_sep_by_space    = -1;
    1013         pLconv->s.p_sign_posn       = -1;
    1014         pLconv->s.n_sign_posn       = -1;
    1015         pLconv->s.int_p_cs_precedes = -1;
    1016         pLconv->s.int_n_cs_precedes = -1;
    1017         pLconv->s.int_p_sep_by_space= -1;
    1018         pLconv->s.int_n_sep_by_space= -1;
    1019         pLconv->s.int_p_sign_posn   = -1;
    1020         pLconv->s.int_n_sign_posn   = -1;
    1021 
    1022         return 0;
    1023     }
    1024 }
     1040    /*
     1041     * Extra stuff (which I don't know which member corresponds to).
     1042     */
     1043    if ((rc = query_item(lobj, uobj, CRNCYSTR, &pLconv->pszCrncyStr)))
     1044        return rc;
     1045
     1046    return localeConvertGrouping(pULconv->mon_grouping, &pLconv->s.mon_grouping);
     1047}
     1048
     1049/**
     1050 * Frees all heap strings in the monetary part of the lconv structure.
     1051 * @param   pLconv  What to work on.
     1052 */
     1053static void localeMessagesFree(__LIBC_PLOCALEMSG pMsg)
     1054{
     1055    if (!pMsg->fConsts)
     1056    {
     1057#define FREE(x) do { if (pMsg->x) free(pMsg->x); pMsg->x = NULL; } while (0)
     1058        FREE(pszYesExpr);
     1059        FREE(pszNoExpr);
     1060        FREE(pszYesStr);
     1061        FREE(pszNoStr);
     1062#undef FREE
     1063    }
     1064    pMsg->fConsts = 0;
     1065}
     1066
     1067
     1068/**
     1069 * Sets the LC_MESSAGES part of the locale.
     1070 *
     1071 * @returns 0 on success.
     1072 * @returns negated errno on failure.
     1073 * @param   pMsg        The messages locale info structure to operate on.
     1074 * @param   uobj        The UconvObject to use.
     1075 * @param   lobj        The LocaleObject to use.
     1076 * @param   pszLocale   Pointer to the locale base specifier.
     1077 */
     1078static int localeMessagesDo(__LIBC_PLOCALEMSG pMsg, UconvObject uobj, LocaleObject lobj, const char *pszLocale)
     1079{
     1080    int     rc;
     1081    /* free any old stuff. */
     1082    localeMessagesFree(pMsg);
     1083
     1084    /*
     1085     * For "C" / "POSIX" we can simply use the static default locale.
     1086     */
     1087    if (    IS_C_LOCALE(pszLocale)
     1088        ||  IS_POSIX_LOCALE(pszLocale))
     1089    {
     1090        memcpy(pMsg, &__libc_gLocaleMsgDefault, sizeof(*pMsg));
     1091        return 0;
     1092    }
     1093
     1094    /* query the items. */
     1095    if (    (rc = query_item(lobj, uobj,     YESEXPR,      &pMsg->pszYesExpr))
     1096        ||  (rc = query_item(lobj, uobj,     NOEXPR,       &pMsg->pszNoExpr))
     1097        ||  (rc = query_item(lobj, uobj,     YESSTR,       &pMsg->pszYesStr))
     1098        ||  (rc = query_item(lobj, uobj,     NOSTR,        &pMsg->pszNoStr))
     1099            )
     1100    {
     1101        return rc;
     1102    }
     1103
     1104    return 0;
     1105}
     1106
    10251107
    10261108/**
     
    10371119    }
    10381120}
     1121
    10391122
    10401123/**
     
    13031386
    13041387        case LC_TIME:
    1305             rc = localeTimeDo(&pTemp->Time, uobj, lobj);
     1388            rc = localeTimeDo(&pTemp->Time, uobj, lobj, pszLocale);
    13061389            break;
    13071390
     
    13311414
    13321415        case LC_MESSAGES:
    1333             /* Nothing to do for now */
     1416            rc = localeMessagesDo(&pTemp->Msg, uobj, lobj, pszLocale);
     1417            break;
     1418
    13341419        default:
    13351420            rc = 0;
     
    15971682    if (pTemp->afProcessed[LC_MESSAGES + 1])
    15981683    {
     1684        localeMessagesFree(&__libc_gLocaleMsg);
     1685        memcpy(&__libc_gLocaleMsg, &pTemp->Msg, sizeof(__libc_gLocaleMsg));
    15991686        pTemp->afProcessed[LC_MESSAGES + 1] = 0;
    16001687        gLocale.apszNames[LC_MESSAGES + 1] = pTemp->Global.apszNames[LC_MESSAGES + 1];
     
    16721759    if (pTemp->afProcessed[LC_MONETARY + 1])
    16731760        localeMonetaryFree(&pTemp->Lconv);
     1761    if (pTemp->afProcessed[LC_MESSAGES + 1])
     1762        localeMessagesFree(&pTemp->Msg);
    16741763    for (iCat = 0; iCat < _LC_LAST; iCat++)
    16751764        if (pTemp->afProcessed[iCat + 1])
Note: See TracChangeset for help on using the changeset viewer.