home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / functions / hexlify-buffer.el < prev    next >
Encoding:
Text File  |  1992-11-25  |  1.8 KB  |  46 lines

  1. ; Newsgroups: gnu.emacs.sources
  2. ; Path: hal.com!decwrl!pacbell.com!iggy.GW.Vitalink.COM!cs.widener.edu!hela.iti.org!nigel.msen.com!emory!swrinde!cs.utexas.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!cis.ohio-state.edu!fly.cnuce.cnr.it!pot
  3. ; From: pot@fly.cnuce.cnr.it (Francesco Potorti`)
  4. ; Subject: hexlify-buffer
  5. ; Organization: Source only  Discussion and requests in gnu.emacs.help.
  6. ; Date: Thu, 12 Nov 1992 12:10:00 GMT
  7. ; This version of hexlify-buffer is twice as fast as the original one in
  8. ; hexl.el.
  9. ; Anyone out there is able to make it better (it is always too S L  O   W)?
  10.  
  11. ;; LCD Archive Entry:
  12. ;; hexlify-buffer|Francesco Potorti`|pot@cnuce.cnr.it|
  13. ;; Convert a binary buffer to hexl format.|
  14. ;; 92-11-12||~/functions/hexlify-buffer.el.Z|
  15.  
  16. (defun hexlify-buffer ()
  17.   "Convert a binary buffer to hexl format"
  18.   (interactive)
  19.   (goto-char (point-min))
  20.   (let (len
  21.     (address 0)
  22.     (chars "")
  23.     (print-chars
  24.      (vconcat
  25.       (mapcar 'char-to-string (make-string 32 ?.))
  26.       (mapcar 'char-to-string " !\"#$%&'()*+,-./0123456789:;<=>?@")
  27.       (mapcar 'char-to-string "ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`")
  28.       (mapcar 'char-to-string "abcdefghijklmnopqrstuvwxyz{|}~")
  29.       (mapcar 'char-to-string (make-string 128 ?.)))))
  30.     (while (not (eobp))
  31.       (setq len (min 16 (- (point-max) (point))))
  32.       (setq chars (buffer-substring (point) (+ (point) len)))
  33.       (delete-char len)
  34.       (insert (format "%08x:    " address)
  35.           (mapconcat '(lambda (arg) (format "%02x" arg)) chars ""))
  36.       (if (eobp) (insert-char ?  (* 2 (- 16 len))))
  37.       (backward-char 28)
  38.       (looking-at
  39.       "\\(....\\)\\(....\\)\\(....\\)\\(....\\)\\(....\\)\\(....\\)\\(....\\)")
  40.       (replace-match " \\1 \\2 \\3  \\4 \\5 \\6 \\7     '")
  41.       (insert (mapconcat '(lambda (c) (aref print-chars c)) chars "") "'\n")
  42.       (setq address (+ address 16)))))
  43.