forked from ikhorn/plget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.c
62 lines (47 loc) · 1.17 KB
/
debug.c
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
#include "debug.h"
#include <stdio.h>
#include <string.h>
void db_dump_buf(void *data, int size)
{
unsigned char *arr = data;
char ascii[17];
int i, j;
ascii[16] = '\0';
for (i = 0; i < size; ++i) {
printf("%02X ", arr[i]);
if (arr[i] >= ' ' && arr[i] <= '~')
ascii[i % 16] = arr[i];
else
ascii[i % 16] = '.';
if ((i + 1) % 8 == 0 || i + 1 == size) {
printf(" ");
if ((i + 1) % 16 == 0) {
printf("| %s \n", ascii);
} else if (i + 1 == size) {
ascii[(i + 1) % 16] = '\0';
if ((i + 1) % 16 <= 8)
printf(" ");
for (j = (i + 1) % 16; j < 16; ++j)
printf(" ");
printf("| %s \n", ascii);
}
}
}
}
#define PROGRESS_WIDTH 72
void pr_progress_bar(char label[], int step, int total)
{
int width, pos, _pct, pct, pct_frag, i;
width = PROGRESS_WIDTH - strlen(label); /* minus label len */
pos = (step * width) / total ;
_pct = (step * 10000) / total;
pct = _pct / 100;
pct_frag = _pct - pct * 100;
printf("%s[", label);
/* fill progress bar with = */
for (i = 0; i < pos; i++)
printf( "%c", '=' );
/* fill progress bar with spaces */
printf("%*c", width - pos + 1, ']');
printf(" %3d.%02d%%\r", pct, pct_frag);
}