]> arthur.barton.de Git - netatalk.git/blob - libatalk/atp/atp_bprint.c
Initial revision
[netatalk.git] / libatalk / atp / atp_bprint.c
1 /*
2  * Copyright (c) 1990,1991 Regents of The University of Michigan.
3  * All Rights Reserved.
4  *
5  * Permission to use, copy, modify, and distribute this software and
6  * its documentation for any purpose and without fee is hereby granted,
7  * provided that the above copyright notice appears in all copies and
8  * that both that copyright notice and this permission notice appear
9  * in supporting documentation, and that the name of The University
10  * of Michigan not be used in advertising or publicity pertaining to
11  * distribution of the software without specific, written prior
12  * permission. This software is supplied as is without expressed or
13  * implied warranties of any kind.
14  *
15  *      Research Systems Unix Group
16  *      The University of Michigan
17  *      c/o Mike Clark
18  *      535 W. William Street
19  *      Ann Arbor, Michigan
20  *      +1-313-763-0525
21  *      netatalk@itd.umich.edu
22  */
23
24 #define BPLEN   48
25 #include <stdio.h>
26 #include <ctype.h>
27 #include <string.h>
28 char    hexdig[] = "0123456789abcdef";
29
30 bprint( data, len )
31     char        *data;
32     int         len;
33 {
34     char        out[ BPLEN ];
35     int         i = 0;
36
37     memset( out, 0, BPLEN );
38     for ( ;; ) {
39         if ( len < 1 ) {
40             printf( "\t%s\n", ( i == 0 ) ? "(end)" : out );
41             break;
42         }
43
44         if ( isgraph( (unsigned char)*data )) {
45             out[ i ] = ' ';
46             out[ i+1 ] = *data;
47         } else {
48             out[ i ] = hexdig[ ( *data & 0xf0 ) >> 4 ];
49             out[ i+1 ] = hexdig[ *data & 0x0f ];
50         }
51         i += 2;
52         len--;
53         data++;
54
55         if ( i > BPLEN - 2 ) {
56             printf( "\t%s\n", out );
57             memset( out, 0, BPLEN );
58             i = 0;
59             continue;
60         }
61         out[ i++ ] = ' ';
62     }
63 }