4590323 [rkeene@sledge /home/rkeene/projects/rivet-cgi/rivet-tcl]$ cat -n import_switch_args.tcl
   1: ##
   2: ## Detect switches from a string (e.g. "-all -regexp -- foo bar args")
   3: ## and extract them into an array.
   4: ##
   5: proc import_switch_args {arrayName argsList {switchList ""}} {
   6:     upvar 1 $arrayName array
   7:     set index 0
   8:     set array(args) ""
   9:     set array(switches) ""
  10:     if {[llength $switchList] > 0} {
  11: 	set proofSwitches 1
  12:     } else {
  13: 	set proofSwitches 0
  14:     }
  15:     foreach arg $argsList {
  16: 	if {[string index $args 0] != "-"} {
  17:             set array(args) [lrange $argsList $index end]
  18:             break
  19:         } elseif {$arg == "--"} {
  20: 	    set array(args) [lrange $argsList [expr $index + 1] end]
  21: 	    break
  22: 	}
  23:         set switch [string range $arg 1 end]
  24: 	if {!$proofSwitches || [lsearch -exact $switchList $switch] >= 0} {
  25:             set array($switch) $index
  26: 	    lappend array(switches) $switch
  27: 	}
  28:         incr index
  29:     }
  30: }
4590324 [rkeene@sledge /home/rkeene/projects/rivet-cgi/rivet-tcl]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2002-03-14 21:57:59