util.tcl (modules-5.1.1.tar.bz2) | : | util.tcl (modules-5.2.0.tar.bz2) | ||
---|---|---|---|---|
skipping to change at line 214 | skipping to change at line 214 | |||
foreach elt $args { | foreach elt $args { | |||
if {![info exists lst] || $elt ni $lst} { | if {![info exists lst] || $elt ni $lst} { | |||
lappend lst $elt | lappend lst $elt | |||
set ret 1 | set ret 1 | |||
} | } | |||
} | } | |||
return $ret | return $ret | |||
} | } | |||
proc replaceFromList {list1 item {item2 {}}} { | proc replaceFromList {list1 item {item2 {}}} { | |||
while {[set xi [lsearch -exact $list1 $item]] >= 0} { | while {[set xi [lsearch -exact $list1 $item]] >= 0} { | |||
set list1 [if {[string length $item2] == 0} {lreplace $list1 $xi $xi}\ | ##nagelfar ignore #2 Badly formed if statement | |||
set list1 [if {[string length $item2] == 0} {lreplace $list1 $xi $xi}\ | ||||
{lreplace $list1 $xi $xi $item2}] | {lreplace $list1 $xi $xi $item2}] | |||
} | } | |||
return $list1 | return $list1 | |||
} | } | |||
# test if 2 lists have at least one element in common | # test if 2 lists have at least one element in common | |||
proc isIntBetweenList {list1 list2} { | proc isIntBetweenList {list1 list2} { | |||
foreach elt $list1 { | foreach elt $list1 { | |||
if {$elt in $list2} { | if {$elt in $list2} { | |||
return 1 | return 1 | |||
} | } | |||
} | } | |||
return 0 | return 0 | |||
skipping to change at line 263 | skipping to change at line 264 | |||
foreach elt $list2 { | foreach elt $list2 { | |||
if {$elt ni $list1} { | if {$elt ni $list1} { | |||
lappend res2 $elt | lappend res2 $elt | |||
} | } | |||
} | } | |||
return [list $res1 $res2] | return [list $res1 $res2] | |||
} | } | |||
# return elements from arr1 not in arr2, elements from arr1 in arr2 but with a | # return elements from arr1 not in arr2, elements from arr1 in arr2 but with a | |||
# different value and elements from arr2 not in arr1 | # different value and elements from arr2 not in arr1. | |||
proc getDiffBetweenArray {arrname1 arrname2} { | # if notset_equals_empty is enabled, not-set element in array is equivalent to | |||
# element set to an empty value. | ||||
# if unordered_lists_compared is enabled, value of array element is considered | ||||
# a list and difference between list entries is made (order insensitive) | ||||
proc getDiffBetweenArray {arrname1 arrname2 {notset_equals_empty 0}\ | ||||
{unordered_lists_compared 0}} { | ||||
upvar $arrname1 arr1 | upvar $arrname1 arr1 | |||
upvar $arrname2 arr2 | upvar $arrname2 arr2 | |||
set notin2 [list] | set notin2 [list] | |||
set diff [list] | set diff [list] | |||
set notin1 [list] | set notin1 [list] | |||
foreach name [array names arr1] { | foreach name [array names arr1] { | |||
# element in arr1 not in arr2 | # element in arr1 not in arr2 | |||
if {![info exists arr2($name)]} { | if {![info exists arr2($name)]} { | |||
lappend notin2 $name | if {!$notset_equals_empty} { | |||
lappend notin2 $name | ||||
# if we consider a not-set entry equal to an empty value, there is a | ||||
# difference only if entry in the other array is not empty | ||||
} elseif {$arr1($name) ne {}} { | ||||
lappend diff $name | ||||
} | ||||
# element present in both arrays but with a different value | # element present in both arrays but with a different value | |||
} elseif {$arr1($name) ne $arr2($name)} { | } elseif {!$unordered_lists_compared} { | |||
lappend diff $name | # but with a different value | |||
if {$arr1($name) ne $arr2($name)} { | ||||
lappend diff $name | ||||
} | ||||
} else { | ||||
# with a different value, not considering order | ||||
lassign [getDiffBetweenList $arr1($name) $arr2($name)] notin2 notin1 | ||||
if {([llength $notin2] + [llength $notin1]) > 0} { | ||||
lappend diff $name | ||||
} | ||||
} | } | |||
} | } | |||
foreach name [array names arr2] { | foreach name [array names arr2] { | |||
# element in arr2 not in arr1 | # element in arr2 not in arr1 | |||
if {![info exists arr1($name)]} { | if {![info exists arr1($name)]} { | |||
lappend notin1 $name | if {!$notset_equals_empty} { | |||
lappend notin1 $name | ||||
} elseif {$arr2($name) ne {}} { | ||||
lappend diff $name | ||||
} | ||||
} | } | |||
} | } | |||
return [list $notin2 $diff $notin1] | return [list $notin2 $diff $notin1] | |||
} | } | |||
proc getCallingProcName {} { | ||||
if {[info level] > 2} { | ||||
set caller [lindex [info level -2] 0] | ||||
} else { | ||||
set caller {} | ||||
} | ||||
return $caller | ||||
} | ||||
# ;;; Local Variables: *** | # ;;; Local Variables: *** | |||
# ;;; mode:tcl *** | # ;;; mode:tcl *** | |||
# ;;; End: *** | # ;;; End: *** | |||
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent: | # vim:set tabstop=3 shiftwidth=3 expandtab autoindent: | |||
End of changes. 8 change blocks. | ||||
10 lines changed or deleted | 44 lines changed or added |