forked from wmcbrine/tivodecode-ng
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhexlib.cxx
51 lines (41 loc) · 952 Bytes
/
hexlib.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* useful hex manipulation routines */
/* Copyright C Qualcomm Inc 1997 */
#ifdef HAVE_CONFIG_H
# include "tdconfig.h"
#endif
#include <cctype>
#include <cstdio>
#include <iostream>
#include <string>
#include "hexlib.hxx"
#define COLS 16
int hexbulk(uint8_t *buf, int n)
{
int i = 0;
while (i < n)
{
int j = 0;
char ch;
char hexdigit[5];
std::string hexstr = "";
std::string strstr = "";
for (j = 0; (j < COLS) && (i < n); j++, i++)
{
ch = buf[i];
if (std::isspace(ch))
ch = ' ';
else if (!std::isprint(ch))
ch = '.';
std::sprintf(hexdigit, "%02x ", buf[i]);
hexstr += hexdigit;
strstr += ch;
}
while (j < COLS)
{
hexstr += " ";
j++;
}
std::cerr << hexstr << " " << strstr << "\n";
}
return 0;
}