File: import_switch_args.tcl

package info (click to toggle)
libapache2-mod-rivet 2.3.3-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 5,156 kB
  • ctags: 1,093
  • sloc: xml: 7,696; tcl: 6,939; ansic: 5,682; sh: 4,862; makefile: 199; sql: 91; lisp: 78
file content (42 lines) | stat: -rw-r--r-- 1,145 bytes parent folder | download | duplicates (2)
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
###
##
## import_switch_args
##
## Detect switches from a string (e.g. "-all -regexp -- foo bar args")
## and extract them into an array.
##
## $Id: import_switch_args.tcl 1300262 2012-03-13 18:05:13Z mxmanghi $
##
###

namespace eval ::rivet {

    proc import_switch_args {arrayName argsList {switchList ""}} {
        upvar 1 $arrayName array
        set index 0
        set array(args) ""
        set array(switches) ""
        if {[llength $switchList] > 0} {
            set proofSwitches 1
        } else {
            set proofSwitches 0
        }

        foreach arg $argsList {
            if {[string index $arg 0] != "-"} {
                set array(args) [lrange $argsList $index end]
                break
            } elseif {$arg == "--"} {
                set array(args) [lrange $argsList [expr {$index + 1}] end]
                break
            }

            set switch [string range $arg 1 end]
            if {!$proofSwitches || [lsearch -exact $switchList $switch] >= 0} {
                set array($switch) $index
                lappend array(switches) $switch
            }
            incr index
        }
    }
}