From 46709093bea8d12c0ef4a8f6401be8f5856b466b Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Tue, 25 Aug 2015 16:05:21 +0200 Subject: [PATCH] * lisp/net/tramp-sh.el (tramp-awk-encode, tramp-awk-decode) (tramp-awk-coding-test): New defconsts. (tramp-remote-coding-commands): Use them. (tramp-find-inline-encoding): Check for Perl only if necessary. --- lisp/net/tramp-sh.el | 73 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 3239107e8b3..9bd22d27d5d 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -873,6 +873,72 @@ Escape sequence %s is replaced with name of Perl binary.") "Perl program to use for decoding a file. Escape sequence %s is replaced with name of Perl binary.") +(defconst tramp-awk-encode + "od -v -t x1 -A n | busybox awk '\\ +BEGIN { + b64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\" + b16 = \"0123456789abcdef\" +} +{ + for (c=1; c<=length($0); c++) { + d=index(b16, substr($0,c,1)) + if (d--) { + for (b=1; b<=4; b++) { + o=o*2+int(d/8); d=(d*2)%%16 + if (++obc==6) { + printf substr(b64,o+1,1) + if (++rc>75) { printf \"\\n\"; rc=0 } + obc=0; o=0 + } + } + } + } +} +END { + if (obc) { + tail=(obc==2) ? \"==\\n\" : \"=\\n\" + while (obc++<6) { o=o*2 } + printf \"%%c\", substr(b64,o+1,1) + } else { + tail=\"\\n\" + } + printf tail +}'" + "Awk program to use for encoding a file. +This string is passed to `format', so percent characters need to be doubled.") + +(defconst tramp-awk-decode + "busybox awk '\\ +BEGIN { + b64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\" +} +{ + for (i=1; i<=length($0); i++) { + c=index(b64, substr($0,i,1)) + if(c--) { + for(b=0; b<6; b++) { + o=o*2+int(c/32); c=(c*2)%%64 + if(++obc==8) { + if (o) { + printf \"%%c\", o + } else { + system(\"dd if=/dev/zero bs=1 count=1 2>/dev/null\") + } + obc=0; o=0 + } + } + } + } +}'" + "Awk program to use for decoding a file. +This string is passed to `format', so percent characters need to be doubled.") + +(defconst tramp-awk-coding-test + "test -c /dev/zero && \ +od -v -t x1 -A n