# proc-args.tcl # Based on .../ns/tcl/ex/rbp_demo.tcl by John Heidemann # # Michele C. Weigle, mweigle@cs.odu.edu # Old Dominion University, November 2006 #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # Command-Line Option Default Values #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: proc parse_default {raw_opt_info} { global opts while {$raw_opt_info != ""} { if {![regexp "^\[^\n\]*\n" $raw_opt_info line]} { break } regsub "^\[^\n\]*\n" $raw_opt_info {} raw_opt_info set line [string trim $line] if {[regexp "^\[ \t\]*\#" $line]} { continue } if {$line == ""} { continue } set result [regexp {^([^ ]+)[ ]+([^\n]+)$} $line dummy key value] if {$result == 1} { set opts($key) $value } else { puts "Error processing raw_opt_info: $line" exit } } } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # Process Command-Line Options #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: proc process_args {} { global argc argv opts # read in defaults default_options # process command line args for {set i 0} {$i < $argc} {incr i} { set key [lindex $argv $i] if {$key == "-?" || $key == "--help" || $key == "-help" \ || $key == "-h"} { usage } regsub {^-} $key {} key if {![info exists opts($key)]} { puts stderr "unknown option $key"; usage } incr i set opts($key) [lindex $argv $i] } } #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: # Dump Values of All Options #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: proc dump_opts {} { global opts exec mkdir -p $opts(datadir) exec touch $opts(datadir)/$opts(expFile) set result [array get opts] exec echo "$result" >> $opts(datadir)/$opts(expFile) set time [exec date "+%H:%M:%S (%m/%d/%y)"] exec echo -n "# START: $time " >> $opts(datadir)/$opts(expFile) }