]> arthur.barton.de Git - netatalk.git/blob - libatalk/util/bprint.c
c192ba753003269a8aa00eb3706f0a5c42474ce8
[netatalk.git] / libatalk / util / bprint.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <ctype.h>
5
6 #include <atalk/util.h>
7
8 static const char       hexdig[] = "0123456789ABCDEF";
9
10 #define BPXLEN  50
11 #define BPALEN  18
12
13 void bprint( data, len )
14     char        *data;
15     int         len;
16 {
17     char        xout[ BPXLEN ], aout[ BPALEN ];
18     int         i;
19
20     memset( xout, 0, BPXLEN );
21     memset( aout, 0, BPALEN );
22
23     for ( i = 0; len; len--, data++, i++ ) {
24         if ( i == 16 ) {
25             printf( "%-48s\t%-16s\n", xout, aout );
26             memset( xout, 0, BPXLEN );
27             memset( aout, 0, BPALEN );
28             i = 0;
29         }
30
31         if (isprint( (unsigned char)*data )) {
32             aout[ i ] = *data;
33         } else {
34             aout[ i ] = '.';
35         }
36
37         xout[ (i*3) ] = hexdig[ ( *data & 0xf0 ) >> 4 ];
38         xout[ (i*3) + 1 ] = hexdig[ *data & 0x0f ];
39         xout[ (i*3) + 2 ] = ' ';
40     }
41
42     if ( i )    
43         printf( "%-48s\t%-16s\n", xout, aout );
44
45     printf("(end)\n");
46 }