forked from g4klx/MMDVMCal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cpp
66 lines (51 loc) · 1.51 KB
/
Utils.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright (C) 2009,2014-2016 Jonathan Naylor, G4KLX
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "Utils.h"
#include <cstdio>
#include <cassert>
void CUtils::dump(const std::string& title, const unsigned char* data, unsigned int length)
{
assert(data != NULL);
#if defined(_WIN32) || defined(_WIN64)
::fprintf(stdout, "%s\n", title.c_str());
#else
::fprintf(stdout, "%s\r\n", title.c_str());
#endif
unsigned int offset = 0U;
while (length > 0U) {
::fprintf(stdout, "%04X: ", offset);
unsigned int bytes = (length > 16U) ? 16U : length;
for (unsigned i = 0U; i < bytes; i++)
::fprintf(stdout, "%02X ", data[offset + i]);
for (unsigned int i = bytes; i < 16U; i++)
::fprintf(stdout, " ");
::fprintf(stdout, " *");
for (unsigned i = 0U; i < bytes; i++) {
unsigned char c = data[offset + i];
if (::isprint(c))
::fprintf(stdout, "%c", c);
else
::fprintf(stdout, ".");
}
#if defined(_WIN32) || defined(_WIN64)
::fprintf(stdout, "*\n");
#else
::fprintf(stdout, "*\r\n");
#endif
offset += 16U;
if (length >= 16U)
length -= 16U;
else
length = 0U;
}
}