1
;;; Software License Agreement (BSD License)
3
;;; Copyright (c) 2008, Abdulaziz Ghuloum.
4
;;; All rights reserved.
6
;;; Redistribution and use of this software in source and binary forms,
7
;;; with or without modification, are permitted provided that the
8
;;; following conditions are met:
10
;;; - Redistributions of source code must retain the above copyright
11
;;; notice, this list of conditions and the following disclaimer.
13
;;; - Redistributions in binary form must reproduce the above copyright
14
;;; notice, this list of conditions and the following disclaimer in
15
;;; the documentation and/or other materials provided with the
18
;;; - The name of the author may not be used to endorse or promote
19
;;; products derived from this software without specific prior written
20
;;; permission from the author.
22
;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23
;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24
;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25
;;; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26
;;; COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27
;;; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28
;;; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29
;;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30
;;; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31
;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32
;;; ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33
;;; POSSIBILITY OF SUCH DAMAGE.
36
;;; hexdump utility for R6RS Scheme.
40
;;; (import (hexdump))
42
;;; (hexdump bytevector)
43
;;; dumps all bytes in bytevector
45
;;; (hexdump bytevector start-index)
46
;;; dumps bytevector from start-index to the end of the bytevector
48
;;; (hexdump bytevector start-index count)
49
;;; dumps count bytes bytevector starting from start-index
8
58
(define hex-string "0123456789ABCDEF")
10
62
(define (dump-hex-bytes i n)
12
64
(dump-hex-bytes (div i 16) (- n 1))
13
(display (string-ref hex-string (mod i 16)))))
65
(D (string-ref hex-string (mod i 16)))))
15
67
(define (dump-line-number i)
17
69
(dump-hex-bytes i 8)
20
72
(define (dump-data bv i j)
23
75
(dump-hex-bytes (bytevector-u8-ref bv i) 2)
24
76
(dump-data bv (+ i 1) j)))