Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F8030847
D1234.id3173.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D1234.id3173.diff
View Options
diff --git a/Core.tcl b/Core.tcl
--- a/Core.tcl
+++ b/Core.tcl
@@ -55,6 +55,44 @@
}
#
+# List procs
+#
+
+# Gets the maximal value of a numeric list
+proc lmax {items} {
+ getultimatecomparedfromlist $items >
+}
+
+# Gets the minimal value of a numeric list
+proc lmin {items} {
+ getultimatecomparedfromlist $items <
+}
+
+# Gets the ultimately compared item from a list
+proc getultimatecomparedfromlist {items op} {
+ set hasValue 0
+ set max {}
+
+ foreach item $items {
+ if {![string is double $item]} {
+ continue
+ }
+
+ if {!$hasValue} {
+ set hasValue 1
+ set max $item
+ continue
+ }
+
+ if {[expr $item $op $max]} {
+ set max $item
+ }
+ }
+
+ return $max
+}
+
+#
# Trivial procs
#
@@ -72,6 +110,14 @@
}
}
+# Returns the value as is if numeric, or "0" if not
+proc zeroornumber {value} {
+ if {$value == "" || ![string is double $value]} {
+ return 0
+ }
+ return $value
+}
+
#Returns "s" if $count implies a plural
#TODO: keep this method for French (ie NOT adjusting values for English)
# and grab the plural proc from wiki.tcl.tk for English.
@@ -162,6 +208,17 @@
format "%0${digits}d" $number
}
+# Maps from a list of words the length of those words
+# e.g. strlenmap "a aaa aa" will return {1 3 2}
+proc strlenmap {words} {
+ lmap key $words { string length $key }
+}
+
+# Search the max string lenghth from a list of strings
+proc strlenmax {words} {
+ zeroornumber [lmax [strlenmap $words]]
+}
+
#
# SQL
#
diff --git a/Tech.tcl b/Tech.tcl
--- a/Tech.tcl
+++ b/Tech.tcl
@@ -14,6 +14,8 @@
bind dcc T tcldoc dcc:tcldoc
+ bind dcc T env dcc:env
+
#
# Helpers methods
#
@@ -193,3 +195,17 @@
putdcc $idx [exec -- grep $arg doc/tcl-commands.doc]
return 1
}
+
+#
+# UNIX environment
+#
+
+proc dcc:env {handle idx arg} {
+ global env
+ set environment [array get env]
+ set keys [dict keys $environment]
+
+ foreach "key value" $environment {
+ putdcc $idx "[format %-[strlenmax $keys]s $key] $value"
+ }
+}
diff --git a/tests/Core.test b/tests/Core.test
--- a/tests/Core.test
+++ b/tests/Core.test
@@ -19,6 +19,68 @@
strlen ""
} -result 0
+test strlenmax {} -body {
+ strlenmax "a aa alpha beta gamma delta omega"
+} -result 5
+
+test strlenmax_empty_words {} -body {
+ strlenmax [list "" "" "" ""]
+} -result 0
+
+test strlenmax_empty_list_one_empty_word {} -body {
+ strlenmax {""}
+} -result 0
+
+test strlenmax_empty_list {} -body {
+ strlenmax {}
+} -result 0
+
+test strlenmap {} -body {
+ strlenmap "a aa aaa aa a"
+} -result "1 2 3 2 1"
+
+test lmax {} -body {
+ lmax "7 10 1 20 11 4 3"
+} -result 20
+
+test lmin {} -body {
+ lmin "7 10 1 20 11 4 3"
+} -result 1
+
+test lmax_from_an_empty_list {
+ When there is no numeric value, nothing should be returned
+} -body {
+ lmax ""
+} -result ""
+
+test lmax_from_an_words_list {
+ When there is no numeric value, nothing should be returned
+} -body {
+ lmax "alpha beta gamma"
+} -result ""
+
+test lmax_from_a_mixed_list {
+ Non numeric numbers should be ignored
+} -body {
+ lmax "7 10 1 20 notanumber 11 4 3"
+} -result 20
+
+test zeroornumber_from_integer {} -body {
+ zeroornumber 4
+} -result 4
+
+test zeroornumber_from_non_numeric_string {} -body {
+ zeroornumber "alpha"
+} -result 0
+
+test zeroornumber_from_zero {} -body {
+ zeroornumber 0
+} -result 0
+
+test zeroornumber_from_empty_list {} -body {
+ zeroornumber ""
+} -result 0
+
###
### Cleanup
###
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, May 8, 00:16 (8 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2638889
Default Alt Text
D1234.id3173.diff (3 KB)
Attached To
Mode
D1234: Provide a .env command to dump environment
Attached
Detach File
Event Timeline
Log In to Comment