Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | [msgcat] revert changes of "msgcat" to previous state before clock-speedup, move this functionality to "clock.tcl"; additionally avoids the usage of catch (uses pair "dict exists/dict get" instead of). |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | sebres-8-6-clock-speedup-cr1 |
Files: | files | file ages | folders |
SHA1: |
67aa09246b81305332ceeeb393f62d30 |
User & Date: | sebres 2017-05-30 16:41:48 |
Context
2017-05-31
| ||
08:31 | Remove "timerate" functionality: this definitely needs a TIP. Also undo changes in library/reg/pkgIn... check-in: 848d01b6ef user: jan.nijtmans tags: sebres-8-6-clock-speedup-cr1 | |
2017-05-30
| ||
16:41 | [msgcat] revert changes of "msgcat" to previous state before clock-speedup, move this functionality ... check-in: 67aa09246b user: sebres tags: sebres-8-6-clock-speedup-cr1 | |
08:46 | small code review: resolves several warning on some compilers check-in: 7303c86999 user: sebres tags: sebres-8-6-clock-speedup-cr1 | |
Changes
Changes to library/clock.tcl.
︙ | ︙ | |||
502 503 504 505 506 507 508 509 510 511 512 513 | # and whose values are lists of quads # comprising start time, UTC offset, # Daylight Saving Time indicator, and # time zone abbreviation. variable FormatProc; # Array mapping format group # and locale to the name of a procedure # that renders the given format } ::tcl::clock::Initialize #---------------------------------------------------------------------- | > > > > > > > > > > > > > > > > > | > | | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > > > > > > > > > > | 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 | # and whose values are lists of quads # comprising start time, UTC offset, # Daylight Saving Time indicator, and # time zone abbreviation. variable FormatProc; # Array mapping format group # and locale to the name of a procedure # that renders the given format variable mcLocales [dict create]; # Dictionary with loaded locales variable mcMergedCat [dict create]; # Dictionary with merged locale catalogs } ::tcl::clock::Initialize #---------------------------------------------------------------------- # mcget -- # # Return the merged translation catalog for the ::tcl::clock namespace # Searching of catalog is similar to "msgcat::mc". # # Contrary to "msgcat::mc" may additionally load a package catalog # on demand. # # Arguments: # loc The locale used for translation. # # Results: # Returns the dictionary object as whole catalog of the package/locale. # proc mcget {loc} { variable mcMergedCat switch -- $loc system { set loc [GetSystemLocale] } current { set loc [mclocale] } if {$loc eq {C}} { set loclist [msgcat::PackagePreferences ::tcl::clock] set loc [lindex $loclist 0] } else { set loc [string tolower $loc] } # try to retrieve now if already available: if {[dict exists $mcMergedCat $loc]} { set mrgcat [dict get $mcMergedCat $loc] return [dict smartref $mrgcat] } # get locales list for given locale (de_de -> {de_de de {}}) variable mcLocales if {[dict exists $mcLocales $loc]} { set loclist [dict get $mcLocales $loc] } else { # save current locale: set prevloc [mclocale] # lazy load catalog on demand (set it will load the catalog) mcpackagelocale set $loc set loclist [msgcat::GetPreferences $loc] dict set $mcLocales $loc $loclist # restore: if {$prevloc ne $loc} { mcpackagelocale set $prevloc } } # get whole catalog: mcMerge $loclist } # mcMerge -- # # Merge message catalog dictionaries to one dictionary. # # Arguments: # locales List of locales to merge. # # Results: # Returns the (weak pointer) to merged dictionary of message catalog. # proc mcMerge {locales} { variable mcMergedCat if {[dict exists $mcMergedCat [set loc [lindex $locales 0]]]} { set mrgcat [dict get $mcMergedCat $loc] return [dict smartref $mrgcat] } # package msgcat currently does not provide possibility to get whole catalog: upvar ::msgcat::Msgs Msgs set ns ::tcl::clock # Merge sequential locales (in reverse order, e. g. {} -> en -> en_en): if {[llength $locales] > 1} { set mrgcat [mcMerge [lrange $locales 1 end]] if {[dict exists $Msgs $ns $loc]} { set mrgcat [dict merge $mrgcat [dict get $Msgs $ns $loc]] } } else { if {[dict exists $Msgs $ns $loc]} { set mrgcat [dict get $Msgs $ns $loc] } else { set mrgcat [dict create] } } dict set mcMergedCat $loc $mrgcat # return smart reference (shared dict as object with exact one ref-counter) return [dict smartref $mrgcat] } #---------------------------------------------------------------------- # # GetSystemLocale -- # # Determines the system locale, which corresponds to "system" |
︙ | ︙ | |||
2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 | # #---------------------------------------------------------------------- proc ::tcl::clock::ClearCaches {} { variable FormatProc variable LocaleFormats variable LocaleNumeralCache variable TimeZoneBad # tell backend - should invalidate: configure -clear # clear msgcat cache: | > | | 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 | # #---------------------------------------------------------------------- proc ::tcl::clock::ClearCaches {} { variable FormatProc variable LocaleFormats variable LocaleNumeralCache variable mcMergedCat variable TimeZoneBad # tell backend - should invalidate: configure -clear # clear msgcat cache: set mcMergedCat [dict create] foreach p [info procs [namespace current]::scanproc'*] { rename $p {} } foreach p [info procs [namespace current]::formatproc'*] { rename $p {} } |
︙ | ︙ |
Changes to library/msgcat/msgcat.tcl.
︙ | ︙ | |||
221 222 223 224 225 226 227 | switch -exact -- [Invoke unknowncmd $args $ns result 1] { 0 { return [uplevel 1 [linsert $args 0 [namespace origin mcunknown]]] } 1 { return [DefaultUnknown {*}$args] } default { return $result } } } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | switch -exact -- [Invoke unknowncmd $args $ns result 1] { 0 { return [uplevel 1 [linsert $args 0 [namespace origin mcunknown]]] } 1 { return [DefaultUnknown {*}$args] } default { return $result } } } # msgcat::mcexists -- # # Check if a catalog item is set or if mc would invoke mcunknown. # # Arguments: # -exactnamespace Only check the exact namespace and no # parent namespaces |
︙ | ︙ | |||
470 471 472 473 474 475 476 | # The following subcommands are available: # set # Set a package locale. # This may load message catalog files and may clear message catalog # items, if the former locale was the default locale. # Returns the normalized set locale. # The default locale is taken, if locale is not given. | < < < < | 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | # The following subcommands are available: # set # Set a package locale. # This may load message catalog files and may clear message catalog # items, if the former locale was the default locale. # Returns the normalized set locale. # The default locale is taken, if locale is not given. # get # Get the locale valid for this package. # isset # Returns true, if a package locale is set # unset # Unset the package locale and activate the default locale. # This loads message catalog file which where missing in the package |
︙ | ︙ | |||
501 502 503 504 505 506 507 | # Arguments: # subcommand see list above # locale package locale (only set subcommand) # # Results: # Empty string, if not stated differently for the subcommand | | < | < | | < < | < < | 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | # Arguments: # subcommand see list above # locale package locale (only set subcommand) # # Results: # Empty string, if not stated differently for the subcommand proc msgcat::mcpackagelocale {subcommand {locale ""}} { # todo: implement using an ensemble variable Loclist variable LoadedLocales variable Msgs variable PackageConfig # Check option # check if required item is exactly provided if {[llength [info level 0]] == 2} { # locale not given unset locale } else { # locale given if {$subcommand in {"get" "isset" "unset" "preferences" "loaded" "clear"} } { return -code error "wrong # args: should be\ \"[lrange [info level 0] 0 1]\"" } set locale [string tolower $locale] } set ns [uplevel 1 {::namespace current}] switch -exact -- $subcommand { get { return [lindex [PackagePreferences $ns] 0] } preferences { return [PackagePreferences $ns] } loaded { return [PackageLocales $ns] } present { return [expr {$locale in [PackageLocales $ns]} ]} isset { return [dict exists $PackageConfig loclist $ns] } set { # set a package locale or add a package locale # Copy the default locale if no package locale set so far if {![dict exists $PackageConfig loclist $ns]} { dict set PackageConfig loclist $ns $Loclist dict set PackageConfig loadedlocales $ns $LoadedLocales } # Check if changed set loclist [dict get $PackageConfig loclist $ns] if {! [info exists locale] || $locale eq [lindex $loclist 0] } { return [lindex $loclist 0] } # Change loclist set loclist [GetPreferences $locale] set locale [lindex $loclist 0] dict set PackageConfig loclist $ns $loclist # load eventual missing locales set loadedLocales [dict get $PackageConfig loadedlocales $ns] if {$locale in $loadedLocales} { return $locale } set loadLocales [ListComplement $loadedLocales $loclist] dict set PackageConfig loadedlocales $ns\ [concat $loadedLocales $loadLocales] Load $ns $loadLocales return $locale } |
︙ | ︙ | |||
586 587 588 589 590 591 592 | if { ![dict exists $PackageConfig loclist $ns] } { return } # unset package locale set loadLocales [ListComplement\ [dict get $PackageConfig loadedlocales $ns] $LoadedLocales] dict unset PackageConfig loadedlocales $ns dict unset PackageConfig loclist $ns | < | 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | if { ![dict exists $PackageConfig loclist $ns] } { return } # unset package locale set loadLocales [ListComplement\ [dict get $PackageConfig loadedlocales $ns] $LoadedLocales] dict unset PackageConfig loadedlocales $ns dict unset PackageConfig loclist $ns # unset keys not in global loaded locales if {[dict exists $Msgs $ns]} { foreach locale [dict keys [dict get $Msgs $ns]] { if {$locale ni $LoadedLocales} { dict unset Msgs $ns $locale } |
︙ | ︙ | |||
913 914 915 916 917 918 919 | } if {[info exists nestedFileLocale]} { set FileLocale $nestedFileLocale } return $x } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 843 844 845 846 847 848 849 850 851 852 853 854 855 856 | } if {[info exists nestedFileLocale]} { set FileLocale $nestedFileLocale } return $x } # msgcat::Invoke -- # # Invoke a set of registered callbacks. # The callback is only invoked, if its registered namespace exists. # # Arguments: # index Index into PackageConfig to get callback command |
︙ | ︙ | |||
1026 1027 1028 1029 1030 1031 1032 | # the source string is used. # # Results: # Returns the new locale. proc msgcat::mcset {locale src {dest ""}} { variable Msgs | < < | 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 | # the source string is used. # # Results: # Returns the new locale. proc msgcat::mcset {locale src {dest ""}} { variable Msgs if {[llength [info level 0]] == 3} { ;# dest not specified set dest $src } set ns [uplevel 1 [list ::namespace current]] set locale [string tolower $locale] dict set Msgs $ns $locale $src $dest return $dest } # msgcat::mcflset -- # # Set the translation for a given string in the current file locale. # |
︙ | ︙ | |||
1076 1077 1078 1079 1080 1081 1082 | # pairs One or more src/dest pairs (must be even length) # # Results: # Returns the number of pairs processed proc msgcat::mcmset {locale pairs} { variable Msgs | < < | 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 | # pairs One or more src/dest pairs (must be even length) # # Results: # Returns the number of pairs processed proc msgcat::mcmset {locale pairs} { variable Msgs set length [llength $pairs] if {$length % 2} { return -code error "bad translation list:\ should be \"[lindex [info level 0] 0] locale {src dest ...}\"" } set locale [string tolower $locale] set ns [uplevel 1 [list ::namespace current]] foreach {src dest} $pairs { dict set Msgs $ns $locale $src $dest } return [expr {$length / 2}] } # msgcat::mcflmset -- # # Set the translation for multiple strings in the mc file locale. |
︙ | ︙ |
Changes to tests/msgcat.test.
︙ | ︙ | |||
807 808 809 810 811 812 813 | } -result {1 0} # Tests msgcat-12.*: [mcpackagelocale] test msgcat-12.1 {mcpackagelocale no subcommand} -body { mcpackagelocale } -returnCodes 1\ | | | 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 | } -result {1 0} # Tests msgcat-12.*: [mcpackagelocale] test msgcat-12.1 {mcpackagelocale no subcommand} -body { mcpackagelocale } -returnCodes 1\ -result {wrong # args: should be "mcpackagelocale subcommand ?locale?"} test msgcat-12.2 {mclpackagelocale wrong subcommand} -body { mcpackagelocale junk } -returnCodes 1\ -result {unknown subcommand "junk": must be clear, get, isset, loaded, present, set, or unset} test msgcat-12.3 {mcpackagelocale set} -setup { |
︙ | ︙ |