source: rtems/c/src/libmisc/dumpbuf/dumpbuf.c @ d5b004b

4.104.114.84.95
Last change on this file since d5b004b was 379d2ed, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 31, 1999 at 7:12:46 PM

New files added to ease debugging.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/*
2 *  COPYRIGHT (c) 1997.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may in
6 *  the file LICENSE in this distribution or at
7 *  http://www.OARcorp.com/rtems/license.html.
8 *
9 *  $Id$
10 */
11
12#include <stdio.h>
13#include <string.h>
14#include <ctype.h>
15#include <rtems/dumpbuf.h>
16 
17/*
18 *  Put the body below Dump_Buffer so it won't get inlined.
19 */
20
21static inline void Dump_Line(
22  unsigned char *buffer, 
23  int            length
24);
25
26void Dump_Buffer(
27  unsigned char *buffer,
28  int            length
29)
30{
31 
32  int i, mod, max;
33 
34  if ( !length ) return;
35 
36  mod = length % 16;
37 
38  max = length - mod;
39 
40  for ( i=0 ; i<max ; i+=16 )
41    Dump_Line( &buffer[ i ], 16 );
42 
43  if ( mod )
44    Dump_Line( &buffer[ max ], mod );
45}
46
47static inline void Dump_Line(
48  unsigned char *buffer,
49  int            length
50)
51{
52 
53  int  i;
54  char line_buffer[120];
55 
56  line_buffer[0] = '\0';
57 
58  for( i=0 ; i<length ; i++ )
59    sprintf( line_buffer, "%s%02x ", line_buffer, buffer[ i ] );
60 
61  for( ; i<16 ; i++ )
62    strcat( line_buffer, "   " );
63 
64  strcat( line_buffer, "|" );
65  for( i=0 ; i<length ; i++ )
66    sprintf( line_buffer, "%s%c", line_buffer,
67             isprint( buffer[ i ] ) ? buffer[ i ] : '.' );
68 
69  for( ; i<16 ; i++ )
70    strcat( line_buffer, " " );
71 
72  strcat( line_buffer, "|\n" );
73 
74  printf( line_buffer );
75}
Note: See TracBrowser for help on using the repository browser.