summaryrefslogtreecommitdiff
path: root/lisp/hexl.el
diff options
context:
space:
mode:
authorGerd Moellmann <gerd@gnu.org>2000-04-19 19:10:46 +0000
committerGerd Moellmann <gerd@gnu.org>2000-04-19 19:10:46 +0000
commit9f6bff44411c75a856b3c426090c8fa7821bfcbf (patch)
tree43b7af76f6e8d1a859d8e10fc75eb40fc893ca81 /lisp/hexl.el
parent92d2bc08426a92074d0fa9bbcb12b423cee9ba7a (diff)
(hexl-insert-hex-string): New command.
Diffstat (limited to 'lisp/hexl.el')
-rw-r--r--lisp/hexl.el25
1 files changed, 25 insertions, 0 deletions
diff --git a/lisp/hexl.el b/lisp/hexl.el
index e5d55b43ca4..aca123a0ade 100644
--- a/lisp/hexl.el
+++ b/lisp/hexl.el
@@ -717,6 +717,31 @@ This discards the buffer's undo information."
(error "Hex number out of range")
(hexl-insert-char num arg))))
+(defun hexl-insert-hex-string (str arg)
+ "Insert hexadecimal string STR at point ARG times.
+Embedded whitespace, dashes, and periods in the string are ignored."
+ (interactive "sHex string: \np")
+ (setq str (replace-regexp-in-string "[- \t.]" "" str))
+ (let ((chars '()))
+ (let ((len (length str))
+ (idx 0))
+ (if (eq (logand len 1) 1)
+ (let ((num (hexl-hex-string-to-integer (substring str 0 1))))
+ (setq chars (cons num chars))
+ (setq idx 1)))
+ (while (< idx len)
+ (let* ((nidx (+ idx 2))
+ (num (hexl-hex-string-to-integer (substring str idx nidx))))
+ (setq chars (cons num chars))
+ (setq idx nidx))))
+ (setq chars (nreverse chars))
+ (while (> arg 0)
+ (let ((chars chars))
+ (while chars
+ (hexl-insert-char (car chars) 1)
+ (setq chars (cdr chars))))
+ (setq arg (- arg 1)))))
+
(defun hexl-insert-decimal-char (arg)
"Insert a ASCII char ARG times at point for a given decimal number."
(interactive "p")