Restored file collection feature from 2.0 branch

r2718 | ffr | 2008-10-01 14:10:50 +1000 (Wed, 01 Oct 2008) | 2 lines
This commit is contained in:
Ferdi Franceschini
2008-10-01 14:10:50 +10:00
committed by Douglas Clowes
parent 82bebc6a5f
commit f0973c6196
3 changed files with 215 additions and 39 deletions

View File

@@ -1,7 +1,7 @@
# Some useful functions for SICS configuration.
# $Revision: 1.17 $
# $Date: 2008-09-24 22:47:12 $
# $Revision: 1.18 $
# $Date: 2008-10-01 04:10:50 $
# Author: Ferdi Franceschini (ffr@ansto.gov.au)
# Last revision by $Author: ffr $
@@ -582,6 +582,66 @@ proc ::utility::callstack {} {
}
}
##
# @brief Raises an error if any options in arglist are not in the list of valid_options
# or if an option is missing a value
#
# @param arglist, is the list of name value pairs passed to you procedure
# @param valid_options, is a list of valid options eg [list "-opt1" "-opt2"]
proc ::utility::check_valid_options {arglist valid_options} {
array set param ""
if [ catch {
foreach {opt val} $arglist {
if { [string index $val 0] == "-" || $val == "" } {
error "ERROR: argument for $opt is missing"
}
if [info exists param($opt)] {
error "ERROR: duplicate option $opt"
}
set opt_valid "false"
foreach valid_opt $valid_options {
if {$opt == $valid_opt} {
set opt_valid "true"
set param($opt) $val
break
}
}
if {$opt_valid == "false"} {
error "ERROR: $opt is an invalid option. It should be one of $valid_options"
}
}
} message ] {
if {$::errorCode=="NONE"} {return $message}
return -code error $message
}
}
##
# @brief Raises an error if any of the required_options are not in the argument list arglist
proc ::utility::check_required_options {arglist required_options} {
if [ catch {
if {$arglist == ""} {
error "ERROR: You must provide the following options: [join $required_options {, }]"
}
foreach req_opt $required_options {
set option_missing "true"
foreach {opt val} $arglist {
if {$req_opt == $opt} {
set option_missing "false"
break
}
}
if {$option_missing} {
error "ERROR: Required option $req_opt is missing"
}
}
} message ] {
if {$::errorCode=="NONE"} {return $message}
return -code error $message
}
}
##
# @brief Splits "args" list into a head and tail, useful for scripts
# where the first argument is a subcommand followed by an argument list.