24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# NOTE: This package absolutely requires the Eagle core script library
# package, even when it is being used by native Tcl. If needed,
# prior to loading this package, the native Tcl auto-path should
# be modified to include the "Eagle1.0" directory (i.e. the one
# containing the Eagle core script library file "init.eagle").
#
package require Eagle.Library
proc stringIsList { value } {
if {[isEagle]} then {
return [string is list $value]
} else {
global tcl_version
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# NOTE: This package absolutely requires the Eagle core script library
# package, even when it is being used by native Tcl. If needed,
# prior to loading this package, the native Tcl auto-path should
# be modified to include the "Eagle1.0" directory (i.e. the one
# containing the Eagle core script library file "init.eagle").
#
package require Eagle.Library
proc formatPackageName { package version } {
return [string trim [appendArgs \
$package " " [getLookupVersion $version]]]
}
proc formatResult { code result } {
switch -exact -- $code {
0 {set codeString ok}
1 {set codeString error}
2 {set codeString return}
3 {set codeString break}
4 {set codeString continue}
default {set codeString [appendArgs unknown( $code )]}
}
if {[string length $result] > 0} then {
return [appendArgs $codeString ": " [list $result]]
} else {
return $codeString
}
}
proc pkgLog { string } {
catch {
tclLog [appendArgs [pid] " : " [clock seconds] " : pkgr : " $string]
}
}
proc stringIsList { value } {
if {[isEagle]} then {
return [string is list $value]
} else {
global tcl_version
|
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
|
#
# NOTE: This version argument to this procedure must be optional, because
# Eagle does not add a version argument when one is not supplied to
# the [package require] sub-command itself.
#
proc packageUnknownHandler { package {version ""} } {
#
# NOTE: First, run our [package unknown] handler.
#
if {[catch {main $package $version handler} error(1)] == 0} then {
#
# NOTE: The repository [package unknown] handler succeeded, run the
# saved [package unknown] handler.
#
if {[catch {
runSavedPackageUnknownHandler $package $version
} error(2)] == 0} then {
#
# NOTE: Success? Just return and let Tcl (or Eagle) handle the
# rest. This is the "happy" path.
#
return
} else {
#
# NOTE: Failure? Attempt to log the error message.
#
catch {
tclLog [appendArgs \
"pkgr: saved handler failed for \"" [appendArgs [string \
trim $package " " $version]] "\", error: " $error(2)]
}
}
} else {
#
# NOTE: Failure? Attempt to log the error message and then maybe
# try the original [package unknown] handler.
#
catch {
tclLog [appendArgs \
"pkgr: new handler failed for \"" [appendArgs [string \
trim $package " " $version]] "\", error: " $error(1)]
}
#
# NOTE: The repository [package unknown] handler failed, run the
# saved [package unknown] handler anyway. There is almost
# no chance of this actually providing the package.
#
if {[catch {
runSavedPackageUnknownHandler $package $version
} error(2)] == 0} then {
#
# NOTE: Success? Just return and let Tcl (or Eagle) handle the
# rest.
#
return
} else {
#
# NOTE: Failure? Attempt to log the error message.
#
catch {
tclLog [appendArgs \
"pkgr: old handler failed for \"" [appendArgs [string \
trim $package " " $version]] "\", error: " $error(2)]
}
}
}
#
# NOTE: Both [package unknown] handlers failed in some way, return the
# error messages (i.e. both of them).
#
error [array get error]
}
proc setupPackageUnknownVars {} {
#
# NOTE: Prevent progress messages from being displayed while downloading
# from the repository, etc? By default, this is enabled.
#
|
>
>
|
|
<
<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
|
|
|
|
|
<
|
<
|
|
|
>
>
>
>
|
|
|
>
|
|
>
>
|
|
<
<
>
|
|
>
>
|
<
<
<
|
<
<
>
|
<
<
<
|
|
<
|
>
|
|
<
|
<
|
<
|
|
>
|
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
|
#
# NOTE: This version argument to this procedure must be optional, because
# Eagle does not add a version argument when one is not supplied to
# the [package require] sub-command itself.
#
proc packageUnknownHandler { package {version ""} } {
variable verboseUnknownResult
#
# NOTE: First, run our [package unknown] handler.
#
set code(1) [catch {main $package $version handler} result(1)]
if {$verboseUnknownResult} then {
pkgLog [appendArgs \
"repository handler results for package \"" [formatPackageName \
$package $version] "\", are " [formatResult $code(1) $result(1)]]
}
#
# NOTE: Next, run the saved [package unknown] handler.
#
set code(2) [catch {
runSavedPackageUnknownHandler $package $version
} result(2)]
if {$verboseUnknownResult} then {
pkgLog [appendArgs \
"saved handler results for package \"" [formatPackageName \
$package $version] "\" are " [formatResult $code(2) $result(2)]]
}
#
# NOTE: Finally, check if the package was actually loaded and then
# optionally record/log the results.
#
set command [list package present $package]
if {[string length $version] > 0} then {lappend command $version}
if {[catch $command] == 0} then {
if {$verboseUnknownResult} then {
pkgLog [appendArgs \
"package \"" [formatPackageName $package $version] \
"\" was loaded."]
}
} else {
if {$verboseUnknownResult} then {
pkgLog [appendArgs \
"package \"" [formatPackageName $package $version] \
"\" was not loaded."]
}
set result(3) [appendArgs \
"can't find package " [formatPackageName $package $version]]
error [array get result]
}
}
proc setupPackageUnknownVars {} {
#
# NOTE: Prevent progress messages from being displayed while downloading
# from the repository, etc? By default, this is enabled.
#
|
888
889
890
891
892
893
894
895
896
897
898
899
900
901
|
# when called from the [package unknown] handler?
#
variable strictUnknownLanguage; # DEFAULT: true
if {![info exists strictUnknownLanguage]} then {
set strictUnknownLanguage true
}
}
proc main { package version caller } {
#
# NOTE: Issue the lookup request to the remote package repository.
#
set data [getLookupData \
|
>
>
>
>
>
>
>
>
>
>
|
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
|
# when called from the [package unknown] handler?
#
variable strictUnknownLanguage; # DEFAULT: true
if {![info exists strictUnknownLanguage]} then {
set strictUnknownLanguage true
}
#
# NOTE: Emit diagnostic messages when a [package unknown] handler
# is called?
#
variable verboseUnknownResult; # DEFAULT: false
if {![info exists verboseUnknownResult]} then {
set verboseUnknownResult false
}
}
proc main { package version caller } {
#
# NOTE: Issue the lookup request to the remote package repository.
#
set data [getLookupData \
|