add regexp matches, inline regsub/replace, asuniqfilename
This commit is contained in:
parent
3ef45af5e0
commit
7745c19cfa
|
@ -1,7 +1,7 @@
|
||||||
Package: sweeper
|
Package: sweeper
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Section: misc
|
Section: misc
|
||||||
Version: 2.1.1
|
Version: 2.1.2
|
||||||
Architecture: mipsel
|
Architecture: mipsel
|
||||||
Maintainer: af123@hummypkg.org.uk
|
Maintainer: af123@hummypkg.org.uk
|
||||||
Depends: webif(>=1.3.0-1)
|
Depends: webif(>=1.3.0-1)
|
||||||
|
|
|
@ -33,6 +33,9 @@ proc ::sweeper::intcomp {ref val} {
|
||||||
|
|
||||||
# Substring/pattern check
|
# Substring/pattern check
|
||||||
proc ::sweeper::strcontains {ref val} {
|
proc ::sweeper::strcontains {ref val} {
|
||||||
|
if {[string index $val 0] eq "~"} {
|
||||||
|
return [regexp -nocase -- [string range $val 1 end] $ref]
|
||||||
|
}
|
||||||
if {[string first "*" $val] > -1} {
|
if {[string first "*" $val] > -1} {
|
||||||
return [string match -nocase $val $ref]
|
return [string match -nocase $val $ref]
|
||||||
}
|
}
|
||||||
|
@ -42,18 +45,19 @@ proc ::sweeper::strcontains {ref val} {
|
||||||
}
|
}
|
||||||
|
|
||||||
set ::sweeper::expand_fns {
|
set ::sweeper::expand_fns {
|
||||||
replace {2}
|
replace {3 {inline fallback}}
|
||||||
regsub {2}
|
regsub {3 {inline fallback}}
|
||||||
asfilename {1 {inline}}
|
asfilename {1 {inline}}
|
||||||
|
asuniqfilename {1 {inline}}
|
||||||
format {2 {inline}}
|
format {2 {inline}}
|
||||||
var {1 {inline}}
|
var {1 {inline}}
|
||||||
}
|
}
|
||||||
|
|
||||||
proc ::sweeper::expand_replace {ts &ret search replace} {
|
proc ::sweeper::expand_fb_replace {ts &ret search replace} {
|
||||||
set ret [string map [list $search $replace] $ret]
|
set ret [string map [list $search $replace] $ret]
|
||||||
}
|
}
|
||||||
|
|
||||||
proc ::sweeper::expand_regsub {ts &ret search replace} {
|
proc ::sweeper::expand_fb_regsub {ts &ret search replace} {
|
||||||
if {[catch {
|
if {[catch {
|
||||||
regsub -all -- $search $ret $replace ret
|
regsub -all -- $search $ret $replace ret
|
||||||
} msg]} {
|
} msg]} {
|
||||||
|
@ -61,10 +65,40 @@ proc ::sweeper::expand_regsub {ts &ret search replace} {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc ::sweeper::expand_replace {ts &ret arg search replace} {
|
||||||
|
set arg [string map [list $search $replace] $arg]
|
||||||
|
return $arg
|
||||||
|
}
|
||||||
|
|
||||||
|
proc ::sweeper::expand_regsub {ts &ret arg search replace} {
|
||||||
|
if {[catch {
|
||||||
|
regsub -all -- $search $arg $replace arg
|
||||||
|
} msg]} {
|
||||||
|
log "Error. %regsub - $msg"
|
||||||
|
}
|
||||||
|
return $arg
|
||||||
|
}
|
||||||
|
|
||||||
proc ::sweeper::expand_asfilename {ts &ret arg} {
|
proc ::sweeper::expand_asfilename {ts &ret arg} {
|
||||||
return [system filename $arg]
|
return [system filename $arg]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc ::sweeper::expand_asuniqfilename {ts &ret arg} {
|
||||||
|
set arg [system filename $arg]
|
||||||
|
if {[string index $arg 0] ne "/"} {
|
||||||
|
set path "[$ts dir]/$arg"
|
||||||
|
} else {
|
||||||
|
set path $arg
|
||||||
|
}
|
||||||
|
if {[file isfile "$path.ts"]} {
|
||||||
|
set i 2
|
||||||
|
while {[file isfile "${path}_$i.ts"]} { incr i }
|
||||||
|
append arg "_$i"
|
||||||
|
}
|
||||||
|
|
||||||
|
return $arg
|
||||||
|
}
|
||||||
|
|
||||||
proc ::sweeper::expand_format {ts &ret format arg} {
|
proc ::sweeper::expand_format {ts &ret format arg} {
|
||||||
if {[catch {set r [format $format $arg]} msg]} {
|
if {[catch {set r [format $format $arg]} msg]} {
|
||||||
log "Error. %format - $msg"
|
log "Error. %format - $msg"
|
||||||
|
@ -109,11 +143,24 @@ proc ::sweeper::expand {ts str {orig ""}} {
|
||||||
# Extract the arguments
|
# Extract the arguments
|
||||||
set pos $chpos
|
set pos $chpos
|
||||||
set fnargs {}
|
set fnargs {}
|
||||||
|
set e -1
|
||||||
while {[llength $fnargs] < $numargs} {
|
while {[llength $fnargs] < $numargs} {
|
||||||
incr pos
|
incr pos
|
||||||
|
set le $e
|
||||||
set e [string first $ch $ret $pos]
|
set e [string first $ch $ret $pos]
|
||||||
if {$e == -1} {
|
if {$e == -1} {
|
||||||
log "Error. %$fn - [llength $fnargs]/$numargs parameters found."
|
# Insufficient arguments.
|
||||||
|
set argcnt [llength $fnargs]
|
||||||
|
if {"fallback" in $flags &&
|
||||||
|
"inline" in $flags &&
|
||||||
|
[expr $argcnt + 1] == $numargs} {
|
||||||
|
log "%$fn - falling back." 2
|
||||||
|
set fn "fb_$fn"
|
||||||
|
set flags {}
|
||||||
|
set e $le
|
||||||
|
} else {
|
||||||
|
log "Error. %$fn - $argcnt/$numargs parameters found."
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
lappend fnargs [::sweeper::expand $ts [
|
lappend fnargs [::sweeper::expand $ts [
|
||||||
|
@ -132,7 +179,9 @@ proc ::sweeper::expand {ts str {orig ""}} {
|
||||||
# the result.
|
# the result.
|
||||||
set fnret [
|
set fnret [
|
||||||
::sweeper::expand_$fn $ts ret {*}$fnargs]
|
::sweeper::expand_$fn $ts ret {*}$fnargs]
|
||||||
|
set oret $ret
|
||||||
set ret [string replace $ret $s $e $fnret]
|
set ret [string replace $ret $s $e $fnret]
|
||||||
|
log " $fn\($oret) -> \[$ret]" 2
|
||||||
} else {
|
} else {
|
||||||
# otherwise, queue the function up for later
|
# otherwise, queue the function up for later
|
||||||
# execution.
|
# execution.
|
||||||
|
|
|
@ -169,8 +169,8 @@ For pattern matching, the following special sequences may appear in the pattern:
|
||||||
<div class="hidden edit_textmatch_help blood"
|
<div class="hidden edit_textmatch_help blood"
|
||||||
id=edit_textmatch_help_textmatch>
|
id=edit_textmatch_help_textmatch>
|
||||||
<br>
|
<br>
|
||||||
You can enter either a substring which must be found somewhere or a pattern<br>
|
You can enter either a substring which must be found somewhere, a pattern<br>
|
||||||
which must be matched.
|
which must be matched or a regular expression prefixed with ~.
|
||||||
<br>
|
<br>
|
||||||
For pattern matching, the following special sequences may appear in the pattern:
|
For pattern matching, the following special sequences may appear in the pattern:
|
||||||
<div style="width: 600px;margin: 1em">
|
<div style="width: 600px;margin: 1em">
|
||||||
|
|
Loading…
Reference in New Issue