Function: tramp-expand-script
tramp-expand-script is a byte-compiled function defined in
tramp-sh.el.gz.
Signature
(tramp-expand-script VEC SCRIPT)
Documentation
Expand SCRIPT with remote files or commands.
"%a", "%h", "%o" and "%p" format specifiers are replaced
by the respective awk, hexdump, od and perl commands.
"%n" is replaced by "2>/dev/null", and "%t" is replaced by
a temporary file name.
If VEC is nil, the respective local commands are used.
If there is a format specifier which cannot be expanded, this
function returns nil.
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
;;; Internal Functions:
(defun tramp-expand-script (vec script)
"Expand SCRIPT with remote files or commands.
\"%a\", \"%h\", \"%o\" and \"%p\" format specifiers are replaced
by the respective `awk', `hexdump', `od' and `perl' commands.
\"%n\" is replaced by \"2>/dev/null\", and \"%t\" is replaced by
a temporary file name.
If VEC is nil, the respective local commands are used.
If there is a format specifier which cannot be expanded, this
function returns nil."
(if (not (string-match-p "\\(^\\|[^%]\\)%[ahnopt]" script))
script
(catch 'wont-work
(let ((awk (when (string-match-p "\\(^\\|[^%]\\)%a" script)
(or
(if vec (tramp-get-remote-awk vec) (executable-find "awk"))
(throw 'wont-work nil))))
(hdmp (when (string-match-p "\\(^\\|[^%]\\)%h" script)
(or
(if vec (tramp-get-remote-hexdump vec)
(executable-find "hexdump"))
(throw 'wont-work nil))))
(dev (when (string-match-p "\\(^\\|[^%]\\)%n" script)
(or
(if vec (concat "2>" (tramp-get-remote-null-device vec))
(if (eq system-type 'windows-nt) ""
(concat "2>" null-device)))
(throw 'wont-work nil))))
(od (when (string-match-p "\\(^\\|[^%]\\)%o" script)
(or (if vec (tramp-get-remote-od vec) (executable-find "od"))
(throw 'wont-work nil))))
(perl (when (string-match-p "\\(^\\|[^%]\\)%p" script)
(or
(if vec
(tramp-get-remote-perl vec) (executable-find "perl"))
(throw 'wont-work nil))))
(tmp (when (string-match-p "\\(^\\|[^%]\\)%t" script)
(or
(if vec
(tramp-file-local-name (tramp-make-tramp-temp-name vec))
(tramp-compat-make-temp-name))
(throw 'wont-work nil)))))
(format-spec
script
(format-spec-make ?a awk ?h hdmp ?n dev ?o od ?p perl ?t tmp))))))