File: utils.tcl

package info (click to toggle)
exmh 1%3A2.9.0-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 4,216 kB
  • sloc: tcl: 38,046; perl: 1,647; makefile: 130; sh: 101; exp: 75; csh: 9; sed: 2
file content (68 lines) | stat: -rw-r--r-- 1,501 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
66
67
68
# setmax - set the variable to the maximum of its current value
# or the value of the second argument
# return 1 if the variable's value was changed.
proc setmax {varName value} {
    upvar $varName var
    if {![info exists var] || ($value > $var)} {
	set var $value
	return 1
    }
    return 0
}
# setmin - set the variable to the minimum of its current value
# or the value of the second argument
# return 1 if the variable's value was changed.
proc setmin {varName value} {
    upvar $varName var
    if {![info exists var] || ($value < $var)} {
	set var $value
	return 1
    }
    return 0
}

# Delete a list item by value.  Returns 1 if the item was present, else 0
proc ldelete {varList value} {
    upvar $varList list
    if ![info exist list] {
	return 0
    }
    set ix [lsearch $list $value]
    if {$ix >= 0} {
	set list [lreplace $list $ix $ix]
	return 1
    } else {
	return 0
    }
}

# Match a value (v) against a list of patterns (l)
proc patlsearch {l v} {
    set i 0
    foreach e $l {
        if {[string match $e $v]} {
            return $i
        }
        incr i
    }
    return -1
}

# This doesn't seem to be used by anything...
#proc makedir { pathname } {
#    file mkdir $pathname
#}

proc Visibility_Wait {win} {
    catch {tkwait visibility $win}
}

proc File_Delete {args} {
    Exmh_Debug "file delete $args"
    foreach f $args {
        if [file isdirectory $f] {
	error "Should not delete directories this way"
        }
        file delete -force $f
    }
}