aboutsummaryrefslogtreecommitdiff
path: root/rex
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-09-15 12:12:23 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2016-09-15 12:12:23 +0300
commitd78ceac8d8e0a8fcb3e5de13bc57a7194dea1352 (patch)
tree4e5e4fe1b0398b21d3e712a5f54ca0d98361a872 /rex
parent573f246363fde78d31ce58a50f50ac324a764ac4 (diff)
downloadrex-d78ceac8d8e0a8fcb3e5de13bc57a7194dea1352.tar.gz
rex-d78ceac8d8e0a8fcb3e5de13bc57a7194dea1352.tar.bz2
Expand {N} within string arguments.
Diffstat (limited to 'rex')
-rwxr-xr-xrex85
1 files changed, 56 insertions, 29 deletions
diff --git a/rex b/rex
index 7e44457..b0eb7dd 100755
--- a/rex
+++ b/rex
@@ -2025,11 +2025,35 @@ proc getiterpreter {name} {
return $retval
}
+proc regsub-eval {args} {
+ set optlist {}
+ while {[llength $args] > 0} {
+ set opt [lshift args]
+ switch -regexp -- $opt {
+ {^--$} {
+ set opt [lshift args]
+ break
+ }
+ {^-.+} { lappend optlist $opt }
+ default { break }
+
+ }
+ }
+ if {[llength $args] != 2} {
+ return -code error "bad # args"
+ }
+ set re $opt
+ set string [lshift args]
+ set cmd [lshift args]
+
+ subst [regsub {*}$optlist -- $re [regsub -all {[][$\\]} $string {\\&}] \
+ \[[regsub -all {&} $cmd {\\&}]\]]
+}
+
proc rex_command args {
global argv0
global argc
global argv
- global option_handler
global config
global env
@@ -2143,34 +2167,41 @@ proc rex_command args {
debug 2 "sudo=$config(sudo), argv=[join $config(argv)]"
# Expand command line arguments
- set newcom [list]
+ set newcom {}
foreach c $config(argv) {
- switch -regexp -matchvar match -- $c {
- "{([0-9]+)}" {
- if {[info exists config(data)]} {
- set i [expr [lindex $match 1] - 1]
- if {$i < [llength $config(data)]} {
- lappend newcom [file tail [lindex $config(data) $i]]
- } else {
- terror "{$i} out of range"
+ if {[string equal $c "{}"]} {
+ if {![info exists config(data)]} {
+ terror "{} used in the absence of -D"
+ exit 1
+ }
+ foreach d $config(data) {
+ lappend newcom [file tail $d]
+ }
+ } else {
+ lappend newcom \
+ [regsub-eval -all "{(\[0-9\]+)?}" $c {
+ global config
+
+ if {![info exists config(data)]} {
+ terror "{\1} used in the absence of -D"
exit 1
}
- } else {
- terror "{N} used in the absence of -D"
- }
- }
- "{}" {
- if {[info exists config(data)]} {
- foreach d $config(data) {
- lappend newcom [file tail $d]
+
+ if {[string equal {\1} {}]} {
+ set arg {}
+ foreach d $config(data) {
+ lappend arg [file tail $d]
+ }
+ return [join $arg]
+ } else {
+ if {\1 > 0 && \1 <= [llength $config(data)]} {
+ return [lindex $config(data) [expr {\1 - 1}]]
+ } else {
+ terror "{\1} out of range"
+ exit 1
+ }
}
- } else {
- terror "{} used in the absence of -D"
- }
- }
- default {
- lappend newcom $c
- }
+ }]
}
}
set config(argv) $newcom
@@ -2211,7 +2242,6 @@ proc rex_list {} {
global argv0
global argc
global argv
- global option_handler
global config
global env
@@ -2275,7 +2305,6 @@ proc rex_copy_from {} {
global argc
global argv
global argv0
- global option_handler
global env
global config
@@ -2311,7 +2340,6 @@ proc rex_copy_to {} {
global argc
global argv
global argv0
- global option_handler
global config
::getopt::parse \
@@ -2395,7 +2423,6 @@ proc rex_login {} {
global argc
global argv
global argv0
- global option_handler
global config
::getopt::parse \

Return to:

Send suggestions and report system problems to the System administrator.