OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [libmisc/] [dumpbuf/] [dumpbuf.c] - Rev 1026

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

/*
 *  COPYRIGHT (c) 1997.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may in
 *  the file LICENSE in this distribution or at
 *  http://www.OARcorp.com/rtems/license.html.
 *
 *  dumpbuf.c,v 1.1 1999/01/31 19:12:46 joel Exp
 */
 
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <rtems/dumpbuf.h>
 
/*
 *  Put the body below Dump_Buffer so it won't get inlined.
 */
 
static inline void Dump_Line(
  unsigned char *buffer, 
  int            length
);
 
void Dump_Buffer(
  unsigned char *buffer,
  int            length
)
{
 
  int i, mod, max;
 
  if ( !length ) return;
 
  mod = length % 16;
 
  max = length - mod;
 
  for ( i=0 ; i<max ; i+=16 )
    Dump_Line( &buffer[ i ], 16 );
 
  if ( mod )
    Dump_Line( &buffer[ max ], mod );
}
 
static inline void Dump_Line(
  unsigned char *buffer,
  int            length
)
{
 
  int  i;
  char line_buffer[120];
 
  line_buffer[0] = '\0';
 
  for( i=0 ; i<length ; i++ )
    sprintf( line_buffer, "%s%02x ", line_buffer, buffer[ i ] );
 
  for( ; i<16 ; i++ )
    strcat( line_buffer, "   " );
 
  strcat( line_buffer, "|" );
  for( i=0 ; i<length ; i++ )
    sprintf( line_buffer, "%s%c", line_buffer,
             isprint( buffer[ i ] ) ? buffer[ i ] : '.' );
 
  for( ; i<16 ; i++ )
    strcat( line_buffer, " " );
 
  strcat( line_buffer, "|\n" );
 
  printf( line_buffer );
}
 

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

powered by: WebSVN 2.1.0

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