aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2015-08-25 16:05:21 +0200
committerMichael Albinus2015-08-25 16:05:21 +0200
commit46709093bea8d12c0ef4a8f6401be8f5856b466b (patch)
tree0e0a0b1095a7d7f112915731b1ab7f7453f55481
parent6dfbe9ffc283c6a49df4a7cace272056ef487443 (diff)
downloademacs-46709093bea8d12c0ef4a8f6401be8f5856b466b.tar.gz
emacs-46709093bea8d12c0ef4a8f6401be8f5856b466b.zip
* 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.
-rw-r--r--lisp/net/tramp-sh.el73
1 files 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.")
873 "Perl program to use for decoding a file. 873 "Perl program to use for decoding a file.
874Escape sequence %s is replaced with name of Perl binary.") 874Escape sequence %s is replaced with name of Perl binary.")
875 875
876(defconst tramp-awk-encode
877 "od -v -t x1 -A n | busybox awk '\\
878BEGIN {
879 b64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\"
880 b16 = \"0123456789abcdef\"
881}
882{
883 for (c=1; c<=length($0); c++) {
884 d=index(b16, substr($0,c,1))
885 if (d--) {
886 for (b=1; b<=4; b++) {
887 o=o*2+int(d/8); d=(d*2)%%16
888 if (++obc==6) {
889 printf substr(b64,o+1,1)
890 if (++rc>75) { printf \"\\n\"; rc=0 }
891 obc=0; o=0
892 }
893 }
894 }
895 }
896}
897END {
898 if (obc) {
899 tail=(obc==2) ? \"==\\n\" : \"=\\n\"
900 while (obc++<6) { o=o*2 }
901 printf \"%%c\", substr(b64,o+1,1)
902 } else {
903 tail=\"\\n\"
904 }
905 printf tail
906}'"
907 "Awk program to use for encoding a file.
908This string is passed to `format', so percent characters need to be doubled.")
909
910(defconst tramp-awk-decode
911 "busybox awk '\\
912BEGIN {
913 b64 = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\"
914}
915{
916 for (i=1; i<=length($0); i++) {
917 c=index(b64, substr($0,i,1))
918 if(c--) {
919 for(b=0; b<6; b++) {
920 o=o*2+int(c/32); c=(c*2)%%64
921 if(++obc==8) {
922 if (o) {
923 printf \"%%c\", o
924 } else {
925 system(\"dd if=/dev/zero bs=1 count=1 2>/dev/null\")
926 }
927 obc=0; o=0
928 }
929 }
930 }
931 }
932}'"
933 "Awk program to use for decoding a file.
934This string is passed to `format', so percent characters need to be doubled.")
935
936(defconst tramp-awk-coding-test
937 "test -c /dev/zero && \
938od -v -t x1 -A n </dev/null && \
939busybox awk '{}' </dev/null"
940 "Test command for checking `tramp-awk-encode' and `tramp-awk-decode'.")
941
876(defconst tramp-stat-marker "/////" 942(defconst tramp-stat-marker "/////"
877 "Marker in stat commands for file attributes.") 943 "Marker in stat commands for file attributes.")
878 944
@@ -4245,7 +4311,7 @@ and end of region, and are expected to replace the region contents
4245with the encoded or decoded results, respectively.") 4311with the encoded or decoded results, respectively.")
4246 4312
4247(defconst tramp-remote-coding-commands 4313(defconst tramp-remote-coding-commands
4248 '((b64 "base64" "base64 -d -i") 4314 `((b64 "base64" "base64 -d -i")
4249 ;; "-i" is more robust with older base64 from GNU coreutils. 4315 ;; "-i" is more robust with older base64 from GNU coreutils.
4250 ;; However, I don't know whether all base64 versions do supports 4316 ;; However, I don't know whether all base64 versions do supports
4251 ;; this option. 4317 ;; this option.
@@ -4255,6 +4321,8 @@ with the encoded or decoded results, respectively.")
4255 (b64 "recode data..base64" "recode base64..data") 4321 (b64 "recode data..base64" "recode base64..data")
4256 (b64 tramp-perl-encode-with-module tramp-perl-decode-with-module) 4322 (b64 tramp-perl-encode-with-module tramp-perl-decode-with-module)
4257 (b64 tramp-perl-encode tramp-perl-decode) 4323 (b64 tramp-perl-encode tramp-perl-decode)
4324 ;; This is painful slow, so we put it on the end.
4325 (b64 tramp-awk-encode tramp-awk-decode ,tramp-awk-coding-test)
4258 (uu "uuencode xxx" "uudecode -o /dev/stdout" "test -c /dev/stdout") 4326 (uu "uuencode xxx" "uudecode -o /dev/stdout" "test -c /dev/stdout")
4259 (uu "uuencode xxx" "uudecode -o -") 4327 (uu "uuencode xxx" "uudecode -o -")
4260 (uu "uuencode xxx" "uudecode -p") 4328 (uu "uuencode xxx" "uudecode -p")
@@ -4333,7 +4401,8 @@ Goes through the list `tramp-local-coding-commands' and
4333 (unless (tramp-send-command-and-check vec rem-test t) 4401 (unless (tramp-send-command-and-check vec rem-test t)
4334 (throw 'wont-work-remote nil))) 4402 (throw 'wont-work-remote nil)))
4335 ;; Check if remote perl exists when necessary. 4403 ;; Check if remote perl exists when necessary.
4336 (when (and (not (stringp rem-enc)) 4404 (when (and (symbolp rem-enc)
4405 (string-match "perl" (symbol-name rem-enc))
4337 (not (tramp-get-remote-perl vec))) 4406 (not (tramp-get-remote-perl vec)))
4338 (throw 'wont-work-remote nil)) 4407 (throw 'wont-work-remote nil))
4339 ;; Check if remote encoding and decoding commands can be 4408 ;; Check if remote encoding and decoding commands can be