]> arthur.barton.de Git - netatalk.git/blob - libatalk/atp/atp_bprint.c
cafacdae095e409b08dbf8e48a19257b6830f18f
[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 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #define BPLEN   48
29 #include <stdio.h>
30 #include <ctype.h>
31 #include <string.h>
32 char    hexdig[] = "0123456789abcdef";
33
34 bprint( data, len )
35     char        *data;
36     int         len;
37 {
38     char        out[ BPLEN ];
39     int         i = 0;
40
41     memset( out, 0, BPLEN );
42     for ( ;; ) {
43         if ( len < 1 ) {
44             printf( "\t%s\n", ( i == 0 ) ? "(end)" : out );
45             break;
46         }
47
48         if ( isgraph( (unsigned char)*data )) {
49             out[ i ] = ' ';
50             out[ i+1 ] = *data;
51         } else {
52             out[ i ] = hexdig[ ( *data & 0xf0 ) >> 4 ];
53             out[ i+1 ] = hexdig[ *data & 0x0f ];
54         }
55         i += 2;
56         len--;
57         data++;
58
59         if ( i > BPLEN - 2 ) {
60             printf( "\t%s\n", out );
61             memset( out, 0, BPLEN );
62             i = 0;
63             continue;
64         }
65         out[ i++ ] = ' ';
66     }
67 }