aboutsummaryrefslogtreecommitdiff
path: root/glob.tcl
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2012-09-22 08:48:06 +1000
committerSteve Bennett <steveb@workware.net.au>2012-09-22 09:45:36 +1000
commitaff4583eebb137bfbe740cce1f91d158344d9cb7 (patch)
treeda66d68fbe0347b20dcfeba88a9898a619efb0f2 /glob.tcl
parent7bf43eb589f738b7bdb3b4837bc0dde304046a2d (diff)
downloadjimtcl-aff4583eebb137bfbe740cce1f91d158344d9cb7.zip
jimtcl-aff4583eebb137bfbe740cce1f91d158344d9cb7.tar.gz
jimtcl-aff4583eebb137bfbe740cce1f91d158344d9cb7.tar.bz2
Allow abbreviations to glob options
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'glob.tcl')
-rw-r--r--glob.tcl40
1 files changed, 26 insertions, 14 deletions
diff --git a/glob.tcl b/glob.tcl
index 5e6abb5..6b1ad39 100644
--- a/glob.tcl
+++ b/glob.tcl
@@ -116,36 +116,48 @@ proc glob {args} {
set nocomplain 0
set base ""
- while {[llength $args] > 0} {
- switch -glob -- [set switch [lindex $args 0]] {
- -directory {
- if {[llength $args] < 2} {
- return -code error "missing argument to \"$switch\""
- }
- set base [lindex $args 1]
- set args [lrange $args 1 end]
+ set n 0
+ foreach arg $args {
+ if {[info exists param]} {
+ set $param $arg
+ unset param
+ incr n
+ continue
+ }
+ switch -glob -- $arg {
+ -d* {
+ set switch $arg
+ set param base
}
- -nocomplain {
+ -n* {
set nocomplain 1
}
- -tails {
+ -t* {
# Ignored for Tcl compatibility
}
-* {
return -code error "bad option \"$switch\": must be -directory, -nocomplain, -tails, or --"
}
- -- -
+ -- {
+ incr n
+ break
+ }
* {
break
}
}
- set args [lrange $args 1 end]
+ incr n
+ }
+ if {[info exists param]} {
+ return -code error "missing argument to \"$switch\""
}
- if {[llength $args] < 1} {
+ if {[llength $args] <= $n} {
return -code error "wrong # args: should be \"glob ?options? pattern ?pattern ...?\""
}
+ set args [lrange $args $n end]
+
set result {}
foreach pattern $args {
set pattern [string map {
@@ -163,7 +175,7 @@ proc glob {args} {
lappend result $name
}
}
- }
+ }
if {!$nocomplain && [llength $result] == 0} {
return -code error "no files matched glob patterns"