2
* Copyright (c) 2012-2018 Rob Clark <robdclark@gmail.com>
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
#include "util/u_math.h"
33
/* old-style program binary XOR'd ascii w/ 0xff */
38
static inline const char *
41
const char *TAB = "\t\t\t\t\t\t\t\t\0";
42
return &TAB[strlen(TAB) - lvl];
46
dump_hex(const void *buf, int sz)
48
uint8_t *ptr = (uint8_t *)buf;
49
uint8_t *end = ptr + sz;
55
printf((i % 8) ? " " : "\t");
60
d |= (uint32_t)*(ptr++) << 24;
77
dump_float(const void *buf, int sz)
79
uint8_t *ptr = (uint8_t *)buf;
80
uint8_t *end = ptr + sz - 3;
86
printf((i % 8) ? " " : "\t");
91
d |= (uint32_t)*(ptr++) << 24;
93
printf("%8f", uif(d));
107
#define is_ok_ascii(c) (isascii(c) && ((c == '\t') || !iscntrl(c)))
110
clean_ascii(char *buf, int sz)
112
uint8_t *ptr = (uint8_t *)buf;
113
uint8_t *end = ptr + sz;
115
*(ptr++) ^= ASCII_XOR;
120
dump_ascii(const void *buf, int sz)
122
uint8_t *ptr = (uint8_t *)buf;
123
uint8_t *end = ptr + sz;
126
uint8_t c = *(ptr++) ^ ASCII_XOR;
129
} else if (c == '\0') {
130
printf("\n\t-----------------------------------\n\t");
131
} else if (is_ok_ascii(c)) {
141
dump_hex_ascii(const void *buf, int sz, int level)
143
uint8_t *ptr = (uint8_t *)buf;
144
uint8_t *end = ptr + sz;
145
uint8_t *ascii = ptr;
148
printf("%s-----------------------------------------------\n", tab(level));
149
printf("%s%d (0x%x) bytes\n", tab(level), sz, sz);
157
printf("%s%06x: ", tab(level), (uint32_t)(ptr - (uint8_t *)buf));
163
d |= (uint32_t)*(ptr++) << 24;
170
for (j = 0; j < 16; j++) {
171
uint8_t c = *(ascii++);
173
printf("%c", (isascii(c) && !iscntrl(c)) ? c : '.');
182
for (int j = 4 - (i % 4); j > 0; j--) {
186
while (ascii < end) {
187
uint8_t c = *(ascii++);
189
printf("%c", (isascii(c) && !iscntrl(c)) ? c : '.');
195
#endif /* __UTIL_H__ */