]>
Commit | Line | Data |
---|---|---|
bc3eb2a9 JF |
1 | /* Minimal - the simplest thing that could possibly work |
2 | * Copyright (C) 2007 Jay Freeman (saurik) | |
3 | */ | |
4 | ||
5 | /* | |
6 | * Redistribution and use in source and binary | |
7 | * forms, with or without modification, are permitted | |
8 | * provided that the following conditions are met: | |
9 | * | |
10 | * 1. Redistributions of source code must retain the | |
11 | * above copyright notice, this list of conditions | |
12 | * and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the | |
14 | * above copyright notice, this list of conditions | |
15 | * and the following disclaimer in the documentation | |
16 | * and/or other materials provided with the | |
17 | * distribution. | |
18 | * 3. The name of the author may not be used to endorse | |
19 | * or promote products derived from this software | |
20 | * without specific prior written permission. | |
21 | * | |
22 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' | |
23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, | |
24 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE | |
27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
29 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | |
33 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | |
34 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
35 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
36 | */ | |
37 | ||
38 | #ifndef MINIMAL_HEXDUMP_H | |
39 | #define MINIMAL_HEXDUMP_H | |
40 | ||
41 | #include "minimal/stdlib.h" | |
42 | ||
ebea5a12 | 43 | _disused static char hexchar(uint8_t value) { |
bc3eb2a9 JF |
44 | return value < 0x20 || value >= 0x80 ? '.' : value; |
45 | } | |
46 | ||
a75f8a40 JF |
47 | #define HexWidth_ 12 |
48 | ||
ebea5a12 | 49 | _disused static void hexdump(const char *mark, const uint8_t *data, size_t size) { |
e7b5b86e | 50 | size_t i = 0, j; |
bc3eb2a9 JF |
51 | |
52 | while (i != size) { | |
a75f8a40 | 53 | if (i % HexWidth_ == 0) |
e7b5b86e | 54 | printf("[%s] 0x%.3zx:", mark, i); |
bc3eb2a9 JF |
55 | |
56 | printf(" %.2x", data[i]); | |
57 | ||
a75f8a40 | 58 | if (++i % HexWidth_ == 0) { |
bc3eb2a9 | 59 | printf(" "); |
a75f8a40 | 60 | for (j = i - HexWidth_; j != i; ++j) |
bc3eb2a9 JF |
61 | printf("%c", hexchar(data[j])); |
62 | printf("\n"); | |
63 | } | |
64 | } | |
65 | ||
a75f8a40 JF |
66 | if (i % HexWidth_ != 0) { |
67 | for (j = i % HexWidth_; j != HexWidth_; ++j) | |
bc3eb2a9 JF |
68 | printf(" "); |
69 | printf(" "); | |
a75f8a40 | 70 | for (j = i / HexWidth_ * HexWidth_; j != i; ++j) |
bc3eb2a9 JF |
71 | printf("%c", hexchar(data[j])); |
72 | printf("\n"); | |
73 | } | |
74 | } | |
75 | ||
76 | #endif/*MINIMAL_HEXDUMP_H*/ |