Changeset 304


Ignore:
Timestamp:
Oct 29, 2005, 4:05:59 PM (20 years ago)
Author:
pr
Message:

Bug 614 fixes for NLS on MCP systems

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1-0/src/helpers/nls.c

    r222 r304  
    4949#include <string.h>
    5050#include <math.h>
     51#include <unidef.h>
     52#include <uconv.h>
    5153
    5254// XWP's setup.h replaces strchr and the like, and
     
    5557#include "setup.h"                      // code generation and debugging options
    5658
     59#include "helpers\dosh.h"
    5760#include "helpers\nls.h"
    5861#include "helpers\prfh.h"
     
    6063
    6164#pragma hdrstop
     65
     66#pragma library("LIBULS")
     67#pragma library("LIBCONV")
    6268
    6369/*
     
    367373 *@@added V0.9.0 [umoeller]
    368374 *@@changed V0.9.7 (2000-12-02) [umoeller]: added cDecimal
     375 *@@changed V1.0.4 (2005-10-15) [bvl]: Added support for Locale object settings on MCP systems @@fixes 614
     376 *@@changed V1.0.4 (2005-10-29) [pr]: Rewritten to prevent memory leaks and errors
    369377 */
    370378
     
    397405                                               "sThousand",
    398406                                               ',');
     407        if (doshIsWarp4()==2)
     408        {
     409            UconvObject         uconv_object;
     410
     411            if (UniCreateUconvObject((UniChar *)L"",
     412                                     &uconv_object) == ULS_SUCCESS)
     413            {
     414                LocaleObject locale_object;
     415
     416                if (UniCreateLocaleObject(UNI_UCS_STRING_POINTER,
     417                                          (UniChar *)L"",
     418                                          &locale_object) == ULS_SUCCESS)
     419                {
     420                    int i;
     421                    struct LOCALE_ITEMLIST
     422                    {
     423                        LocaleItem      lclItem;
     424                        PVOID           vTarget;
     425                        int             iType;
     426                    } itemList[] = {
     427                        { LOCI_iDate, &pcs->ulDateFormat, 1 },
     428                        { LOCI_iTime, &pcs->ulTimeFormat, 1 },
     429                        { LOCI_sDate, &pcs->cDateSep, 2 },
     430                        { LOCI_sTime, &pcs->cTimeSep, 2 },
     431                        { LOCI_sDecimal, &pcs->cDecimal, 2 },
     432                        { LOCI_sThousand, &pcs->cThousands, 2 }
     433                                   };
     434
     435                    for (i = 0;
     436                         i < sizeof(itemList) / sizeof(itemList[0]);
     437                         i++)
     438                    {
     439                        UniChar *pItem;
     440
     441                        if (UniQueryLocaleItem(locale_object,
     442                                               itemList[i].lclItem,
     443                                               &pItem) == ULS_SUCCESS)
     444                        {
     445                            int iLen = UniStrlen(pItem) + 1;
     446                            PSZ pszResult = malloc(iLen);
     447
     448                            if (UniStrFromUcs(uconv_object,
     449                                              pszResult,
     450                                              pItem,
     451                                              iLen) == ULS_SUCCESS)
     452                            {
     453                                switch(itemList[i].iType)
     454                                {
     455                                    case 1:
     456                                        *((ULONG *) itemList[i].vTarget) = atol(pszResult);
     457                                        break;
     458
     459                                    case 2:
     460                                        *((CHAR *) itemList[i].vTarget) = pszResult[0];
     461                                        break;
     462                                }
     463                            }
     464
     465                            free(pszResult);
     466                            UniFreeMem(pItem);
     467                        }
     468                    }
     469
     470                    UniFreeLocaleObject(locale_object);
     471                }
     472
     473                UniFreeUconvObject(uconv_object);
     474            }
     475        }
    399476    }
    400477}
  • trunk/src/helpers/nls.c

    r257 r304  
    4949#include <string.h>
    5050#include <math.h>
     51#include <unidef.h>
     52#include <uconv.h>
    5153
    5254// XWP's setup.h replaces strchr and the like, and
     
    5557#include "setup.h"                      // code generation and debugging options
    5658
     59#include "helpers\dosh.h"
    5760#include "helpers\nls.h"
    5861#include "helpers\prfh.h"
     
    6063
    6164#pragma hdrstop
     65
     66#pragma library("LIBULS")
     67#pragma library("LIBCONV")
    6268
    6369/*
     
    372378 *
    373379 *@@added V1.0.1 (2003-01-17) [umoeller]
     380 *@@changed V1.0.4 (2005-10-15) [pr]: Added support for Locale object settings on MCP systems @@fixes 614
    374381 */
    375382
     
    389396                          pampm->sz1159,
    390397                          sizeof(pampm->sz1159));
     398    if (doshIsWarp4()==2)
     399    {
     400        UconvObject         uconv_object;
     401
     402        if (UniCreateUconvObject((UniChar *)L"",
     403                                 &uconv_object) == ULS_SUCCESS)
     404        {
     405            LocaleObject locale_object;
     406
     407            if (UniCreateLocaleObject(UNI_UCS_STRING_POINTER,
     408                                      (UniChar *)L"",
     409                                      &locale_object) == ULS_SUCCESS)
     410            {
     411                int i;
     412                struct LOCALE_ITEMLIST
     413                {
     414                    LocaleItem      lclItem;
     415                    PVOID           vTarget;
     416                    int             iType;
     417                } itemList[] = {
     418                    { LOCI_s2359, &pampm->sz2359, 3 },
     419                    { LOCI_s1159, &pampm->sz1159, 3 }
     420                               };
     421
     422                for (i = 0;
     423                     i < sizeof(itemList) / sizeof(itemList[0]);
     424                     i++)
     425                {
     426                    UniChar *pItem;
     427
     428                    if (UniQueryLocaleItem(locale_object,
     429                                           itemList[i].lclItem,
     430                                           &pItem) == ULS_SUCCESS)
     431                    {
     432                        int iLen = UniStrlen(pItem) + 1;
     433                        PSZ pszResult = malloc(iLen);
     434
     435                        if (UniStrFromUcs(uconv_object,
     436                                          pszResult,
     437                                          pItem,
     438                                          iLen) == ULS_SUCCESS)
     439                        {
     440                            switch(itemList[i].iType)
     441                            {
     442                                case 1:
     443                                    *((ULONG *) itemList[i].vTarget) = atol(pszResult);
     444                                    break;
     445
     446                                case 2:
     447                                    *((CHAR *) itemList[i].vTarget) = pszResult[0];
     448                                    break;
     449
     450                                case 3:
     451                                    strcpy (itemList[i].vTarget, pszResult);
     452                                    break;
     453                            }
     454                        }
     455
     456                        free(pszResult);
     457                        UniFreeMem(pItem);
     458                    }
     459                }
     460
     461                UniFreeLocaleObject(locale_object);
     462            }
     463
     464            UniFreeUconvObject(uconv_object);
     465        }
     466    }
    391467}
    392468
     
    410486 *@@added V0.9.0 [umoeller]
    411487 *@@changed V0.9.7 (2000-12-02) [umoeller]: added cDecimal
     488 *@@changed V1.0.4 (2005-10-15) [bvl]: Added support for Locale object settings on MCP systems @@fixes 614
     489 *@@changed V1.0.4 (2005-10-29) [pr]: Rewritten to prevent memory leaks and errors
    412490 */
    413491
     
    441519                                               "sThousand",
    442520                                               ',');
     521        if (doshIsWarp4()==2)
     522        {
     523            UconvObject         uconv_object;
     524
     525            if (UniCreateUconvObject((UniChar *)L"",
     526                                     &uconv_object) == ULS_SUCCESS)
     527            {
     528                LocaleObject locale_object;
     529
     530                if (UniCreateLocaleObject(UNI_UCS_STRING_POINTER,
     531                                          (UniChar *)L"",
     532                                          &locale_object) == ULS_SUCCESS)
     533                {
     534                    int i;
     535                    struct LOCALE_ITEMLIST
     536                    {
     537                        LocaleItem      lclItem;
     538                        PVOID           vTarget;
     539                        int             iType;
     540                    } itemList[] = {
     541                        { LOCI_iDate, &pcs->ulDateFormat, 1 },
     542                        { LOCI_iTime, &pcs->ulTimeFormat, 1 },
     543                        { LOCI_sDate, &pcs->cDateSep, 2 },
     544                        { LOCI_sTime, &pcs->cTimeSep, 2 },
     545                        { LOCI_sDecimal, &pcs->cDecimal, 2 },
     546                        { LOCI_sThousand, &pcs->cThousands, 2 }
     547                                   };
     548
     549                    for (i = 0;
     550                         i < sizeof(itemList) / sizeof(itemList[0]);
     551                         i++)
     552                    {
     553                        UniChar *pItem;
     554
     555                        if (UniQueryLocaleItem(locale_object,
     556                                               itemList[i].lclItem,
     557                                               &pItem) == ULS_SUCCESS)
     558                        {
     559                            int iLen = UniStrlen(pItem) + 1;
     560                            PSZ pszResult = malloc(iLen);
     561
     562                            if (UniStrFromUcs(uconv_object,
     563                                              pszResult,
     564                                              pItem,
     565                                              iLen) == ULS_SUCCESS)
     566                            {
     567                                switch(itemList[i].iType)
     568                                {
     569                                    case 1:
     570                                        *((ULONG *) itemList[i].vTarget) = atol(pszResult);
     571                                        break;
     572
     573                                    case 2:
     574                                        *((CHAR *) itemList[i].vTarget) = pszResult[0];
     575                                        break;
     576
     577                                    case 3:
     578                                        strcpy (itemList[i].vTarget, pszResult);
     579                                        break;
     580                                }
     581                            }
     582
     583                            free(pszResult);
     584                            UniFreeMem(pItem);
     585                        }
     586                    }
     587
     588                    UniFreeLocaleObject(locale_object);
     589                }
     590
     591                UniFreeUconvObject(uconv_object);
     592            }
     593        }
    443594
    444595        nlsGetAMPM(&pcs2->ampm);
Note: See TracChangeset for help on using the changeset viewer.