aboutsummaryrefslogtreecommitdiff
path: root/func.go
diff options
context:
space:
mode:
authorFumitoshi Ukai <fumitoshi.ukai@gmail.com>2015-06-10 14:56:49 +0900
committerFumitoshi Ukai <fumitoshi.ukai@gmail.com>2015-06-10 14:58:44 +0900
commit76b609ea4989d058a62bb6888a90430cc0bd9342 (patch)
tree1db6943f8ad0749ba9d0dfdc8ad26cb7f1b057c0 /func.go
parentb69bf8a7ac05ad382c588c0c40fe416c92e697be (diff)
downloadkati-76b609ea4989d058a62bb6888a90430cc0bd9342.tar.gz
android rot13
before: $ ./repo/android.sh kati -c -use_find_cache -kati_stats *kati*: eval time: "34.677942345s" *kati*: shell func time: "13.71144088s" 559 *kati*: dep build prepare time: "213.586963ms" *kati*: 52737 variables *kati*: 78461 explicit rules *kati*: 0 implicit rules *kati*: 1 suffix rules *kati*: dep build time: "2.016057014s" ./repo/android.sh kati -c -use_find_cache -kati_stats 36.32s user 22.01s system 157% cpu 37.023 total after: $ ./repo/android.sh kati -c -use_find_cache -kati_stats *kati*: eval time: "30.99209655s" *kati*: shell func time: "10.133065433s" 385 *kati*: dep build prepare time: "236.542165ms" *kati*: 52737 variables *kati*: 78461 explicit rules *kati*: 0 implicit rules *kati*: 1 suffix rules *kati*: dep build time: "1.880664823s" ./repo/android.sh kati -c -use_find_cache -kati_stats 36.65s user 18.09s system 164% cpu 33.218 total
Diffstat (limited to 'func.go')
-rw-r--r--func.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/func.go b/func.go
index 869aa39..a0d743b 100644
--- a/func.go
+++ b/func.go
@@ -764,6 +764,12 @@ func (f *funcShell) Compact() Value {
return f
}
// hack for android
+ if v, ok := matchAndroidRot13(expr); ok {
+ return &funcShellAndroidRot13{
+ funcShell: f,
+ v: v,
+ }
+ }
if dir, ok := matchAndroidFindFileInDir(expr); ok {
androidFindCache.init()
return &funcShellAndroidFindFileInDir{
@@ -790,6 +796,59 @@ func (f *funcShell) Compact() Value {
return f
}
+// pattern in repo/android/build/core/definisions.mk
+// rot13
+// echo $(1) | tr 'a-zA-Z' 'n-za-mN-ZA-M'
+func matchAndroidRot13(expr Expr) (Value, bool) {
+ // literal: "echo "
+ // paramref: 1
+ // literal: " | tr 'a-zA-Z' 'n-za-mN-ZA-M'"
+ if len(expr) != 3 {
+ return nil, false
+ }
+ if expr[0] != literal("echo ") {
+ return nil, false
+ }
+ if expr[1] != paramref(1) {
+ return nil, false
+ }
+ if expr[2] != literal(" | tr 'a-zA-Z' 'n-za-mN-ZA-M'") {
+ return nil, false
+ }
+ return expr[1], true
+}
+
+type funcShellAndroidRot13 struct {
+ *funcShell
+ v Value
+}
+
+func rot13(buf []byte) {
+ for i, b := range buf {
+ // tr 'a-zA-Z' 'n-za-mN-ZA-M'
+ if b >= 'a' && b <= 'z' {
+ b += 'n' - 'a'
+ if b > 'z' {
+ b -= 'z' - 'a' + 1
+ }
+ } else if b >= 'A' && b <= 'Z' {
+ b += 'N' - 'A'
+ if b > 'Z' {
+ b -= 'Z' - 'A' + 1
+ }
+ }
+ buf[i] = b
+ }
+}
+
+func (f *funcShellAndroidRot13) Eval(w io.Writer, ev *Evaluator) {
+ abuf := newBuf()
+ fargs := ev.args(abuf, f.v)
+ rot13(fargs[0])
+ w.Write(fargs[0])
+ freeBuf(abuf)
+}
+
// pattern in repo/android/build/core/definitions.mk
// find-subdir-assets
// if [ -d $1 ] ; then cd $1 ; find ./ -not -name '.*' -and -type f -and -not -type l ; fi