-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
80 lines (70 loc) · 1.95 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <cstdio>
#include <cctype>
#include <cstdint>
#include <cstddef>
#include "at.h"
static inline void log_hex(std::string_view str)
{
if (str.empty())
return;
auto bin_to_char = [](uint8_t bin) {
return "0123456789abcdef"[bin & 0xf];
};
auto p = str.data();
for (size_t i = 0; i < str.size(); ++i) {
if (!(i & 15)) {
putchar('|');
putchar(' ');
}
putchar(bin_to_char(p[i] >> 4));
putchar(bin_to_char(p[i] & 0xF));
putchar(' ');
if ((i & 7) == 7)
putchar(' ');
if ((i & 15) == 15) {
putchar('|');
for (int j = 15; j >= 0; --j) {
char c = p[i - j];
putchar(isprint(c) ? c : '.');
}
putchar('|');
putchar('\n');
}
}
int rem = str.size() - ((str.size() >> 4) << 4);
if (rem) {
for (int j = (16 - rem) * 3 + ((~rem & 8) >> 3); j >= 0; --j)
putchar(' ');
putchar('|');
for (int j = rem; j; --j) {
char c = p[str.size() - j];
putchar(isprint(c) ? c : '.');
}
for (int j = 0; j < 16 - rem; ++j)
putchar('.');
putchar('|');
putchar('\n');
}
}
int main()
{
at::parser<64> parser;
parser.setup("+TEST");
parser.clear();
while (1) {
parser.process(getc(stdin));
if (parser.full() ||
parser.acquired() ||
parser.response() != at::invalid)
{
puts("+-------RAW_-------+");
log_hex(parser.get_raw());
puts("+-------LINE-------+");
log_hex(parser.get_line());
puts("+-------ARGS-------+");
log_hex(parser.get_args());
puts("+------------------+");
parser.clear();
}
}
}