You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by da...@apache.org on 2002/03/14 22:57:59 UTC

cvs commit: tcl-rivet/rivet/rivet-tcl import_switch_args.tcl import_keyvalue_pairs.tcl

damonc      02/03/14 13:57:59

  Modified:    rivet/rivet-tcl import_keyvalue_pairs.tcl
  Added:       rivet/rivet-tcl import_switch_args.tcl
  Log:
  Added import_switch_args command.
  
  Cleaned up import_keyvalue_pairs a little.
  
  Revision  Changes    Path
  1.2       +7 -7      tcl-rivet/rivet/rivet-tcl/import_keyvalue_pairs.tcl
  
  Index: import_keyvalue_pairs.tcl
  ===================================================================
  RCS file: /home/cvs/tcl-rivet/rivet/rivet-tcl/import_keyvalue_pairs.tcl,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- import_keyvalue_pairs.tcl	14 Mar 2002 21:17:22 -0000	1.1
  +++ import_keyvalue_pairs.tcl	14 Mar 2002 21:57:59 -0000	1.2
  @@ -6,19 +6,17 @@
   	return
       }
   
  -    set endit 0
  +    set index 0
       set looking 0
       set data(args) ""
       foreach arg $argsList {
  -	if {$endit} {
  -	    lappend data(args) $arg
  -	} elseif {$looking} {
  +	if {$looking} {
   	    set data($varName) $arg
   	    set looking 0
   	} elseif {[string index $arg 0] == "-"} {
   	    if {$arg == "--"} {
  -		set endit 1
  -		continue
  +		set data(args) [lrange $argsList [expr $index + 1] end]
  +		break
   	    }
   	    if {$arg == "-args"} {
   		return -code error "-args is a reserved value."
  @@ -26,7 +24,9 @@
   	    set varName [string range $arg 1 end]
   	    set looking 1
   	} else {
  -	    lappend data(args) $arg
  +	    set data(args) [lrange $argsList $index end]
  +	    break
   	}
  +	incr index
       }
   }
  
  
  
  1.1                  tcl-rivet/rivet/rivet-tcl/import_switch_args.tcl
  
  Index: import_switch_args.tcl
  ===================================================================
  ##
  ## Detect switches from a string (e.g. "-all -regexp -- foo bar args")
  ## and extract them into an array.
  ##
  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 $args 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
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-dev-help@tcl.apache.org