-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbprint.c
More file actions
52 lines (41 loc) · 1.01 KB
/
bprint.c
File metadata and controls
52 lines (41 loc) · 1.01 KB
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
/*
* Copyright (c) Regents of The University of Michigan
* See COPYING.
*/
#define BPXLEN 50
#define BPALEN 18
#include <ctype.h>
#include <stdio.h>
#include <strings.h>
#include "bprint.h"
char hexdig[] = "0123456789ABCDEF";
void
bprint(char *data, int len) {
char xout[ BPXLEN ], aout[ BPALEN ];
int i = 0;
bzero(xout, BPXLEN);
bzero(aout, BPALEN);
for (i = 0; len; len--) {
if (i == 16) {
printf("%-48s\t%-16s\n", xout, aout);
bzero(xout, BPXLEN);
bzero(aout, BPALEN);
i = 0;
}
if (isascii((unsigned char)*data) && isprint((unsigned char)*data)) {
aout[ i ] = *data;
} else {
aout[ i ] = '.';
}
xout[ (i * 3) ] = hexdig[ (*data & 0xf0) >> 4 ];
xout[ (i * 3) + 1 ] = hexdig[ *data & 0x0f ];
xout[ (i * 3) + 2 ] = ' ';
data++;
i++;
}
if (i) {
printf("%-48s\t%-16s\n", xout, aout);
}
printf("%s\n", "(end)");
return;
}