OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [libmisc/] [dumpbuf/] [dumpbuf.c] - Blame information for rev 218

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
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: dumpbuf.c,v 1.2 2001-09-27 12:01:42 chris Exp $
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
 
21
static inline void Dump_Line(
22
  unsigned char *buffer,
23
  int            length
24
);
25
 
26
void 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
 
47
static 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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.