Changeset 242 for trunk/src/helpers/nls.c
- Timestamp:
- Jan 19, 2003, 8:42:16 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/nls.c
r222 r242 349 349 350 350 /* 351 *@@ nlsGetAMPM: 352 * 353 *@@added V1.0.1 (2003-01-17) [umoeller] 354 */ 355 356 VOID nlsGetAMPM(PCOUNTRYAMPM pampm) 357 { 358 PrfQueryProfileString(HINI_USER, 359 "PM_National", 360 "s2359", // key 361 "PM", // default 362 pampm->sz2359, 363 sizeof(pampm->sz2359)); 364 365 PrfQueryProfileString(HINI_USER, 366 "PM_National", 367 "s1159", // key 368 "AM", // default 369 pampm->sz1159, 370 sizeof(pampm->sz1159)); 371 } 372 373 /* 351 374 *@@ nlsQueryCountrySettings: 352 375 * this returns the most frequently used country settings … … 369 392 */ 370 393 371 VOID nlsQueryCountrySettings(PCOUNTRYSETTINGS pcs) 372 { 373 if (pcs) 374 { 394 VOID nlsQueryCountrySettings(PCOUNTRYSETTINGS2 pcs2) 395 { 396 if (pcs2) 397 { 398 PCOUNTRYSETTINGS pcs = &pcs2->cs; 375 399 pcs->ulDateFormat = PrfQueryProfileInt(HINI_USER, 376 400 (PSZ)PMINIAPP_NATIONAL, … … 397 421 "sThousand", 398 422 ','); 423 424 nlsGetAMPM(&pcs2->ampm); 399 425 } 400 426 } … … 424 450 CHAR cThousands) // in: separator char (e.g. '.') 425 451 { 426 USHORT ust, uss, usc; 427 CHAR szTemp[40]; 428 usc = sprintf(szTemp, "%lu", ul); // V0.9.20 (2002-07-03) [umoeller] 429 430 ust = 0; 431 // usc = strlen(szTemp); 432 for (uss = 0; uss < usc; uss++) 452 CHAR szTemp[30]; 453 USHORT ust = 0, 454 uss, 455 usLen = sprintf(szTemp, "%lu", ul); // V0.9.20 (2002-07-03) [umoeller] 456 457 for (uss = 0; 458 uss < usLen; 459 ++uss) 433 460 { 434 461 if (uss) 435 if ( ((usc - uss) % 3) == 0)462 if (0 == ((usLen - uss) % 3)) 436 463 { 437 464 pszTarget[ust] = cThousands; 438 465 ust++; 439 466 } 440 pszTarget[ust] = szTemp[uss]; 441 ust++; 442 } 467 468 pszTarget[ust++] = szTemp[uss]; 469 } 470 443 471 pszTarget[ust] = '\0'; 444 472 … … 473 501 CHAR cThousands) 474 502 { 475 USHORT ust, uss, us c;503 USHORT ust, uss, usLen; 476 504 CHAR szTemp[40]; 477 us c= sprintf(szTemp, "%.0f", floor(dbl)); // V0.9.20 (2002-07-03) [umoeller]505 usLen = sprintf(szTemp, "%.0f", floor(dbl)); // V0.9.20 (2002-07-03) [umoeller] 478 506 479 507 ust = 0; 480 // usc = strlen(szTemp); 481 for (uss = 0; uss < usc; uss++) 508 for (uss = 0; uss < usLen; uss++) 482 509 { 483 510 if (uss) 484 if (((us c- uss) % 3) == 0)511 if (((usLen - uss) % 3) == 0) 485 512 { 486 513 pszTarget[ust] = cThousands; … … 547 574 * 548 575 *@@changed V0.9.0 (99-11-07) [umoeller]: now calling nlsDateTime 549 */ 550 551 VOID nlsFileDate(PSZ pszBuf, // out: string returned 552 FDATE *pfDate, // in: date information 553 ULONG ulDateFormat, // in: date format (0-3) 554 CHAR cDateSep) // in: date separator (e.g. '.') 555 { 556 DATETIME dt; 557 dt.day = pfDate->day; 558 dt.month = pfDate->month; 559 dt.year = pfDate->year + 1980; 560 561 nlsDateTime(pszBuf, 562 NULL, // no time 563 &dt, 564 ulDateFormat, 565 cDateSep, 566 0, 0); // no time 576 *@@changed V1.0.1 (2003-01-17) [umoeller]: prototype changed for optimization, this was not exported 577 */ 578 579 VOID nlsFileDate(PSZ pszBuf, // out: string returned 580 const FDATE *pfDate, // in: date information 581 const COUNTRYSETTINGS2 *pcs) 582 { 583 nlsDate(pcs, 584 pszBuf, 585 pfDate->year + 1980, 586 pfDate->month, 587 pfDate->day); 567 588 } 568 589 … … 590 611 *@@changed V0.8.5 (99-03-15) [umoeller]: fixed 12-hour crash 591 612 *@@changed V0.9.0 (99-11-07) [umoeller]: now calling nlsDateTime 613 *@@changed V1.0.1 (2003-01-17) [umoeller]: prototype changed for optimization, this was not exported 592 614 */ 593 615 594 616 VOID nlsFileTime(PSZ pszBuf, // out: string returned 595 FTIME *pfTime, // in: time information 596 ULONG ulTimeFormat, // in: 24-hour time format (0 or 1) 597 CHAR cTimeSep) // in: time separator (e.g. ':') 598 { 599 DATETIME dt; 600 dt.hours = pfTime->hours; 601 dt.minutes = pfTime->minutes; 602 dt.seconds = pfTime->twosecs * 2; 603 604 nlsDateTime(NULL, // no date 605 pszBuf, 606 &dt, 607 0, 0, // no date 608 ulTimeFormat, 609 cTimeSep); 617 const FTIME *pfTime, // in: time information 618 const COUNTRYSETTINGS2 *pcs) 619 { 620 nlsTime(pcs, 621 pszBuf, 622 pfTime->hours, 623 pfTime->minutes, 624 pfTime->twosecs * 2); 625 } 626 627 /* 628 *@@ nlsDate: 629 * 630 *@@added V1.0.1 (2003-01-17) [umoeller] 631 */ 632 633 VOID nlsDate(const COUNTRYSETTINGS2 *pcs2, 634 PSZ pszDate, // out: date string returned 635 USHORT year, 636 BYTE month, 637 BYTE day) 638 { 639 switch (pcs2->cs.ulDateFormat) 640 { 641 case 0: // mm.dd.yyyy (English) 642 sprintf(pszDate, "%02d%c%02d%c%04d", 643 month, 644 pcs2->cs.cDateSep, 645 day, 646 pcs2->cs.cDateSep, 647 year); 648 break; 649 650 case 1: // dd.mm.yyyy (e.g. German) 651 sprintf(pszDate, "%02d%c%02d%c%04d", 652 day, 653 pcs2->cs.cDateSep, 654 month, 655 pcs2->cs.cDateSep, 656 year); 657 break; 658 659 case 2: // yyyy.mm.dd (Japanese) 660 sprintf(pszDate, "%04d%c%02d%c%02d", 661 year, 662 pcs2->cs.cDateSep, 663 month, 664 pcs2->cs.cDateSep, 665 day); 666 break; 667 668 default: // yyyy.dd.mm 669 sprintf(pszDate, "%04d%c%02d%c%02d", 670 year, 671 pcs2->cs.cDateSep, 672 day, 673 pcs2->cs.cDateSep, 674 month); 675 break; 676 } 677 } 678 679 /* 680 *@@ nlsTime: 681 * 682 *@@added V1.0.1 (2003-01-17) [umoeller] 683 */ 684 685 VOID nlsTime(const COUNTRYSETTINGS2 *pcs2, 686 PSZ pszTime, // out: time string returned 687 BYTE hours, 688 BYTE minutes, 689 BYTE seconds) 690 { 691 if (!pcs2->cs.ulTimeFormat) 692 { 693 // for 12-hour clock, we need additional INI data 694 if (hours >= 12) // V0.9.16 (2001-12-05) [pr] if (hours > 12) 695 { 696 // yeah cool Paul, now we get 00:20 PM if it's 20 past noon 697 // V0.9.18 (2002-02-13) [umoeller] 698 ULONG ulHours; 699 if (!(ulHours = hours % 12)) 700 ulHours = 12; 701 702 // >= 12h: PM. 703 sprintf(pszTime, "%02d%c%02d%c%02d %s", 704 // leave 12 == 12 (not 0) 705 ulHours, 706 pcs2->cs.cTimeSep, 707 minutes, 708 pcs2->cs.cTimeSep, 709 seconds, 710 pcs2->ampm.sz2359); 711 } 712 else 713 { 714 // < 12h: AM 715 sprintf(pszTime, "%02d%c%02d%c%02d %s", 716 hours, 717 pcs2->cs.cTimeSep, 718 minutes, 719 pcs2->cs.cTimeSep, 720 seconds, 721 pcs2->ampm.sz1159); 722 } 723 } 724 else 725 // 24-hour clock 726 sprintf(pszTime, "%02d%c%02d%c%02d", 727 hours, 728 pcs2->cs.cTimeSep, 729 minutes, 730 pcs2->cs.cTimeSep, 731 seconds); 610 732 } 611 733 … … 616 738 * for more detailed parameter descriptions. 617 739 * 740 * Use of this function is deprecated. Use the 741 * speedier nlsDateTime2 instead. 742 * 618 743 *@@added V0.9.0 (99-11-07) [umoeller] 619 744 *@@changed V0.9.16 (2001-12-05) [pr]: fixed AM/PM hour bug 620 745 *@@changed V0.9.18 (2002-02-13) [umoeller]: fixed AM/PM hour bug fix 746 *@@changed V1.0.1 (2003-01-17) [umoeller]: extracted nlsDate, nlsTime 621 747 */ 622 748 623 749 VOID nlsDateTime(PSZ pszDate, // out: date string returned (can be NULL) 624 750 PSZ pszTime, // out: time string returned (can be NULL) 625 DATETIME *pDateTime, // in: date/time information751 const DATETIME *pDateTime, // in: date/time information 626 752 ULONG ulDateFormat, // in: date format (0-3); see nlsFileDate 627 753 CHAR cDateSep, // in: date separator (e.g. '.') … … 629 755 CHAR cTimeSep) // in: time separator (e.g. ':') 630 756 { 757 COUNTRYSETTINGS2 cs2; 631 758 if (pszDate) 632 759 { 633 switch (ulDateFormat) 634 { 635 case 0: // mm.dd.yyyy (English) 636 sprintf(pszDate, "%02d%c%02d%c%04d", 637 pDateTime->month, 638 cDateSep, 639 pDateTime->day, 640 cDateSep, 641 pDateTime->year); 642 break; 643 644 case 1: // dd.mm.yyyy (e.g. German) 645 sprintf(pszDate, "%02d%c%02d%c%04d", 646 pDateTime->day, 647 cDateSep, 648 pDateTime->month, 649 cDateSep, 650 pDateTime->year); 651 break; 652 653 case 2: // yyyy.mm.dd (Japanese) 654 sprintf(pszDate, "%04d%c%02d%c%02d", 655 pDateTime->year, 656 cDateSep, 657 pDateTime->month, 658 cDateSep, 659 pDateTime->day); 660 break; 661 662 default: // yyyy.dd.mm 663 sprintf(pszDate, "%04d%c%02d%c%02d", 664 pDateTime->year, 665 cDateSep, 666 pDateTime->day, 667 cDateSep, 668 pDateTime->month); 669 break; 670 } 760 cs2.cs.ulDateFormat = ulDateFormat; 761 cs2.cs.cDateSep = cDateSep; 762 nlsDate(&cs2, 763 pszDate, // out: date string returned 764 pDateTime->year, 765 pDateTime->month, 766 pDateTime->day); 671 767 } 672 768 673 769 if (pszTime) 674 770 { 675 if (ulTimeFormat == 0) 676 { 677 // for 12-hour clock, we need additional INI data 678 CHAR szAMPM[10] = "err"; 679 680 if (pDateTime->hours >= 12) // V0.9.16 (2001-12-05) [pr] if (pDateTime->hours > 12) 681 { 682 // yeah cool Paul, now we get 00:20 PM if it's 20 past noon 683 // V0.9.18 (2002-02-13) [umoeller] 684 ULONG ulHours; 685 if (!(ulHours = pDateTime->hours % 12)) 686 ulHours = 12; 687 688 // >= 12h: PM. 689 PrfQueryProfileString(HINI_USER, 690 "PM_National", 691 "s2359", // key 692 "PM", // default 693 szAMPM, sizeof(szAMPM)-1); 694 sprintf(pszTime, "%02d%c%02d%c%02d %s", 695 // leave 12 == 12 (not 0) 696 ulHours, 697 cTimeSep, 698 pDateTime->minutes, 699 cTimeSep, 700 pDateTime->seconds, 701 szAMPM); 702 } 703 else 704 { 705 // < 12h: AM 706 PrfQueryProfileString(HINI_USER, 707 "PM_National", 708 "s1159", // key 709 "AM", // default 710 szAMPM, sizeof(szAMPM)-1); 711 sprintf(pszTime, "%02d%c%02d%c%02d %s", 712 pDateTime->hours, 713 cTimeSep, 714 pDateTime->minutes, 715 cTimeSep, 716 pDateTime->seconds, 717 szAMPM); 718 } 719 } 720 else 721 // 24-hour clock 722 sprintf(pszTime, "%02d%c%02d%c%02d", 723 pDateTime->hours, 724 cTimeSep, 725 pDateTime->minutes, 726 cTimeSep, 727 pDateTime->seconds); 771 cs2.cs.ulTimeFormat = ulTimeFormat; 772 cs2.cs.cTimeSep = cTimeSep; 773 nlsGetAMPM(&cs2.ampm); 774 nlsTime(&cs2, 775 pszTime, 776 pDateTime->hours, 777 pDateTime->minutes, 778 pDateTime->seconds); 728 779 } 729 780 } … … 752 803 } 753 804 805 /* 806 *@@ nlsDateTime2: 807 * speedier version of nlsDateTime that caches 808 * all information and needs _no_ Prf* call 809 * any more. 810 * 811 *@@added V1.0.1 (2003-01-17) [umoeller] 812 */ 813 814 VOID nlsDateTime2(PSZ pszDate, 815 PSZ pszTime, 816 const DATETIME *pDateTime, 817 const COUNTRYSETTINGS2 *pcs2) 818 { 819 if (pszDate) 820 nlsDate(pcs2, 821 pszDate, 822 pDateTime->year, 823 pDateTime->month, 824 pDateTime->day); 825 826 if (pszTime) 827 nlsTime(pcs2, 828 pszTime, 829 pDateTime->hours, 830 pDateTime->minutes, 831 pDateTime->seconds); 832 } 833 754 834 CHAR G_szUpperMap[257]; 755 835 BOOL G_fUpperMapInited = FALSE;
Note:
See TracChangeset
for help on using the changeset viewer.